We're Hiring!

How to retrieve the original file path?

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.

How to retrieve the original file path?

Postby jwarren » Thu Jul 10, 2014 2:35 pm

On the page Omero 5 page it states one of the new features of omero5 is that:
"Files are uploaded in their original format, meaning file names and any nested directory structure are preserved on the server"

How can I retrieve the original path from omero using python or java - ideally both? I would also like to be able to retrieve images based on their original path using uris and the web framework- is this possible?

(I need this because this is like the primary key of our images. Our other database is rebuilt on a weekly basis and so this is the only reliable way of linking our other data with the correct image).

I guess the other option is to add the original path as an annotation when uploading?

Thanks

Jonathan.
jwarren
 
Posts: 102
Joined: Wed Jul 09, 2014 1:35 pm

Re: How to retrieve the original file path?

Postby PaulVanSchayck » Fri Jul 11, 2014 8:52 am

Dear Jonathan,

I'm using this to retrieve the original file in Python. Unsure whether it is the best method:
Code: Select all
def getOriginalFile(imageObj):
    fileset = imageObj.getFileset()

    for origFile in fileset.listFiles():
        name = origFile.getName()
        path = origFile.getPath()
   
    return path, name

Where imageObj can be retrieved in several ways. Like this for example:
Code: Select all
imageObj = conn.getObject("Image", imageId)

The path returned will be relative to /OMERO/ManagedRepository.

Kind regards,

Paul
PaulVanSchayck
 
Posts: 41
Joined: Tue May 20, 2014 7:04 am

Re: How to retrieve the original file path?

Postby mtbc » Fri Jul 11, 2014 9:30 am

Paul indeed has the right idea. The paths returned by this method are /-separated rooted under the directory configured by omero.managed.dir, and they have enough of the original depth preserved for their structure to be understood by Bio-Formats. The names may have been altered slightly to be legal under the rules of https://www.openmicroscopy.org/site/sup ... file-names

The original paths from where on the client system the files were originally imported are also preserved, for instance,
Code: Select all
query = 'SELECT clientPath FROM FilesetEntry WHERE fileset.id = :id'
params = omero.sys.ParametersI()
params.addId(omero.rtypes.rlong(filesetId))

for path in queryService.projection(query, params):
    print path[0].val

will tell you those paths for the given fileset ID. (Paul's query is a bit like the above, but with a query of 'SELECT o.path || o.name FROM OriginalFile o, FilesetEntry e WHERE e.originalFile = o AND e.fileset.id = :id'.)

You could of course still add an annotation to images. If you have external ID numbers you could even use a LongAnnotation in a special namespace or suchlike.

I am not aware of anything in the web gateway that does anything like this for you already, the URI-based retrievals are all by image ID. We have been actively working on improving search for 5.0.3 though so if something through that API might be useful for you, do feel free to ask and I can check into how to index and retrieve the paths through Hibernate Search / Lucene.

Cheers,
Mark
User avatar
mtbc
Team Member
 
Posts: 282
Joined: Tue Oct 23, 2012 10:59 am
Location: Dundee, Scotland

Re: How to retrieve the original file path?

Postby jwarren » Fri Jul 11, 2014 11:10 am

Great - thanks Paul and Mark. By combining your answers I've got what I needed and in the worst case scenario can make a solr Index containing the omero id and the original path to join our systems :)

for anyone else who maybe intersested my python code snippet is this:

Code: Select all
print image.getId()
fileset = image.getFileset()
filesetId=fileset.getId()
query = 'SELECT clientPath FROM FilesetEntry WHERE fileset.id = :id'
params = omero.sys.ParametersI()
params.addId(omero.rtypes.rlong(filesetId))
for path in conn.getQueryService().projection(query, params):
  print path[0].val
jwarren
 
Posts: 102
Joined: Wed Jul 09, 2014 1:35 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest