Skip to content
Snippets Groups Projects
pybis_example.ipynb 10.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • {
     "cells": [
      {
       "cell_type": "code",
       "execution_count": 1,
       "metadata": {},
       "outputs": [],
       "source": [
        "from pybis import Openbis\n",
        "import getpass\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Connecting to openBIS"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 2,
       "metadata": {},
       "outputs": [],
       "source": [
        "o = Openbis('https://limb.ethz.ch/openbis:8443', verify_certificates=False)"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 5,
    
       "metadata": {},
       "outputs": [
        {
         "name": "stdin",
         "output_type": "stream",
         "text": [
          " ·····················\n"
         ]
        }
       ],
       "source": [
        "username = 'hluetcke'\n",
        "pw = getpass.getpass()"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 6,
    
       "metadata": {},
       "outputs": [],
       "source": [
        "o.login(username, pw, save_token=True)   # saves the session token in ~/.pybis/example.com.token\n",
        "del pw"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 7,
    
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
    
           "'hluetcke-181024154540290xCA25DBE8ED8C9FB138503F6C3F0C8D69'"
    
         "execution_count": 7,
    
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "o.token"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 8,
    
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/plain": [
           "True"
          ]
         },
    
         "execution_count": 8,
    
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "o.is_session_active()"
       ]
      },
      {
       "cell_type": "code",
    
       "execution_count": 9,
    
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/html": [
           "<div>\n",
           "<style scoped>\n",
           "    .dataframe tbody tr th:only-of-type {\n",
           "        vertical-align: middle;\n",
           "    }\n",
           "\n",
           "    .dataframe tbody tr th {\n",
           "        vertical-align: top;\n",
           "    }\n",
           "\n",
           "    .dataframe thead th {\n",
           "        text-align: right;\n",
           "    }\n",
           "</style>\n",
           "<table border=\"1\" class=\"dataframe\">\n",
           "  <thead>\n",
           "    <tr style=\"text-align: right;\">\n",
           "      <th></th>\n",
           "      <th>code</th>\n",
           "      <th>downloadUrl</th>\n",
           "      <th>hostUrl</th>\n",
           "    </tr>\n",
           "  </thead>\n",
           "  <tbody>\n",
           "    <tr>\n",
           "      <th>0</th>\n",
           "      <td>DSS1</td>\n",
           "      <td>https://limb.ethz.ch:443/datastore_server</td>\n",
           "      <td>https://limb.ethz.ch:443</td>\n",
           "    </tr>\n",
           "  </tbody>\n",
           "</table>\n",
           "</div>"
          ],
          "text/plain": [
           "   code                                downloadUrl                   hostUrl\n",
           "0  DSS1  https://limb.ethz.ch:443/datastore_server  https://limb.ethz.ch:443"
          ]
         },
    
         "execution_count": 9,
    
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "o.get_datastores()"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Masterdata"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 8,
       "metadata": {},
       "outputs": [
        {
         "data": {
          "text/html": [
           "<div>\n",
           "<style scoped>\n",
           "    .dataframe tbody tr th:only-of-type {\n",
           "        vertical-align: middle;\n",
           "    }\n",
           "\n",
           "    .dataframe tbody tr th {\n",
           "        vertical-align: top;\n",
           "    }\n",
           "\n",
           "    .dataframe thead th {\n",
           "        text-align: right;\n",
           "    }\n",
           "</style>\n",
           "<table border=\"1\" class=\"dataframe\">\n",
           "  <thead>\n",
           "    <tr style=\"text-align: right;\">\n",
           "      <th></th>\n",
           "      <th>code</th>\n",
           "      <th>description</th>\n",
           "      <th>modificationDate</th>\n",
           "    </tr>\n",
           "  </thead>\n",
           "  <tbody>\n",
           "    <tr>\n",
           "      <th>0</th>\n",
           "      <td>IHC</td>\n",
           "      <td>Immunohistochemistry</td>\n",
           "      <td>2010-10-01 15:27:15</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>1</th>\n",
           "      <td>LACZ</td>\n",
           "      <td>Experiments with lacZ staining.</td>\n",
           "      <td>2010-10-06 16:24:22</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>2</th>\n",
           "      <td>CULTURE</td>\n",
           "      <td>Culture</td>\n",
           "      <td>2010-08-19 08:49:11</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>3</th>\n",
           "      <td>ISH</td>\n",
           "      <td>in situ hybridization</td>\n",
           "      <td>2010-08-19 08:49:25</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>4</th>\n",
           "      <td>SKELETAL</td>\n",
           "      <td>Skeletal</td>\n",
           "      <td>2010-08-19 08:49:34</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>5</th>\n",
           "      <td>METHODS</td>\n",
           "      <td>Folder to store protocols</td>\n",
           "      <td>2016-05-24 16:36:12</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>6</th>\n",
           "      <td>PAPER</td>\n",
           "      <td>Experiments from a paper.</td>\n",
           "      <td>2010-11-12 12:08:37</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>7</th>\n",
           "      <td>LIGHTSHEET</td>\n",
           "      <td>Lightsheet imaging</td>\n",
           "      <td>2018-05-31 13:29:04</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>8</th>\n",
           "      <td>SAMPLE</td>\n",
           "      <td>For Sample registration.</td>\n",
           "      <td>2010-11-22 10:28:53</td>\n",
           "    </tr>\n",
           "    <tr>\n",
           "      <th>9</th>\n",
           "      <td>MATERIALS</td>\n",
           "      <td>Folder to store biological and chemical samples</td>\n",
           "      <td>2016-05-24 16:35:51</td>\n",
           "    </tr>\n",
           "  </tbody>\n",
           "</table>\n",
           "</div>"
          ],
          "text/plain": [
           "    code        description                                      modificationDate\n",
           "--  ----------  -----------------------------------------------  -------------------\n",
           " 0  IHC         Immunohistochemistry                             2010-10-01 15:27:15\n",
           " 1  LACZ        Experiments with lacZ staining.                  2010-10-06 16:24:22\n",
           " 2  CULTURE     Culture                                          2010-08-19 08:49:11\n",
           " 3  ISH         in situ hybridization                            2010-08-19 08:49:25\n",
           " 4  SKELETAL    Skeletal                                         2010-08-19 08:49:34\n",
           " 5  METHODS     Folder to store protocols                        2016-05-24 16:36:12\n",
           " 6  PAPER       Experiments from a paper.                        2010-11-12 12:08:37\n",
           " 7  LIGHTSHEET  Lightsheet imaging                               2018-05-31 13:29:04\n",
           " 8  SAMPLE      For Sample registration.                         2010-11-22 10:28:53\n",
           " 9  MATERIALS   Folder to store biological and chemical samples  2016-05-24 16:35:51"
          ]
         },
         "execution_count": 8,
         "metadata": {},
         "output_type": "execute_result"
        }
       ],
       "source": [
        "o.get_experiment_types()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_sample_types()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_sample_type('PLATE')"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_material_types()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_dataset_types()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_terms()"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### List and get datasets"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "datasets = o.get_datasets(type='HISTOLOGY')"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "counter = 0\n",
        "for ds in datasets:\n",
        "    print(ds)\n",
        "    counter += 1\n",
        "    if counter > 10:\n",
        "        break"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "ds = o.get_dataset('20101105142920015-6525')"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "ds.get_files(start_folder='original')"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Download and import files"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "ds.download(files='original/441_x40001.tif', destination='data', wait_until_finished=True)"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "plt.imshow(plt.imread('data/20101105142920015-6525/original/441_x40001.tif'))"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.logout()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_experiment_types()"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "metadata": {},
       "outputs": [],
       "source": [
        "o.get_dataset_types()"
       ]
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python [default]",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
       "version": "3.6.5"
    
      }
     },
     "nbformat": 4,
     "nbformat_minor": 2
    }