We're Hiring!

Unable to run the script

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Re: Unable to run the script

Postby bhcho » Tue Mar 01, 2011 5:37 pm

the message box after I ran my script is like the attached picture.

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()
Attachments
error.jpg
error.jpg (17.86 KiB) Viewed 2102 times
output.tar
(5 KiB) Downloaded 169 times
Processor.tar.gz
(23.63 KiB) Downloaded 165 times
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: Unable to run the script

Postby jburel » Tue Mar 01, 2011 8:14 pm

Hi
We had a problem with the handling of the results that now has been fixed but only in our develop branch.
http://trac.openmicroscopy.org.uk/ome/ticket/3915
Which version are you using? 4.2?
If so I will have to backport the fix to the 4.2 branch.

Thanks
Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Re: Unable to run the script

Postby bhcho » Tue Mar 01, 2011 9:15 pm

we are using 4.2.1.

BK
bhcho
 
Posts: 236
Joined: Mon Apr 05, 2010 2:15 pm

Re: Unable to run the script

Postby jburel » Wed Mar 02, 2011 12:58 pm

Hi BK

The fixed has been back ported, you should grab the latest client and let us know if you still have the problems.
Go to http://hudson.openmicroscopy.org.uk/view/Beta4.2/ and grab the latest insight build.

Jmarie
User avatar
jburel
Team Member
 
Posts: 348
Joined: Thu May 21, 2009 6:38 pm
Location: dundee

Previous

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest