{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example of using the IDR web API" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OMERO.web uses a default session backend authentication scheme for authentication.\n", "First create a HTTP session using the [`requests`](http://docs.python-requests.org/en/master/) library:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# initial data\n", "IDR_BASE_URL = \"http://idr.openmicroscopy.org\"\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import requests\n", "\n", "INDEX_PAGE = \"%s/webclient/?experimenter=-1\" % IDR_BASE_URL\n", "\n", "# create http session\n", "with requests.Session() as session:\n", " request = requests.Request('GET', INDEX_PAGE)\n", " prepped = session.prepare_request(request)\n", " response = session.send(prepped)\n", " if response.status_code != 200:\n", " response.raise_for_status()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Studies:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Study map annotation:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(u'Study Type', u'high content screen')\n", "(u'Screen Type', u'primary screen')\n", "(u'Screen Technology Type', u'RNAi screen')\n", "(u'Imaging Method', u'fluorescence microscopy')\n", "(u'Publication Title', u'Integration of biological data by kernels on graph nodes allows prediction of new genes involved in mitotic chromosome condensation.')\n", "(u'Publication Authors', u'Heriche JK, Lees JG, Morilla I, Walter T, Petrova B, Roberti MJ, Hossain MJ, Adler P, Fernandez JM, Krallinger M, Haering CH, Vilo J, Valencia A, Ranea JA, Orengo C, Ellenberg J.')\n", "(u'PubMed ID', u'24943848 http://www.ncbi.nlm.nih.gov/pubmed/24943848')\n", "(u'PMC ID', u'PMC4142622 http://europepmc.org/search?query=PMC4142622')\n", "(u'Publication DOI', u'10.1091/mbc.E13-04-0221 http://dx.doi.org/10.1091/mbc.E13-04-0221')\n", "(u'Annotation File', u'idr0002-screenA-annotation.csv https://github.com/IDR/idr-metadata/blob/master/idr0002-heriche-condensation/screenA/idr0002-screenA-annotation.csv')\n" ] } ], "source": [ "MAP_URL = \"{base}/webclient/api/annotations/?type=map&{type}={screen_id}\"\n", "\n", "SCREEN_ID = 102\n", "\n", "qs = {'base': IDR_BASE_URL, 'type': 'screen', 'screen_id': SCREEN_ID}\n", "url = MAP_URL.format(**qs)\n", "for a in session.get(url).json()['annotations']:\n", " namespace = a['ns']\n", " for v in a['values']:\n", " key = v[0]\n", " value = v[1]\n", " print (key, value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Plates in the given Screen:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Plate: 422, Name: plate1_1_013, Children: 1\n", "Plate: 492, Name: plate1_2_006, Children: 1\n", "Plate: 559, Name: plate1_3_003, Children: 1\n", "Plate: 620, Name: plate1_7_015, Children: 1\n", "Plate: 680, Name: plate2_2_007, Children: 1\n", "Plate: 728, Name: plate2_3_018, Children: 1\n", "Plate: 800, Name: plate2_5_015, Children: 1\n", "Plate: 869, Name: plate2_7_028, Children: 1\n", "Plate: 944, Name: plate3_11_007, Children: 1\n", "Plate: 1015, Name: plate3_4_034, Children: 1\n", "Plate: 1072, Name: plate3_5_002, Children: 1\n", "Plate: 4554, Name: plate3_8_010, Children: 1\n" ] } ], "source": [ "PLATES_URL = \"{base}/webclient/api/plates/?id={screen_id}\"\n", "\n", "SCREEN_ID = 102\n", "\n", "qs = {'base': IDR_BASE_URL, 'screen_id': SCREEN_ID}\n", "url = PLATES_URL.format(**qs)\n", "for p in session.get(url).json()['plates']:\n", " plate_id = p['id']\n", " print(\"Plate: {id}, Name: {name}, Children: {childCount}\".format(**p))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get PlateGrid:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Well: 1046859, Image: 1938559\n", "Well: 1046944, Image: 1938650\n", "Well: 1046877, Image: 1938583\n", "Well: 1046904, Image: 1938610\n", "Well: 1046910, Image: 1938616\n", "Well: 1046869, Image: 1938575\n", "Well: 1046864, Image: 1938570\n", "Well: 1046940, Image: 1938646\n", "Well: 1046930, Image: 1938636\n", "Well: 1046853, Image: 1938560\n", "Well: 1046920, Image: 1938626\n", "Well: 1046863, Image: 1938569\n", "Well: 1046890, Image: 1938596\n", "Well: 1046889, Image: 1938595\n", "Well: 1046942, Image: 1938648\n", "Well: 1046915, Image: 1938621\n", "Well: 1046934, Image: 1938640\n", "Well: 1046880, Image: 1938586\n", "Well: 1046881, Image: 1938587\n", "Well: 1046919, Image: 1938625\n", "Well: 1046870, Image: 1938576\n", "Well: 1046947, Image: 1938653\n", "Well: 1046892, Image: 1938598\n", "Well: 1046856, Image: 1938563\n", "Well: 1046900, Image: 1938606\n", "Well: 1046901, Image: 1938607\n", "Well: 1046945, Image: 1938651\n", "Well: 1046873, Image: 1938579\n", "Well: 1046936, Image: 1938642\n", "Well: 1046908, Image: 1938614\n", "Well: 1046897, Image: 1938603\n", "Well: 1046867, Image: 1938573\n", "Well: 1046865, Image: 1938571\n", "Well: 1046921, Image: 1938627\n", "Well: 1046922, Image: 1938628\n", "Well: 1046855, Image: 1938562\n", "Well: 1046887, Image: 1938593\n", "Well: 1046906, Image: 1938612\n", "Well: 1046931, Image: 1938637\n", "Well: 1046875, Image: 1938581\n", "Well: 1046866, Image: 1938572\n", "Well: 1046854, Image: 1938561\n", "Well: 1046860, Image: 1938566\n", "Well: 1046911, Image: 1938617\n", "Well: 1046907, Image: 1938613\n", "Well: 1046876, Image: 1938582\n", "Well: 1046857, Image: 1938564\n", "Well: 1046926, Image: 1938632\n", "Well: 1046932, Image: 1938638\n", "Well: 1046891, Image: 1938597\n", "Well: 1046874, Image: 1938580\n", "Well: 1046903, Image: 1938609\n", "Well: 1046935, Image: 1938641\n", "Well: 1046898, Image: 1938604\n", "Well: 1046899, Image: 1938605\n", "Well: 1046939, Image: 1938645\n", "Well: 1046858, Image: 1938565\n", "Well: 1046923, Image: 1938629\n", "Well: 1046896, Image: 1938602\n", "Well: 1046912, Image: 1938618\n", "Well: 1046884, Image: 1938590\n", "Well: 1046924, Image: 1938630\n", "Well: 1046937, Image: 1938643\n", "Well: 1046938, Image: 1938644\n", "Well: 1046941, Image: 1938647\n", "Well: 1046893, Image: 1938599\n", "Well: 1046861, Image: 1938567\n", "Well: 1046928, Image: 1938634\n", "Well: 1046927, Image: 1938633\n", "Well: 1046948, Image: 1938654\n", "Well: 1046933, Image: 1938639\n", "Well: 1046862, Image: 1938568\n", "Well: 1046929, Image: 1938635\n", "Well: 1046888, Image: 1938594\n", "Well: 1046917, Image: 1938623\n", "Well: 1046902, Image: 1938608\n", "Well: 1046918, Image: 1938624\n", "Well: 1046882, Image: 1938588\n", "Well: 1046943, Image: 1938649\n", "Well: 1046885, Image: 1938591\n", "Well: 1046879, Image: 1938585\n", "Well: 1046916, Image: 1938622\n", "Well: 1046871, Image: 1938577\n", "Well: 1046946, Image: 1938652\n", "Well: 1046914, Image: 1938620\n", "Well: 1046905, Image: 1938611\n", "Well: 1046886, Image: 1938592\n", "Well: 1046909, Image: 1938615\n", "Well: 1046868, Image: 1938574\n", "Well: 1046895, Image: 1938601\n", "Well: 1046925, Image: 1938631\n", "Well: 1046883, Image: 1938589\n", "Well: 1046913, Image: 1938619\n", "Well: 1046894, Image: 1938600\n", "Well: 1046878, Image: 1938584\n", "Well: 1046872, Image: 1938578\n" ] } ], "source": [ "WELLS_IMAGES_URL = \"{base}/webgateway/plate/{plate_id}/{field}/\"\n", "\n", "qs = {'base': IDR_BASE_URL, 'plate_id': plate_id, 'field': 0}\n", "url = WELLS_IMAGES_URL.format(**qs)\n", "grid = session.get(url).json()\n", "rowlabels = grid['rowlabels']\n", "collabels = grid['collabels']\n", "for row in grid['grid']:\n", " for cell in row:\n", " if cell is not None:\n", " print(\"Well: {wellId}, Image: {id}\".format(**cell))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Image Thumbnail:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "