├── .gitignore ├── Recipes ├── CGC │ ├── Setup_API_environment.ipynb │ ├── access_CCLE_via_DatasetsAPI.ipynb │ ├── apps_copyFromMyProject.ipynb │ ├── apps_copyFromPublicApps.ipynb │ ├── apps_detailOne.ipynb │ ├── apps_listAll.ipynb │ ├── files_copyFromMyProject.ipynb │ ├── files_copyFromPublicReference.ipynb │ ├── files_detailOne.ipynb │ ├── files_listAll.ipynb │ ├── files_moveToFolder.ipynb │ ├── files_upload_and_setMetadata.ipynb │ ├── images │ │ ├── CGC_overview-02.png │ │ ├── example_sbgrc_file.png │ │ ├── projects_addNew-01.png │ │ ├── projects_getDetails-01.png │ │ ├── projects_getMembers-01.png │ │ └── projects_listAll-01.png │ ├── projects_addMembers.ipynb │ ├── projects_detailOne.ipynb │ ├── projects_listAll.ipynb │ ├── projects_makeNew.ipynb │ ├── projects_membersOne.ipynb │ ├── readme.md │ ├── tasks_create.ipynb │ └── tasks_monitorAndGetResults.ipynb └── SBPLAT │ ├── Setup_API_environment.ipynb │ ├── app_jsons │ └── samtools-view.json │ ├── apps_copyFromMyProject.ipynb │ ├── apps_copyFromPublicApps.ipynb │ ├── apps_detailOne.ipynb │ ├── apps_installFromJSON.ipynb │ ├── apps_listAll.ipynb │ ├── billing_getTotalForPeriod.ipynb │ ├── files_copyFromMyProject.ipynb │ ├── files_copyFromPublicReference.ipynb │ ├── files_detailOne.ipynb │ ├── files_listAll.ipynb │ ├── files_listByMetadata.ipynb │ ├── files_listByMetadataRecursive.ipynb │ ├── files_upload_and_setMetadata.ipynb │ ├── images │ ├── CGC_overview-02.png │ ├── example_sbgrc_file.png │ ├── projects_addNew-01.png │ ├── projects_getDetails-01.png │ ├── projects_getMembers-01.png │ └── projects_listAll-01.png │ ├── projects_addMembers.ipynb │ ├── projects_detailOne.ipynb │ ├── projects_listAll.ipynb │ ├── projects_makeNew.ipynb │ ├── projects_membersOne.ipynb │ ├── readme.md │ ├── tasks_create.ipynb │ ├── tasks_monitorAndGetResults.ipynb │ ├── volumes_readFromCloudStorage.ipynb │ └── volumes_writeToCloudStorage.ipynb ├── Tutorials ├── CGC │ ├── Get_my_VCFs.ipynb │ ├── Setup_API_environment.ipynb │ ├── Task automation with tumor-normal matched samples.ipynb │ ├── Tumor Tissue Normal Matched TCGA.ipynb │ ├── access_TCGA_on_AWS.ipynb │ ├── access_TCGA_on_AWS_via_DatasetsAPI.ipynb │ ├── images │ │ ├── TCGA_AWS_0.png │ │ ├── TCGA_AWS_1.png │ │ ├── TCGA_AWS_2.png │ │ ├── TCGA_AWS_3.png │ │ └── example_sbgrc_file.png │ └── readme.md └── SBPLAT │ ├── Get_my_VCFs.ipynb │ ├── Setup_API_environment.ipynb │ ├── Task automation with tumor-normal matched samples.ipynb │ ├── Tumor Tissue Normal Matched TCGA.ipynb │ ├── batch_o_tasks_custom.ipynb │ ├── batch_o_tasks_standard.ipynb │ ├── files │ ├── CNVnator_WF.json │ ├── rna-seq-diff-expression-first.json │ └── rna-seq-diff-expression-second.json │ ├── images │ ├── CCLE_0.png │ ├── CCLE_1.png │ ├── CCLE_2.png │ └── example_sbgrc_file.png │ ├── quickstart.ipynb │ └── readme.md ├── _images ├── SB_logo.jpg └── SB_logo_navy.jpg ├── license.txt ├── readme.md └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *~ 3 | .ipynb_checkpoints/ 4 | .project 5 | .pydevproject 6 | .python-version 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /Recipes/CGC/Setup_API_environment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How to setup Seven Bridges Public API python library\n", 11 | "## Overview\n", 12 | "Here you will learn the three possible ways to setup Seven Bridges Public API Python library.\n", 13 | "\n", 14 | "## Prerequisites\n", 15 | "\n", 16 | "1. You need to install _sevenbridges-python_ library. Library details are available [here](http://sevenbridges-python.readthedocs.io/en/latest/sevenbridges/)\n", 17 | "\n", 18 | " The easiest way to install sevenbridges-python is using pip:\n", 19 | "\n", 20 | " $ pip install sevenbridges-python\n", 21 | "\n", 22 | " Alternatively, you can get the code. sevenbridges-python is actively developed on GitHub, where the [code](https://github.com/sbg/sevenbridges-python) is always available. To clone the public repository :\n", 23 | "\n", 24 | " $ git clone git://github.com/sbg/sevenbridges-python.git\n", 25 | "\n", 26 | " Once you have a copy of the source, you can embed it in your Python\n", 27 | " package, or install it into your site-packages by invoking:\n", 28 | "\n", 29 | " $ python setup.py install\n", 30 | "\n", 31 | "2. You need your _authentication token_ which you can get [here](https://cgc.sbgenomics.com/account#developer)\n", 32 | "\n", 33 | " \n", 34 | "### Notes and Compatibility\n", 35 | "\n", 36 | "Python package is intended to be used with both Python 2.7+ and Python 3.x versions. \n", 37 | "Following packages are necessary requirements:\n", 38 | "\n", 39 | "1. Requests package, used to make HTTP requests easily\n", 40 | "2. Six package, providing compatibility for Python versions 2.x and 3.x\n", 41 | "3. Enum34 backport package for providing enum on Python versions < 3.4" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "collapsed": false, 49 | "deletable": true, 50 | "editable": true 51 | }, 52 | "outputs": [], 53 | "source": [ 54 | "# Import the library\n", 55 | "import sevenbridges as sbg" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": { 61 | "deletable": true, 62 | "editable": true 63 | }, 64 | "source": [ 65 | "### Initialize the library\n", 66 | "\n", 67 | "You can initialize the library explicitly or by supplying the necessary information in the .sbgrc file\n", 68 | "\n", 69 | "There are generally three ways to initialize the library:\n", 70 | " 1. Explicitly, when calling api constructor, like:\n", 71 | " ``` python\n", 72 | " api = sbg.Api(url='https://cgc-api.sbgenomics.com/v2', token='MY AUTH TOKEN')\n", 73 | " ```\n", 74 | " \n", 75 | " 2. By using OS environment to store the url and authentication token\n", 76 | " ```\n", 77 | " export AUTH_TOKEN=\n", 78 | " export API_ENDPOINT='https://cgc-api.sbgenomics.com/v2'\n", 79 | " ```\n", 80 | " 3. By using ini file `$HOME/.sevenbridges/credentials` (for MS Windows, the file should be located in \\%UserProfile\\%\\.sevenbridges\\credentials) and specifying a profile to use. The format of the credentials file is standard ini file format, as shown below:\n", 81 | "\n", 82 | " ```bash\n", 83 | " [sbpla]\n", 84 | " api_endpoint = https://api.sbgenomics.com/v2\n", 85 | " auth_token = 700992f7b24a470bb0b028fe813b8100\n", 86 | "\n", 87 | " [cgc]\n", 88 | " api_endpoint = https://cgc-api.sbgenomics.com/v2\n", 89 | " auth_token = 910975f5b24a470bb0b028fe813b8100\n", 90 | " ```\n", 91 | " \n", 92 | " 0. to **create** this file1, use the following steps in your _Terminal_:\n", 93 | " 1.\n", 94 | " ```bash\n", 95 | " cd ~\n", 96 | " mkdir .sevenbridges\n", 97 | " touch .sevenbridges/credentials\n", 98 | " vi .sevenbridges/credentials\n", 99 | " ```\n", 100 | " 2. Press \"i\" then enter to go into **insert mode**\n", 101 | " 3. write the text above for each environment.\n", 102 | " 4. Press \"ESC\" then type \":wq\" to save the file and exit vi\n", 103 | " \n", 104 | "1 If the file already exists, omit the _touch_ command" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": { 110 | "deletable": true, 111 | "editable": true 112 | }, 113 | "source": [ 114 | "### Test if you have stored the token correctly\n", 115 | "Below are the three options presented above, test **one** of them. Logically, if you have only done **Step 3**, then testing **Step 2** will return an error." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": { 122 | "collapsed": false, 123 | "deletable": true, 124 | "editable": true 125 | }, 126 | "outputs": [], 127 | "source": [ 128 | "# (1.) You can also instantiate library by explicitly \n", 129 | "# specifying API url and authentication token\n", 130 | "api_explicitly = sbg.Api(url='https://cgc-api.sbgenomics.com/v2',\n", 131 | " token='')" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": { 138 | "collapsed": false, 139 | "deletable": true, 140 | "editable": true 141 | }, 142 | "outputs": [], 143 | "source": [ 144 | "# (2.) If you have not specified profile, the python-sbg library \n", 145 | "# will search for configuration in the environment\n", 146 | "c = sbg.Config()\n", 147 | "api_via_environment = sbg.Api(config=c)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": { 154 | "collapsed": false, 155 | "deletable": true, 156 | "editable": true 157 | }, 158 | "outputs": [], 159 | "source": [ 160 | "# (3.) If you have .sbgrc setup correctly, you only need to specify the profile\n", 161 | "config_file = sbg.Config(profile='cgc')\n", 162 | "api_via_ini_file = sbg.Api(config=config_file)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": { 168 | "collapsed": false, 169 | "deletable": true, 170 | "editable": true 171 | }, 172 | "source": [ 173 | "#### PROTIP\n", 174 | "* We _recommend_ the approach with configuration file (the **.sevenbridges/credentials** file in option #3), especially if you are using multiple environments (like SBPLA and CGC)." 175 | ] 176 | } 177 | ], 178 | "metadata": { 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.5.2" 195 | } 196 | }, 197 | "nbformat": 4, 198 | "nbformat_minor": 0 199 | } 200 | -------------------------------------------------------------------------------- /Recipes/CGC/apps_copyFromMyProject.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I _copy_ an app from one of my other _projects_?\n", 8 | "### Overview\n", 9 | "Apps can be copied from one of two sources:\n", 10 | "1. other projects you are a member of\n", 11 | "2. public reference. \n", 12 | "\n", 13 | "Here we focus on copying an app from _another project_. \n", 14 | "\n", 15 | "### Prerequisites\n", 16 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 17 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 18 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 19 | " 4. You understand how to list apps within your project (we will just use that call directly and pick one here).\n", 20 | " \n", 21 | "## Imports\n", 22 | "We import the _Api_ class from the official sevenbridges-python bindings below." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": { 29 | "collapsed": false 30 | }, 31 | "outputs": [], 32 | "source": [ 33 | "import sevenbridges as sbg" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Initialize the object\n", 41 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "collapsed": true 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "# [USER INPUT] specify platform {cgc, sbg}\n", 53 | "prof = 'cgc'\n", 54 | "\n", 55 | "config_config_file = sbg.Config(profile=prof)\n", 56 | "api = sbg.Api(config=config_config_file)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Copy our own App\n", 64 | "We will first list all our projects, then list the apps within the first project, and finally copy an app between the first and second project. (Note that here there is a chance to copy also a specific version of the app, by changing the last character of the following variable to the version you want:\n", 65 | "```python\n", 66 | "my_apps_source.id[a_index]\n", 67 | "```\n", 68 | "The critical information for this POST is the **app_id**. Note, you are **not** allowed to copy the same app **and** assign the same name1 more than once. If you change the name, it is ok.\n", 69 | "\n", 70 | "To make these results very obvious, use an empty project as your TARGET\\_PROJECT (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome'1\n", 71 | "\n", 72 | "1 Note that setting the **name** of an app, actually changes the **id**. We are working on fixing this inconsistency.\n", 73 | "\n", 74 | "#### Why am I getting an Error Code 6000?\n", 75 | "You found a known bug, we are _very sorry_ for this. It is already being worked on and should be ok soon. Known affected workflows:\n", 76 | "* Exome Coverage QC 1.0\n", 77 | "* RNA-Seq De Novo Assembly and Analysis - Trinity 2.0.6\n", 78 | "* RNA-Seq De Novo Assembly - Trinity 2.0.6\n", 79 | "* Whole Exome Sequencing GATK 2.3.9.-lite" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": null, 85 | "metadata": { 86 | "collapsed": false 87 | }, 88 | "outputs": [], 89 | "source": [ 90 | "# [USER INPUT] Set project name; project (p_) and file (f_) indices here:\n", 91 | "source_project_name = 'Keep on Smiling'\n", 92 | "my_project_name = 'Life is Beautiful'\n", 93 | "app_id = 'jack_digi/keep-on-smiling/TorrentMappingAlignmentProgramMap4'\n", 94 | "revision_number = 0\n", 95 | "\n", 96 | "# pull out target project\n", 97 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 98 | " if p.name == my_project_name]\n", 99 | "source_project = [p for p in api.projects.query(limit=100).all() \\\n", 100 | " if p.name == source_project_name]\n", 101 | "\n", 102 | "# Double-check that target project exist\n", 103 | "if not source_project:\n", 104 | " print('Source project (%s) not found, check spelling' % source_project_name)\n", 105 | " raise KeyboardInterrupt\n", 106 | "else:\n", 107 | " source_project = source_project[0]\n", 108 | " \n", 109 | "if not my_project:\n", 110 | " print('Target project (%s) not found, check spelling' % my_project_name)\n", 111 | " raise KeyboardInterrupt\n", 112 | "else:\n", 113 | " my_project = my_project[0]\n", 114 | "\n", 115 | "my_app_source = api.apps.get_revision(id=app_id, revision=revision_number) \n", 116 | "\n", 117 | "duplicate_app = [a for a in my_apps.all() if a.name == my_app_source.name]\n", 118 | "\n", 119 | "if duplicate_app:\n", 120 | " print('App already exists in second project, please try another app')\n", 121 | "else:\n", 122 | " print('App (%s) does not exist in Project (%s); copying now' % \\\n", 123 | " (my_app_source.name, my_project.name))\n", 124 | " \n", 125 | " my_new_app = my_app_source.copy(project = my_project.id, name = my_app_source.name)\n", 126 | " \n", 127 | " # re-list apps in target project to verify the copy worked\n", 128 | " my_apps = api.apps.query(project = my_project.id, limit=100)\n", 129 | " my_app_names = [a.name for a in my_apps.all()]\n", 130 | " \n", 131 | " if my_app_source.name in my_app_names:\n", 132 | " print('Sucessfully copied one app!')\n", 133 | " else:\n", 134 | " print('Something went wrong...') " 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Additional Information\n", 142 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/copy-an-app-secondary-method)" 143 | ] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "Python 2", 149 | "language": "python", 150 | "name": "python2" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 2 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython2", 162 | "version": "2.7.12" 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 0 167 | } 168 | -------------------------------------------------------------------------------- /Recipes/CGC/apps_copyFromPublicApps.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I _copy_ an app from the _public apps_?\n", 8 | "### Overview\n", 9 | "Apps can be copied from one of two sources:\n", 10 | "1. other projects you are a member of\n", 11 | "2. public reference. \n", 12 | "\n", 13 | "Here we focus on copying an app from _public reference_. \n", 14 | " \n", 15 | "### Prerequisites\n", 16 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 17 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 18 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 19 | " 4. You understand how to list apps within your project (we will just use that call directly and pick one here).\n", 20 | " \n", 21 | "## Imports\n", 22 | "We import the _Api_ class from the official sevenbridges-python bindings below." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": { 29 | "collapsed": true 30 | }, 31 | "outputs": [], 32 | "source": [ 33 | "import sevenbridges as sbg" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Initialize the object\n", 41 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "collapsed": true 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "# [USER INPUT] specify platform {cgc, sbg}\n", 53 | "prof = 'cgc'\n", 54 | "\n", 55 | "config_config_file = sbg.Config(profile=prof)\n", 56 | "api = sbg.Api(config=config_config_file)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Copy a Public App\n", 64 | "We will first list all our projects, then list the apps within the Public Reference project1, and finally copy an app between the Public Reference to the my_project. Here we also explicitly set _'limit':100_ inside the _query_. This helps speed up the auto-pagination feature within the object constructor.\n", 65 | "\n", 66 | "The critical information for this POST is the **app_id**. Note, you are **not** allowed to copy the same app **and** assign the same name more than once. If you change the name, it is ok.\n", 67 | "\n", 68 | "To make these results very obvious, use an empty project as your MY\\_PROJECT (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome'2\n", 69 | "\n", 70 | "1 Unlike files, apps are accesssible **both** *within* a project (here the Public Reference project) **and** by a *visibility* property (which may be set to 'public')\n", 71 | "\n", 72 | "#### Why am I getting an Error Code 6000?\n", 73 | "You found a known bug, we are _very sorry_ for this. It is already being worked on and should be ok soon. Try copying the app named **'Torrent Mapping Alignment Program Map4'**, this will work. Known affected workflows:\n", 74 | "* Exome Coverage QC 1.0\n", 75 | "* RNA-Seq De Novo Assembly and Analysis - Trinity 2.0.6\n", 76 | "* RNA-Seq De Novo Assembly - Trinity 2.0.6\n", 77 | "* Whole Exome Sequencing GATK 2.3.9.-lite" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "outputs": [], 87 | "source": [ 88 | "# [USER INPUT] Set project name; project (p_) and file (f_) indices here:\n", 89 | "my_project_name = 'Keep on Smiling'\n", 90 | "a_name = 'Torrent Mapping Alignment Program Map4'\n", 91 | "\n", 92 | "\n", 93 | "# pull out target project\n", 94 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 95 | " if p.name == my_project_name]\n", 96 | "\n", 97 | "# Double-check that target project exists\n", 98 | "if not my_project:\n", 99 | " print('Target project (%s) not found, check spelling' % my_project_name)\n", 100 | " raise KeyboardInterrupt\n", 101 | "else:\n", 102 | " my_project = my_project[0]\n", 103 | " \n", 104 | "my_apps = api.apps.query(project = my_project.id, limit=100)\n", 105 | "my_app_source = [a for a in api.apps.query(visibility='public', limit=100) \\\n", 106 | " if a.name == a_name][0]\n", 107 | "\n", 108 | "duplicate_app = [a for a in my_apps.all() if a.name == my_app_source.name]\n", 109 | "\n", 110 | "if duplicate_app:\n", 111 | " print('App already exists in second project, please try another app')\n", 112 | "else:\n", 113 | " print('App (%s) does not exist in Project (%s); copying now' % \\\n", 114 | " (a_name, my_project.name))\n", 115 | " \n", 116 | " my_new_app = my_app_source.copy(project = my_project.id, name = a_name)\n", 117 | " \n", 118 | " # re-list apps in target project to verify the copy worked\n", 119 | " my_apps = api.apps.query(project = my_project.id, limit=100)\n", 120 | " my_app_names = [a.name for a in my_apps.all()]\n", 121 | " \n", 122 | " if a_name in my_app_names:\n", 123 | " print('Sucessfully copied one app!')\n", 124 | " else:\n", 125 | " print('Something went wrong...')" 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "## Additional Information\n", 133 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/copy-an-app-secondary-method)" 134 | ] 135 | } 136 | ], 137 | "metadata": { 138 | "kernelspec": { 139 | "display_name": "Python 2", 140 | "language": "python", 141 | "name": "python2" 142 | }, 143 | "language_info": { 144 | "codemirror_mode": { 145 | "name": "ipython", 146 | "version": 2 147 | }, 148 | "file_extension": ".py", 149 | "mimetype": "text/x-python", 150 | "name": "python", 151 | "nbconvert_exporter": "python", 152 | "pygments_lexer": "ipython2", 153 | "version": "2.7.11" 154 | } 155 | }, 156 | "nbformat": 4, 157 | "nbformat_minor": 0 158 | } 159 | -------------------------------------------------------------------------------- /Recipes/CGC/apps_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# What are the details of one of my _apps_?\n", 8 | "### Overview\n", 9 | "Here we focus on _getting the details_ from a single app. This will be important later when we want to start a task. As with any **detail**-type call, we will get extensive information about one app but must first know that app's id. \n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 15 | " 4. You understand how to list apps within one of your projects (we will just use that call directly here). This is a **great place** to get the **app_id** you will need in this recipe.\n", 16 | " 5. You have at least one app in your project, maybe from copying one\n", 17 | " \n", 18 | "## Imports\n", 19 | "We import the _Api_ class from the official sevenbridges-python bindings below." 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": { 26 | "collapsed": false 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "import sevenbridges as sbg" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Initialize the object\n", 38 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": { 45 | "collapsed": true 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "# [USER INPUT] specify platform {cgc, sbg}\n", 50 | "prof = 'cgc'\n", 51 | "\n", 52 | "config_config_file = sbg.Config(profile=prof)\n", 53 | "api = sbg.Api(config=config_config_file)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "## Dig into your app\n", 61 | "We start by listing all of your projects, then list the apps within the first one. A **detail**-call for apps returns the following *attributes*:\n", 62 | "* **id** _Unique_ identifier for the app\n", 63 | "* **name** Name of the app, note this **is** metadata and can be _changed_\n", 64 | "* **href** Address1 of the app.\n", 65 | "* **raw** Details of the app\n", 66 | "* **project** Project the app is in\n", 67 | "* **revision** App revision\n", 68 | "\n", 69 | "The **raw** dictionary2:\n", 70 | "* stdout\n", 71 | "* sbg:categories - categories that app belongs to \n", 72 | "* sbg:copyOf - what is the app this one was copied from\n", 73 | "* sbg:toolAuthor - author of the tool\n", 74 | "* id - app id\n", 75 | "* successCodes - list of success codes for a tool\n", 76 | "* sbg:revision - revision of the app\n", 77 | "* sbg:latestRevision - latest revision available\n", 78 | "* sbg:modifiedBy - user who modified the app revision \n", 79 | "* sbg:toolkitVersion - version of the toolkit \n", 80 | "* label - User friendly naming of the app (like *Picard MergeSamFiles*)\n", 81 | "* arguments\n", 82 | "* sbg:createdBy - which user originally created the app\n", 83 | "* inputs - description of the inputs \n", 84 | "* sbg:links - links to original documentation for the tools\n", 85 | "* description \n", 86 | "* sbg:sbgMaintained - notes whether the app is maintained by Seven Bridges or not\n", 87 | "* sbg:modifiedOn - modified info timestamp\n", 88 | "* outputs - description of the outputs\n", 89 | "* baseCommand - base command that executes (for example `java -jar /opt/picard-tools-1.140/picard.jar MergeSamFiles`, but in more complex format)\n", 90 | "* sbg:contributors - list of contributors to the app\n", 91 | "* sbg:validationErrors - app validation errors if they exist\n", 92 | "* requirements \n", 93 | "* temporaryFailCodes - codes that cause temporary failure (which can be retried)\n", 94 | "* class \n", 95 | "* sbg:job \n", 96 | "* hints - contains info on memory, CPU requirements and the link to actual *docker* image that executes\n", 97 | "* sbg:id \n", 98 | "* sbg:createdOn - timestamp when the app was created\n", 99 | "* sbg:toolkit - toolkit version \n", 100 | "* stdin \n", 101 | "* sbg:cmdPreview - preview of the command line, for example:\n", 102 | "```java\n", 103 | "java -Xmx2048M -jar /opt/picard-tools-1.140/picard.jar CollectAlignmentSummaryMetrics INPUT=/root/folder/example.bam REFERENCE_SEQUENCE=/root/directory/example.fasta OUTPUT=example.summary_metrics.txt METRIC_ACCUMULATION_LEVEL=ALL_READS INPUT=/root/folder/example.bam /root/folder/example.bam\n", 104 | "```\n", 105 | "* sbg:license - licencing for the tool \n", 106 | "* sbg:revisionsInfo - contains info on revisions\n", 107 | "* sbg:project - what is the project that contains the app\n", 108 | "\n", 109 | "1 This is the address where, by using API you can get this resource\n", 110 | "\n", 111 | "2 Many of these fields are related to the [Common Workflow Language](http://docs.cancergenomicscloud.org/docs/sdk-overview) JSON describing the app." 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": { 118 | "collapsed": false 119 | }, 120 | "outputs": [], 121 | "source": [ 122 | "# [USER INPUT] Set project name:\n", 123 | "project_name = 'Keep on Smiling' # project to check\n", 124 | "app_id = 'jack_digi/keep-on-smiling/TorrentMappingAlignmentProgramMap4'\n", 125 | "revision_number = 0\n", 126 | "\n", 127 | "# LIST all projects\n", 128 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 129 | " if p.name == project_name][0] \n", 130 | "\n", 131 | "\n", 132 | "my_app_source = api.apps.get_revision(id=app_id, revision=revision_number)\n", 133 | "\n", 134 | "print('You have selected app (%s), which was created by (%s). \\n It has %i inputs:' % \\\n", 135 | " (single_app.name, single_app.raw['sbg:createdBy'], len(single_app.raw['inputs'])))\n", 136 | "for ii in single_app.raw['inputs']:\n", 137 | " print(ii['id'][1:])" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "## Get a dictionary of the App's ~CWL\n", 145 | "This is a useful **first look** at the app description, but please **be careful** since we have wrapped it in a function, it is **not a JSON**. You would want to \n", 146 | "\n", 147 | "1. go to the GUI\n", 148 | "2. click on the app\n", 149 | "3. in the top right, click \"Export\"\n", 150 | "4. **save** that page as a json. (do not copy paste as that introduces surpsring errors)\n", 151 | "5. load the json file into python.\n", 152 | "6. convert it into a json (see this [tutorial](../../Tutorials/CGC/batch_SAMtoolsView.ipynb) for a good example)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": null, 158 | "metadata": { 159 | "collapsed": false 160 | }, 161 | "outputs": [], 162 | "source": [ 163 | "# # !!! UNFINISHED !!!\n", 164 | "\n", 165 | "# cwl = single_app.raw\n", 166 | "# print(cwl) # TODO: resolve copy/paste JSON issues" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Additional Information\n", 174 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/get-file-details) and [here](http://docs.cancergenomicscloud.org/docs/get-raw-app-information)" 175 | ] 176 | } 177 | ], 178 | "metadata": { 179 | "kernelspec": { 180 | "display_name": "Python 2", 181 | "language": "python", 182 | "name": "python2" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 2 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython2", 194 | "version": "2.7.12" 195 | } 196 | }, 197 | "nbformat": 4, 198 | "nbformat_minor": 0 199 | } 200 | -------------------------------------------------------------------------------- /Recipes/CGC/apps_listAll.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Which _apps_ are in my project?\n", 8 | "### Overview\n", 9 | "Here we focus on listing all apps within a single project. As with any **list**-type call, we will get minimal information about each apps. There are two versions of this call:\n", 10 | "\n", 11 | " 1. (default) **paginated** call that will return 50 apps\n", 12 | " 2. **all-records** call that will page through and return all apps .\n", 13 | "\n", 14 | "Note, we can also query all available apps (in all our projects).\n", 15 | "\n", 16 | "### Prerequisites\n", 17 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 18 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 19 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 20 | " 4. You have at least one app in your project, maybe from copying one\n", 21 | " \n", 22 | "## Imports\n", 23 | "We import the _Api_ class from the official sevenbridges-python bindings below." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": { 30 | "collapsed": true 31 | }, 32 | "outputs": [], 33 | "source": [ 34 | "import sevenbridges as sbg" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "## Initialize the object\n", 42 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": null, 48 | "metadata": { 49 | "collapsed": true 50 | }, 51 | "outputs": [], 52 | "source": [ 53 | "# User input: specify platform {cgc, sbg}\n", 54 | "prof = 'cgc'\n", 55 | "\n", 56 | "config_config_file = sbg.Config(profile=prof)\n", 57 | "api = sbg.Api(config=config_config_file)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "## List all apps within a project\n", 65 | "Here we can return the apps in a specific project or all the apps in projects you are a member of. A **list**-call for apps returns the following useful *attributes*:\n", 66 | "* **id** _Unique_ identifier for each app, including the latest version number\n", 67 | "* **name** Name of app, maybe _non-unique_\n", 68 | "* **project** Project the app is in.\n", 69 | "* **href** Address1 of the app.\n", 70 | "\n", 71 | "1 This is the address where, by using API you can get this resource" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "By passing a **project_id** into the _api.apps.query()_ below, we will get the apps **inside that project**." 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": { 85 | "collapsed": false 86 | }, 87 | "outputs": [], 88 | "source": [ 89 | "# [USER INPUT] Set project name:\n", 90 | "project_name = 'Keep on Smiling'\n", 91 | "\n", 92 | "\n", 93 | "# LIST all projects and check for name match\n", 94 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 95 | " if p.name == project_name] \n", 96 | "\n", 97 | "if not my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 98 | " print('The project named (%s) does not exist, please check spelling (especially trailing spaces)' \\\n", 99 | " % project_name)\n", 100 | " raise KeyboardInterrupt\n", 101 | "else:\n", 102 | " my_project = my_project[0]\n", 103 | " # list the apps in ONE project \n", 104 | " my_apps = api.apps.query(project = my_project.id, limit=100)\n", 105 | " print(' In Project (%s), you have %i apps.' % (my_project.name, my_apps.total))\n", 106 | "\n", 107 | " for aa in my_apps.all(): \n", 108 | " print('App name is (%s); \\t App id is (%s)' % (aa.name, aa.id))\n", 109 | " print('\\n')" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "By **not** passing any **project_id** into the _api.apps.query()_ below, we will get all the apps for **any project** you are a member of." 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": { 123 | "collapsed": false 124 | }, 125 | "outputs": [], 126 | "source": [ 127 | "# list the app in ALL your projects\n", 128 | "my_apps_all_projects = api.apps.query(limit=100)\n", 129 | "\n", 130 | "print(' In all your projects, you have %i apps.' % (my_apps_all_projects.total))\n", 131 | " \n", 132 | "for aa in my_apps_all_projects.all(): \n", 133 | " print('App name is (%s); \\t App id is (%s)' % (aa.name, aa.id))\n", 134 | "print('\\n')" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Additional Information\n", 142 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-all-your-projects)" 143 | ] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "Python 2", 149 | "language": "python", 150 | "name": "python2" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 2 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython2", 162 | "version": "2.7.11" 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 0 167 | } 168 | -------------------------------------------------------------------------------- /Recipes/CGC/files_copyFromMyProject.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I _copy_ a file from another on of _my projects_?\n", 8 | "### Overview\n", 9 | "Files can be copied from one of two sources:\n", 10 | "1. other projects you are a member of\n", 11 | "2. public reference. \n", 12 | "\n", 13 | "Here we focus on copying a file from _your own project_. \n", 14 | "\n", 15 | "### Prerequisites\n", 16 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 17 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 18 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 19 | " 4. You understand how to list files within one of your projects (we will just use that call directly here).\n", 20 | "\n", 21 | "### Warning\n", 22 | "You are only permitted to copy a TCGA-protected file to a _target project_ if that project also has TCGA-protected permissions.\n", 23 | "\n", 24 | "## Imports\n", 25 | "We import the _Api_ class from the official sevenbridges-python bindings below." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "import sevenbridges as sbg" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "## Initialize the object\n", 44 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": { 51 | "collapsed": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# User input: specify platform {cgc, sbg}\n", 56 | "prof = 'cgc'\n", 57 | "\n", 58 | "config_config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "## Copy a file from another project\n", 67 | "We will first find our _source\\_project_ and _my\\_project_ (target), then list the files within the source project, and copy a file from **_source\\_project_ -> _my\\_project_**.\n", 68 | "\n", 69 | "The critical information for this POST is the **file_id**. Note, you are allow to copy the same file as many times as you like. However, duplicates will be automatically have a prefix attached of (\\_1\\_, \\_2\\_, etc) depending on how many times you copy the file.\n", 70 | "\n", 71 | "To make these results very obvious, use an empty project as your MY\\_PROJECT (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome.copy'" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": { 78 | "collapsed": false 79 | }, 80 | "outputs": [], 81 | "source": [ 82 | "# [USER INPUT] Set your project name; source project name; and file (f_) indices here:\n", 83 | "source_project_name = 'Life is Really Beautiful' \n", 84 | "my_project_name = 'Keep on Smiling'\n", 85 | "f_index = 2 # file to copy\n", 86 | "\n", 87 | "\n", 88 | "# Find TARGET and YOUR projects\n", 89 | "source_project = [p for p in api.projects.query(limit=100).all() \\\n", 90 | " if p.name == source_project_name]\n", 91 | "\n", 92 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 93 | " if p.name == my_project_name]\n", 94 | "\n", 95 | "# Double-check that all projects exist\n", 96 | "if not source_project:\n", 97 | " print('Source project (%s) not found, check spelling' % source_project_name)\n", 98 | " raise KeyboardInterrupt\n", 99 | "else:\n", 100 | " source_project = source_project[0]\n", 101 | " \n", 102 | "if not my_project:\n", 103 | " print('Target project (%s) not found, check spelling' % my_project_name)\n", 104 | " raise KeyboardInterrupt\n", 105 | "else:\n", 106 | " my_project = my_project[0]\n", 107 | "\n", 108 | "# LIST all files in the source and target project\n", 109 | "my_files = api.files.query(limit = 100, project = my_project.id).all()\n", 110 | "source_files = list(api.files.query(limit = 100, project = source_project.id).all())\n", 111 | "\n", 112 | "# pop out the file names \n", 113 | "my_file_names = [f.name for f in my_files]\n", 114 | "source_file_names = [f.name for f in source_files]\n", 115 | "\n", 116 | "# Check if first file already exists in the target project\n", 117 | "if source_file_names[f_index] in my_file_names:\n", 118 | " print('file already exists in second project, please try another file')\n", 119 | "else:\n", 120 | " print('File (%s) does not exist in Project (%s); copying now' % \\\n", 121 | " (source_file_names[f_index], my_project.id))\n", 122 | " source_file = [curr_file for curr_file in source_files \\\n", 123 | " if curr_file.name == source_file_names[f_index]][0]\n", 124 | " my_new_file = source_file.copy(project = my_project.id, \\\n", 125 | " name = source_file.name)\n", 126 | "\n", 127 | " # re-list files in target project to verify the copy worked\n", 128 | " my_files = [f.name for f in api.files.query(limit = 100, project = my_project.id).all()]\n", 129 | " \n", 130 | " if source_file.name in my_files:\n", 131 | " print('Sucessfully copied one file!')\n", 132 | " else:\n", 133 | " print('Something went wrong...')" 134 | ] 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "metadata": {}, 139 | "source": [ 140 | "## Additional Information\n", 141 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/copy-a-file)" 142 | ] 143 | } 144 | ], 145 | "metadata": { 146 | "kernelspec": { 147 | "display_name": "Python 3", 148 | "language": "python", 149 | "name": "python3" 150 | }, 151 | "language_info": { 152 | "codemirror_mode": { 153 | "name": "ipython", 154 | "version": 3 155 | }, 156 | "file_extension": ".py", 157 | "mimetype": "text/x-python", 158 | "name": "python", 159 | "nbconvert_exporter": "python", 160 | "pygments_lexer": "ipython3", 161 | "version": "3.5.2" 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 0 166 | } 167 | -------------------------------------------------------------------------------- /Recipes/CGC/files_copyFromPublicReference.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I _copy_ a file from the _Public Reference_ files?\n", 8 | "### Overview\n", 9 | "Files can be copied from other projects you are a member of or public reference. Here we focus on copying a file from _public reference_.\n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 15 | " \n", 16 | "## Imports\n", 17 | "We import the _Api_ class from the official sevenbridges-python bindings below." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import sevenbridges as sbg" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Initialize the object\n", 36 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# User input: specify platform {cgc, sbg}\n", 48 | "prof = 'cgc'\n", 49 | "\n", 50 | "config_config_file = sbg.Config(profile=prof)\n", 51 | "api = sbg.Api(config=config_config_file)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## Copy a file from the Public Reference\n", 59 | "We will first find our _source\\_project_ (the Public Reference Files), then list the files within the source project1, and copy a file from **_source\\_project_ -> _my\\_project_**.\n", 60 | "\n", 61 | "The critical information for this POST is the **file_id**. Note, you are allow to copy the same file as many times as you like. However, duplicates will be automatically have a prefix attached of (\\_1\\_, \\_2\\_, etc) depending on how many times you copy the file.\n", 62 | "\n", 63 | "To make these results very obvious, use an empty project as your MY\\_PROJECT (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome.copy'\n", 64 | "\n", 65 | "1 Files are only accessible **within** a project - here the Public Reference project (**warning** we may change this project name in the future)." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "# [USER INPUT] Set your project name; source project name; and file (f_) indices here:\n", 77 | "source_project_id = 'admin/sbg-public-data' \n", 78 | "my_project_name = 'Keep on Smiling'\n", 79 | "f_index = 12 # file to copy\n", 80 | "\n", 81 | "\n", 82 | "# Find your project\n", 83 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 84 | " if p.name == my_project_name]\n", 85 | "\n", 86 | "# Double-check that your project exists\n", 87 | "if not my_project:\n", 88 | " print('Target project (%s) not found, check spelling' % my_project_name)\n", 89 | " raise KeyboardInterrupt\n", 90 | "else:\n", 91 | " my_project = my_project[0]\n", 92 | "\n", 93 | "# LIST all files in the source and target project\n", 94 | "my_files = api.files.query(limit = 100, project = my_project.id).all()\n", 95 | "source_files = list(api.files.query(limit = 100, project = source_project_id).all())\n", 96 | "\n", 97 | "# pop out the file names \n", 98 | "my_file_names = [f.name for f in my_files]\n", 99 | "source_file_names = [f.name for f in source_files]\n", 100 | "\n", 101 | "# Check if first file already exists in the target project\n", 102 | "if source_file_names[f_index] in my_file_names:\n", 103 | " print('file already exists in second project, please try another file')\n", 104 | "else:\n", 105 | " print('File (%s) does not exist in Project (%s); copying now' % \\\n", 106 | " (source_file_names[f_index], my_project.id))\n", 107 | " source_file = [curr_file for curr_file in source_files \\\n", 108 | " if curr_file.name == source_file_names[f_index]][0]\n", 109 | " \n", 110 | " my_new_file = source_file.copy(project = my_project.id, \\\n", 111 | " name = source_file.name)\n", 112 | "\n", 113 | " # re-list files in target project to verify the copy worked\n", 114 | " my_files = [f.name for f in api.files.query(limit = 100, project = my_project.id).all()]\n", 115 | " \n", 116 | " if source_file.name in my_files:\n", 117 | " print('Sucessfully copied one file!')\n", 118 | " else:\n", 119 | " print('Something went wrong...')" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "## Additional Information\n", 127 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/copy-a-file)" 128 | ] 129 | } 130 | ], 131 | "metadata": { 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.5.2" 148 | } 149 | }, 150 | "nbformat": 4, 151 | "nbformat_minor": 0 152 | } 153 | -------------------------------------------------------------------------------- /Recipes/CGC/files_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# What are the details (metadata) of one of my _files_?\n", 8 | "### Overview\n", 9 | "Here we focus on _getting the details_ (or _metadata_) from a single file. As with any **detail**-type call, we will get extensive information about one file but must first know that files's id. \n", 10 | " \n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 15 | " 4. You understand how to list files within one of your projects (we will just use that call directly here).\n", 16 | " 5. Your project needs to have at least one file inside\n", 17 | " \n", 18 | "## Imports\n", 19 | "We import the _Api_ class from the official sevenbridges-python bindings below." 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": { 26 | "collapsed": true 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "import sevenbridges as sbg" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Initialize the object\n", 38 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": { 45 | "collapsed": true 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "# User input: specify platform {cgc, sbg}\n", 50 | "prof = 'cgc'\n", 51 | "\n", 52 | "config_config_file = sbg.Config(profile=prof)\n", 53 | "api = sbg.Api(config=config_config_file)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "## List my files and detail the first one\n", 61 | "We start by listing all of your files, then get more information on the first one. A **detail**-call for files returns the following *attributes*:\n", 62 | "* **created_on** File creation date\n", 63 | "* **id** _Unique_ identifier for the file\n", 64 | "* **name** Name of the file, note this **is** metadata and can be _changed_\n", 65 | "* **href** Address1 of the file.\n", 66 | "* **modified_on** File modification date\n", 67 | "* **metadata** Dictionary of metadata\n", 68 | "* **origin** Will link back to a *task* if this is an output file \n", 69 | "* **project** Project the file is in\n", 70 | "* **size** file size in bytes\n", 71 | "\n", 72 | "The **metadata** dictionary contains all metadata properties. Note there are **SUBSTANTIAL DIFFERENCES** here between _TCGA_ and _uploaded_ files. For TCGA files, metadata is **immutable** and the list is:\n", 73 | "* vital_status\n", 74 | "* reference_genome\n", 75 | "* aliquot_id\n", 76 | "* age_at_diagnosis\n", 77 | "* sample_id\n", 78 | "* days_to_death\n", 79 | "* ethnicity\n", 80 | "* sample_uuid\n", 81 | "* sample_type\n", 82 | "* platform\n", 83 | "* data_subtype\n", 84 | "* experimental_strategy\n", 85 | "* case_uuid\n", 86 | "* data_type\n", 87 | "* case_id\n", 88 | "* investigation\n", 89 | "* aliquot_uuid\n", 90 | "* disease_type\n", 91 | "* gender\n", 92 | "* data_format\n", 93 | "* race\n", 94 | "* primary_site\n", 95 | "\n", 96 | "In contrast the metadata is **mutable** for user uploaded files.\n", 97 | "\n", 98 | "1 This is the address where, by using API you can get this resource" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": { 105 | "collapsed": false 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "# [USER INPUT] Set project name and file (f_) indices here:\n", 110 | "project_name = 'Life is Beautiful' \n", 111 | "f_index = 0\n", 112 | "\n", 113 | "\n", 114 | "# LIST all projects and check for name match\n", 115 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 116 | " if p.name == project_name] \n", 117 | "\n", 118 | "if not my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 119 | " print('The project (%s) does not exist, please check spelling (especially trailing spaces)' \\\n", 120 | " % project_name)\n", 121 | " raise KeyboardInterrupt\n", 122 | "else:\n", 123 | " # list the files in the target project\n", 124 | " my_files = [f for f in api.files.query(my_project[0].id).all()]\n", 125 | " # get details of the first file inside the project\n", 126 | " single_file = api.files.get(id = my_files[f_index].id)\n", 127 | " print('You have selected file %s (size %s [bytes]). \\n' % (single_file.name, single_file.size))\n", 128 | "\n", 129 | " # TODO: work on this for SBPLAT compatibility\n", 130 | " if hasattr(single_file, 'metadata') and single_file.metadata is not None:\n", 131 | " if ('age_at_diagnosis' in single_file.metadata.keys()) \\\n", 132 | " and ('experimental_strategy' in single_file.metadata.keys()):\n", 133 | " print(('Subject was %i years old at diagnosis; alliquot was processed with %s' % \\\n", 134 | " (single_file.metadata['age_at_diagnosis'], \\\n", 135 | " single_file.metadata['experimental_strategy'] ))) " 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "## Additional Information\n", 143 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/get-file-details)" 144 | ] 145 | } 146 | ], 147 | "metadata": { 148 | "kernelspec": { 149 | "display_name": "Python 2", 150 | "language": "python", 151 | "name": "python2" 152 | }, 153 | "language_info": { 154 | "codemirror_mode": { 155 | "name": "ipython", 156 | "version": 2 157 | }, 158 | "file_extension": ".py", 159 | "mimetype": "text/x-python", 160 | "name": "python", 161 | "nbconvert_exporter": "python", 162 | "pygments_lexer": "ipython2", 163 | "version": "2.7.12" 164 | } 165 | }, 166 | "nbformat": 4, 167 | "nbformat_minor": 0 168 | } 169 | -------------------------------------------------------------------------------- /Recipes/CGC/files_listAll.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Which _files_ are in my project?\n", 11 | "### Overview\n", 12 | "Here we focus on listing all files within a single project. Importantly, files are only accessible **within** a project1. As with any **list**-type call, we will get minimal information about each file. \n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 18 | " 4. Your project needs to have at least one file inside\n", 19 | " \n", 20 | "## Imports\n", 21 | "We import the _Api_ class from the official sevenbridges-python bindings below.\n", 22 | "\n", 23 | "1 There is no \"list **all** *files*\" API call that parallels the \"list **all**\" calls for *projects* and *apps*" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": { 30 | "collapsed": true, 31 | "deletable": true, 32 | "editable": true 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "import sevenbridges as sbg" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": { 42 | "deletable": true, 43 | "editable": true 44 | }, 45 | "source": [ 46 | "## Initialize the object\n", 47 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": { 54 | "collapsed": true, 55 | "deletable": true, 56 | "editable": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "# [USER INPUT] specify platform {cgc, sbg}\n", 61 | "prof = 'cgc'\n", 62 | "\n", 63 | "config_config_file = sbg.Config(profile=prof)\n", 64 | "api = sbg.Api(config=config_config_file)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": { 70 | "deletable": true, 71 | "editable": true 72 | }, 73 | "source": [ 74 | "## List (up to 50 of) my files\n", 75 | "A **list**-call for projects returns the following *attributes*:\n", 76 | "* **id** _Unique_ identifier for each file, generated by the CGC\n", 77 | "* **name** Name of file, maybe _non-unique_\n", 78 | "* **href** Address1 of the file.\n", 79 | "\n", 80 | "Since we are not setting the **limit** parameter in api.files.query(), it _defaults_ to 50 records returned\n", 81 | "\n", 82 | "1 This is the address where, by using API you can get this resource" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": { 89 | "collapsed": false, 90 | "deletable": true, 91 | "editable": true 92 | }, 93 | "outputs": [], 94 | "source": [ 95 | "# [USER INPUT] Set project name here, (pick one with files):\n", 96 | "project_name = 'Gene Expression'\n", 97 | "\n", 98 | "\n", 99 | "# LIST all projects and check for name match\n", 100 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 101 | " if p.name == project_name] \n", 102 | "\n", 103 | "if not my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 104 | " print('The project named (%s) does not exist, please check spelling (especially trailing spaces)' \\\n", 105 | " % project_name)\n", 106 | " raise KeyboardInterrupt\n", 107 | "else:\n", 108 | " # list the files in the target project\n", 109 | " my_files = api.files.query(my_project[0].id)\n", 110 | "\n", 111 | "# print up to the first 10 files\n", 112 | "for ii in range(min(10,my_files.total)):\n", 113 | " print('file name is (%s); \\t file id is (%s)' % (my_files[ii].name, my_files[ii].id))" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": { 119 | "deletable": true, 120 | "editable": true 121 | }, 122 | "source": [ 123 | "#### Note\n", 124 | "If you had more than 50 files in your project you would hit pagination. For an example of how to deal with that see projects_listAll.ipynb\n", 125 | "\n", 126 | "## Let's get all the files\n", 127 | "Using the **.all()** method will take care of pagination for us" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": null, 133 | "metadata": { 134 | "collapsed": false, 135 | "deletable": true, 136 | "editable": true 137 | }, 138 | "outputs": [], 139 | "source": [ 140 | "# print all files\n", 141 | "for f in my_files.all():\n", 142 | " print('file name is (%s); \\t file id is (%s)' % (f.name, f.id))" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": { 148 | "deletable": true, 149 | "editable": true 150 | }, 151 | "source": [ 152 | "## Additional Information\n", 153 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-files-in-a-project)" 154 | ] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "Python 3", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.5.2" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 0 178 | } 179 | -------------------------------------------------------------------------------- /Recipes/CGC/images/CGC_overview-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/CGC_overview-02.png -------------------------------------------------------------------------------- /Recipes/CGC/images/example_sbgrc_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/example_sbgrc_file.png -------------------------------------------------------------------------------- /Recipes/CGC/images/projects_addNew-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/projects_addNew-01.png -------------------------------------------------------------------------------- /Recipes/CGC/images/projects_getDetails-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/projects_getDetails-01.png -------------------------------------------------------------------------------- /Recipes/CGC/images/projects_getMembers-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/projects_getMembers-01.png -------------------------------------------------------------------------------- /Recipes/CGC/images/projects_listAll-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/CGC/images/projects_listAll-01.png -------------------------------------------------------------------------------- /Recipes/CGC/projects_addMembers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I add members to one my _projects_?\n", 8 | "### Overview\n", 9 | "Here we focus on _adding a member_ to one of your projects. Importantly, you **must** be the admin of this project.\n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 15 | " \n", 16 | "## Imports\n", 17 | "We import the _Api_ class from the official sevenbridges-python bindings below." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import sevenbridges as sbg" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Initialize the object\n", 36 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# [USER INPUT] specify platform {cgc, sbg}\n", 48 | "prof = 'cgc'\n", 49 | "\n", 50 | "config_config_file = sbg.Config(profile=prof)\n", 51 | "api = sbg.Api(config=config_config_file)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## List all your projects\n", 59 | "We start by listing all of your projects, then get more information on the first one. A **detail**-call for projects returns the following *attributes*:\n", 60 | "* **description** The user specified project description\n", 61 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 62 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 63 | "* **href** Address1 of the project.\n", 64 | "* **tags** List of tags, currently tags[0] = 'tcga' if protected data is used\n", 65 | "* **type** (unimportant) this is always equal to 'v2'\n", 66 | "* **flag** (unimportant) this is set by the object constructor, here always 'longList':False \n", 67 | "\n", 68 | "1 This is the address where, by using API you can get this resource" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "# [USER INPUT] Set project name here to add members to:\n", 80 | "project_name = 'Life is Really Beautiful'\n", 81 | "\n", 82 | "\n", 83 | "# check if this project already exists. LIST all projects and check for name match\n", 84 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 85 | " if p.name == project_name]\n", 86 | "\n", 87 | "if not my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 88 | " print('Target project (%s) not found, please check spelling' % (project_name))\n", 89 | " raise KeyboardInterrupt\n", 90 | "else:\n", 91 | " my_project = api.projects.get(id = my_project[0].id)\n", 92 | " print('You have selected project (%s).' % (my_project.name))\n", 93 | " if hasattr(my_project, 'description'): \n", 94 | " # Need to check if description has been entered, GUI created project have default text, \n", 95 | " # but it is not in the metadata.\n", 96 | " print('Project description: %s \\n' % (my_project.description))" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "## Add members\n", 104 | "In the list **user\\_names** below, add some actual user names. Then run the script and they will be added to your project.\n", 105 | "\n", 106 | "### Note\n", 107 | "This is **fail** if you try to add a user **without** _TCGA Controlled Data access_ to a project containing _TCGA Controlled Data_. Please don't do that." 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "collapsed": false 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "user_names =['',\n", 119 | " '']\n", 120 | "\n", 121 | "# here we are assigning all users in the list the same permissions, this could also be a list\n", 122 | "user_permissions = {'write': True,\n", 123 | " 'read': True,\n", 124 | " 'copy': True,\n", 125 | " 'execute': False,\n", 126 | " 'admin': False\n", 127 | " }\n", 128 | "\n", 129 | "for name in user_names:\n", 130 | " my_project.add_member(user = name, permissions = user_permissions)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "## Additional Information\n", 138 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/add-a-member-to-a-project)" 139 | ] 140 | } 141 | ], 142 | "metadata": { 143 | "kernelspec": { 144 | "display_name": "Python 2", 145 | "language": "python", 146 | "name": "python2" 147 | }, 148 | "language_info": { 149 | "codemirror_mode": { 150 | "name": "ipython", 151 | "version": 2 152 | }, 153 | "file_extension": ".py", 154 | "mimetype": "text/x-python", 155 | "name": "python", 156 | "nbconvert_exporter": "python", 157 | "pygments_lexer": "ipython2", 158 | "version": "2.7.11" 159 | } 160 | }, 161 | "nbformat": 4, 162 | "nbformat_minor": 0 163 | } 164 | -------------------------------------------------------------------------------- /Recipes/CGC/projects_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# What are the details of one of my _projects_?\n", 8 | "### Overview\n", 9 | "There are a number of API calls related to projects. Here we focus on _getting the details_ of a single project. As with any **detail**-type call, we will get extensive information about one project but must first know that project's id.\n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 15 | " \n", 16 | "## Imports\n", 17 | "We import the _Api_ class from the official sevenbridges-python bindings below." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import sevenbridges as sbg" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Initialize the object\n", 36 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# [USER INPUT] specify platform {cgc, sbg}\n", 48 | "prof = 'cgc'\n", 49 | "\n", 50 | "config_config_file = sbg.Config(profile=prof)\n", 51 | "api = sbg.Api(config=config_config_file)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## List some projects & get details of one of them\n", 59 | "We start by listing all of your projects, then get more information on the first one. A **detail**-call for projects returns the following *attributes*:\n", 60 | "* **description** The user specified project description\n", 61 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 62 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 63 | "* **href** Address1 of the project.\n", 64 | "* **tags** List of tags, currently tags[0] = 'tcga' if protected data is used on the **CGC**. This does not apply to **SBPLAT**\n", 65 | "* **type** (unimportant) this is _always_ equal to 'v2'\n", 66 | "\n", 67 | "1 This is the address where, by using API you can get this resource" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "outputs": [], 77 | "source": [ 78 | "# [USER INPUT] project index\n", 79 | "p_index = 0\n", 80 | "\n", 81 | "\n", 82 | "existing_projects = [p for p in api.projects.query().all()]\n", 83 | "single_project = api.projects.get(id=existing_projects[p_index].id)\n", 84 | "\n", 85 | "print('You have selected project (%s).' % (single_project.name))\n", 86 | "if hasattr(single_project, 'description'): \n", 87 | " # Need to check if description has been entered, GUI created project have default text, \n", 88 | " # but it is not in the metadata.\n", 89 | " print('Project description: %s \\n' % (single_project.description))\n", 90 | " \n", 91 | "if len(single_project.tags) > 0:\n", 92 | " if single_project.tags[0] == 'tcga':\n", 93 | " print('This is a CONTROLLED data project.')\n", 94 | " else:\n", 95 | " print('This is an OPEN data project.') " 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "## Additional Information\n", 103 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/get-project-details)" 104 | ] 105 | } 106 | ], 107 | "metadata": { 108 | "kernelspec": { 109 | "display_name": "Python 2", 110 | "language": "python", 111 | "name": "python2" 112 | }, 113 | "language_info": { 114 | "codemirror_mode": { 115 | "name": "ipython", 116 | "version": 2 117 | }, 118 | "file_extension": ".py", 119 | "mimetype": "text/x-python", 120 | "name": "python", 121 | "nbconvert_exporter": "python", 122 | "pygments_lexer": "ipython2", 123 | "version": "2.7.11" 124 | } 125 | }, 126 | "nbformat": 4, 127 | "nbformat_minor": 0 128 | } 129 | -------------------------------------------------------------------------------- /Recipes/CGC/projects_listAll.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# What _projects_ am I a member of?\n", 8 | "### Overview\n", 9 | "There are a number of API calls related to projects. Here we focus on listing projects. As with any **list**-type call, we will get minimal information about each project. There are two versions of this call:\n", 10 | "\n", 11 | " 1. (default) **paginated** call that will return 50 projects\n", 12 | " 2. **all-records** call that will page through and return all projects \n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " \n", 18 | "## Imports\n", 19 | "We import the _Api_ class from the official sevenbridges-python bindings below." 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": { 26 | "collapsed": false 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "import sevenbridges as sbg" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "## Initialize the object\n", 38 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": { 45 | "collapsed": true 46 | }, 47 | "outputs": [], 48 | "source": [ 49 | "# [USER INPUT] specify platform {cgc, sbg}\n", 50 | "prof = 'cgc'\n", 51 | "\n", 52 | "config_config_file = sbg.Config(profile=prof)\n", 53 | "api = sbg.Api(config=config_config_file)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "## Get _some_ projects\n", 61 | "We will start with the basic list call. A **list**-call for projects returns the following *attributes*:\n", 62 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 63 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 64 | "* **href** Address1 of the project.\n", 65 | "\n", 66 | "All list API calls will feature pagination, by _default_ 50 items will be returned. We will also show how to specify a different limit and page forward and backwards. \n", 67 | "\n", 68 | "1 This is the address where, by using API you can get this resource" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "collapsed": false 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "# list (up to) 50 projects\n", 80 | "my_projects = api.projects.query()\n", 81 | "\n", 82 | "print(' List of project ids and names:')\n", 83 | "for project in my_projects:\n", 84 | " print('%s \\t %s' % (project.id, project.name))" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": { 91 | "collapsed": false 92 | }, 93 | "outputs": [], 94 | "source": [ 95 | "# use a short query to highlight pagination\n", 96 | "my_projects = api.projects.query(limit=3)\n", 97 | "\n", 98 | "print(' List of first 3 project ids and names:')\n", 99 | "for project in my_projects:\n", 100 | " print('%s \\t %s' % (project.id, project.name))\n", 101 | " \n", 102 | "# method to retrieve the next page of results\n", 103 | "next_page_of_projects = my_projects.next_page()\n", 104 | "\n", 105 | "print('\\n List of next 3 project ids and names:')\n", 106 | "for project in next_page_of_projects:\n", 107 | " print('%s \\t %s' % (project.id, project.name))" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "#### Note\n", 115 | "For the pagination above, we used the **.next_page()** and could have also used the **.prior_page()** methods. These will return another list with an limit equal to the prior call and a offset based on the prior call" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "## Get _all_ projects\n", 123 | "It's probably most useful to know all of your projects. Regardless of the query limit, the project object knows the actual total number of projects. We only need to use the **.all** attribute to get all projects." 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": { 130 | "collapsed": false 131 | }, 132 | "outputs": [], 133 | "source": [ 134 | "existing_projects = my_projects.all()\n", 135 | "\n", 136 | "print(' List of all project ids and names:')\n", 137 | "for project in existing_projects:\n", 138 | " print('%s \\t %s' % (project.id, project.name))" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "### Note\n", 146 | "Each time you do **anything** with this _generator object_, it will become exhausted. The next call will be an empty list" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "metadata": { 153 | "collapsed": false 154 | }, 155 | "outputs": [], 156 | "source": [ 157 | "# NOTE, after each time you operate on the existing_projects generator object, it will become an empty list\n", 158 | "existing_projects = my_projects.all()\n", 159 | "print(existing_projects)\n", 160 | "print('\\n For the first list() operation, there are %i projects in the generator' % (len(list(existing_projects))))\n", 161 | "print(' For the next list() operation, there are %i projects in the generator' % (len(list(existing_projects))))" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "## Additional Information\n", 169 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-all-your-projects)" 170 | ] 171 | } 172 | ], 173 | "metadata": { 174 | "kernelspec": { 175 | "display_name": "Python 2", 176 | "language": "python", 177 | "name": "python2" 178 | }, 179 | "language_info": { 180 | "codemirror_mode": { 181 | "name": "ipython", 182 | "version": 2 183 | }, 184 | "file_extension": ".py", 185 | "mimetype": "text/x-python", 186 | "name": "python", 187 | "nbconvert_exporter": "python", 188 | "pygments_lexer": "ipython2", 189 | "version": "2.7.11" 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 0 194 | } 195 | -------------------------------------------------------------------------------- /Recipes/CGC/projects_makeNew.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# How do I make a new _project_?\n", 8 | "### Overview\n", 9 | "There are a number of API calls related to projects. Here we focus on _creating a **new**_ project. Along the way, we will also show how to [list billing groups](http://docs.cancergenomicscloud.org/docs/list-your-billing-groups).\n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 15 | " \n", 16 | "## Imports\n", 17 | "We import the _Api_ class from the official sevenbridges-python bindings below." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import sevenbridges as sbg" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Initialize the object\n", 36 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# [USER INPUT] specify platform {cgc, sbg}\n", 48 | "prof = 'cgc'\n", 49 | "\n", 50 | "config_config_file = sbg.Config(profile=prof)\n", 51 | "api = sbg.Api(config=config_config_file)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## Make a new project using your first billing group\n", 59 | "We start by listing all of your projects and your billing groups. Next we create the JSON that will be passed to the API to create the project. The dictionary should include:\n", 60 | "* **billing_group** *Billing group* that will be charged for this project\n", 61 | "* **description** (optional) Project description\n", 62 | "* **name** Name of the project, may be *non-unique*1\n", 63 | "* **tags** List of tags, set tags[0] = 'tcga' if you will use *protected data*\n", 64 | "\n", 65 | "**After** creating the project, you can re-check the project list and get *additional* details assigned by the CGC, including:\n", 66 | "\n", 67 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 68 | "* **href** Address2 of the project.\n", 69 | "* **type** (unimportant) this is always equal to 'v2'\n", 70 | "\n", 71 | "1 Please **don't** use non-unique *project names*. However, if you insist (on the GUI), the backend will allow it and assign a unique **id** to you project.\n", 72 | "2 This is the address where, by using API you can get this resource" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": { 79 | "collapsed": false 80 | }, 81 | "outputs": [], 82 | "source": [ 83 | "# [USER INPUT] Set project name here:\n", 84 | "new_project_name = 'Michael Diamond' \n", 85 | " \n", 86 | " \n", 87 | "# What are my funding sources?\n", 88 | "billing_groups = api.billing_groups.query() \n", 89 | "\n", 90 | "# Pick the first group (arbitrary)\n", 91 | "print((billing_groups[0].name + \\\n", 92 | " ' will be charged for computation and storage (if applicable) for your new project'))\n", 93 | "\n", 94 | "# Set up the information for your new project\n", 95 | "new_project = {\n", 96 | " 'billing_group': billing_groups[0].id,\n", 97 | " 'description': \"\"\"A project created by the API recipe (projects_makeNew.ipynb).\n", 98 | " This also supports **markdown**\n", 99 | " _Pretty cool_, right?\n", 100 | " \"\"\",\n", 101 | " 'name': new_project_name, \n", 102 | " 'tags': ['tcga']\n", 103 | "}\n", 104 | "\n", 105 | "# check if this project already exists. LIST all projects and check for name match\n", 106 | "my_project = [p for p in api.projects.query(limit=100).all() \\\n", 107 | " if p.name == new_project_name] \n", 108 | " \n", 109 | "if my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 110 | " print('A project with the name (%s) already exists, please choose a unique name' \\\n", 111 | " % new_project_name)\n", 112 | " raise KeyboardInterrupt\n", 113 | "else:\n", 114 | " # CREATE the new project\n", 115 | " my_project = api.projects.create(name = new_project['name'], \\\n", 116 | " billing_group = new_project['billing_group'], \\\n", 117 | " description = new_project['description'], \\\n", 118 | " tags = new_project['tags'])\n", 119 | " \n", 120 | " # (re)list all projects, and get your new project\n", 121 | " my_project = [p for p in api.projects.query(limit=100).all() \\\n", 122 | " if p.name == new_project_name][0]\n", 123 | "\n", 124 | " print('Your new project %s has been created.' % (my_project.name))\n", 125 | " if hasattr(my_project, 'description'): # need to check if description has been entered\n", 126 | " print('Project description: %s \\n' % (my_project.description))\n", 127 | " \n", 128 | " if my_project.tags[0] == 'tcga':\n", 129 | " print('This is a PROTECTED data project.')\n", 130 | " else:\n", 131 | " print('This is an OPEN data project.') " 132 | ] 133 | }, 134 | { 135 | "cell_type": "markdown", 136 | "metadata": {}, 137 | "source": [ 138 | "## Additional Information\n", 139 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/create-a-new-project)" 140 | ] 141 | } 142 | ], 143 | "metadata": { 144 | "kernelspec": { 145 | "display_name": "Python 2", 146 | "language": "python", 147 | "name": "python2" 148 | }, 149 | "language_info": { 150 | "codemirror_mode": { 151 | "name": "ipython", 152 | "version": 2 153 | }, 154 | "file_extension": ".py", 155 | "mimetype": "text/x-python", 156 | "name": "python", 157 | "nbconvert_exporter": "python", 158 | "pygments_lexer": "ipython2", 159 | "version": "2.7.11" 160 | } 161 | }, 162 | "nbformat": 4, 163 | "nbformat_minor": 0 164 | } 165 | -------------------------------------------------------------------------------- /Recipes/CGC/projects_membersOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Who are the members of one of my _projects_?\n", 8 | "### Overview\n", 9 | "There are a number of API calls related to projects. Here we focus on _getting the members_ of a single project. \n", 10 | "\n", 11 | "### Prerequisites\n", 12 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 13 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 14 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 15 | " \n", 16 | "## Imports\n", 17 | "We import the _Api_ class from the official sevenbridges-python bindings below." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "collapsed": true 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import sevenbridges as sbg" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Initialize the object\n", 36 | "The _Api_ object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "# [USER INPUT] specify platform {cgc, sbg}\n", 48 | "prof = 'cgc'\n", 49 | "\n", 50 | "config_config_file = sbg.Config(profile=prof)\n", 51 | "api = sbg.Api(config=config_config_file)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## List some projects & get members of one of them\n", 59 | "We start by listing all of your projects, then get more information on the first one. A **detail**-call for projects returns the following *attributes*:\n", 60 | "* **description** The user specified project description\n", 61 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 62 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 63 | "* **href** Address1 of the project.\n", 64 | "* **tags** List of tags, currently tags[0] = 'tcga' if protected data is used on the **CGC**. This does not apply to **SBPLAT**\n", 65 | "* **type** (unimportant) this is _always_ equal to 'v2'\n", 66 | "\n", 67 | "1 This is the address where, by using API you can get this resource" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "outputs": [], 77 | "source": [ 78 | "# [USER INPUT] project index\n", 79 | "p_index = 0\n", 80 | "\n", 81 | "\n", 82 | "existing_projects = [p for p in api.projects.query(limit=100).all()]\n", 83 | "project_members = existing_projects[p_index].get_members()\n", 84 | "\n", 85 | "print('The selected project (%s) has %i members:' % \\\n", 86 | " (existing_projects[p_index].name, len(project_members)))\n", 87 | "\n", 88 | "for member in project_members:\n", 89 | " if member.permissions[\"admin\"]:\n", 90 | " print('\\t User %s is a project ADMIN' % (member.username))\n", 91 | " else:\n", 92 | " print('\\t User %s is a project MEMBER' % (member.username))" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "### Note\n", 100 | "Each time you do **anything** with this _generator object_, it will become exhausted. The next operation on project\\_members will show an empty list" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "## Additional Information\n", 108 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-members-of-a-project)" 109 | ] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "Python 2", 115 | "language": "python", 116 | "name": "python2" 117 | }, 118 | "language_info": { 119 | "codemirror_mode": { 120 | "name": "ipython", 121 | "version": 2 122 | }, 123 | "file_extension": ".py", 124 | "mimetype": "text/x-python", 125 | "name": "python", 126 | "nbconvert_exporter": "python", 127 | "pygments_lexer": "ipython2", 128 | "version": "2.7.12" 129 | } 130 | }, 131 | "nbformat": 4, 132 | "nbformat_minor": 0 133 | } 134 | -------------------------------------------------------------------------------- /Recipes/CGC/readme.md: -------------------------------------------------------------------------------- 1 | # API Recipes for the Cancer Genomics Cloud (CGC) 2 | Our goals were to 3 | 4 | * Educate users about how the API works by using a friendly Python wrapper 5 | * Provide re-usable blocks of API code to solve common problems 6 | 7 | We also wanted to: 8 | 9 | * Use open access files 10 | * Show both the _wrapped_ calls and _more raw_ calls which more closely match our extensive [documentation](http://docs.cancergenomicscloud.org/docs/the-cgc-api) 11 | 12 | ## How does the CGC work? 13 | An important first concept is how the CGC (and SBPLAT) works. A user has access to multiple **projects**, she may either be the owner of those projects or a member of someone else's project. Within each project, there is a collection of **files** and **apps**. The owner can combine a set of files, configuration inputs, and an app to generate a **task**. Once this task is complete, any **output files** will be put into 14 | the project where the task was started. 15 | 16 | ![CGC Overview](images/CGC_overview-02.png) 17 | 18 | ## Recipes in this cookbook 19 | 20 | Each of the main components in the CGC is accessible by the API. These recipes are _purposefully_ repetitive to highlight the logic of the API and hopefully help users understand some of the tools available to solve problems. The current _cookbook_ includes1 21 | 22 | * Projects 23 | * list [projects_listsAll.ipynb] 24 | * get details [projects_detailOne.ipynb] 25 | * get members [projects_membersOne.ipynb] 26 | * add members [projects_addMembers.ipynb] 27 | * make new [projects_makeNew.ipynb] 28 | 29 | * Files 30 | * list (_within a project_) [files_listAll.ipynb] 31 | * get details [files_detailOne.ipynb] 32 | * copy Public Reference file [files_copyFromMyProject.ipynb] 33 | * copy from another project [files_copyFromPublicReference.ipynb] 34 | 35 | * Apps 36 | * list [apps_listAll.ipynb] 37 | * get details [apps_detailOne.ipynb] 38 | * copy from Public Apps [apps_copyFromPublicApps.ipynb] 39 | * copy from another project [apps_copyFromMyProject.ipynb] 40 | 41 | * Tasks 42 | * create and start [tasks_create.ipynb] 43 | * monitor & get outputs [tasks_monitorAndGetResults.ipynb] 44 | 45 | ### Notes 46 | We ask that you limit parallel tasks to **300** at a time. If you need to run more, that is **great**, but please get in touch with us so we don't _run out of cloud_. 47 | 48 | 1 We are happy to add more cookbooks, please request what helps you most effectively get stuff done. Already in the queue are: 49 | 50 | * Files 51 | * list (_within a project_ and _matching metadata properties_) [files_listByMetadata.ipynb] 52 | 53 | * [files_makeProcessingList]. A way to screen through the metadata on all the files in your project. Can be passed to a (or a batch of) task(s) 54 | * [files_uploadViaAPI] New functionality to add files to the CGC via the API 55 | * [files_setMetadata] Create or adapt the metadata of a (non-TCGA) file on the CGC. **see also** _Tutorials/SBPLAT/quickstart_RNAseq.ipynb_ for an example of this 56 | 57 | ### Extra Pictures of API calls 58 | ![Projects LIST](images/projects_listAll-01.png) 59 | ![Project DETAIL](images/projects_getDetails-01.png) 60 | ![Project DETAIL](images/projects_getDetails-01.png) 61 | ![Project Create](images/projects_addNew-01.png) -------------------------------------------------------------------------------- /Recipes/SBPLAT/Setup_API_environment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How to setup Seven Bridges Public API python library\n", 11 | "## Overview\n", 12 | "Here you will learn the three possible ways to setup Seven Bridges Public API Python library.\n", 13 | "\n", 14 | "## Prerequisites\n", 15 | "\n", 16 | "1. You need to install _sevenbridges-python_ library. Library details are available [here](http://sevenbridges-python.readthedocs.io/en/latest/sevenbridges/)\n", 17 | "\n", 18 | " The easiest way to install sevenbridges-python is using pip:\n", 19 | "\n", 20 | " $ pip install sevenbridges-python\n", 21 | "\n", 22 | " Alternatively, you can get the code. sevenbridges-python is actively developed on GitHub, where the [code](https://github.com/sbg/sevenbridges-python) is always available. To clone the public repository :\n", 23 | "\n", 24 | " $ git clone git://github.com/sbg/sevenbridges-python.git\n", 25 | "\n", 26 | " Once you have a copy of the source, you can embed it in your Python\n", 27 | " package, or install it into your site-packages by invoking:\n", 28 | "\n", 29 | " $ python setup.py install\n", 30 | "\n", 31 | "2. You need your _authentication token_ which you can get [here](https://igor.sbgenomics.com/developer/token)\n", 32 | "\n", 33 | " \n", 34 | "### Notes and Compatibility\n", 35 | "\n", 36 | "Python package is intended to be used with Python 3.6+ versions." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": false, 44 | "deletable": true, 45 | "editable": true, 46 | "jupyter": { 47 | "outputs_hidden": false 48 | } 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "# Import the library\n", 53 | "import sevenbridges as sbg" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "deletable": true, 60 | "editable": true 61 | }, 62 | "source": [ 63 | "### Initialize the library\n", 64 | "\n", 65 | "You can initialize the library explicitly or by supplying the necessary information in the $HOME/.sevenbridges/credentials file\n", 66 | "\n", 67 | "There are generally three ways to initialize the library:\n", 68 | " 1. Explicitly, when calling api constructor, like:\n", 69 | " ``` python\n", 70 | " api = sbg.Api(url='https://api.sbgenomics.com/v2', token='MY AUTH TOKEN')\n", 71 | " ```\n", 72 | " \n", 73 | " 2. By using OS environment to store the url and authentication token\n", 74 | " ```\n", 75 | " export AUTH_TOKEN=\n", 76 | " export API_ENDPOINT='https://api.sbgenomics.com/v2'\n", 77 | " ```\n", 78 | " 3. By using ini file $HOME/.sevenbridges/credentials (for MS Windows, the file should be located in \\%UserProfile\\%.sevenbridges\\credentials) and specifying a profile to use. The format of the credentials file is standard ini file format, as shown below:\n", 79 | "\n", 80 | " ```bash\n", 81 | " [sbpla]\n", 82 | " api_endpoint = https://api.sbgenomics.com/v2\n", 83 | " auth_token = 700992f7b24a470bb0b028fe813b8100\n", 84 | "\n", 85 | " [cgc]\n", 86 | " api_endpoint = https://cgc-api.sbgenomics.com/v2\n", 87 | " auth_token = 910975f5b24a470bb0b028fe813b8100\n", 88 | " ```\n", 89 | " \n", 90 | " 0. to **create** this file1, use the following steps in your _Terminal_:\n", 91 | " 1.\n", 92 | " ```bash\n", 93 | " cd ~\n", 94 | " mkdir .sevenbridges\n", 95 | " touch .sevenbridges/credentials\n", 96 | " vi .sevenbridges/credentials\n", 97 | " ```\n", 98 | " 2. Press \"i\" then enter to go into **insert mode**\n", 99 | " 3. write the text above for each environment. \n", 100 | " 4. Press \"ESC\" then type \":wq\" to save the file and exit vi\n", 101 | " \n", 102 | "1 If the file already exists, omit the _touch_ command" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": { 108 | "deletable": true, 109 | "editable": true 110 | }, 111 | "source": [ 112 | "### Test if you have stored the token correctly\n", 113 | "Below are the three options presented above, test **one** of them. Logically, if you have only done **Step 3**, then testing **Step 2** will return an error." 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": { 120 | "collapsed": false, 121 | "deletable": true, 122 | "editable": true, 123 | "jupyter": { 124 | "outputs_hidden": false 125 | } 126 | }, 127 | "outputs": [], 128 | "source": [ 129 | "# (1.) You can also instantiate library by explicitly \n", 130 | "# specifying API url and authentication token\n", 131 | "api_explicitly = sbg.Api(url='https://api.sbgenomics.com/v2',\n", 132 | " token='')\n", 133 | "api_explicitly.users.me()" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": { 140 | "collapsed": false, 141 | "deletable": true, 142 | "editable": true, 143 | "jupyter": { 144 | "outputs_hidden": false 145 | } 146 | }, 147 | "outputs": [], 148 | "source": [ 149 | "# (2.) If you have not specified profile, the python-sbg library \n", 150 | "# will search for configuration in the environment\n", 151 | "c = sbg.Config()\n", 152 | "api_via_environment = sbg.Api(config=c)\n", 153 | "api_via_environment.users.me()" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": { 160 | "collapsed": false, 161 | "deletable": true, 162 | "editable": true, 163 | "jupyter": { 164 | "outputs_hidden": false 165 | } 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "# (3.) If you have credentials setup correctly, you only need to specify the profile\n", 170 | "config_file = sbg.Config(profile='default')\n", 171 | "api_via_ini_file = sbg.Api(config=config_file)\n", 172 | "api_via_ini_file.users.me()" 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": { 178 | "deletable": true, 179 | "editable": true 180 | }, 181 | "source": [ 182 | "#### PROTIP\n", 183 | "* We _recommend_ the approach with configuration file (the **.sevenbridges/credentials** file in option #3), especially if you are using multiple environments (like SBPLA and CGC)." 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "kernelspec": { 189 | "display_name": "Python 3", 190 | "language": "python", 191 | "name": "python3" 192 | }, 193 | "language_info": { 194 | "codemirror_mode": { 195 | "name": "ipython", 196 | "version": 3 197 | }, 198 | "file_extension": ".py", 199 | "mimetype": "text/x-python", 200 | "name": "python", 201 | "nbconvert_exporter": "python", 202 | "pygments_lexer": "ipython3", 203 | "version": "3.8.3" 204 | } 205 | }, 206 | "nbformat": 4, 207 | "nbformat_minor": 4 208 | } 209 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/apps_copyFromMyProject.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I _copy_ an app from one of my other _projects_?\n", 11 | "## Overview\n", 12 | "Apps include both tools (individual bioinformatics utilities) and workflows (chains or pipelines of connected tools). Apps are located in one of two places: the [Seven Bridges Public Apps repository](https://igor.sbgenomics.com/public/apps) or a user-created project.\n", 13 | "\n", 14 | "## Objective\n", 15 | "You can copy an app from the Public App repository or from a project of which you're a member. Here, we focus on **copying an app from another project**. [[reference](http://docs.sevenbridges.com/docs/copy-an-app)]\n", 16 | "\n", 17 | "## Procedure\n", 18 | "1. We'll define the project and app IDs\n", 19 | "2. We'll copy an app to the destination project.\n", 20 | "\n", 21 | "## Prerequisites\n", 22 | " 1. You need to be a member (or owner) of at least two projects, one with the app that should be copied and another one where the app needs to be copied to. Learn more about creating a new project. [[recipe](projects_makeNew.ipynb)] [[reference](http://docs.sevenbridges.com/docs/create-a-new-project)].\n", 23 | " 2. You need your **authentication token** and the API needs to know about it. See Setup_API_environment.ipynb for details. Learn more about [obtaining your authentication token](http://docs.sevenbridges.com/v1.0/docs/get-your-authentication-token).\n", 24 | " 3. You have at least one app in one project. If not, you can copy one from the Public Apps repository. [[recipe](apps_copyFromPublicApps.ipynb)] [[reference](http://docs.sevenbridges.com/docs/copy-an-app)]\n", 25 | " 4. You can find app and project ID. We can find entity IDs via API or on the platform visual interface. [[reference](https://docs.sevenbridges.com/docs/the-api#identifying-projects-users-apps-files-tasks-and-inputs)]\n", 26 | " 5. You understand how to list apps within a project. We will use this call below and find the copied app. [[recipe](apps_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-apps-available-to-you)]\n", 27 | " \n", 28 | "Note that as with all okAPI recipes, this recipe makes use of the [Seven Bridges Public API Python library](../Tutorials/SBPLAT/Setup_API_environment.ipynb)\n", 29 | " \n", 30 | "## Imports\n", 31 | "We import the `Api` class from the official `sevenbridges-python` bindings below. \n", 32 | "We also import the `Conflict` error to handle situations when trying to copy over an existing app." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "collapsed": false, 40 | "deletable": true, 41 | "editable": true, 42 | "jupyter": { 43 | "outputs_hidden": false 44 | } 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "import sevenbridges as sbg\n", 49 | "from sevenbridges.errors import Conflict" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": { 55 | "deletable": true, 56 | "editable": true 57 | }, 58 | "source": [ 59 | "## Initialize the object\n", 60 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": { 67 | "collapsed": false, 68 | "deletable": true, 69 | "editable": true, 70 | "jupyter": { 71 | "outputs_hidden": false 72 | } 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 77 | "prof = 'default'\n", 78 | "\n", 79 | "config_file = sbg.Config(profile=prof)\n", 80 | "api = sbg.Api(config=config_file)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": { 86 | "deletable": true, 87 | "editable": true 88 | }, 89 | "source": [ 90 | "## Copy an app you can access\n", 91 | "First, we'll define which app we want to copy and to which project. Then, we'll try to copy an app to the second project. (Note that here you can also choose to copy a specific version of the app, by changing the last fragment of the `app_id` variable to the version you want).\n", 92 | "\n", 93 | "The critical information for this `POST` request is the **app_id**. Note, you are **not** allowed to copy the same app **and** assign the same name1 more than once. If you change the name, it is ok. \n", 94 | "\n", 95 | "To make these results very obvious, use an empty project as your my\\_project (e.g. your cookbook example project) or add the _name_ arguement to something ridiculous like 'Orange Mocha Frapachino Maker'. In this example, we will handle these situations with a predefined error `Conflict` for this situation.\n", 96 | "\n", 97 | "1 Note that setting the **name** of a copied app defines the app **id**, which must be unique on the platform. Saving over an existing ID will raise a `Conflict` error." 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": { 104 | "collapsed": false, 105 | "deletable": true, 106 | "editable": true, 107 | "jupyter": { 108 | "outputs_hidden": false 109 | } 110 | }, 111 | "outputs": [], 112 | "source": [ 113 | "# [USER INPUT] Set destination_project_id and app_id here:\n", 114 | "\n", 115 | "# Set project ID in format 'user-name/project-name' or in enterprise mode 'division-name/project-name'\n", 116 | "destination_project_id = 'username/destination-project-name'\n", 117 | "# Set app ID in format 'user-name/project-name/app-name/revision' or in division context `division-name/project-name/app-name/revision'\n", 118 | "# Omitting the revision will use the latest revision of the app\n", 119 | "app_id = 'username/source-project-name/graf-germline-variant-detection-workflow-1-0/1' \n", 120 | "\n", 121 | "# Get the app and the project and try to copy the app\n", 122 | "source_app = api.apps.get(app_id)\n", 123 | "destination_project = api.projects.get(destination_project_id)\n", 124 | "try:\n", 125 | " new_app = source_app.copy(project=destination_project_id)\n", 126 | " print('App {} copied to Project {}.'.format(source_app.name, destination_project.name))\n", 127 | "except Conflict:\n", 128 | " new_app = [a for a in api.apps.query(project=destination_project_id) if a.name == source_app.name][0]\n", 129 | " print('App already exists in the destination project, reusing existing app.')\n", 130 | "\n", 131 | "# re-list apps in target project to verify the copy worked\n", 132 | "my_app_names = [a.name for a in api.apps.query(\n", 133 | " project=destination_project_id, limit=100\n", 134 | ").all()]\n", 135 | " \n", 136 | "if source_app.name in my_app_names:\n", 137 | " print('Sucessfully copied or reused one app!')\n", 138 | "else:\n", 139 | " print('Something went wrong...') " 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": { 145 | "deletable": true, 146 | "editable": true 147 | }, 148 | "source": [ 149 | "## Additional Information\n", 150 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/copy-an-app)." 151 | ] 152 | } 153 | ], 154 | "metadata": { 155 | "kernelspec": { 156 | "display_name": "Python 3", 157 | "language": "python", 158 | "name": "python3" 159 | }, 160 | "language_info": { 161 | "codemirror_mode": { 162 | "name": "ipython", 163 | "version": 3 164 | }, 165 | "file_extension": ".py", 166 | "mimetype": "text/x-python", 167 | "name": "python", 168 | "nbconvert_exporter": "python", 169 | "pygments_lexer": "ipython3", 170 | "version": "3.8.3" 171 | } 172 | }, 173 | "nbformat": 4, 174 | "nbformat_minor": 4 175 | } 176 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/apps_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# What are the details of one of my _apps_?\n", 11 | "## Overview\n", 12 | "Obtaining a single app's details is an important step for starting a task. The app, which can be either a tool or a workflow, should be one located in a project that you can access. This could be an app that has been uploaded to the Seven Bridges Platform by a project member, or a publicly available app that has been copied to the project. \n", 13 | "\n", 14 | "As with any **detail**-type call, we will get extensive information about one app. However, we must first obtain that app's id. \n", 15 | "\n", 16 | "## Objective\n", 17 | "\n", 18 | "In this recipe we focus on **getting the details** from a single app. [[reference](http://docs.sevenbridges.com/v1.0/docs/get-details-of-an-app)]\n", 19 | "\n", 20 | "## Procedure\n", 21 | "1. We'll list all our projects. [[recipe](projects_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-your-projects)]\n", 22 | "2. Then, we'll list the apps within the first project on the list generated above. [[recipe](apps_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-apps-available-to-you)]\n", 23 | "3. Lastly, we'll get the details for the first app in that project. [[reference](http://docs.sevenbridges.com/v1.0/docs/get-details-of-an-app)]\n", 24 | "\n", 25 | "## Prerequisites\n", 26 | " 1. You need to be a member (or owner) of at least one project. Learn more about creating a new project. [[recipe](projects_makeNew.ipynb)] [[reference](http://docs.sevenbridges.com/docs/create-a-new-project)].\n", 27 | " 2. You need your **authentication token** and the API needs to know about it. See Setup_API_environment.ipynb for details. Learn more about [obtaining your authentication token](http://docs.sevenbridges.com/v1.0/docs/get-your-authentication-token).\n", 28 | " 3. You understand how to list projects of which you are a member. We will use this call directly to select a project below. [[recipe](projects_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-your-projects)]\n", 29 | " 4. You have at least one app in your selected project. If not, you can copy one from the Public Apps repository. [[recipe](apps_copyFromPublicApps.ipynb)] [[reference](http://docs.sevenbridges.com/docs/copy-an-app)]\n", 30 | " 5. You understand how to list apps within a project. We will use this call below and select an app. Note that this is a great place to get the **app_id** you will need in this recipe. [[recipe](apps_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-apps-available-to-you)]\n", 31 | " \n", 32 | "Note that as with all okAPI recipes, this recipe makes use of the [Seven Bridges Public API Python library](../Tutorials/SBPLAT/Setup_API_environment.ipynb).\n", 33 | " \n", 34 | " \n", 35 | "## Imports\n", 36 | "We import the `Api` class from the official `sevenbridges-python` bindings below." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": false, 44 | "deletable": true, 45 | "editable": true, 46 | "jupyter": { 47 | "outputs_hidden": false 48 | } 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "import sevenbridges as sbg" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": { 58 | "deletable": true, 59 | "editable": true 60 | }, 61 | "source": [ 62 | "## Initialize the object\n", 63 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the .sbgrc file in your home directory. For other options see Setup_API_environment.ipynb." 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": { 70 | "deletable": true, 71 | "editable": true 72 | }, 73 | "outputs": [], 74 | "source": [ 75 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 76 | "prof = 'default'\n", 77 | "\n", 78 | "config_file = sbg.Config(profile=prof)\n", 79 | "api = sbg.Api(config=config_file)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": { 85 | "deletable": true, 86 | "editable": true 87 | }, 88 | "source": [ 89 | "## Dig into your app\n", 90 | "First, we list all of your projects. Then, we list the apps within the first one. Lastly, we obtain the details for the first app in that list. A **detail**-call for an app returns the following attributes:\n", 91 | "* **`id`,** the unique identifier for the app\n", 92 | "* **`name`,** the name of the app. Note this **is metadata and can be changed**.\n", 93 | "* **`href`,** the address1 of the app\n", 94 | "* **`raw`,** the details of the app described with the [Common Workflow Language standard](https://www.commonwl.org/)2 \n", 95 | "* **`project`,** the project the app is in\n", 96 | "* **`revision`,** the specific revision number of the app\n", 97 | "\n", 98 | "1 This is the address where, by using API you can get this resource\n", 99 | "\n", 100 | "2 The raw app description also includes some Seven Bridges extensions marged with `sbg:`. These extensions don't affect app portability." 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": { 107 | "collapsed": false, 108 | "deletable": true, 109 | "editable": true, 110 | "jupyter": { 111 | "outputs_hidden": false 112 | } 113 | }, 114 | "outputs": [], 115 | "source": [ 116 | "# [USER INPUT] Set project name:\n", 117 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 118 | "project_name = 'My project name' \n", 119 | "a_name = 'GRAF Germline Variant Detection Workflow'\n", 120 | "\n", 121 | "\n", 122 | "# list all projects and get the first one\n", 123 | "my_project = api.projects.query(name=project_name)\n", 124 | "\n", 125 | "\n", 126 | "# list the apps in ONE project\n", 127 | "my_apps = api.apps.query(project = my_project.id, limit=100).all()\n", 128 | "\n", 129 | "# get details of the app\n", 130 | "single_app = [a for a in my_apps if a.name == a_name][0]\n", 131 | "\n", 132 | "print('You have selected app (%s), which was created by (%s). \\n\\nIt has %i inputs:' % \\\n", 133 | " (single_app.name, single_app.raw['sbg:createdBy'], len(single_app.raw['inputs'])))\n", 134 | "for ii in single_app.raw['inputs']:\n", 135 | " print(ii['id'].lstrip('#'))" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": { 141 | "deletable": true, 142 | "editable": true 143 | }, 144 | "source": [ 145 | "## Additional Information\n", 146 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/get-details-of-an-app). Conversely, if you're looking for the raw CWL of an app, see the documentation [here](http://docs.sevenbridges.com/docs/get-raw-cwl-for-an-app)." 147 | ] 148 | } 149 | ], 150 | "metadata": { 151 | "kernelspec": { 152 | "display_name": "Python 3", 153 | "language": "python", 154 | "name": "python3" 155 | }, 156 | "language_info": { 157 | "codemirror_mode": { 158 | "name": "ipython", 159 | "version": 3 160 | }, 161 | "file_extension": ".py", 162 | "mimetype": "text/x-python", 163 | "name": "python", 164 | "nbconvert_exporter": "python", 165 | "pygments_lexer": "ipython3", 166 | "version": "3.8.3" 167 | } 168 | }, 169 | "nbformat": 4, 170 | "nbformat_minor": 4 171 | } 172 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/apps_listAll.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Which _apps_ are in my project?\n", 11 | "## Overview\n", 12 | "You can lists all apps available to you on the Platform. By default, all of the apps within your project(s) are returned to you. You can also choose to only list the apps within a specific project. Conversely, you can set the parameter `visibility=public` to list all apps available to you from the Seven Bridges' [Public Apps repository](http://docs.sevenbridges.com/v1.0/docs/public-apps) of tools and workflows. \n", 13 | "\n", 14 | "More generally, as with any **list**-type call, we will get minimal information about each app. There are two versions of this call:\n", 15 | "\n", 16 | " 1. (default) A **paginated** call that will return 50 apps.\n", 17 | " 2. An **all-records** call that will page through and return all apps.\n", 18 | "\n", 19 | "## Objective\n", 20 | "Here we focus on **listing all apps within one project**. [[reference](http://docs.sevenbridges.com/docs/list-all-apps-available-to-you)]\n", 21 | "\n", 22 | "## Procedure\n", 23 | "1. We'll list all our projects.\n", 24 | "2. Then, we'll list the apps within the first project on the list generated above.\n", 25 | "3. Lastly, we'll list all apps within any of our projects by not specifying a project ID in our request.\n", 26 | "\n", 27 | "## Prerequisites\n", 28 | " 1. You need to be a member (or owner) of at least one project. Learn more about creating a new project. [[recipe](projects_makeNew.ipynb)] [[reference](http://docs.sevenbridges.com/docs/create-a-new-project)].\n", 29 | " 2. You need your **authentication token** and the API needs to know about it. See Setup_API_environment.ipynb for details. Learn more about [obtaining your authentication token](http://docs.sevenbridges.com/v1.0/docs/get-your-authentication-token).\n", 30 | " 3. You understand how to list projects of which you are a member. We will use this call directly to select a project below. [[recipe](projects_listAll.ipynb)] [[reference](http://docs.sevenbridges.com/docs/list-all-your-projects)]\n", 31 | " 4. You have at least one app in your selected project. If not, you can copy one from the Public Apps repository. [[recipe](apps_copyFromPublicApps.ipynb)] [[reference](http://docs.sevenbridges.com/docs/copy-an-app)]\n", 32 | "\n", 33 | "Note that as with all okAPI recipes, this recipe makes use of the [Seven Bridges Public API Python library](../Tutorials/SBPLAT/Setup_API_environment.ipynb).\n", 34 | " \n", 35 | "## Imports\n", 36 | "We import the `Api` class from the official `sevenbridges-python` bindings below." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "deletable": true, 44 | "editable": true 45 | }, 46 | "outputs": [], 47 | "source": [ 48 | "import sevenbridges as sbg" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": { 54 | "deletable": true, 55 | "editable": true 56 | }, 57 | "source": [ 58 | "## Initialize the object\n", 59 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": { 66 | "deletable": true, 67 | "editable": true 68 | }, 69 | "outputs": [], 70 | "source": [ 71 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 72 | "prof = 'default'\n", 73 | "\n", 74 | "config_file = sbg.Config(profile=prof)\n", 75 | "api = sbg.Api(config=config_file)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": { 81 | "deletable": true, 82 | "editable": true 83 | }, 84 | "source": [ 85 | "## List all apps within a project\n", 86 | "Here we can return the apps in a specific project or all the apps in projects of which you are a member. A **list**-call for apps returns the following useful *attributes*:\n", 87 | "* **`id`,** the *unique* identifier for each app, including the latest version number\n", 88 | "* **`name`,** the name of the app, which maybe _non-unique_\n", 89 | "* **`project`,** the project the app is in.\n", 90 | "* **`href`,** the address1 of the app.\n", 91 | "\n", 92 | "1 This is the address where, by using API, you can get this resource" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": { 98 | "deletable": true, 99 | "editable": true 100 | }, 101 | "source": [ 102 | "By passing a `project_id` into the `api.apps.query()` below, we will get the apps **inside that project**." 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "collapsed": false, 110 | "deletable": true, 111 | "editable": true, 112 | "jupyter": { 113 | "outputs_hidden": false 114 | } 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "# [USER INPUT] Set project name:\n", 119 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 120 | "project_name = 'test shellquote'\n", 121 | "\n", 122 | "\n", 123 | "# LIST all projects and check for name match\n", 124 | "my_project = api.projects.query(limit=100, name=project_name)\n", 125 | "\n", 126 | "if not my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 127 | " print('The project named (%s) does not exist, please check spelling (especially trailing spaces)' \\\n", 128 | " % project_name)\n", 129 | " raise KeyboardInterrupt\n", 130 | "else:\n", 131 | " my_project = my_project[0]\n", 132 | " \n", 133 | " # list the apps in my project \n", 134 | " my_apps = api.apps.query(project=my_project.id, limit=100)\n", 135 | " print(' In project {}, you have {} apps.'.format(\n", 136 | " my_project.name, my_apps.total))\n", 137 | "\n", 138 | " for a in my_apps.all(): \n", 139 | " print('App name: {}; \\t App id: {}\\n'.format(\n", 140 | " a.name, a.id))" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": { 146 | "deletable": true, 147 | "editable": true 148 | }, 149 | "source": [ 150 | "By **not** passing a `project_id` into the `api.apps.query()` below, we will get all the apps for **any project** of which you are a member." 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": { 157 | "collapsed": false, 158 | "deletable": true, 159 | "editable": true, 160 | "jupyter": { 161 | "outputs_hidden": false 162 | } 163 | }, 164 | "outputs": [], 165 | "source": [ 166 | "# list the app in ALL your projects.\n", 167 | "my_apps_all_projects = api.apps.query(limit=100)\n", 168 | "\n", 169 | "print(' In ALL your projects, you have {} apps.'.format(\n", 170 | " my_apps_all_projects.total))\n", 171 | "\n", 172 | "for a in my_apps_all_projects.all(): \n", 173 | " print('App name: {}; \\t App id: {}\\n'.format(\n", 174 | " a.name, a.id))" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": { 180 | "deletable": true, 181 | "editable": true 182 | }, 183 | "source": [ 184 | "## Additional Information\n", 185 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/list-all-apps-available-to-you)." 186 | ] 187 | } 188 | ], 189 | "metadata": { 190 | "kernelspec": { 191 | "display_name": "Python 3", 192 | "language": "python", 193 | "name": "python3" 194 | }, 195 | "language_info": { 196 | "codemirror_mode": { 197 | "name": "ipython", 198 | "version": 3 199 | }, 200 | "file_extension": ".py", 201 | "mimetype": "text/x-python", 202 | "name": "python", 203 | "nbconvert_exporter": "python", 204 | "pygments_lexer": "ipython3", 205 | "version": "3.8.3" 206 | } 207 | }, 208 | "nbformat": 4, 209 | "nbformat_minor": 4 210 | } 211 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_copyFromMyProject.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I _copy_ a file from another one of _my projects_?\n", 11 | "### Overview\n", 12 | "Files can be copied from one of two sources:\n", 13 | "1. other projects you are a member of\n", 14 | "2. public reference. \n", 15 | "\n", 16 | "Here we focus on copying a file from _your own project_. \n", 17 | "\n", 18 | "### Prerequisites\n", 19 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 20 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 21 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 22 | " 4. You understand how to list files within one of your projects (we will just use that call directly here).\n", 23 | "\n", 24 | "### Warning\n", 25 | "You are only permitted to copy a file from a `controlled` project to a _target project_ if that project is also a `controlled` project.\n", 26 | "\n", 27 | "## Imports\n", 28 | "We import the _Api_ class from the official sevenbridges-python bindings below." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "deletable": true, 36 | "editable": true 37 | }, 38 | "outputs": [], 39 | "source": [ 40 | "import sevenbridges as sbg" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": { 46 | "deletable": true, 47 | "editable": true 48 | }, 49 | "source": [ 50 | "## Initialize the object\n", 51 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": null, 57 | "metadata": { 58 | "deletable": true, 59 | "editable": true 60 | }, 61 | "outputs": [], 62 | "source": [ 63 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 64 | "prof = 'default'\n", 65 | "\n", 66 | "config_file = sbg.Config(profile=prof)\n", 67 | "api = sbg.Api(config=config_file)" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": { 73 | "deletable": true, 74 | "editable": true 75 | }, 76 | "source": [ 77 | "## Copy a file from another project\n", 78 | "We will first find our _source\\_project_ and _my\\_project_ (target), then list the files within the source project, and copy a file from **_source\\_project_ -> _destination\\_project_**.\n", 79 | "\n", 80 | "The critical information for this POST is the **file_id**. Note, you are allowed to copy the same file as many times as you like. However, duplicates will be automatically have a prefix attached of (\\_1\\_, \\_2\\_, etc) depending on how many times you copy the file.\n", 81 | "\n", 82 | "To make these results very obvious, use an empty project as your destination\\_project (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome.copy'\n", 83 | "\n", 84 | "---\n", 85 | "**NOTE**\n", 86 | "The file listing method does not list files in subfolders, only the files and folders in root of the project are listed\n", 87 | "\n", 88 | "---" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": { 95 | "collapsed": false, 96 | "deletable": true, 97 | "editable": true, 98 | "jupyter": { 99 | "outputs_hidden": false 100 | } 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "# [USER INPUT] Set source project id, destination project id and file index here:\n", 105 | "source_project_id = 'username/source-project' \n", 106 | "destination_project_id = 'username/destination-project'\n", 107 | "f_index = # file to copy, here we take the first file from the source project\n", 108 | "\n", 109 | "\n", 110 | "# Find TARGET and YOUR projects\n", 111 | "source_project = api.projects.get(source_project_id)\n", 112 | "destination_project = api.projects.get(destination_project_id)\n", 113 | "\n", 114 | "# LIST all files in the source project and pick the first one\n", 115 | "source_files = api.files.query(limit=100, project=source_project)\n", 116 | "source_file = source_files[f_index]\n", 117 | "\n", 118 | "# LIST all files in the destination project. We add the names parameter to only list file with the source file name\n", 119 | "destination_files = list(api.files.query(limit=100, project=destination_project, names=[source_file.name]))\n", 120 | "\n", 121 | "# Check if first file already exists in the target project\n", 122 | "if destination_files:\n", 123 | " print('File already exists in second project, skipping.')\n", 124 | "else:\n", 125 | " print('File {} does not exist in project {}; copying now.'.format(\n", 126 | " source_file_names[f_index], destination_project.id))\n", 127 | " \n", 128 | " \n", 129 | " my_new_file = source_file.copy(project=destination_project.id,\n", 130 | " name=source_file.name)\n", 131 | "\n", 132 | " # re-list files in target project to verify the copy worked\n", 133 | " my_files = [f.name for f in api.files.query(\n", 134 | " limit=100, project=destination_project.id).all()]\n", 135 | " \n", 136 | " if source_file.name in my_files:\n", 137 | " print('Sucessfully copied one file!')\n", 138 | " else:\n", 139 | " print('Something went wrong...')" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": { 145 | "deletable": true, 146 | "editable": true 147 | }, 148 | "source": [ 149 | "## Additional Information\n", 150 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/copy-a-file)" 151 | ] 152 | } 153 | ], 154 | "metadata": { 155 | "kernelspec": { 156 | "display_name": "Python 3", 157 | "language": "python", 158 | "name": "python3" 159 | }, 160 | "language_info": { 161 | "codemirror_mode": { 162 | "name": "ipython", 163 | "version": 3 164 | }, 165 | "file_extension": ".py", 166 | "mimetype": "text/x-python", 167 | "name": "python", 168 | "nbconvert_exporter": "python", 169 | "pygments_lexer": "ipython3", 170 | "version": "3.8.3" 171 | } 172 | }, 173 | "nbformat": 4, 174 | "nbformat_minor": 4 175 | } 176 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_copyFromPublicReference.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I _copy_ a file from the _Public Reference_ files?\n", 11 | "### Overview\n", 12 | "Files can be copied from other projects you are a member of or from the public reference files page. Here we focus on copying a file from _public reference files_ page.\n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 18 | " \n", 19 | "## Imports\n", 20 | "We import the _Api_ class from the official sevenbridges-python bindings below." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "deletable": true, 28 | "editable": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "import sevenbridges as sbg" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "deletable": true, 39 | "editable": true 40 | }, 41 | "source": [ 42 | "## Initialize the object\n", 43 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "deletable": true, 51 | "editable": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 56 | "prof = 'default'\n", 57 | "\n", 58 | "config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "deletable": true, 66 | "editable": true 67 | }, 68 | "source": [ 69 | "## Copy a file from the Public Reference\n", 70 | "We will first find our _source\\_project_ (the Public Reference Files), then list the files within the source project1, and copy a file from **_source\\_project_ -> _my\\_project_**.\n", 71 | "\n", 72 | "The critical information for this POST is the **file_id**. Note, you are allow to copy the same file as many times as you like. However, duplicates will be automatically have a prefix attached of (\\_1\\_, \\_2\\_, etc) depending on how many times you copy the file.\n", 73 | "\n", 74 | "To make these results very obvious, use an empty project as your MY\\_PROJECT (e.g. your cookbook example project) or change the _name_ in the _data_ dictionary to something like 'Dept of Awesome.copy'\n", 75 | "\n", 76 | "---\n", 77 | "**NOTE**\n", 78 | "The file listing method does not list files in subfolders, only the files and folders in root of the project are listed\n", 79 | "\n", 80 | "---\n", 81 | "\n", 82 | "1 Files are only accessible **within** a project - here the Public Reference project (**warning** we may change this project id in the future)." 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": { 89 | "collapsed": false, 90 | "deletable": true, 91 | "editable": true, 92 | "jupyter": { 93 | "outputs_hidden": false 94 | } 95 | }, 96 | "outputs": [], 97 | "source": [ 98 | "# [USER INPUT] Set your project name; and files to copy here:\n", 99 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 100 | "my_project_name = 'Shiny and new' \n", 101 | "files_list = ['example_human_Illumina.pe_1.fastq',\n", 102 | " 'example_human_Illumina.pe_2.fastq']\n", 103 | "\n", 104 | "# Public reference and test files on the platform are available in the same project 'admin/sbg-public-data'\n", 105 | "source_project_id = 'admin/sbg-public-data' \n", 106 | "\n", 107 | "# Double-check that your project exists\n", 108 | "my_project = api.projects.query(name=my_project_name)\n", 109 | "if not my_project:\n", 110 | " print('Your project (%s) not found, check spelling' % my_project_name)\n", 111 | " raise KeyboardInterrupt\n", 112 | "else:\n", 113 | " my_project = my_project[0]\n", 114 | " \n", 115 | "# LIST all file names in your project and file objects from source project\n", 116 | "# Note that listing files in a project does not list subfolders\n", 117 | "my_file_names = [f.name for f in \n", 118 | " api.files.query(limit=100, project=my_project).all()]\n", 119 | "\n", 120 | "source_files = api.files.query(\n", 121 | " limit=100, project=source_project_id, names=files_list\n", 122 | ")\n", 123 | "\n", 124 | "if not source_files:\n", 125 | " print('Source files not found, check spelling and project id')\n", 126 | " raise KeyboardInterrupt\n", 127 | " \n", 128 | "# Copy files if they don't already exist in my_project\n", 129 | "for f in source_files:\n", 130 | " if f.name in my_file_names:\n", 131 | " print('File {} already exists in second project, skipping'.format(f.name))\n", 132 | " else:\n", 133 | " print('File {} does not exist in {}; copying now'.format(\n", 134 | " f.name, my_project.name))\n", 135 | "\n", 136 | " new_file = f.copy(project=my_project, name=f.name)\n", 137 | "\n", 138 | " # re-list files in target project to verify the copy worked\n", 139 | " my_files = [f.name for f in api.files.query(\n", 140 | " limit=100,project=my_project).all()]\n", 141 | "\n", 142 | " if f.name in my_files:\n", 143 | " print('Sucessfully copied one file!')\n", 144 | " else:\n", 145 | " print('Something went wrong...')" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": { 151 | "deletable": true, 152 | "editable": true 153 | }, 154 | "source": [ 155 | "## Additional Information\n", 156 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/copy-a-file)" 157 | ] 158 | } 159 | ], 160 | "metadata": { 161 | "kernelspec": { 162 | "display_name": "Python 3", 163 | "language": "python", 164 | "name": "python3" 165 | }, 166 | "language_info": { 167 | "codemirror_mode": { 168 | "name": "ipython", 169 | "version": 3 170 | }, 171 | "file_extension": ".py", 172 | "mimetype": "text/x-python", 173 | "name": "python", 174 | "nbconvert_exporter": "python", 175 | "pygments_lexer": "ipython3", 176 | "version": "3.8.3" 177 | } 178 | }, 179 | "nbformat": 4, 180 | "nbformat_minor": 4 181 | } 182 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# What are the details (metadata) of one of my _files_?\n", 11 | "### Overview\n", 12 | "Here we focus on _getting the details_ (or _metadata_) from a single file. As with any **detail**-type call, we will get extensive information about one file but must first know that files's id. \n", 13 | " \n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 18 | " 4. You understand how to list files within one of your projects (we will just use that call directly here).\n", 19 | " 5. Your project needs to have at least one file inside\n", 20 | " \n", 21 | "## Imports\n", 22 | "We import the _Api_ class from the official sevenbridges-python bindings below." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": { 29 | "deletable": true, 30 | "editable": true 31 | }, 32 | "outputs": [], 33 | "source": [ 34 | "import sevenbridges as sbg" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "deletable": true, 41 | "editable": true 42 | }, 43 | "source": [ 44 | "## Initialize the object\n", 45 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": { 52 | "deletable": true, 53 | "editable": true 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 58 | "prof = 'default'\n", 59 | "\n", 60 | "config_file = sbg.Config(profile=prof)\n", 61 | "api = sbg.Api(config=config_file)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": { 67 | "deletable": true, 68 | "editable": true 69 | }, 70 | "source": [ 71 | "## List my files and detail the first one\n", 72 | "We start by listing all of your files, then get more information on the first one. A **detail**-call for files returns the following *attributes*:\n", 73 | "* **created_on** File creation date\n", 74 | "* **id** _Unique_ identifier for the file\n", 75 | "* **name** Name of the file, note this **is** metadata and can be _changed_\n", 76 | "* **href** Address1 of the file.\n", 77 | "* **modified_on** File modification date\n", 78 | "* **tags** File tags\n", 79 | "* **metadata** Dictionary of metadata\n", 80 | "* **origin** Will link back to a *task* if this is an output file \n", 81 | "* **project** ID of the project the file is in\n", 82 | "* **parent** ID of the folder the file is in\n", 83 | "* **type** file or folder\n", 84 | "* **size** File size in bytes\n", 85 | "* **storage.type** Indicates whether the file is on platform built-in storage or on a connected cloud storage (Volume)\n", 86 | "* **storage.hosted_on_locations** Shows which cloud regions the file is stored in\n", 87 | "\n", 88 | "The **metadata** dictionary contains all metadata properties. For files on SBPLAT, metadata is **mutable**.\n", 89 | "\n", 90 | "\n", 91 | "---\n", 92 | "**NOTE**\n", 93 | "The file listing method does not list files in subfolders, only the files and folders in root of the project are listed\n", 94 | "\n", 95 | "---\n", 96 | "\n", 97 | "1 This is the address where, by using API you can get this resource" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": { 104 | "collapsed": false, 105 | "deletable": true, 106 | "editable": true, 107 | "jupyter": { 108 | "outputs_hidden": false 109 | } 110 | }, 111 | "outputs": [], 112 | "source": [ 113 | "# [USER INPUT] Set project name and file (f_) index here:\n", 114 | "project_id = 'username/my-project' \n", 115 | "f_index = 0\n", 116 | "\n", 117 | "# list the files in the target project. make sure not to include folders with f.type == 'file'\n", 118 | "my_files = [f for f in api.files.query(project_id).all() if f.type == 'file']\n", 119 | "# get details of one file inside the project\n", 120 | "single_file = api.files.get(my_files[f_index].id)\n", 121 | "print('You have selected file {} (size {} [bytes]). \\n'.format(\n", 122 | " single_file.name, single_file.size))" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": { 128 | "deletable": true, 129 | "editable": true 130 | }, 131 | "source": [ 132 | "## Additional Information\n", 133 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/get-file-details)" 134 | ] 135 | } 136 | ], 137 | "metadata": { 138 | "kernelspec": { 139 | "display_name": "Python 3", 140 | "language": "python", 141 | "name": "python3" 142 | }, 143 | "language_info": { 144 | "codemirror_mode": { 145 | "name": "ipython", 146 | "version": 3 147 | }, 148 | "file_extension": ".py", 149 | "mimetype": "text/x-python", 150 | "name": "python", 151 | "nbconvert_exporter": "python", 152 | "pygments_lexer": "ipython3", 153 | "version": "3.8.3" 154 | } 155 | }, 156 | "nbformat": 4, 157 | "nbformat_minor": 4 158 | } 159 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_listAll.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Which _files_ are in my project?\n", 11 | "### Overview\n", 12 | "Here we focus on listing all files within a single project. Importantly, files are only accessible **within** a project1. As with any **list**-type call, we will get minimal information about each file. \n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 18 | " 4. Your project needs to have at least one file inside. You can get files from here.\n", 19 | "\n", 20 | "1 There is no \"list **all** *files*\" API call that parallels the \"list **all**\" calls for *projects* and *apps*.\n", 21 | "\n", 22 | "## Imports\n", 23 | "We import the _Api_ class from the official sevenbridges-python bindings below." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 1, 29 | "metadata": { 30 | "deletable": true, 31 | "editable": true 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "import sevenbridges as sbg" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": { 41 | "deletable": true, 42 | "editable": true 43 | }, 44 | "source": [ 45 | "## Initialize the object\n", 46 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 2, 52 | "metadata": { 53 | "deletable": true, 54 | "editable": true 55 | }, 56 | "outputs": [], 57 | "source": [ 58 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 59 | "prof = 'default'\n", 60 | "\n", 61 | "config_file = sbg.Config(profile=prof)\n", 62 | "api = sbg.Api(config=config_file)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": { 68 | "deletable": true, 69 | "editable": true 70 | }, 71 | "source": [ 72 | "## List (up to 50 of) my files\n", 73 | "A **list**-call for projects returns the following *attributes*:\n", 74 | "* **id** _Unique_ identifier for each file, generated by the CGC\n", 75 | "* **name** Name of file, maybe _non-unique_\n", 76 | "* **href** Address1 of the file.\n", 77 | "\n", 78 | "Since we are not setting the **limit** parameter in api.files.query(), it _defaults_ to 50 records returned\n", 79 | "\n", 80 | "\n", 81 | "---\n", 82 | "**NOTE**\n", 83 | "The file listing method does not list files in subfolders, only the files and folders in root of the project are listed\n", 84 | "\n", 85 | "---\n", 86 | "\n", 87 | "1 This is the address where, by using API you can get this resource" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": { 94 | "collapsed": false, 95 | "deletable": true, 96 | "editable": true, 97 | "jupyter": { 98 | "outputs_hidden": false 99 | } 100 | }, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "file name: 20.intervals; \t file id: 602515d87c487916fca36124\n", 107 | "file name: chr20.intervals; \t file id: 602515d87c487916fca36123\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "# [USER INPUT] Set project name here, (pick one with files):\n", 113 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 114 | "project_name = 'test shellquote'\n", 115 | "\n", 116 | "# LIST all projects and check for name match\n", 117 | "my_project = api.projects.query(name=project_name)\n", 118 | "\n", 119 | "if not my_project: # empty list is False, {list, tuple, etc} is True\n", 120 | " print(\"\"\"The project named {} does not exist, \n", 121 | " please check spelling (especially trailing spaces)\"\"\".format(\n", 122 | " project_name))\n", 123 | " raise KeyboardInterrupt\n", 124 | "else:\n", 125 | " my_project = my_project[0]\n", 126 | " # list the files in the target project\n", 127 | " my_files = api.files.query(project=my_project)\n", 128 | "\n", 129 | "# print up to the first 10 files\n", 130 | "for ii in range(min(10,my_files.total)):\n", 131 | " print('file name: {}; \\t file id: {}'.format(\n", 132 | " my_files[ii].name, my_files[ii].id))" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "metadata": { 138 | "deletable": true, 139 | "editable": true 140 | }, 141 | "source": [ 142 | "#### Note\n", 143 | "If you had more than 50 files in your project (e.g. the _Copy of Cancer Cell Line Encyclopedia (CCLE)_ project) you would load only the first page that returns 50 files. For an example of how to deal with that see projects_listAll.ipynb\n", 144 | "\n", 145 | "## Let's get all the files\n", 146 | "Using the **.all()** method will take care of pagination for us." 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 6, 152 | "metadata": { 153 | "collapsed": false, 154 | "deletable": true, 155 | "editable": true, 156 | "jupyter": { 157 | "outputs_hidden": false 158 | } 159 | }, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "There are 2 files in project test shellquote \n", 166 | "\n", 167 | "file name: 20.intervals; \t file id: 602515d87c487916fca36124\n", 168 | "file name: chr20.intervals; \t file id: 602515d87c487916fca36123\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "# The .total field contains the total number of files\n", 174 | "print('There are {} files in project {} \\n'.format(\n", 175 | " my_files.total, my_project.name))\n", 176 | "\n", 177 | "# Use .all() method to make a generator object, loop through it\n", 178 | "for f in my_files.all():\n", 179 | " print('file name: {}; \\t file id: {}'.format(\n", 180 | " f.name, f.id))" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": { 186 | "deletable": true, 187 | "editable": true 188 | }, 189 | "source": [ 190 | "## Additional Information\n", 191 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/list-files-in-a-project)" 192 | ] 193 | } 194 | ], 195 | "metadata": { 196 | "kernelspec": { 197 | "display_name": "Python 3", 198 | "language": "python", 199 | "name": "python3" 200 | }, 201 | "language_info": { 202 | "codemirror_mode": { 203 | "name": "ipython", 204 | "version": 3 205 | }, 206 | "file_extension": ".py", 207 | "mimetype": "text/x-python", 208 | "name": "python", 209 | "nbconvert_exporter": "python", 210 | "pygments_lexer": "ipython3", 211 | "version": "3.8.3" 212 | } 213 | }, 214 | "nbformat": 4, 215 | "nbformat_minor": 4 216 | } 217 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_listByMetadata.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I get a list of all files that _match_ a particular metadata _property_?\n", 11 | "\n", 12 | "### Overview\n", 13 | "Here we focus on listing all files within a single project that **match** a particular metadata property. One _use-case_ which will benefit greatly from this is:\n", 14 | "\n", 15 | " * I have _hundreds_ of files in my project\n", 16 | " * I want to run a task(s) which only uses _type X_ files\n", 17 | " * I want to query all _type X_ files with one call\n", 18 | "\n", 19 | "You can use the basic strategy to:\n", 20 | "\n", 21 | " 1. List all the files (n = _N_)\n", 22 | " 2. Loop through the list\n", 23 | " 3. Get the metadata of every file (as [here](files_detailOne.ipynb))\n", 24 | " 4. If the property matches, add it to a _list_ of files to process\n", 25 | "\n", 26 | "This works, but will result in up to **_N_+1 API calls**. Here we will show how to do this with only **one API** call.\n", 27 | "\n", 28 | "### Prerequisites\n", 29 | " 1. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 30 | " 2. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 31 | " 3. You have already cloned the Public Project _Cancer Cell Line Encyclopedia (CCLE)_.\n", 32 | " \n", 33 | "## Imports\n", 34 | "We import the _Api_ class from the official sevenbridges-python bindings below." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": { 41 | "collapsed": false, 42 | "deletable": true, 43 | "editable": true, 44 | "jupyter": { 45 | "outputs_hidden": false 46 | } 47 | }, 48 | "outputs": [], 49 | "source": [ 50 | "import sevenbridges as sbg" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "deletable": true, 57 | "editable": true 58 | }, 59 | "source": [ 60 | "## Initialize the object\n", 61 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": { 68 | "deletable": true, 69 | "editable": true 70 | }, 71 | "outputs": [], 72 | "source": [ 73 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 74 | "prof = 'default'\n", 75 | "\n", 76 | "config_file = sbg.Config(profile=prof)\n", 77 | "api = sbg.Api(config=config_file)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": { 83 | "deletable": true, 84 | "editable": true 85 | }, 86 | "source": [ 87 | "## Search by metadata\n", 88 | "This is the **optimal** way to query files matching a particular metadata. Here, we check two (hard-coded) metadata properties. It's possible to check as many as you'd like. We are going to use _Copy of Cancer Cell Line Encyclopedia (CCLE)_ which is a nice big project with **2555** files.\n", 89 | "\n", 90 | "\n", 91 | "---\n", 92 | "**NOTE**\n", 93 | "The file listing method does not list files in subfolders, only the files and folders in root of the project are listed\n", 94 | "\n", 95 | "---" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": null, 101 | "metadata": { 102 | "collapsed": false, 103 | "deletable": true, 104 | "editable": true, 105 | "jupyter": { 106 | "outputs_hidden": false 107 | } 108 | }, 109 | "outputs": [], 110 | "source": [ 111 | "# [USER INPUT] Set metadata properties and values here; set project name\n", 112 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 113 | "project_name = 'Copy of Cancer Cell Line Encyclopedia (CCLE)'\n", 114 | "metadata_to_match = {'experimental_strategy': 'WXS',\n", 115 | " 'platform':'Illumina'}\n", 116 | "\n", 117 | "# Find project\n", 118 | "my_project = api.projects.query(name=project_name)\n", 119 | "\n", 120 | "if not my_project: # empty list is False, {list, tuple, etc} is True\n", 121 | " print('Target project ({}) not found, please check spelling'.format(project_name))\n", 122 | " raise KeyboardInterrupt\n", 123 | "else:\n", 124 | " my_project = my_project[0]\n", 125 | "\n", 126 | "# How many files do we have?\n", 127 | "my_files = api.files.query(project = my_project)\n", 128 | "print('There are {} files in your project'.format(my_files.total))\n", 129 | "\n", 130 | "# Query by metadata\n", 131 | "my_matched_files = api.files.query(\n", 132 | " project=my_project, limit=100, \n", 133 | " metadata=metadata_to_match)\n", 134 | " \n", 135 | "print(\"\"\"\n", 136 | "There are {} files matching the metadata criteria.\n", 137 | "This is {} percent of the dataset.\n", 138 | "\"\"\".format(my_matched_files.total,\n", 139 | " 100*(my_matched_files.total/my_files.total)))" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": { 145 | "deletable": true, 146 | "editable": true 147 | }, 148 | "source": [ 149 | "## Additional Information\n", 150 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-files-in-a-project)" 151 | ] 152 | } 153 | ], 154 | "metadata": { 155 | "kernelspec": { 156 | "display_name": "Python 3", 157 | "language": "python", 158 | "name": "python3" 159 | }, 160 | "language_info": { 161 | "codemirror_mode": { 162 | "name": "ipython", 163 | "version": 3 164 | }, 165 | "file_extension": ".py", 166 | "mimetype": "text/x-python", 167 | "name": "python", 168 | "nbconvert_exporter": "python", 169 | "pygments_lexer": "ipython3", 170 | "version": "3.8.3" 171 | } 172 | }, 173 | "nbformat": 4, 174 | "nbformat_minor": 4 175 | } 176 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/files_listByMetadataRecursive.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I get a list of all files (including subfolders) that _match_ a particular metadata _property_?\n", 11 | "\n", 12 | "### Overview\n", 13 | "\n", 14 | "This recipe is mainly used to show how to run through the project folder structure and find files of interest. Here we focus on listing all files within a single project that a particular metadata property, but same can be applied on other attributes, such as file name. One _use-case_ which will benefit greatly from this is:\n", 15 | "\n", 16 | " * I have _hundreds_ of files in my project\n", 17 | " * I want to run a task(s) which only uses _type X_ files\n", 18 | " * I want to query all _type X_ files with one call\n", 19 | " * I want to traverse the subdirectories\n", 20 | "\n", 21 | "You can use the basic strategy to:\n", 22 | "\n", 23 | " 1. List all the files and folders (n = _N_)\n", 24 | " 2. Loop through the list \n", 25 | " 3. If item is a file - get the metadata of every file (as [here](files_detailOne.ipynb)), if the property matches, add it to a _list_ of files to process\n", 26 | " 4. Else if item is a folder start from 1. for that folder\n", 27 | "\n", 28 | "\n", 29 | "### Prerequisites\n", 30 | " 1. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 31 | " 2. You understand how to list projects you are a member of (we will just use that call directly and pick one here).\n", 32 | " 3. You have already cloned the Public Project _Cancer Cell Line Encyclopedia (CCLE)_.\n", 33 | " \n", 34 | "## Imports\n", 35 | "We import the _Api_ class from the official sevenbridges-python bindings below." 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": { 42 | "collapsed": false, 43 | "deletable": true, 44 | "editable": true, 45 | "jupyter": { 46 | "outputs_hidden": false 47 | } 48 | }, 49 | "outputs": [], 50 | "source": [ 51 | "import sevenbridges as sbg" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": { 57 | "deletable": true, 58 | "editable": true 59 | }, 60 | "source": [ 61 | "## Initialize the object\n", 62 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": { 69 | "deletable": true, 70 | "editable": true 71 | }, 72 | "outputs": [], 73 | "source": [ 74 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 75 | "prof = 'default'\n", 76 | "\n", 77 | "config_file = sbg.Config(profile=prof)\n", 78 | "api = sbg.Api(config=config_file)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "deletable": true, 85 | "editable": true 86 | }, 87 | "source": [ 88 | "## Search by metadata\n" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": { 95 | "collapsed": false, 96 | "deletable": true, 97 | "editable": true, 98 | "jupyter": { 99 | "outputs_hidden": false 100 | } 101 | }, 102 | "outputs": [], 103 | "source": [ 104 | "# [USER INPUT] Set metadata properties and values here; set project ID\n", 105 | "project_id = 'my-name/my-project'\n", 106 | "metadata_to_match = {'experimental_strategy': 'WXS',\n", 107 | " 'platform':'Illumina'}\n", 108 | "\n", 109 | "\n", 110 | "def find_files_by_metadata(project_id, metadata_to_match, parent=None):\n", 111 | " \"\"\"\n", 112 | " If parent is set, it is a folder id to search in.\n", 113 | " \"\"\"\n", 114 | "\n", 115 | " \n", 116 | " if not parent:\n", 117 | " # Query by metadata in the root\n", 118 | " matched_files = list(api.files.query(\n", 119 | " project=project_id, limit=100, \n", 120 | " metadata=metadata_to_match).all())\n", 121 | " for item in api.files.query(limit=100, project=project_id).all():\n", 122 | " if item.is_folder():\n", 123 | " matched_files.extend(find_files_by_metadata(project_id, metadata_to_match, item.id))\n", 124 | " else:\n", 125 | " # Query by metadata in the folder\n", 126 | " matched_files = list(api.files.query(\n", 127 | " parent=parent, limit=100, \n", 128 | " metadata=metadata_to_match).all())\n", 129 | " for item in api.files.query(limit=100, parent=parent).all():\n", 130 | " if item.is_folder():\n", 131 | " matched_files.extend(find_files_by_metadata(project_id, metadata_to_match, item.id))\n", 132 | " return matched_files\n", 133 | " \n", 134 | " \n", 135 | "matched_files = find_files_by_metadata(project_id, metadata_to_match)\n", 136 | "print(\"Total matched files {}\".format(len(matched_files)))" 137 | ] 138 | }, 139 | { 140 | "cell_type": "markdown", 141 | "metadata": { 142 | "deletable": true, 143 | "editable": true 144 | }, 145 | "source": [ 146 | "## Additional Information\n", 147 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.cancergenomicscloud.org/docs/list-files-in-a-project)" 148 | ] 149 | } 150 | ], 151 | "metadata": { 152 | "kernelspec": { 153 | "display_name": "Python 3", 154 | "language": "python", 155 | "name": "python3" 156 | }, 157 | "language_info": { 158 | "codemirror_mode": { 159 | "name": "ipython", 160 | "version": 3 161 | }, 162 | "file_extension": ".py", 163 | "mimetype": "text/x-python", 164 | "name": "python", 165 | "nbconvert_exporter": "python", 166 | "pygments_lexer": "ipython3", 167 | "version": "3.8.3" 168 | } 169 | }, 170 | "nbformat": 4, 171 | "nbformat_minor": 4 172 | } 173 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/CGC_overview-02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/CGC_overview-02.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/example_sbgrc_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/example_sbgrc_file.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/projects_addNew-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/projects_addNew-01.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/projects_getDetails-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/projects_getDetails-01.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/projects_getMembers-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/projects_getMembers-01.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/images/projects_listAll-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Recipes/SBPLAT/images/projects_listAll-01.png -------------------------------------------------------------------------------- /Recipes/SBPLAT/projects_addMembers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I add members to one my _projects_?\n", 11 | "### Overview\n", 12 | "Here we focus on _adding a member_ to one of your projects. Importantly, you **must** be the admin of this project.\n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 18 | " \n", 19 | "## Imports\n", 20 | "We import the _Api_ class from the official sevenbridges-python bindings below." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "deletable": true, 28 | "editable": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "import sevenbridges as sbg" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "deletable": true, 39 | "editable": true 40 | }, 41 | "source": [ 42 | "## Initialize the object\n", 43 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "deletable": true, 51 | "editable": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 56 | "prof = 'default'\n", 57 | "\n", 58 | "config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "deletable": true, 66 | "editable": true 67 | }, 68 | "source": [ 69 | "## List all your projects\n", 70 | "We start by listing all of your projects, then get more information on the first one." 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": { 77 | "collapsed": false, 78 | "deletable": true, 79 | "editable": true, 80 | "jupyter": { 81 | "outputs_hidden": false 82 | } 83 | }, 84 | "outputs": [], 85 | "source": [ 86 | "# [USER INPUT] Set project name here to add members to:\n", 87 | "# Note that you can have multiple apps or projects with the same name. It is best practice to reference entities by ID.\n", 88 | "project_name = 'MAL'\n", 89 | "\n", 90 | "# check if this project already exists. LIST all projects and check for name match\n", 91 | "my_project = api.projects.query(name=project_name)\n", 92 | "\n", 93 | "if not my_project: # exploit fact that empty list is False\n", 94 | " print('Target project ({}) not found, please check spelling'.format(project_name))\n", 95 | " raise KeyboardInterrupt\n", 96 | "else:\n", 97 | " my_project = my_project[0]\n", 98 | " my_project = api.projects.get(id=my_project.id)\n", 99 | " print('You have selected project {}.'.format(my_project.name))\n", 100 | " if hasattr(my_project, 'description'): \n", 101 | " # Need to check if description has been entered, GUI created project have default text, \n", 102 | " # but it is not in the metadata.\n", 103 | " print('Project description: {} \\n'.format(my_project.description)) " 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": { 109 | "deletable": true, 110 | "editable": true 111 | }, 112 | "source": [ 113 | "## Add members\n", 114 | "In the list **user\\_names** below, add some actual user names. Then run the script and they will be added to your project." 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": { 121 | "collapsed": false, 122 | "deletable": true, 123 | "editable": true, 124 | "jupyter": { 125 | "outputs_hidden": false 126 | } 127 | }, 128 | "outputs": [], 129 | "source": [ 130 | "user_names =['',\n", 131 | " '']\n", 132 | "\n", 133 | "# here we are assigning all users in the list the same permissions, this could also be a list\n", 134 | "user_permissions = {'write': True,\n", 135 | " 'read': True,\n", 136 | " 'copy': True,\n", 137 | " 'execute': False,\n", 138 | " 'admin': False}\n", 139 | "\n", 140 | "for name in user_names:\n", 141 | " my_project.add_member(user=name, permissions=user_permissions)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": { 147 | "deletable": true, 148 | "editable": true 149 | }, 150 | "source": [ 151 | "## Additional Information\n", 152 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/add-a-member-to-a-project)" 153 | ] 154 | } 155 | ], 156 | "metadata": { 157 | "kernelspec": { 158 | "display_name": "Python 3", 159 | "language": "python", 160 | "name": "python3" 161 | }, 162 | "language_info": { 163 | "codemirror_mode": { 164 | "name": "ipython", 165 | "version": 3 166 | }, 167 | "file_extension": ".py", 168 | "mimetype": "text/x-python", 169 | "name": "python", 170 | "nbconvert_exporter": "python", 171 | "pygments_lexer": "ipython3", 172 | "version": "3.8.3" 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 4 177 | } 178 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/projects_detailOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# What are the details of one of my _projects_?\n", 11 | "### Overview\n", 12 | "There are a number of API calls related to projects. Here we focus on _getting the details_ of a single project. As with any **detail**-type call, we will get extensive information about one project but must first know that project's id.\n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 18 | " \n", 19 | "## Imports\n", 20 | "We import the _Api_ class from the official sevenbridges-python bindings below." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "deletable": true, 28 | "editable": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "import sevenbridges as sbg" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "deletable": true, 39 | "editable": true 40 | }, 41 | "source": [ 42 | "## Initialize the object\n", 43 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "deletable": true, 51 | "editable": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 56 | "prof = 'default'\n", 57 | "\n", 58 | "config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "deletable": true, 66 | "editable": true 67 | }, 68 | "source": [ 69 | "## List some projects & get details of one of them\n", 70 | "We start by listing all of your projects, then get more information on the first one. A **detail**-call for projects returns the following *attributes*:\n", 71 | "* **description** The user specified project description\n", 72 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 73 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 74 | "* **href** Address1 of the project.\n", 75 | "* **tags** List of tags\n", 76 | "* **created_on** Project creation time\n", 77 | "* **modified_on** Project modification time\n", 78 | "* **created_by** User that created the project\n", 79 | "* **root_folder** ID of the root folder for that project\n", 80 | "* **billing_group** ID of the billing group for the project\n", 81 | "* **settings** Dictionary with project settings for storage and task execution\n", 82 | "\n", 83 | "1 This is the address where, by using API you can get this resource" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": { 90 | "collapsed": false, 91 | "deletable": true, 92 | "editable": true, 93 | "jupyter": { 94 | "outputs_hidden": false 95 | } 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "# [USER INPUT] project index\n", 100 | "p_index = 0\n", 101 | "\n", 102 | "existing_projects = [p for p in api.projects.query().all()]\n", 103 | "single_project = api.projects.get(id=existing_projects[p_index].id)\n", 104 | "\n", 105 | "print('You have selected project {}.'.format(single_project.name))\n", 106 | "if hasattr(single_project, 'description'): \n", 107 | " # Need to check if description has been entered, GUI created project have default text, \n", 108 | " # but it is not in the metadata.\n", 109 | " print('Project description: {} \\n'.format(single_project.description)) " 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": { 115 | "deletable": true, 116 | "editable": true 117 | }, 118 | "source": [ 119 | "## Additional Information\n", 120 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/get-project-details)" 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "Python 3", 127 | "language": "python", 128 | "name": "python3" 129 | }, 130 | "language_info": { 131 | "codemirror_mode": { 132 | "name": "ipython", 133 | "version": 3 134 | }, 135 | "file_extension": ".py", 136 | "mimetype": "text/x-python", 137 | "name": "python", 138 | "nbconvert_exporter": "python", 139 | "pygments_lexer": "ipython3", 140 | "version": "3.8.3" 141 | } 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 4 145 | } 146 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/projects_makeNew.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How do I make a new _project_?\n", 11 | "### Overview\n", 12 | "There are a number of API calls related to projects. Here we focus on _creating a **new**_ project. Along the way, we will also show how to [list billing groups](http://docs.cancergenomicscloud.org/docs/list-your-billing-groups).\n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 18 | " \n", 19 | "## Imports\n", 20 | "We import the _Api_ class from the official sevenbridges-python bindings below." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "deletable": true, 28 | "editable": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "import sevenbridges as sbg" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "deletable": true, 39 | "editable": true 40 | }, 41 | "source": [ 42 | "## Initialize the object\n", 43 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "deletable": true, 51 | "editable": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 56 | "prof = 'default'\n", 57 | "\n", 58 | "config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "deletable": true, 66 | "editable": true 67 | }, 68 | "source": [ 69 | "## Make a new project using your first billing group\n", 70 | "We start by listing all of your projects and your billing groups. Next we create the JSON that will be passed to the API to create the project. The dictionary should include:\n", 71 | "* **billing_group** *Billing group* that will be charged for this project\n", 72 | "* **description** (optional) Project description\n", 73 | "* **name** Name of the project, may be *non-unique*1\n", 74 | "\n", 75 | "**After** creating the project, you can re-check the project list. A **detail**-call for projects returns the following *attributes*:\n", 76 | "* **description** The user specified project description\n", 77 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 78 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 79 | "* **href** Address1 of the project.\n", 80 | "* **tags** List of tags\n", 81 | "* **created_on** Project creation time\n", 82 | "* **modified_on** Project modification time\n", 83 | "* **created_by** User that created the project\n", 84 | "* **root_folder** ID of the root folder for that project\n", 85 | "* **billing_group** ID of the billing group for the project\n", 86 | "* **settings** Dictionary with project settings for storage and task execution\n", 87 | "\n", 88 | "\n", 89 | "1 Please **don't** use non-unique *project names*. However, if you insist (on the GUI), the backend will allow it and assign a unique **id** to you project." 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": { 96 | "collapsed": false, 97 | "deletable": true, 98 | "editable": true, 99 | "jupyter": { 100 | "outputs_hidden": false 101 | } 102 | }, 103 | "outputs": [], 104 | "source": [ 105 | "# [USER INPUT] Set project name and billing group index here:\n", 106 | "new_project_name = 'Michael Diamond' \n", 107 | "index_billing = -1 \n", 108 | "\n", 109 | "# Check if this project already exists. LIST all projects and check for name match\n", 110 | "my_project = api.projects.query(name=new_project_name)\n", 111 | " \n", 112 | "if my_project: # exploit fact that empty list is False, {list, tuple, etc} is True\n", 113 | " print('A project named {} exists, please choose a unique name'\n", 114 | " .format(new_project_name))\n", 115 | " raise KeyboardInterrupt\n", 116 | "else:\n", 117 | " # Create a new project\n", 118 | " # What are my funding sources?\n", 119 | " billing_groups = api.billing_groups.query() \n", 120 | " print((billing_groups[index_billing].name + \\\n", 121 | " ' will be charged for computation and storage (if applicable)'))\n", 122 | "\n", 123 | " # Set up the information for your new project\n", 124 | " new_project = {\n", 125 | " 'billing_group': billing_groups[index_billing].id,\n", 126 | " 'description': \"\"\"A project created by the API recipe (projects_makeNew.ipynb).\n", 127 | " This also supports **markdown**\n", 128 | " _Pretty cool_, right?\n", 129 | " \"\"\",\n", 130 | " 'name': new_project_name\n", 131 | " }\n", 132 | "\n", 133 | " my_project = api.projects.create(\n", 134 | " name=new_project['name'], billing_group=new_project['billing_group'], \n", 135 | " description=new_project['description']\n", 136 | " )\n", 137 | " \n", 138 | " # (re)list all projects, and get your new project\n", 139 | " my_project = [p for p in api.projects.query(limit=100).all() \n", 140 | " if p.name == new_project_name][0]\n", 141 | "\n", 142 | " print('Your new project {} has been created.'.format(\n", 143 | " my_project.name))\n", 144 | " # Print description if it exists\n", 145 | " if hasattr(my_project, 'description'): \n", 146 | " print('Project description: \\n {}'.format(my_project.description)) " 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": { 152 | "deletable": true, 153 | "editable": true 154 | }, 155 | "source": [ 156 | "## Additional Information\n", 157 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/create-a-new-project)" 158 | ] 159 | } 160 | ], 161 | "metadata": { 162 | "kernelspec": { 163 | "display_name": "Python 3", 164 | "language": "python", 165 | "name": "python3" 166 | }, 167 | "language_info": { 168 | "codemirror_mode": { 169 | "name": "ipython", 170 | "version": 3 171 | }, 172 | "file_extension": ".py", 173 | "mimetype": "text/x-python", 174 | "name": "python", 175 | "nbconvert_exporter": "python", 176 | "pygments_lexer": "ipython3", 177 | "version": "3.8.3" 178 | } 179 | }, 180 | "nbformat": 4, 181 | "nbformat_minor": 4 182 | } 183 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/projects_membersOne.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Who are the members of one of my _projects_?\n", 11 | "### Overview\n", 12 | "There are a number of API calls related to projects. Here we focus on _getting the members_ of a single project. \n", 13 | "\n", 14 | "### Prerequisites\n", 15 | " 1. You need to be a member (or owner) of _at least one_ project.\n", 16 | " 2. You need your _authentication token_ and the API needs to know about it. See **Setup_API_environment.ipynb** for details.\n", 17 | " 3. You understand how to list projects you are a member of (we will just use that call directly here).\n", 18 | " \n", 19 | "## Imports\n", 20 | "We import the _Api_ class from the official sevenbridges-python bindings below." 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": { 27 | "deletable": true, 28 | "editable": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "import sevenbridges as sbg" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": { 38 | "deletable": true, 39 | "editable": true 40 | }, 41 | "source": [ 42 | "## Initialize the object\n", 43 | "The `Api` object needs to know your **auth\\_token** and the correct path. Here we assume you are using the credentials file in your home directory. For other options see Setup_API_environment.ipynb" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "deletable": true, 51 | "editable": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "# [USER INPUT] specify credentials file profile {cgc, sbg, default}\n", 56 | "prof = 'default'\n", 57 | "\n", 58 | "config_file = sbg.Config(profile=prof)\n", 59 | "api = sbg.Api(config=config_file)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": { 65 | "deletable": true, 66 | "editable": true 67 | }, 68 | "source": [ 69 | "## List some projects & get members of one of them\n", 70 | "We start by listing all of your projects, then get more information on the first one. A **detail**-call for projects returns the following *attributes*:\n", 71 | "* **description** The user specified project description\n", 72 | "* **id** _Unique_ identifier for the project, generated based on Project Name\n", 73 | "* **name** Name of project specified by the user, maybe _non-unique_\n", 74 | "* **href** Address1 of the project.\n", 75 | "* **tags** List of tags\n", 76 | "* **created_on** Project creation time\n", 77 | "* **modified_on** Project modification time\n", 78 | "* **created_by** User that created the project\n", 79 | "* **root_folder** ID of the root folder for that project\n", 80 | "* **billing_group** ID of the billing group for the project\n", 81 | "* **settings** Dictionary with project settings for storage and task execution\n", 82 | "\n", 83 | "1 This is the address where, by using API you can get this resource" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": { 90 | "collapsed": false, 91 | "deletable": true, 92 | "editable": true, 93 | "jupyter": { 94 | "outputs_hidden": false 95 | } 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "# [USER INPUT] project index\n", 100 | "p_index = 0\n", 101 | "\n", 102 | "existing_projects = list(api.projects.query(limit=100).all())\n", 103 | "project_members = existing_projects[p_index].get_members()\n", 104 | "\n", 105 | "print('The selected project (%s) has %i members:' % \\\n", 106 | " (existing_projects[p_index].name, len(project_members)))\n", 107 | "\n", 108 | "for member in project_members:\n", 109 | " if member.permissions['admin']:\n", 110 | " print('\\t User %s is a project ADMIN' % (member.username))\n", 111 | " else:\n", 112 | " print('\\t User %s is a project MEMBER' % (member.username))" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": { 118 | "deletable": true, 119 | "editable": true 120 | }, 121 | "source": [ 122 | "## Additional Information\n", 123 | "Detailed documentation of this particular REST architectural style request is available [here](http://docs.sevenbridges.com/docs/list-members-of-a-project)" 124 | ] 125 | } 126 | ], 127 | "metadata": { 128 | "kernelspec": { 129 | "display_name": "Python 3", 130 | "language": "python", 131 | "name": "python3" 132 | }, 133 | "language_info": { 134 | "codemirror_mode": { 135 | "name": "ipython", 136 | "version": 3 137 | }, 138 | "file_extension": ".py", 139 | "mimetype": "text/x-python", 140 | "name": "python", 141 | "nbconvert_exporter": "python", 142 | "pygments_lexer": "ipython3", 143 | "version": "3.8.3" 144 | } 145 | }, 146 | "nbformat": 4, 147 | "nbformat_minor": 4 148 | } 149 | -------------------------------------------------------------------------------- /Recipes/SBPLAT/readme.md: -------------------------------------------------------------------------------- 1 | # API Recipes for the Seven Bridges Platform (SBPLAT) 2 | Our goals are: 3 | 4 | * Educate users about how the API works by using a friendly Python wrapper 5 | * Provide re-usable blocks of API code to solve common problems 6 | 7 | ## How does the Seven Bridges Platform work? 8 | An important first concept is how the Seven Bridges Platform (and CGC) works. A user has access to multiple **projects**, she may either be the owner of those projects or a member of someone else's project. Within each project, there is a collection of **files** and **apps**. The owner can combine a set of files, configuration inputs, and an app to generate a **task**. Once this task is complete, any **output files** will be put into 9 | the project where the task was started. 10 | 11 | ![CGC Overview](images/CGC_overview-02.png) 12 | 13 | ## Recipes in this cookbook 14 | 15 | Each Seven Bridges Platform component is accessible by the API. These recipes are _purposefully_ repetitive to highlight the logic of the API and hopefully help users understand some of the tools available to solve problems. The current _cookbook_ includes1 the following recipes: 16 | 17 | * Projects 18 | * list [projects\_listsAll.ipynb] 19 | * get details [projects\_detailOne.ipynb] 20 | * get members [projects\_membersOne.ipynb] 21 | * make new [projects\_makeNew.ipynb] 22 | * add members [projects\_addMembers.ipynb] 23 | 24 | * Files 25 | * list (within a project) [files\_listAll.ipynb] 26 | * list based on metadata [files\_screenbyMetadata.ipynb] 27 | * list based on metadata recursive [files\_listByMetadataRecursive.ipynb] 28 | * get details [files\_detailOne.ipynb] 29 | * copy Public Reference file [files\_copyFromMyProject.ipynb] 30 | * copy from another project [files\_copyFromPublicReference.ipynb] 31 | * upload and set metadata [files\_upload_and_setMetadata.ipynb] 32 | 33 | * Apps 34 | * list [apps\_listAll.ipynb] 35 | * get details [apps\_detailOne.ipynb] 36 | * copy from Public Apps [apps\_copyFromPublicApps.ipynb] 37 | * copy from another project [apps\_copyFromMyProject.ipynb] 38 | * install (upload) from a Common Workflow Language JSON [apps\_installFromJSON.ipynb] 39 | 40 | * Tasks 41 | * create and start [tasks\_create.ipynb] 42 | * monitor & get outputs [tasks\_monitorAndGetResults.ipynb] 43 | 44 | * Volumes 45 | * mount and write to volume [volumes\_writeToCloudStorage.ipynb] 46 | * mount and read from volume [volumes\_readFromCloudStorage.ipynb] 47 | 48 | ### Notes 49 | 1 We are happy to add more recipes, please request what helps you most effectively get stuff done. Already in the queue is: 50 | 51 | * [billing\_\*] we definity have neglected billing, sorry. 52 | -------------------------------------------------------------------------------- /Tutorials/CGC/Setup_API_environment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How to setup Seven Bridges Public API python library\n", 11 | "## Overview\n", 12 | "Here you will learn the three possible ways to setup Seven Bridges Public API Python library.\n", 13 | "\n", 14 | "## Prerequisites\n", 15 | "\n", 16 | "1. You need to install _sevenbridges-python_ library. Library details are available [here](http://sevenbridges-python.readthedocs.io/en/latest/sevenbridges/)\n", 17 | "\n", 18 | " The easiest way to install sevenbridges-python is using pip:\n", 19 | "\n", 20 | " $ pip install sevenbridges-python\n", 21 | "\n", 22 | " Alternatively, you can get the code. sevenbridges-python is actively developed on GitHub, where the [code](https://github.com/sbg/sevenbridges-python) is always available. To clone the public repository :\n", 23 | "\n", 24 | " $ git clone git://github.com/sbg/sevenbridges-python.git\n", 25 | "\n", 26 | " Once you have a copy of the source, you can embed it in your Python\n", 27 | " package, or install it into your site-packages by invoking:\n", 28 | "\n", 29 | " $ python setup.py install\n", 30 | "\n", 31 | "2. You need your _authentication token_ which you can get [here](https://cgc.sbgenomics.com/account#developer)\n", 32 | "\n", 33 | " \n", 34 | "### Notes and Compatibility\n", 35 | "\n", 36 | "Python package is intended to be used with both Python 2.7+ and Python 3.x versions. \n", 37 | "Following packages are necessary requirements:\n", 38 | "\n", 39 | "1. Requests package, used to make HTTP requests easily\n", 40 | "2. Six package, providing compatibility for Python versions 2.x and 3.x\n", 41 | "3. Enum34 backport package for providing enum on Python versions < 3.4" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "collapsed": false, 49 | "deletable": true, 50 | "editable": true 51 | }, 52 | "outputs": [], 53 | "source": [ 54 | "# Import the library\n", 55 | "import sevenbridges as sbg" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": { 61 | "deletable": true, 62 | "editable": true 63 | }, 64 | "source": [ 65 | "### Initialize the library\n", 66 | "\n", 67 | "You can initialize the library explicitly or by supplying the necessary information in the .sbgrc file\n", 68 | "\n", 69 | "There are generally three ways to initialize the library:\n", 70 | " 1. Explicitly, when calling api constructor, like:\n", 71 | " ``` python\n", 72 | " api = sbg.Api(url='https://cgc-api.sbgenomics.com/v2', token='MY AUTH TOKEN')\n", 73 | " ```\n", 74 | " \n", 75 | " 2. By using OS environment to store the url and authentication token\n", 76 | " ```\n", 77 | " export AUTH_TOKEN=\n", 78 | " export API_ENDPOINT='https://cgc-api.sbgenomics.com/v2'\n", 79 | " ```\n", 80 | " 3. By using ini file `$HOME/.sevenbridges/credentials` (for MS Windows, the file should be located in \\%UserProfile\\%\\.sevenbridges\\credentials) and specifying a profile to use. The format of the credentials file is standard ini file format, as shown below:\n", 81 | "\n", 82 | " ```bash\n", 83 | " [sbpla]\n", 84 | " api_endpoint = https://api.sbgenomics.com/v2\n", 85 | " auth_token = 700992f7b24a470bb0b028fe813b8100\n", 86 | "\n", 87 | " [cgc]\n", 88 | " api_endpoint = https://cgc-api.sbgenomics.com/v2\n", 89 | " auth_token = 910975f5b24a470bb0b028fe813b8100\n", 90 | " ```\n", 91 | " \n", 92 | " 0. to **create** this file1, use the following steps in your _Terminal_:\n", 93 | " 1.\n", 94 | " ```bash\n", 95 | " cd ~\n", 96 | " mkdir .sevenbridges\n", 97 | " touch .sevenbridges/credentials\n", 98 | " vi .sevenbridges/credentials\n", 99 | " ```\n", 100 | " 2. Press \"i\" then enter to go into **insert mode**\n", 101 | " 3. write the text above for each environment.\n", 102 | " 4. Press \"ESC\" then type \":wq\" to save the file and exit vi\n", 103 | " \n", 104 | "1 If the file already exists, omit the _touch_ command" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": { 110 | "deletable": true, 111 | "editable": true 112 | }, 113 | "source": [ 114 | "### Test if you have stored the token correctly\n", 115 | "Below are the three options presented above, test **one** of them. Logically, if you have only done **Step 3**, then testing **Step 2** will return an error." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": { 122 | "collapsed": false, 123 | "deletable": true, 124 | "editable": true 125 | }, 126 | "outputs": [], 127 | "source": [ 128 | "# (1.) You can also instantiate library by explicitly \n", 129 | "# specifying API url and authentication token\n", 130 | "api_explicitly = sbg.Api(url='https://cgc-api.sbgenomics.com/v2',\n", 131 | " token='')" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": { 138 | "collapsed": false, 139 | "deletable": true, 140 | "editable": true 141 | }, 142 | "outputs": [], 143 | "source": [ 144 | "# (2.) If you have not specified profile, the python-sbg library \n", 145 | "# will search for configuration in the environment\n", 146 | "c = sbg.Config()\n", 147 | "api_via_environment = sbg.Api(config=c)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": { 154 | "collapsed": false, 155 | "deletable": true, 156 | "editable": true 157 | }, 158 | "outputs": [], 159 | "source": [ 160 | "# (3.) If you have .sbgrc setup correctly, you only need to specify the profile\n", 161 | "config_file = sbg.Config(profile='cgc')\n", 162 | "api_via_ini_file = sbg.Api(config=config_file)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "markdown", 167 | "metadata": { 168 | "collapsed": false, 169 | "deletable": true, 170 | "editable": true 171 | }, 172 | "source": [ 173 | "#### PROTIP\n", 174 | "* We _recommend_ the approach with configuration file (the **.sevenbridges/credentials** file in option #3), especially if you are using multiple environments (like SBPLA and CGC)." 175 | ] 176 | } 177 | ], 178 | "metadata": { 179 | "kernelspec": { 180 | "display_name": "Python 3", 181 | "language": "python", 182 | "name": "python3" 183 | }, 184 | "language_info": { 185 | "codemirror_mode": { 186 | "name": "ipython", 187 | "version": 3 188 | }, 189 | "file_extension": ".py", 190 | "mimetype": "text/x-python", 191 | "name": "python", 192 | "nbconvert_exporter": "python", 193 | "pygments_lexer": "ipython3", 194 | "version": "3.5.2" 195 | } 196 | }, 197 | "nbformat": 4, 198 | "nbformat_minor": 0 199 | } 200 | -------------------------------------------------------------------------------- /Tutorials/CGC/images/TCGA_AWS_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/CGC/images/TCGA_AWS_0.png -------------------------------------------------------------------------------- /Tutorials/CGC/images/TCGA_AWS_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/CGC/images/TCGA_AWS_1.png -------------------------------------------------------------------------------- /Tutorials/CGC/images/TCGA_AWS_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/CGC/images/TCGA_AWS_2.png -------------------------------------------------------------------------------- /Tutorials/CGC/images/TCGA_AWS_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/CGC/images/TCGA_AWS_3.png -------------------------------------------------------------------------------- /Tutorials/CGC/images/example_sbgrc_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/CGC/images/example_sbgrc_file.png -------------------------------------------------------------------------------- /Tutorials/CGC/readme.md: -------------------------------------------------------------------------------- 1 | 2 | # tutor me 3 | We are happy to share a few _use-cases_ that have been useful for our customers. We are even happier to hear your **needs** so we can make things run more smoothly for you. 4 | 5 | These scripts include [USER INPUTS] for particular _workflows_; however, they are _extensively commented_ so they can be easily adapted to other tasks. 6 | 7 | ## How could I access TCGA data on Amazon Web Services via _Datasets API_? 8 | The [**access\_TCGA\_on\_AWS\_via\_DatasetsAPI.ipynb**] tutorial strives to empower the public to access [TCGA](https://wiki.nci.nih.gov/display/TCGA/TCGA+Home) data via [Amazon Web Services](https://aws.amazon.com/). It uses the **Datasets API** SPARQL query, which allows easily formatting a query across phenomic fields. The difference relative to the _next_ tutorial is that here you need to use an additional API. However, this allows you to use **simple key-value** pairs to completely define the query. 9 | 10 | ## How could I access TCGA data on Amazon Web Services via _SPARQL_? 11 | The [**access\_TCGA\_on\_AWS.ipynb**] tutorial strives to empower the public to access [TCGA](https://wiki.nci.nih.gov/display/TCGA/TCGA+Home) data via [Amazon Web Services](https://aws.amazon.com/). It uses a **SPARQL query**, which allows rapidly querying and returning a list of more than 4,000 Cases. The difference relative to the _prior_ tutorial is that here you need to be able to write the SPARQL query. However, this extra work allows you to use **more advanced syntax** and also **returns metadata** which can be _directly used_ for additional processing. 12 | 13 | ## How could I get VCF files to pass to a tertiary analysis software? 14 | The [**Get\_my\_VCFs.ipynb**] tutorial searches for _VCF_ files within a particular project OR within a particular tasks inside of a particular project. 15 | 16 | ## Integration with Synapse for the DREAM challenge 17 | Gaurav has co-organized a [DREAM Challenge](http://www.cancergenomicscloud.org/dreamchallenge/) for RNA somatic mutation calling. Python scripts which call the API are available in his github [repo](https://github.com/sbg/dreamwebinars). 18 | 19 | ### Notes 20 | 1. _Extensive_ and _beautiful_ API documentation for the Seven Bridges Platform is available [here](http://docs.cancergenomicscloud.org/docs/the-cgc-api) 21 | 2. The **advanced-access** branch still has MUCH better tutorials. -------------------------------------------------------------------------------- /Tutorials/SBPLAT/Setup_API_environment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# How to setup Seven Bridges Public API python library\n", 11 | "## Overview\n", 12 | "Here you will learn the three possible ways to setup Seven Bridges Public API Python library.\n", 13 | "\n", 14 | "## Prerequisites\n", 15 | "\n", 16 | "1. You need to install _sevenbridges-python_ library. Library details are available [here](http://sevenbridges-python.readthedocs.io/en/latest/sevenbridges/)\n", 17 | "\n", 18 | " The easiest way to install sevenbridges-python is using pip:\n", 19 | "\n", 20 | " $ pip install sevenbridges-python\n", 21 | "\n", 22 | " Alternatively, you can get the code. sevenbridges-python is actively developed on GitHub, where the [code](https://github.com/sbg/sevenbridges-python) is always available. To clone the public repository :\n", 23 | "\n", 24 | " $ git clone git://github.com/sbg/sevenbridges-python.git\n", 25 | "\n", 26 | " Once you have a copy of the source, you can embed it in your Python\n", 27 | " package, or install it into your site-packages by invoking:\n", 28 | "\n", 29 | " $ python setup.py install\n", 30 | "\n", 31 | "2. You need your _authentication token_ which you can get [here](https://igor.sbgenomics.com/developer/token)\n", 32 | "\n", 33 | " \n", 34 | "### Notes and Compatibility\n", 35 | "\n", 36 | "Python package is intended to be used with Python 3.6+ versions." 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": { 43 | "collapsed": false, 44 | "deletable": true, 45 | "editable": true, 46 | "jupyter": { 47 | "outputs_hidden": false 48 | } 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "# Import the library\n", 53 | "import sevenbridges as sbg" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "deletable": true, 60 | "editable": true 61 | }, 62 | "source": [ 63 | "### Initialize the library\n", 64 | "\n", 65 | "You can initialize the library explicitly or by supplying the necessary information in the $HOME/.sevenbridges/credentials file\n", 66 | "\n", 67 | "There are generally three ways to initialize the library:\n", 68 | " 1. Explicitly, when calling api constructor, like:\n", 69 | " ``` python\n", 70 | " api = sbg.Api(url='https://api.sbgenomics.com/v2', token='MY AUTH TOKEN')\n", 71 | " ```\n", 72 | " \n", 73 | " 2. By using OS environment to store the url and authentication token\n", 74 | " ```\n", 75 | " export AUTH_TOKEN=\n", 76 | " export API_ENDPOINT='https://api.sbgenomics.com/v2'\n", 77 | " ```\n", 78 | " 3. By using ini file $HOME/.sevenbridges/credentials (for MS Windows, the file should be located in \\%UserProfile\\%.sevenbridges\\credentials) and specifying a profile to use. The format of the credentials file is standard ini file format, as shown below:\n", 79 | "\n", 80 | " ```bash\n", 81 | " [sbpla]\n", 82 | " api_endpoint = https://api.sbgenomics.com/v2\n", 83 | " auth_token = 700992f7b24a470bb0b028fe813b8100\n", 84 | "\n", 85 | " [cgc]\n", 86 | " api_endpoint = https://cgc-api.sbgenomics.com/v2\n", 87 | " auth_token = 910975f5b24a470bb0b028fe813b8100\n", 88 | " ```\n", 89 | " \n", 90 | " 0. to **create** this file1, use the following steps in your _Terminal_:\n", 91 | " 1.\n", 92 | " ```bash\n", 93 | " cd ~\n", 94 | " mkdir .sevenbridges\n", 95 | " touch .sevenbridges/credentials\n", 96 | " vi .sevenbridges/credentials\n", 97 | " ```\n", 98 | " 2. Press \"i\" then enter to go into **insert mode**\n", 99 | " 3. write the text above for each environment. \n", 100 | " 4. Press \"ESC\" then type \":wq\" to save the file and exit vi\n", 101 | " \n", 102 | "1 If the file already exists, omit the _touch_ command" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": { 108 | "deletable": true, 109 | "editable": true 110 | }, 111 | "source": [ 112 | "### Test if you have stored the token correctly\n", 113 | "Below are the three options presented above, test **one** of them. Logically, if you have only done **Step 3**, then testing **Step 2** will return an error." 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": { 120 | "collapsed": false, 121 | "deletable": true, 122 | "editable": true, 123 | "jupyter": { 124 | "outputs_hidden": false 125 | } 126 | }, 127 | "outputs": [], 128 | "source": [ 129 | "# (1.) You can also instantiate library by explicitly \n", 130 | "# specifying API url and authentication token\n", 131 | "api_explicitly = sbg.Api(url='https://api.sbgenomics.com/v2',\n", 132 | " token='')\n", 133 | "api_explicitly.users.me()" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": { 140 | "collapsed": false, 141 | "deletable": true, 142 | "editable": true, 143 | "jupyter": { 144 | "outputs_hidden": false 145 | } 146 | }, 147 | "outputs": [], 148 | "source": [ 149 | "# (2.) If you have not specified profile, the python-sbg library \n", 150 | "# will search for configuration in the environment\n", 151 | "c = sbg.Config()\n", 152 | "api_via_environment = sbg.Api(config=c)\n", 153 | "api_via_environment.users.me()" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": { 160 | "collapsed": false, 161 | "deletable": true, 162 | "editable": true, 163 | "jupyter": { 164 | "outputs_hidden": false 165 | } 166 | }, 167 | "outputs": [], 168 | "source": [ 169 | "# (3.) If you have credentials setup correctly, you only need to specify the profile\n", 170 | "config_file = sbg.Config(profile='sbpla')\n", 171 | "api_via_ini_file = sbg.Api(config=config_file)\n", 172 | "api_via_ini_file.users.me()" 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": { 178 | "deletable": true, 179 | "editable": true 180 | }, 181 | "source": [ 182 | "#### PROTIP\n", 183 | "* We _recommend_ the approach with configuration file (the **.sevenbridges/credentials** file in option #3), especially if you are using multiple environments (like SBPLA and CGC)." 184 | ] 185 | } 186 | ], 187 | "metadata": { 188 | "kernelspec": { 189 | "display_name": "Python 3", 190 | "language": "python", 191 | "name": "python3" 192 | }, 193 | "language_info": { 194 | "codemirror_mode": { 195 | "name": "ipython", 196 | "version": 3 197 | }, 198 | "file_extension": ".py", 199 | "mimetype": "text/x-python", 200 | "name": "python", 201 | "nbconvert_exporter": "python", 202 | "pygments_lexer": "ipython3", 203 | "version": "3.8.3" 204 | } 205 | }, 206 | "nbformat": 4, 207 | "nbformat_minor": 4 208 | } 209 | -------------------------------------------------------------------------------- /Tutorials/SBPLAT/images/CCLE_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/SBPLAT/images/CCLE_0.png -------------------------------------------------------------------------------- /Tutorials/SBPLAT/images/CCLE_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/SBPLAT/images/CCLE_1.png -------------------------------------------------------------------------------- /Tutorials/SBPLAT/images/CCLE_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/SBPLAT/images/CCLE_2.png -------------------------------------------------------------------------------- /Tutorials/SBPLAT/images/example_sbgrc_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/Tutorials/SBPLAT/images/example_sbgrc_file.png -------------------------------------------------------------------------------- /Tutorials/SBPLAT/readme.md: -------------------------------------------------------------------------------- 1 | 2 | # tutor me 3 | We are happy to share a few _use-cases_ that have been useful for our customers. We are even happier to hear your **needs** so we can make things run more smoothly for you. 4 | 5 | These scripts include [USER INPUTS] for particular _workflows_; however, they are _extensively commented_ so they can be easily adapted to other tasks. 6 | 7 | ## How do I get started with the platform? 8 | The [**quickstart.ipynb**] tutorial creates a project, adds reference files and a workflow, creates a task, and finally shows the outputs. 9 | 10 | ## How do I create and run a batch of tasks (over a _single-input_)? 11 | The [**batch\_o\_tasks\_standard.ipynb**] tutorial creates a project, copies WGS bam files from the [CCLE](https://igor.sbgenomics.com/u/sevenbridges/cancer-cell-line-encyclopedia-ccle/) project, uploads a workflow from a JSON, creates a batch of tasks over the _bam\_files_ input. If this batch of tasks passes _validation checks_, then the tasks will begin running. 12 | 13 | ## How do I provide out create and run tasks, wait for completion and then provide outputs to a second task? 14 | The [**batch\_o\_tasks\_custom.ipynb**] tutorial shows an example of a simple task orchestration. The tutorial creates a project, copies WGS bam files from the [CCLE](https://igor.sbgenomics.com/u/sevenbridges/cancer-cell-line-encyclopedia-ccle/) project, uploads two workflows from a JSON, starts tasks with one workflow and monitors task execution. After all tasks in stage one are completed, this tutorial shows how to run the second workflow with the first workflow task outputs. 15 | 16 | ## How do I create and run a batch of tasks (over a _multiple inputs_)? 17 | [**Task automation with tumor-normal matched samples.ipynb**] is slightly more complex than the prior tutorial. Here, we create a project, copy WGS bam files from the [CCLE](https://igor.sbgenomics.com/u/sevenbridges/cancer-cell-line-encyclopedia-ccle/) project, uploads a workflow from a JSON, and work to organize the files into _normal_ and _tumor_ pairs. Then we use a for loop to create task for each pair of input files. 18 | 19 | ## How could I get VCF files to pass to a tertiary analysis software? 20 | The [**Get\_my\_VCFs.ipynb**] tutorial searches for _VCF_ files within a particular project OR within a particular tasks inside of a particular project. 21 | 22 | ### Notes 23 | 1. _Extensive_ and _beautiful_ API documentation for the Seven Bridges Platform is available [here](http://docs.sevenbridges.com/docs/the-api) -------------------------------------------------------------------------------- /_images/SB_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/_images/SB_logo.jpg -------------------------------------------------------------------------------- /_images/SB_logo_navy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbg/okAPI/4dbf9e917e2a53241fc2a58ddb51ccc9a990b348/_images/SB_logo_navy.jpg -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | # ok, API 3 | 4 | Official branch (master) 5 | 6 | [![sevenbridges-python version](https://img.shields.io/badge/sevenbridges--python-2.0.1-green)](https://pypi.python.org/pypi/sevenbridges-python) 7 | [![Licence](https://img.shields.io/badge/okAPI%20license-Creative%20Commons-brightgreen.svg)](https://github.com/sbg/okAPI/blob/master/license.txt) 8 | 9 | To help people maximize the _extensibility_ and _automation_ capability of Seven Bridges products, we're happy to share example **API** code. _ok, API_ contains examples have been used to address common user _wants_ and _needs_. They are divided into **recipes** & **tutorials**. 10 | 11 | * **_"How do I do this one thing?"_** You want a **recipe**, which is a _modular_ example of common operations. 12 | * **_"How do I complete my entire analysis?"_** You want a **tutorial**, which may _combine multiple recipes_ to go from start to finish of an analysis. 13 | 14 | The _recipe_ and _tutorial_ folders in this repository are subdivided into **CGC** (the Cancer Genomics Cloud) and **SBPLAT** (the Seven Bridges Platform). This separation ensures we link to the appropriate docs. 15 | 16 | --- 17 | **NOTE** 18 | 19 | The recipes and tutorials in the CGC folders are not actively maintained. Please refer to the SBPLA folder for latest recipes. 20 | 21 | --- 22 | 23 | Switching between environments is as easy as choosing a different authentication token and API endpoint or a different profile from the `sevenbridges credentials` file [(explained here)](https://sevenbridges-python.readthedocs.io/en/latest/quickstart/#initialize-the-library-using-a-configuration-file). Feedback and improvements are welcome. 24 | 25 | ## Background 26 | This repository mainly covered the Seven Bridges Plaform and the Cancer Genomics Cloud Platform, but the recipes and tutorials are applicable to any other installation of the Seven Bridges Platform (the EU platform, the Cavatica Platform, the BioDataCatalyst Powered by Seven Bridges Platform and others). To learn more, see the respective platform documentation. 27 | * The Seven Bridges Platform documentation is at [docs.sevenbridges.com](http://docs.sevenbridges.com/). In particular, see the [API documentation](http://docs.sevenbridges.com/docs/the-api). 28 | * The Cancer Genomics Cloud documentation is at [docs.cancergenomicscloud.com](http://docs.cancergenomicscloud.org/). In particular, see the [API documentation](http://docs.cancergenomicscloud.org/docs/the-cgc-api). 29 | * The Cavatica platform documentation is at [docs.cavatica.org/docs/getting-started](https://docs.cavatica.org/docs/getting-started). 30 | * The BioDataCatalyst powered by Seven Bridges platform documentation is at [https://sb-biodatacatalyst.readme.io/docs](https://sb-biodatacatalyst.readme.io/docs) 31 | 32 | ### Notes 33 | 1. This is compatible with **Python 3.6+**. 34 | 2. This is in **beta** and we are constantly working on improving our examples. Expect the awesomeness to continue. 35 | 3. We are happy to recieve Pull Requests with your _improvements_ or Issues which we will fix asap. 36 | 37 | Good luck, have fun! 38 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | sevenbridges-python>=2.0.0 --------------------------------------------------------------------------------