We're Hiring!

Generating OMERO.Figures in Python using json templates

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.

Generating OMERO.Figures in Python using json templates

Postby jstitlow » Wed Sep 12, 2018 12:33 pm

Sharing a Python function (modified from code written by wmoore and carandraug) to generate OMERO.Figures in Python using json text files as a template. It's useful for iterating Figure generation over a whole dataset.

Also posting to ask if it is possible to delete OMERO.Figures in CLI using the Figure ID. While testing the code below I accidentally generated several blank Figures, which for some reason can't be deleted from the Figure GUI.

Thanks!
j

Code: Select all
def make_figure(data):   # where data is a json.txt file

    # convert json.txt to a json dict
    figure_json = json.load(data)

    # generate OMERO figure and save with new ID
    name = figure_json['figureName']
    description = {'name': name}
    file_ann = conn.createFileAnnfromLocalFile(figure_fpath,
        origFilePathAndName=name, mimetype='application/json',
        ns='omero.web.figure.json', desc=description)
jstitlow
 
Posts: 18
Joined: Sat Feb 03, 2018 9:07 pm

Re: Generating OMERO.Figures in Python using json templates

Postby jstitlow » Wed Sep 12, 2018 1:44 pm

Presumably the Figures live in OMERO as FileAnnotations..?

They appear to be deleted when I ran this:

Code: Select all
FigureIDs = [2115475, 2115470]
conn.deleteObjects("FileAnnotation", FigureIDs)
jstitlow
 
Posts: 18
Joined: Sat Feb 03, 2018 9:07 pm

Re: Generating OMERO.Figures in Python using json templates

Postby jmoore » Thu Sep 13, 2018 11:50 am

Josh,

Indeed:

Code: Select all
[jamoore@ome-demoserver ~]$ omero hql -q "select fa from FileAnnotation fa where fa.id = 3062"
# | Class           | Id   | ns                    | description                                             | file                | details
---+-----------------+------+-----------------------+---------------------------------------------------------+---------------------+-----------------
0 | FileAnnotationI | 3062 | omero.web.figure.json | {"name": "Figure_2018-9-13_13:46:29", "imageId": 24256} | OriginalFileI:68299 | owner=0;group=0
(1 row)


[jamoore@ome-demoserver ~]$ omero -q delete --report FileAnnotation:3062
omero.cmd.Delete2 FileAnnotation:3062 ok
Steps: 6
Elapsed time: 0.118 secs.
Flags: []
Deleted objects
  FileAnnotation:3062
  OriginalFile:68299


All the best,
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests