{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sM4TB7pp-4Xp" }, "source": [ "# ISB-CGC Community Notebooks\n", "\n", "Check out more notebooks at our [Community Notebooks Repository](https://github.com/isb-cgc/Community-Notebooks)!\n", "\n", "```\n", "Title: How to Use ISB-CGC APIs\n", "Author: Lauren Hagen\n", "Created: 2019-09-16\n", "Purpose: Introduction to using ISB-CGC APIs with Python\n", "URL: https://github.com/isb-cgc/Community-Notebooks/blob/master/Notebooks/How_to_use_ISB-CGC_APIs.ipynb\n", "Notes:\n", "```\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "zfnyQon4OSmi" }, "source": [ "# How to Use ISB-CGC APIs" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "jEhcHLyfNoZF" }, "source": [ "## Overview of Notebook\n", "This notebook is designed as a quick introduction to the ISB-CGC APIs and how to access them with Python.\n", "\n", "Topic Covered:\n", "* Overviews of APIs, Swagger, JSON, endpoints\n", "* Use Cases for ISB-CGC APIs\n", "* Examples of ISB-CGC API endpoints\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "xKMj6vYXNS9v" }, "source": [ "## About ISB-CGC APIs\n", "ISB-CGC has created several APIs to interact with ISB-CGC and user data available on Google Cloud Platforms. They were created with Google’s OpenAPI Endpoints and can be accessed through a [SwaggerUI interface](https://api-dot-isb-cgc.appspot.com/v4/swagger/). For more information on ISB-CGC APIs, please visit [our documentation](https://isb-cancer-genomics-cloud.readthedocs.io/en/latest/sections/progapi/progAPI-v4/Programmatic-Demo.html)." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "Mnkz-GYtNXG8" }, "source": [ "### Overview of APIs\n", "An API or application-programming interface is a software intermediary that allows two applications to talk to each other. In other words, an API is the messenger that delivers your request to the provider that you’re requesting it from and then delivers the response back to you [(Wikipedia)](https://en.wikipedia.org/wiki/Application_programming_interface). Each action that an API can take is called an \"endpoint\".\n", "\n", "Some useful tutorials and quick start guides on APIs are:\n", "* [GDC's Getting Started guide for APIs](https://docs.gdc.cancer.gov/API/Users_Guide/Getting_Started/)\n", "* [API Integration in Python](https://realpython.com/api-integration-in-python/)\n", "* [Python API Tutorial: Getting Started with APIs](https://www.dataquest.io/blog/python-api-tutorial/)\n", "* [Accessing APIs from R (and a little R programming)](https://www.r-bloggers.com/accessing-apis-from-r-and-a-little-r-programming/)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "d8EpGT1_NfaV" }, "source": [ "### What is SwaggerUI?\n", "\n", "[SwaggerUI](https://swagger.io/tools/swagger-ui/) is a user interface that allows users to try out the APIs and view their documentation easily. A tutorial on how to use the ISB-CGC APIs on the SwaggerUI can be found [here](https://isb-cancer-genomics-cloud.readthedocs.io/en/latest/sections/progapi/progAPI-v4/Programmatic-Demo.html#apis-demo)." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "d70M_3VBNjTN" }, "source": [ "### What is JSON?\n", "\n", "JSON or JavaScript Object Notation is a lightweight data-interchange format that is easy for humans and machines to work with. More information can be found at [json.org](https://www.json.org/)." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "XRajgslw_iUt" }, "source": [ "### What is an endpoint?\n", "\n", "An endpoint is the *call* for a specific functionally of an API. For example, `/data/availabile` at the end of the API request URL `https://api-dot-isb-cgc.appspot.com/v4/data/available` is an endpoint that returns (or GETs) information about the available programs and data sets." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "3k8fV64qOCnY" }, "source": [ "### Python library `requests`\n", "\n", "In order to use the ISB-CGC APIs with Python, the `requests` library needs to be installed and then imported." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "3goCNgQW-wgS" }, "outputs": [], "source": [ "# Install requests if needed\n", "# pip install requests\n", "\n", "# Import the requests library\n", "import requests" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "9wMMTcuuNlkt" }, "source": [ "## Use cases for ISB-CGC APIs\n", "\n", "The ISB-CGC APIs can be used for a number of different tasks for interacting with the Google Cloud Platform and BigQuery. It can be used to subset data into cohorts or to access cohorts that have been created using the WebApp. It can also be used to interact with the user's GCP to retrieve available user projects along with registering projects with ISB-CGC." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "JpGspd-bNrJl" }, "source": [ "## Example: `about` Endpoint\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "OPCsbygUb_EW" }, "source": [ "We are first going to explore the `about` endpoint using the 'get' request to the API. This API will give you information about the ISB-CGC API such a link to the Swagger UI interface and the documentation." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "LNGPVvHwHSnl" }, "outputs": [], "source": [ "# First submit the 'get' request to the API\n", "about_req = requests.get('https://api-dot-isb-cgc.appspot.com/v4/about')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "0KuvDe63dOjK" }, "source": [ "Now that we have the request response, we are going to check that we didn't receive an error code or if the request was successful. If the request was successful, then the status code will come back as 200 but if something went wrong then the status code may be something 404 or 503. If you have recieved any error codes, you can check out Google's [Troubleshooting response errors guide](https://cloud.google.com/endpoints/docs/openapi/troubleshoot-response-errors)." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "-qMcWo6peb6e" }, "outputs": [], "source": [ "# Check that there wasn't an error with the request\n", "if about_req.status_code != 200:\n", " # Print the error code if something went wrong\n", " print(about_req.status_code)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "etcXVRH9gvch" }, "source": [ "Finally, we will print out the information that we have received from the API. This response returns as a dictionary though responses can also be a combination of dictionaries and lists depending on which endpoint is called. This means that you can access different data in the response the same way that you would access dictionaries and lists as demonstarted below." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 224 }, "colab_type": "code", "id": "keNiLV68hLnj", "outputId": "c69f4485-ab49-4b8d-a539-5829b4a1f49a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Full response:\n", "\n", "{'code': 200, 'documentation': 'SwaggerUI interface available at .Documentation available at ', 'message': 'Welcome to the ISB-CGC API, Version 4.'}\n", "\n", "Message:\n", "\n", "Welcome to the ISB-CGC API, Version 4.\n", "\n", "Documentation:\n", "\n", "SwaggerUI interface available at .Documentation available at \n" ] } ], "source": [ "# Print the full response\n", "print(\"Full response:\\n\")\n", "print(about_req.json(), end='\\n\\n')\n", "\n", "# Print the message portion of the response\n", "print(\"Message:\\n\")\n", "print(about_req.json()['message'], end='\\n\\n')\n", "\n", "# Print the documentation portion of the response\n", "print(\"Documentation:\\n\")\n", "print(about_req.json()['documentation'])" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "aNaUuDSGhKHC" }, "source": [ "That wasn't difficult at all! Next we will cover a few of the other information APIs." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "2VYM2_WINzTo" }, "source": [ "## Example: `/data/available` Endpoint" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "P20YZDWB1wrr" }, "source": [ "The `/data/available` Endpoint is designed to return the data sets and programs available on the WebApp along with the projects or studies that are within those data sets and programs. This endpoint returns a more complicated JSON object which has a combination of lists and dictionaries. We will first retrieve the request and then view if there was an error code within the response." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "TqrOUl65zPEj" }, "outputs": [], "source": [ "# Retrieve the response from the API endpoint\n", "programs_req = requests.get('https://api-dot-isb-cgc.appspot.com/v4/data/available')\n", "\n", "# Check that there wasn't an error with the request\n", "if programs_req.status_code != 200:\n", " # Print the error code if something went wrong\n", " print(programs_req.status_code)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "Wox-rs9Grxqc" }, "source": [ "\n", "We are going to use the library `json` in order to view the response more easily.\n" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "61qMkFH4qFim" }, "outputs": [], "source": [ "# Install requests if needed\n", "# pip install requests\n", "\n", "# install pip json\n", "import json" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "colab_type": "code", "id": "MAzFxZvdzugs", "outputId": "e86ad700-4a8f-49fb-d03e-5c6bc0978989" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"code\": 200,\n", " \"datasets_for_registration\": \"None found\",\n", " \"programs_for_cohorts\": [\n", " {\n", " \"description\": null,\n", " \"name\": \"TCGA\",\n", " \"program_privacy\": \"Public\",\n", " \"projects\": [\n", " {\n", " \"description\": null,\n", " \"name\": \"ACC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"DLBC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"READ\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"GBM\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"LGG\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"THCA\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"STAD\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"UCEC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"PCPG\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"CESC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"UCS\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"TGCT\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"LIHC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"CHOL\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"HNSC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"UVM\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"SKCM\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"COAD\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"PAAD\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"THYM\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"LUSC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"MESO\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"OV\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"ESCA\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"SARC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"KIRP\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"BLCA\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"LAML\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"PRAD\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"LUAD\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"BRCA\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"KIRC\"\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"KICH\"\n", " }\n", " ]\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"CCLE\",\n", " \"program_privacy\": \"Public\",\n", " \"projects\": [\n", " {\n", " \"description\": \"Controls\",\n", " \"name\": \"CNTL\"\n", " },\n", " {\n", " \"description\": \"FFPE Pilot Phase II\",\n", " \"name\": \"FPPP\"\n", " },\n", " {\n", " \"description\": \"Sarcoma\",\n", " \"name\": \"SARC\"\n", " },\n", " {\n", " \"description\": \"Skin Cutaneous Melanoma\",\n", " \"name\": \"SKCM\"\n", " },\n", " {\n", " \"description\": \"Mesothelioma\",\n", " \"name\": \"MESO\"\n", " },\n", " {\n", " \"description\": \"Acute Myeloid Leukemia\",\n", " \"name\": \"LAML\"\n", " },\n", " {\n", " \"description\": \"Pheochromocytoma and Paraganglioma\",\n", " \"name\": \"PCPG\"\n", " },\n", " {\n", " \"description\": \"Prostate Adenocarcinoma\",\n", " \"name\": \"PRAD\"\n", " },\n", " {\n", " \"description\": \"Kidney Renal Clear Cell Carcinoma\",\n", " \"name\": \"KIRC\"\n", " },\n", " {\n", " \"description\": \"Esophageal Carcinoma\",\n", " \"name\": \"ESCA\"\n", " },\n", " {\n", " \"description\": \"Brain Lower Grade Glioma\",\n", " \"name\": \"LGG\"\n", " },\n", " {\n", " \"description\": \"Lung Adenocarcinoma\",\n", " \"name\": \"LUAD\"\n", " },\n", " {\n", " \"description\": \"Pancreatic Adenocarcinoma\",\n", " \"name\": \"PAAD\"\n", " },\n", " {\n", " \"description\": \"Kidney Chromophobe\",\n", " \"name\": \"KICH\"\n", " },\n", " {\n", " \"description\": \"Chronic Lymphocytic Leukemia\",\n", " \"name\": \"LCLL\"\n", " },\n", " {\n", " \"description\": \"Kidney Renal Papillary Cell Carcinoma\",\n", " \"name\": \"KIRP\"\n", " },\n", " {\n", " \"description\": \"Glioblastoma Multiforme\",\n", " \"name\": \"GBM\"\n", " },\n", " {\n", " \"description\": \"Miscellaneous\",\n", " \"name\": \"MISC\"\n", " },\n", " {\n", " \"description\": \"Lung Squamous Cell Carcinoma\",\n", " \"name\": \"LUSC\"\n", " },\n", " {\n", " \"description\": \"Thymoma\",\n", " \"name\": \"THYM\"\n", " },\n", " {\n", " \"description\": \"Head and Neck Squamous Cell Carcinoma\",\n", " \"name\": \"HNSC\"\n", " },\n", " {\n", " \"description\": \"Testicular Germ Cell Tumors\",\n", " \"name\": \"TGCT\"\n", " },\n", " {\n", " \"description\": \"Bladder Urothelial Carcinoma\",\n", " \"name\": \"BLCA\"\n", " },\n", " {\n", " \"description\": \"Thyroid Carcinoma\",\n", " \"name\": \"THCA\"\n", " },\n", " {\n", " \"description\": \"Uterine Carcinosarcoma\",\n", " \"name\": \"UCS\"\n", " },\n", " {\n", " \"description\": \"Cholangiocarcinoma\",\n", " \"name\": \"CHOL\"\n", " },\n", " {\n", " \"description\": \"Multiple Myeloma\",\n", " \"name\": \"MM\"\n", " },\n", " {\n", " \"description\": \"Breast Invasive Carcinoma\",\n", " \"name\": \"BRCA\"\n", " },\n", " {\n", " \"description\": \"Cervical Squamous Cell Carcinoma and Endocervical Adenocarcinoma\",\n", " \"name\": \"CESC\"\n", " },\n", " {\n", " \"description\": \"Lymphoid Neoplasm Diffuse Large B-cell Lymphoma\",\n", " \"name\": \"DLBC\"\n", " },\n", " {\n", " \"description\": \"Uveal Melanoma\",\n", " \"name\": \"UVM\"\n", " },\n", " {\n", " \"description\": \"Liver Hepatocellular Carcinoma\",\n", " \"name\": \"LIHC\"\n", " },\n", " {\n", " \"description\": \"Colon Adenocarcinoma\",\n", " \"name\": \"COAD\"\n", " },\n", " {\n", " \"description\": \"Rectum Adenocarcinoma\",\n", " \"name\": \"READ\"\n", " },\n", " {\n", " \"description\": \"Uterine Corpus Endometrial Carcinoma\",\n", " \"name\": \"UCEC\"\n", " },\n", " {\n", " \"description\": \"Ovarian Serous Cystadenocarcinoma\",\n", " \"name\": \"OV\"\n", " },\n", " {\n", " \"description\": \"Stomach Adenocarcinoma\",\n", " \"name\": \"STAD\"\n", " },\n", " {\n", " \"description\": \"Adrenocortical Carcinoma\",\n", " \"name\": \"ACC\"\n", " },\n", " {\n", " \"description\": \"Chronic Myelogenous Leukemia\",\n", " \"name\": \"LCML\"\n", " }\n", " ]\n", " },\n", " {\n", " \"description\": null,\n", " \"name\": \"TARGET\",\n", " \"program_privacy\": \"Public\",\n", " \"projects\": [\n", " {\n", " \"description\": \"Rhabdoid Tumor\",\n", " \"name\": \"RT\"\n", " },\n", " {\n", " \"description\": \"Neuroblastoma\",\n", " \"name\": \"NBL\"\n", " },\n", " {\n", " \"description\": \"Clear Cell Sarcoma of the Kidney\",\n", " \"name\": \"CCSK\"\n", " },\n", " {\n", " \"description\": \"High-Risk Wilms Tumor\",\n", " \"name\": \"WT\"\n", " },\n", " {\n", " \"description\": \"Osteosarcoma\",\n", " \"name\": \"OS\"\n", " },\n", " {\n", " \"description\": \"Acute Lymphoblastic Leukemia - Phase II\",\n", " \"name\": \"ALL-P2\"\n", " },\n", " {\n", " \"description\": \"Acute Lymphoblastic Leukemia - Phase I\",\n", " \"name\": \"ALL-P1\"\n", " },\n", " {\n", " \"description\": \"Acute Myeloid Leukemia\",\n", " \"name\": \"AML\"\n", " }\n", " ]\n", " }\n", " ]\n", "}\n" ] } ], "source": [ "# Create a variable with the JSON output\n", "program_json = json.dumps(programs_req.json(), sort_keys=True, indent=4)\n", "\n", "# Print the program JSON text\n", "print(program_json)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "D0pxiO6TtklT" }, "source": [ "We can now see easily that our information that we are interested in is a combination of a dictionaries and lists. Next we will we will iterate over the JSON object to neatly return the data sets/programs along with which projects/studies are available." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 68 }, "colab_type": "code", "id": "OmM4GKs_u6w3", "outputId": "fcfa9808-c490-4d49-82ea-a1a329235822" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The TCGA program has 33 projects.\n", "The CCLE program has 39 projects.\n", "The TARGET program has 8 projects.\n" ] } ], "source": [ "# Create a variable with the dataset information\n", "datasets = programs_req.json()['programs_for_cohorts']\n", "\n", "# Create an empty dictionary for the program names\n", "programs = {}\n", "\n", "# For each dataset, create a list of available programs and add it to the\n", "# dictionary with the dataset name.\n", "for data in datasets:\n", " # Create a blank list for the projects\n", " projects = []\n", " # for each project, add it to the list of projects for the data set\n", " for project in data['projects']:\n", " projects.append(project['name'])\n", " # Add the program name and list of projects to the dictionary\n", " programs[data['name']] = projects\n", " # Print the name of the program and the number of projects available\n", " print(\"The {} program has {} projects.\".format(data['name'], len(projects)))" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "LzjPrdYi0XkV" }, "source": [ "We now have an easy dictionary of programs with lists of the projects for each program. Let us look at which projects are available in the TCGA data set." ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 578 }, "colab_type": "code", "id": "or-yCoRW1D1K", "outputId": "63126695-e878-4dea-ba41-089f837e4ebb" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ACC\n", "DLBC\n", "READ\n", "GBM\n", "LGG\n", "THCA\n", "STAD\n", "UCEC\n", "PCPG\n", "CESC\n", "UCS\n", "TGCT\n", "LIHC\n", "CHOL\n", "HNSC\n", "UVM\n", "SKCM\n", "COAD\n", "PAAD\n", "THYM\n", "LUSC\n", "MESO\n", "OV\n", "ESCA\n", "SARC\n", "KIRP\n", "BLCA\n", "LAML\n", "PRAD\n", "LUAD\n", "BRCA\n", "KIRC\n", "KICH\n" ] } ], "source": [ "for project in programs['TCGA']:\n", " print(project)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "Xu_qEvqJ1gAW" }, "source": [ "Wow, that is a lot of projects/studies available within the TCGA data set. Descriptions of the different data sets and programs can be found in our [documentation](https://isb-cancer-genomics-cloud.readthedocs.io/en/latest/sections/Hosted-Data.html)." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "5nP_GUuhN1m3" }, "source": [ "## Example: `cohort` Endpoint\n", "\n", "This last section will cover the get `cohorts` Endpoint which requires authorization before submitting the request to the API. This endpoint retrieves information about user generated cohorts from within the WebApp or with the ISB-CGC API. " ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "jMu18sE11tvk" }, "source": [ "### Notes on Authorization and Credentials\n", "In order to use several of the ISB-CGC APIs, you need have authorization with ISB-CGC.\n", "\n", "The following steps are required to use an API that Requires Authorization:\n", "\n", "1. Create Google Cloud Project set up*\n", "2. Register with the ISB-CGC WebApp*\n", "3. Create a Credential File on your local machine by using the [isb_auth.py script](https://github.com/isb-cgc/ISB-CGC-API/blob/master/scripts/isb_auth.py) from the [ISB-CGC-API Repository](https://github.com/isb-cgc/ISB-CGC-API)\n", " * This script can be run from the command line or from within Python but has to occur on your local machine.\n", "4. Find the location of the Credential File on your local machine\n", " * By default, it will save the file in the users folder of your local machine with the file name: \".isb_credentials\"\n", "5. Load the Credential file into the cloud environment you are using (if needed)\n", "\n", "*The 'Quick Start Guide to ISB-CGC' Notebook in the [Community Notebook Repository](https://github.com/isb-cgc/Community-Notebooks/tree/master/Notebooks) and the [How to Get Started on ISB-CGC](https://isb-cancer-genomics-cloud.readthedocs.io/en/latest/sections/HowToGetStartedonISB-CGC.html) can assist you with these steps." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "YxN-104cqZMR" }, "outputs": [], "source": [ "# If you skipped earlier sections, you will need these two packages to run the\n", "# code below\n", "# Install requests if needed\n", "#pip install requests\n", "\n", "# Install pip json\n", "#import json\n", "\n", "# Import the requests library\n", "#import requests" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "B-QyDYmiXbs1" }, "outputs": [], "source": [ "# Import files helper for Colab\n", "from google.colab import files" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 74, "resources": { "http://localhost:8080/nbextensions/google.colab/files.js": { "data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAKLy8KLy8gVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2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kIHsKICAgIHJlc3BvbnNlOiB7CiAgICAgIGFjdGlvbjogJ2NvbXBsZXRlJywKICAgIH0KICB9Owp9CgpzY29wZS5nb29nbGUgPSBzY29wZS5nb29nbGUgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYiA9IHNjb3BlLmdvb2dsZS5jb2xhYiB8fCB7fTsKc2NvcGUuZ29vZ2xlLmNvbGFiLl9maWxlcyA9IHsKICBfdXBsb2FkRmlsZXMsCiAgX3VwbG9hZEZpbGVzQ29udGludWUsCn07Cn0pKHNlbGYpOwo=", "headers": [ [ "content-type", "application/javascript" ] ], "ok": true, "status": 200, "status_text": "" } } }, "colab_type": "code", "id": "AUqu8bf_16Ba", "outputId": "ee03f5a4-c150-482b-c217-0f3dff7285e7" }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " Upload widget is only available when the cell has been executed in the\n", " current browser session. Please rerun this cell to enable.\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Saving .isb_credentials to .isb_credentials (2)\n" ] } ], "source": [ "# Upload your credentials to the cloud environment\n", "uploaded = files.upload()" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "O9nD45o_KV3S" }, "source": [ "Now that we have the Credentials file created and uploaded to the cloud environment, we can open the file to create the header information need for the API to verify that you have Authorization." ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "3EeeApmTWJh8" }, "outputs": [], "source": [ "# Open the credentials file\n", "token = open(\".isb_credentials\", \"r\")\n", "# Create a json object from teh credential file\n", "token = json.loads(token.read())\n", "# Get Credentials from the token\n", "creds = token['token_response']['id_token']\n", "# Create a json object for requests header\n", "head = {'Authorization': 'Bearer ' + creds}" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "7W1A74r9KEx4" }, "source": [ "**Note:** the credentials file will expire after 1 hour and a new one will need to be generated. If a new file is not generated with the isb_auth script, you can delete the original file and try running the script again.\n", "\n", "If you are having any issues, you can contact us at feedback@isb-cgc.org" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "oppOXZKjL_It" }, "source": [ "Finally, we can make a `get` request to the `cohorts` ISB-CGC API.\n", "\n" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "colab": {}, "colab_type": "code", "id": "DRF4T41SgAIm" }, "outputs": [], "source": [ "# Make API request\n", "cohort_req = requests.get('https://api-dot-isb-cgc.appspot.com/v4/cohorts', headers=head)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "vr_ECKLPMSqU" }, "source": [ "Now we can format the response for easy view and view it." ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "colab_type": "code", "id": "3Psin-zKwWEf", "outputId": "9bd4ff36-832f-4e88-cbdb-9dfc3472ca2e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"code\": 200,\n", " \"data\": [\n", " {\n", " \"filters\": {\n", " \"TCGA\": [\n", " {\n", " \"name\": \"gender\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"FEMALE\"\n", " },\n", " {\n", " \"name\": \"age_at_diagnosis\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"70 to 79\"\n", " }\n", " ]\n", " },\n", " \"id\": 1962,\n", " \"name\": \"Test 1\",\n", " \"permission\": \"OWNER\"\n", " },\n", " {\n", " \"filters\": {},\n", " \"id\": 1,\n", " \"name\": \"All TCGA Data\",\n", " \"permission\": \"READER\"\n", " },\n", " {\n", " \"filters\": {\n", " \"TCGA\": [\n", " {\n", " \"name\": \"tumor_tissue_site\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"Breast\"\n", " },\n", " {\n", " \"name\": \"sample_type\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"01\"\n", " },\n", " {\n", " \"name\": \"vital_status\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"Alive\"\n", " }\n", " ]\n", " },\n", " \"id\": 1972,\n", " \"name\": \"Test 2\",\n", " \"permission\": \"OWNER\"\n", " },\n", " {\n", " \"filters\": {\n", " \"TCGA\": [\n", " {\n", " \"name\": \"disease_code\",\n", " \"program\": \"TCGA\",\n", " \"value\": \"PAAD\"\n", " }\n", " ]\n", " },\n", " \"id\": 2217,\n", " \"name\": \"Test 4\",\n", " \"permission\": \"OWNER\"\n", " }\n", " ]\n", "}\n" ] } ], "source": [ "cohorts_json = json.dumps(cohort_req.json(), sort_keys=True, indent=4)\n", "print(cohorts_json)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "OA4RtA8q9nle" }, "source": [ "Then we can retrieve the contents of the response and view which cohorts have been created." ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "colab_type": "code", "id": "w6mAoLI-7vKE", "outputId": "ee8c8acb-5cb8-4930-9044-bffbc453e243" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[{'filters': {'TCGA': [{'name': 'gender', 'program': 'TCGA', 'value': 'FEMALE'}, {'name': 'age_at_diagnosis', 'program': 'TCGA', 'value': '70 to 79'}]}, 'id': 1962, 'name': 'Test 1', 'permission': 'OWNER'}, {'filters': {}, 'id': 1, 'name': 'All TCGA Data', 'permission': 'READER'}, {'filters': {'TCGA': [{'name': 'tumor_tissue_site', 'program': 'TCGA', 'value': 'Breast'}, {'name': 'sample_type', 'program': 'TCGA', 'value': '01'}, {'name': 'vital_status', 'program': 'TCGA', 'value': 'Alive'}]}, 'id': 1972, 'name': 'Test 2', 'permission': 'OWNER'}, {'filters': {'TCGA': [{'name': 'disease_code', 'program': 'TCGA', 'value': 'PAAD'}]}, 'id': 2217, 'name': 'Test 4', 'permission': 'OWNER'}]\n" ] } ], "source": [ "# Create a variable with the dataset information\n", "cohorts = cohort_req.json()['data']\n", "print(cohorts)" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "GjMDyygr9oUG" }, "source": [ "We can then see what filters were applied by choosing the number of the cohort you wish to see." ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 85 }, "colab_type": "code", "id": "-hPy2Oqf8GaU", "outputId": "a0b43efd-61f2-4ca4-f91f-5adf80f3e920" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Test 1\n", "All TCGA Data\n", "Test 2\n", "Test 4\n" ] } ], "source": [ "# View the names of the cohorts\n", "for k in cohorts:\n", " print(k['name'])" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "id": "hlQ6kj3y8clI", "outputId": "c1af8dfb-d4b9-45e7-8523-46cfa4ed9659" }, "outputs": [ { "data": { "text/plain": [ "{'TCGA': [{'name': 'gender', 'program': 'TCGA', 'value': 'FEMALE'},\n", " {'name': 'age_at_diagnosis', 'program': 'TCGA', 'value': '70 to 79'}]}" ] }, "execution_count": 27, "metadata": { "tags": [] }, "output_type": "execute_result" } ], "source": [ "# View the filters that have been applied to the first cohort\n", "cohorts[0]['filters']" ] } ], "metadata": { "colab": { "collapsed_sections": [], "include_colab_link": true, "name": "How_to_use_ISB-CGC_APIs.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }