and the script is
- Code: Select all
import sys
import omero
import omero.clients
from omero.rtypes import *
from omero.rtypes import wrap, rstring, rlong, rint, robject
import omero.scripts as scripts
import omero.constants
from omero.rtypes import *
import omero_api_Gateway_ice # see http://tinyurl.com/icebuserror
import omero.util.script_utils as scriptUtil
import os
from collections import defaultdict
def SearchImgsbyFullText(client, value):
"""
Search images within the client account by the "value" of the attached text (xml) file
@param client The OMERO client
@param value query value
"""
search = client.sf.createSearchService()
search.onlyType("Image")
search.byFullText(value)
ids = [x.id.val for x in search.results()]
return ids
def list_intersection(list1, list2):
bag = defaultdict(int)
for elt in list1:
bag[elt] += 1
result = []
for elt in list2:
if elt in bag:
# remove elt from bag, making sure
# that bag counts are kept positive
if bag[elt] == 1:
del bag[elt]
else:
bag[elt] -= 1
result.append(elt)
return result
def runAsScript():
"""
The main entry point of the script, as called by the client via the scripting service, passing the required parameters.
"""
methods = [rstring('AND'), rstring('OR')]
## path = create_path("omero",".tmp")
client = scripts.client('Search_by_Context.py', """Search Images by Context Meta Data""",
# 1. Protocol
scripts.String("Reference", optional=True, grouping="1.1",
description="Reference"),
scripts.String("Fixation", optional=True, grouping="1.2",
description="Fixation"),
scripts.String("Permeabilization", optional=True, grouping="1.3",
description="Permeabilization"),
scripts.String("Substrate", optional=True, grouping="1.4",
description="Substrate"),
scripts.String("Temperature", optional=True, grouping="1.5",
description="Temperature"),
scripts.String("Author", optional=True, grouping="1.6",
description="Author"),
scripts.String("Title", optional=True, grouping="1.7",
description="Title"),
# 2. Cell Type
scripts.String("Cell_Type_Name", optional=True, grouping="2.1",
description="Cell Type Name"),
scripts.String("Organism", optional=True, grouping="2.2",
description="Organism"),
scripts.String("atcc_number", optional=True, grouping="2.3",
description="atcc number"),
scripts.String("cell_mesh_heading", optional=True, grouping="2.4",
description="cell_mesh_heading"),
scripts.String("cell_mesh_tree_number", optional=True, grouping="2.5",
description="cell_mesh_tree_number"),
version = "4.2.1",
authors = ["Baek Hwan Cho", "Murphy Lab"],
institutions = ["Carnegie Mellon University"],
contact = "bhcho@cmu.edu",
)
try:
session = client.getSession()
## # create the services we're going to need
## metadataService = session.getMetadataService()
## queryService = session.getQueryService()
## updateService = session.getUpdateService()
## rawFileStore = session.createRawFileStore()
# process the list of args above.
parameterMap = {}
for key in client.getInputKeys():
if client.getInput(key):
parameterMap[key] = client.getInput(key).getValue()
query_queue = []
try:
Reference = parameterMap["Reference"]
query_string = "Slide.Protocol.Reference:" + str(Reference)
query_queue.append(query_string)
except:
Reference = None
try:
Fixation = parameterMap["Fixation"]
query_string = "Slide.Protocol.Fixation:" + str(Fixation)
query_queue.append(query_string)
except:
Fixation = None
try:
Permeabilization = parameterMap["Permeabilization"]
query_string = "Slide.Protocol.Permeabilization:" + str(Permeabilization)
query_queue.append(query_string)
except:
Permeabilization = None
try:
Substrate = parameterMap["Substrate"]
query_string = "Slide.Protocol.Substrate:" + str(Substrate)
query_queue.append(query_string)
except:
Substrate = None
try:
Temperature = parameterMap["Temperature"]
query_string = "Slide.Protocol.Temperature:" + str(Temperature)
query_queue.append(query_string)
except:
Temperature = None
try:
Author = parameterMap["Author"]
query_string = "Slide.Protocol.Author:" + str(Author)
query_queue.append(query_string)
except:
Author = None
try:
Title = parameterMap["Title"]
query_string = "Slide.Protocol.Title:" + str(Title)
query_queue.append(query_string)
except:
Title = None
try:
Cell_Type_Name = parameterMap["Cell_Type_Name"]
query_string = "Slide.Cell_Type.Name:" + str(Cell_Type_Name)
query_queue.append(query_string)
except:
Cell_Type_Name = None
try:
Organism = parameterMap["Organism"]
query_string = "Slide.Cell_Type.Organism:" + str(Organism)
query_queue.append(query_string)
except:
Organism = None
try:
atcc_number = parameterMap["atcc_number"]
query_string = "Slide.Cell_Type.atcc_number:" + str(atcc_number)
query_queue.append(query_string)
except:
atcc_number = None
try:
cell_mesh_heading = parameterMap["cell_mesh_heading"]
query_string = "Slide.Cell_Type.cell_mesh_heading:" + str(cell_mesh_heading)
query_queue.append(query_string)
except:
cell_mesh_heading = None
try:
cell_mesh_tree_number = parameterMap["cell_mesh_tree_number"]
query_string = "Slide.Cell_Type.cell_mesh_tree_number:" + str(cell_mesh_tree_number)
query_queue.append(query_string)
except:
cell_mesh_tree_number = None
searched_img_IDs = []
search = client.sf.createSearchService()
search.onlyType("Image")
for q in query_queue:
search.byFullText(q)
try:
ids = [x.id.val for x in search.results()]
searched_img_IDs.append(ids)
except:
tmp=[]
# search the common IDs
final_searched_img_IDs = []
if searched_img_IDs != []:
id_list1 = searched_img_IDs[0]
for id_list2 in searched_img_IDs:
result = list_intersection(id_list1, id_list2)
id_list1 = result
final_searched_img_IDs = id_list1
txt = " ".join(map(str,final_searched_img_IDs))
print "List = %s" % txt
client.setOutput("Message", rstring("Script Ran OK. list = %s" % txt))
finally:
client.closeSession()
if __name__ == "__main__":
runAsScript()