Skip to content

Instantly share code, notes, and snippets.

@atarkowska
Last active September 15, 2016 14:09
Show Gist options
  • Save atarkowska/980caed8c1c26d09672e1f9d79277b4e to your computer and use it in GitHub Desktop.
Save atarkowska/980caed8c1c26d09672e1f9d79277b4e to your computer and use it in GitHub Desktop.
Example of REST API usage. Load data from IDR
import requests
# put here project/screen ids
containers = (101,)
list_datasets_url = "http://idr-demo.openmicroscopy.org/webclient/api/datasets/?id={container_id}&page=0"
list_images_url = "http://idr-demo.openmicroscopy.org/webclient/api/images/?id={id}&page=1"
image_link = "http://idr-demo.openmicroscopy.org/webclient/?show=image-{id}"
image_viewer_link = "http://idr-demo.openmicroscopy.org/webclient/img_detail/{id}/"
thumbnail_url = "http://idr-demo.openmicroscopy.org/webclient/render_thumbnail/size/96/{id}/"
map_url = "http://idr-demo.openmicroscopy.org/webclient/api/annotations/?type=map&image={id}"
for c in containers:
print 'Container:', c
for d in requests.get(list_datasets_url.format(**{'container_id': c })).json()['datasets']:
_url = list_images_url.format(**d)
for i in requests.get(_url).json()['images']:
print 'image iD:', i['id']
print "image link:", image_link.format(**i)
print "image viewer link:", image_viewer_link.format(**i)
print 'thumbnail URL:', thumbnail_url.format(**i)
for a in requests.get(map_url.format(**i)).json()['annotations']:
print 'Annotaitons:'
print a['values']
@atarkowska
Copy link
Author

atarkowska commented Aug 24, 2016

The output looks like:

$ python rest_api.py
Container: 101
image iD: 1920093
image link: http://idr-demo.openmicroscopy.org/webclient/?show=image-1920093
image viewer link: http://idr-demo.openmicroscopy.org/webclient/img_detail/1920093/
thumbnail URL: http://idr-demo.openmicroscopy.org/webclient/render_thumbnail/size/96/1920093/
Annotaitons:
[[u'Organism Part', u'brain'], [u'Sex', u'female'], [u'Individual', u'Bazla-14-100'], [u'Genotype', u'Baz1a knockout'], [u'Gene Identifier', u'ENSMUSG00000035021'], [u'Gene Identifier URL', u'http://www.ensembl.org/id/ENSMUSG00000035021'], [u'Gene Symbol', u'Baz1a'], [u'Human Ortholog', u'ENSG00000198604'], [u'Human Ortholog URL', u'http://www.ensembl.org/id/ENSG00000198604'], [u'Human Ortholog Gene Symbol', u'BAZ1A']]
...

@IlincaTudose
Copy link

Thanks, Ola! This looks great, exactly what I need in the first place.

@IlincaTudose
Copy link

Do the project ids (i.e. 101) stay the same over data releases? I imagine that if you need to re-import all data these ids will change as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment