From 747f28a7fc88e108f37cdb23b089f1167aa1c58b Mon Sep 17 00:00:00 2001 From: Swen Vermeul <swen@ethz.ch> Date: Fri, 8 Jul 2016 11:26:27 +0200 Subject: [PATCH] jupyter notebook added --- .../pybis/pybis playground localhost.ipynb | 434 ++++++++++++++++++ 1 file changed, 434 insertions(+) create mode 100644 src/python/pybis/pybis playground localhost.ipynb diff --git a/src/python/pybis/pybis playground localhost.ipynb b/src/python/pybis/pybis playground localhost.ipynb new file mode 100644 index 00000000000..d2cf51a4176 --- /dev/null +++ b/src/python/pybis/pybis playground localhost.ipynb @@ -0,0 +1,434 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Using pybis" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Log into openBIS" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "路路路路路路路路\n" + ] + }, + { + "data": { + "text/plain": [ + "'vermeul-160707110248298xF6BBB7B360CEB4604AAC9914FFC064A5'" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from pybis import Openbis\n", + "import getpass\n", + "o = Openbis('https://localhost:8443', verify_certificates=False)\n", + "\n", + "password = getpass.getpass()\n", + "o.login('vermeul',password)\n", + "o.token" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## create a sample" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "new_sample = o.new_sample(sample_name='oh_wie_schoen_ist_panama5', space_name='VERMEUL', tags=['uno','due','tre'])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'/VERMEUL/OH_WIE_SCHOEN_IST_PANAMA5'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_sample.ident" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## get a sample" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'20160630112919449-91'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s = o.get_sample(\"/VERMEUL/OH_WIE_SCHOEN_IST_PANAMA4\")\n", + "s.permid" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'/VERMEUL/OH_WIE_SCHOEN_IST_PANAMA4'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s.ident" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "datasets = s.get_datasets()\n", + "ds1 = datasets[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'@id': 1,\n", + " '@type': 'FileInfoDssDTO',\n", + " 'crc32Checksum': None,\n", + " 'fileSize': '-1',\n", + " 'isDirectory': True,\n", + " 'pathInDataSet': 'original',\n", + " 'pathInListing': 'original'},\n", + " {'@id': 2,\n", + " '@type': 'FileInfoDssDTO',\n", + " 'crc32Checksum': None,\n", + " 'fileSize': '-1',\n", + " 'isDirectory': True,\n", + " 'pathInDataSet': 'original/results',\n", + " 'pathInListing': 'original/results'},\n", + " {'@id': 3,\n", + " '@type': 'FileInfoDssDTO',\n", + " 'crc32Checksum': -895786725,\n", + " 'fileSize': '16',\n", + " 'isDirectory': False,\n", + " 'pathInDataSet': 'original/results/blublu',\n", + " 'pathInListing': 'original/results/blublu'}]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ds1.get_file_list()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "ds1.download('original/results/blublu')" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "this is my data." + ] + } + ], + "source": [ + "cat localhost/20160705171928021-202/original/results/blublu" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## create a dataset and upload data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "dataset = o.new_dataset(\n", + " sample=s, type='JUPYTER_NOTEBOOK', \n", + " datastore='DSS1', \n", + " files=['pybis_playground_localhost.ipynb']\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "dataset.register()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Analysis ##\n", + "An analysis has a name, description and parent dataset. Anytime it is saved, a new version of it is saved. On openBIS, an analysis is a container object which contains the result datafiles and the jupyter notebook. If an analysis is saved a second time, two new datasets are generated, both having parents of their previous datasets set." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "analysis = o.new_analysis(\n", + " parent=dataset,\n", + " name=\"my analysis\",\n", + " description= \"this time, there should be a meaningful explanation\",\n", + " results=[\"results/blublu_processed\"]\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "analysis.save()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## get available dataset types" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\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>kind</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>ELN_PREVIEW</td>\n", + " <td>ELN Preview image</td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>SEQ_FILE</td>\n", + " <td></td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>RAW_DATA</td>\n", + " <td></td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>ANALYZED_DATA</td>\n", + " <td></td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>ATTACHMENT</td>\n", + " <td></td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>5</th>\n", + " <td>DRAWING_BOARD</td>\n", + " <td></td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>6</th>\n", + " <td>JUPYTER_CONTAINER</td>\n", + " <td>Jupyter Analysis Results</td>\n", + " <td>CONTAINER</td>\n", + " </tr>\n", + " <tr>\n", + " <th>7</th>\n", + " <td>JUPYTER_NOTEBOOK</td>\n", + " <td>Analysis Notebook Files</td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>8</th>\n", + " <td>UNKNOWN</td>\n", + " <td>Unknown</td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " <tr>\n", + " <th>9</th>\n", + " <td>JUPYTER_RESULT</td>\n", + " <td>Analysis Results Files</td>\n", + " <td>PHYSICAL</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "</div>" + ], + "text/plain": [ + " code description kind\n", + "0 ELN_PREVIEW ELN Preview image PHYSICAL\n", + "1 SEQ_FILE PHYSICAL\n", + "2 RAW_DATA PHYSICAL\n", + "3 ANALYZED_DATA PHYSICAL\n", + "4 ATTACHMENT PHYSICAL\n", + "5 DRAWING_BOARD PHYSICAL\n", + "6 JUPYTER_CONTAINER Jupyter Analysis Results CONTAINER\n", + "7 JUPYTER_NOTEBOOK Analysis Notebook Files PHYSICAL\n", + "8 UNKNOWN Unknown PHYSICAL\n", + "9 JUPYTER_RESULT Analysis Results Files PHYSICAL" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.get_dataset_types()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} -- GitLab