We're Hiring!

Dataset image

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.

Dataset image

Postby johnjhufnagle » Thu Aug 12, 2010 7:47 pm

If I have a Java client and have an image id. What would be the hql and then the api to iterate (ImageI.iterateDatasetLinks() ??) over the containing dataset object...or is that plural? Can an image be associated with more than 1 dataset?

Thank you
John
johnjhufnagle
 
Posts: 34
Joined: Tue Dec 15, 2009 8:50 pm

Re: Dataset image

Postby cxallan » Fri Aug 13, 2010 9:51 am

An image can be associated with more than one dataset. Some example Java code follows:

Code: Select all
import omero.client;
import omero.api.IQueryPrx;
import omero.api.ServiceFactoryPrx;
import omero.model.Dataset;
import omero.model.Image;
import omero.sys.ParametersI;


public class Example
{
    private client client;
    private IQueryPrx iq;
   
    public static final long IMAGE_ID = 1L;
    public static final String HOST = "localhost";
    public static final String USERNAME = "example";
    public static final String PASSWORD = "example";

    Example() throws Exception
    {
        client = new client(HOST);
    }

    public void init() throws Exception
    {
        ServiceFactoryPrx sf = client.createSession(USERNAME, PASSWORD);
        iq = sf.getQueryService();
    }

    public void run() throws Exception
    {
        ParametersI params = new ParametersI();
        params.addId(IMAGE_ID);
        Image i = (Image) iq.findByQuery(
                "select i from Image as i " +
                "left outer join fetch i.datasetLinks link " +
                "join fetch link.parent " +
                "where i.id = :id", params);
        if (i == null)
        {
            System.err.println("Unable to find Image id:" + IMAGE_ID);
            return;
        }
        System.out.println("Image: " + i.getName().getValue());
        System.out.println("Dataset count: " + i.sizeOfDatasetLinks());
        for (Dataset d : i.linkedDatasetList())
        {
            System.out.println("Dataset name: " + d.getName().getValue());
        }
    }

    public void cleanup() throws Exception
    {
        client.closeSession();
    }

    public static void main(String[] args) throws Exception
    {
        Example e = new Example();
        try
        {
            e.init();
            e.run();
        }
        finally
        {
            e.cleanup();
        }
    }
}
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am

Re: Dataset image

Postby johnjhufnagle » Fri Aug 13, 2010 10:44 am

Thank you Chris.
John
johnjhufnagle
 
Posts: 34
Joined: Tue Dec 15, 2009 8:50 pm

Re: Dataset image

Postby cxallan » Fri Aug 13, 2010 11:03 am

No problem.
cxallan
Site Admin
 
Posts: 509
Joined: Fri May 01, 2009 8:07 am


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest