diff --git a/MatlabOpenbis_wrapper.m b/MatlabOpenbis_wrapper.m new file mode 100644 index 0000000000000000000000000000000000000000..143d63130d1aca90663cda6824bfc9d307929794 --- /dev/null +++ b/MatlabOpenbis_wrapper.m @@ -0,0 +1,33 @@ +% wrapper / demo script for Matlab openBIS toolbox +% Todo: convert to ML live script + +%% Enter connection info for openBIS +% connection details can be stored in the file user_data.json or entered manually +try + user_data = jsondecode(fileread('user_data.json')); + username = user_data.User; + url = user_data.URL; +catch + username = ''; % enter valid user name + url = 'https://XYZ.ethz.ch/openbis:8443'; % replace with correct URL +end +% specify openBIS password +pw = passwordEntryDialog('CheckPasswordLength',0); + +%% Connect to openBIS +login(url, username, pw) +clear pw % remove password from workspace + +% login will create a global variable called obi +global obi + +%% Check if connection is still active +% we can check if the connection has timed-out or is still valid +if obi.is_session_active + fprintf('\nConnection to host %s is still valid.\n', char(obi.url)) +else + disp('Connection is not active. Please re-connect.') +end + +%% Logout +obi.logout() \ No newline at end of file diff --git a/MatlabPybis_example.m b/MatlabPybis_example.m index 7059eda238d9def21b644defd9a2e3912eae0e3b..22a3ec175213aea3a63a8076114416ff127108ed 100644 --- a/MatlabPybis_example.m +++ b/MatlabPybis_example.m @@ -7,16 +7,25 @@ %% first check the Python version pyversion % a different Python version can be selected by specifying the Python -% executable +% executable % on OS X: pyversion /Users/Henry/miniconda3/bin/python % on Windows: pyversion 3.6 -%% enter username and password for openBIS -username = 'XYZ'; % enter user name +%% connection details for openBIS +% connection details can be stored in the file user_data.json or entered manually +try + user_data = jsondecode(fileread('user_data.json')); + username = user_data.User; + url = user_data.URL; +catch + username = ''; % enter valid user name + url = 'https://XYZ.ethz.ch/openbis:8443'; % replace with correct URL +end +% specify openBIS password pw = passwordEntryDialog('CheckPasswordLength',0); + %% connect to openBIS -url = 'https://XYZ.ethz.ch/openbis:8443'; % replace with correct URL obi = py.pybis.Openbis(url, pyargs('verify_certificates', 0)); obi.login(username, pw, pyargs('save_token', 1)); clear pw diff --git a/download_ds_files.m b/download_ds_files.m index 9a8497a35a27017f2d7b9c2ae7ba56b6ae19de8f..d4fc355ca0c6db5a369c465c2aa9c06ce12b3a32 100644 --- a/download_ds_files.m +++ b/download_ds_files.m @@ -10,4 +10,3 @@ ds.download(pyargs('destination', data_dir, 'wait_until_finished', false)); file_list = cell(ds.get_file_list); end - diff --git a/get_experiment_types.m b/get_experiment_types.m new file mode 100644 index 0000000000000000000000000000000000000000..befeaeccbe9a8f7bf106016f5e918052106ab62d --- /dev/null +++ b/get_experiment_types.m @@ -0,0 +1,15 @@ +function experiment_types = get_experiment_types +%UNTITLED2 Summary of this function goes here +% Detailed explanation goes here + +global obi + +% test connection +test_connection(obi) + +experiment_types = obi.get_experiment_types(); +experiment_types = df_to_cell(experiment_types.df); + + +end + diff --git a/pybis_example.ipynb b/pybis_example.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..4008e1d7517dc8108a1930f7aa4e1336c133cbda --- /dev/null +++ b/pybis_example.ipynb @@ -0,0 +1,449 @@ +{ + "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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + " 路路路路路路路路路路路路路路路路路路路路路\n" + ] + } + ], + "source": [ + "username = 'hluetcke'\n", + "pw = getpass.getpass()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hluetcke-181024130359554x90E8C39FF84921ECC3D5436AE2ECFD05'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.token" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.is_session_active()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "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": 7, + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/pybis_test.ipynb b/pybis_test.ipynb deleted file mode 100644 index d4442417ae3fc12e6d22a254aae7dcc482a12e81..0000000000000000000000000000000000000000 --- a/pybis_test.ipynb +++ /dev/null @@ -1,172 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from pybis import Openbis\n", - "import getpass\n", - "import matplotlib.pyplot as plt\n", - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Login to openBIS" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "o = Openbis('https://XYZ.ethz.ch/openbis:8443', verify_certificates=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "username = ''\n", - "pw = getpass.getpass()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "o.login(username, pw, save_token=True) # saves the session token in ~/.pybis/example.com.token" - ] - }, - { - "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 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.6.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/test_connection.m b/test_connection.m new file mode 100644 index 0000000000000000000000000000000000000000..a550daf5330b082aa9020f106dcdaafb568fb572 --- /dev/null +++ b/test_connection.m @@ -0,0 +1,11 @@ +function test_connection(obi) + +if ~ismethod(obi, 'is_session_active') + error('No connection to openBIS. Did you log in?') +end +if ~obi.is_session_active + error('No active connection found. Try to re-connect.') +end + +end +