Page 1 of 1

How to retrieve the original file path?

PostPosted: Thu Jul 10, 2014 2:35 pm
by jwarren
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.

Re: How to retrieve the original file path?

PostPosted: Fri Jul 11, 2014 8:52 am
by PaulVanSchayck
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

Re: How to retrieve the original file path?

PostPosted: Fri Jul 11, 2014 9:30 am
by mtbc
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

Re: How to retrieve the original file path?

PostPosted: Fri Jul 11, 2014 11:10 am
by jwarren
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