diff --git a/tutorial_notebooks/Quick_Example_AnnoMate_Reviewer.ipynb b/tutorial_notebooks/Quick_Example_AnnoMate_Reviewer.ipynb index 324e044..7663560 100644 --- a/tutorial_notebooks/Quick_Example_AnnoMate_Reviewer.ipynb +++ b/tutorial_notebooks/Quick_Example_AnnoMate_Reviewer.ipynb @@ -4,7 +4,10 @@ "cell_type": "markdown", "id": "d2aedd2d-b1d5-4d2d-8e95-61ff06292438", "metadata": { - "tags": [] + "tags": [], + "pycharm": { + "name": "#%% md\n" + } }, "source": [ "# Quick Example AnnoMate Reviewer\n", @@ -16,8 +19,8 @@ "- We recommend using pre-built reviewers if **one already exists** for a task you want to perform and/or **you consider yourself less technically experienced.** See the [AnnnoMate Reviewer Catalog](https://github.com/getzlab/AnnoMate/blob/master/catalog/README.md) for existing reviewers.\n", "\n", "## Prerequistes:\n", - "- User is familiar with executing cells in jupyter notebooks and consider themselves **beginner - intermeidate level python**\n", - "- User wants to learn some of the basic built-in functionality of customizing pre-built Annomate Reviewers\n", + "- User is familiar with executing cells in jupyter notebooks and considers themself **beginner or intermediate level** in python\n", + "- User wants to learn some of the basic built-in functionality for customizing pre-built Annomate Reviewers\n", "\n", "## Outcomes:\n", "- Get a basic AnnoMate reviewer running\n", @@ -28,7 +31,10 @@ "cell_type": "markdown", "id": "670b8f2a-af59-4f15-8551-fa038ea8849e", "metadata": { - "tags": [] + "tags": [], + "pycharm": { + "name": "#%% md\n" + } }, "source": [ "## Installation" @@ -37,7 +43,11 @@ { "cell_type": "markdown", "id": "9e1078a8-0e56-4642-9b6f-3610ddf1377f", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "Option 1: Using pypi (recommended)\n", "1. Create an environment: `conda create --name --file requirements.txt python==3.8`\n", @@ -48,7 +58,11 @@ { "cell_type": "markdown", "id": "49d4fe42-17fe-4ea6-aaa7-85b7c0718788", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "Option 2: Using git\n", "1. Download the repository: `git clone git@github.com:getzlab/AnnoMate.git` \n", @@ -61,7 +75,11 @@ { "cell_type": "markdown", "id": "e637c8ae-2ca2-487a-9522-de96383ae80f", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "Option 3: Running from docker container. You need to open at least 2 ports if you are using Mac or Windows:\n", "1. A port to open jupyter lab (in this case, ``)\n", @@ -75,29 +93,127 @@ }, { "cell_type": "markdown", - "id": "6429e242-eb91-4419-ba41-3b63e6f1ae6d", - "metadata": {}, "source": [ - "## Running this notebook\n", + "Finally, make sure to update your kernel to the conda environment `` you just created. And then run the following cell (though you can skip the ***Google Colab*** section.\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "# set mode for dash app\n", + "mode='tab'" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "### If running tutorial in Google Colab\n", + "Run these cells to install AnnoMate in the Colab environment from the github source code.\n", "\n", - "Make sure to update your kernel to the conda environment `` you just created.\n" - ] + "*As the installed Colab packages change over time, this installation procedure is not guaranteed to work in the future.*" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "!pip install --ignore-installed blinker=1.6.2 # gets around an installation error due to an old Colab dependency\n", + "!git clone git@github.com:getzlab/AnnoMate.git\n", + "!cd AnnoMate; pip install ." + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "There may be some installation errors, but as long as it reports that AnnoMate was installed successfully, you should be good to go." + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "# move into tutorial_notebooks folder to access example_data\n", + "%cd AnnoMate/tutorial_notebooks" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "# set mode for dash app\n", + "mode='external'" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } }, { "cell_type": "markdown", "id": "31fae173", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "## Run an Example Reviewer\n", "\n", - "Here we are setting up a basic reviewer that displays fake sample data." + "Here we set up a basic reviewer that displays fake sample data. Make sure you have access to the example_data folder contained in the same directory as this tutorial." ] }, { "cell_type": "code", "execution_count": 1, "id": "a9657940", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "%load_ext autoreload\n", @@ -108,7 +224,11 @@ "cell_type": "code", "execution_count": 3, "id": "ef37cc47", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -120,7 +240,11 @@ "cell_type": "code", "execution_count": 9, "id": "b0aaeb3b-a736-41d5-9d3b-5cd00fa6d40d", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "# get data\n", @@ -133,7 +257,11 @@ "cell_type": "code", "execution_count": 27, "id": "04a55062-3ae8-4ecb-b4eb-de3a65ba220e", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -182,13 +310,17 @@ "\n", "my_reviewer.set_default_review_data_annotations_configuration()\n", "my_reviewer.set_default_autofill()\n", - "my_reviewer.run(collapsable=True, port=8056, mode='tab')" + "my_reviewer.run(collapsable=True, port=8056, mode=mode)" ] }, { "cell_type": "markdown", "id": "2a06283e-b1cb-452a-8d8d-46e2ebf538ea", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "Accessing the Dash App:\n", "> **If you are using a VM:** Make sure to open a ssh tunnel to the specified port number\n", @@ -198,13 +330,19 @@ "> **If you are running from a docker container:** Make sure to open the port for accessing the dash app (`reviewer.run(port=, ...)`) when you open the container\n", "> - `docker run -it -p : -p : gcr.io/broad-getzlab-workflows/annomate:dev_branch_v385`\n", "> - You can add more ports by adding more `-p :` arguments\n", - "> - If you are on Linux, you can replace `-p` arguments with `--network host`" + "> - If you are on Linux, you can replace `-p` arguments with `--network host`\n", + "\n", + "> **If you are running in Google Colab:** All you need to do is click the link populated above (something like http://0.0.0.0:8056/), which will open another tab to display the interactive Dash App." ] }, { "cell_type": "markdown", "id": "8476f28b-85f4-48b5-8a99-ccd6503dfa67", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Use a table to navigate between samples rather than dropdown\n", "\n", @@ -215,7 +353,11 @@ "cell_type": "code", "execution_count": 30, "id": "8158587c-270a-45f0-a769-52f6dbab95ae", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -244,14 +386,18 @@ " review_data_table_df=df[['gender', 'age', 'tissue_origin']], \n", " review_data_table_page_size=7,\n", " port=8056,\n", - " mode='tab'\n", + " mode=mode\n", ")" ] }, { "cell_type": "markdown", "id": "cc355478-4b2f-4dea-b8f4-f2743a3737d2", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Disable test mode" ] @@ -259,7 +405,11 @@ { "cell_type": "markdown", "id": "8da6a3c8-18eb-4382-9aab-4031be0ad167", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "On initial load, you'll notice a `Freeze data` button. Once you are happy with your input data and are ready to start reviewing your data, press this button to disable test mode and freeze your data. Note that once this button is pressed, you will not be able to unfreeze your data / revert back to test mode." ] @@ -267,7 +417,11 @@ { "cell_type": "markdown", "id": "a015ccb4", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Retrieving annotations made in the dashbaord\n", "After submitting annotations in the dashboard, you can view your progress by accessing the annotation table or history table:" @@ -277,7 +431,11 @@ "cell_type": "code", "execution_count": 35, "id": "8bff62a2", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { @@ -381,7 +539,11 @@ "cell_type": "code", "execution_count": 36, "id": "852bf6fa-9016-493a-89e9-cfa29e37d9c1", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { @@ -509,7 +671,11 @@ { "cell_type": "markdown", "id": "7fea16ef", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "Now you can export this table to a file that you can then share, upload to Terra, or use for further analysis." ] @@ -517,7 +683,11 @@ { "cell_type": "markdown", "id": "defbae62-fe6d-4e0d-b0a3-7f3ac522fc23", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "## Make modifications to the Dashboard in the notebook" ] @@ -526,18 +696,25 @@ "cell_type": "code", "execution_count": 37, "id": "34d7128c-36bd-4da3-92c0-8962770dc0a9", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "from AnnoMate.Data import DataAnnotation\n", - "import AnnoMate.AnnotationDisplayComponent as adc\n", - "import numpy as np" + "import AnnoMate.AnnotationDisplayComponent as adc" ] }, { "cell_type": "markdown", "id": "ada89ed7-0ffd-4fe1-993d-ddc9f5e2b2b8", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Add another table component\n", "\n", @@ -550,7 +727,11 @@ "cell_type": "code", "execution_count": 38, "id": "9fd80758", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "my_reviewer.app.add_table_from_path(\n", @@ -565,7 +746,11 @@ { "cell_type": "markdown", "id": "4dfb58a3-b5a8-4dff-a5a8-1a4ae4ff5184", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Update existing annotation options and display\n", "\n", @@ -576,7 +761,11 @@ "cell_type": "code", "execution_count": 40, "id": "53cb2bf6-a874-425c-bc6c-0afff25a05a1", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "my_reviewer.add_review_data_annotation(\n", @@ -595,48 +784,64 @@ { "cell_type": "markdown", "id": "0d62cad4-2508-4528-a456-f0c45e83d05f", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Add more annotations\n", "\n", - "Here we add a dropdown menu to track another annotation that is not included in the pre-built ExampleReviewer class" + "Here we add a dropdown menu to track the annotation of the mut_vafs color, as this is not included in the pre-built ExampleReviewer class" ] }, { "cell_type": "code", "execution_count": 42, "id": "85edf720-e28f-40c2-8ef2-4ee0917d065d", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "# Dropdown/Select\n", "my_reviewer.add_review_data_annotation(\n", - " annot_name='A dropdown menu', \n", + " annot_name='Histogram color',\n", " review_data_annotation=DataAnnotation(\n", " annot_value_type='string', \n", - " options=['Option A', 'Option B', 'Option C']\n", + " options=['red', 'blue', 'green']\n", " )\n", ")\n", "my_reviewer.add_annotation_display_component(\n", - " annot_name='A dropdown menu', \n", + " annot_name='Histogram color',\n", " annot_display_component=adc.SelectAnnotationDisplay())" ] }, { "cell_type": "markdown", "id": "936bd35f-0920-4c71-9b2e-31db813541aa", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Remove annotation from display\n", "\n", - "Note this will only remove the annotation input from the dashboard. It will not delete the column in the annotation table (`reviewer.get_annot()`)." + "Note this will only remove the annotation input from the dashboard. It will not delete the column in the annotation table (what is displayed when calling `reviewer.get_annot()`)." ] }, { "cell_type": "code", "execution_count": 43, "id": "f5d59a4c-e5c5-482b-bcc3-544b909a4fa6", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { @@ -668,7 +873,11 @@ "cell_type": "code", "execution_count": 44, "id": "95ff8056-3b62-489e-8bf6-8809bcdfedeb", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { @@ -690,7 +899,11 @@ { "cell_type": "markdown", "id": "10700832-b886-4568-a0ae-d582e367d0a5", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Add annotation autofill button\n", "\n", @@ -703,7 +916,11 @@ "cell_type": "code", "execution_count": 49, "id": "eff8b6fe-f965-4a78-8097-6aa19fc3a2cc", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "from dash.dependencies import State\n", @@ -717,7 +934,11 @@ { "cell_type": "markdown", "id": "e5ebf97b-fb62-4768-bbb3-af4516ab5c16", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "### Change which components and the order the components are displayed" ] @@ -726,7 +947,11 @@ "cell_type": "code", "execution_count": 50, "id": "ad199e40-f8ef-4528-b6f3-f2335d9c9a06", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { @@ -748,7 +973,11 @@ "cell_type": "code", "execution_count": 51, "id": "71659b78-7085-4e07-8fca-85efbc9bfc31", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "name": "stdout", @@ -763,14 +992,19 @@ "source": [ "my_reviewer.run(\n", " port=8056,\n", - " components_name_order=['sample-info-component', 'Treatment file', 'Mut vafs']\n", + " components_name_order=['sample-info-component', 'Treatment file', 'Mut vafs'],\n", + " mode=mode\n", ")" ] }, { "cell_type": "markdown", "id": "fe4762ca-2cb4-41f2-a486-74d4cfd4c08e", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "**NOTE**: Some reviewers may have components that listen to each other, so if you keep one but not the other, some of the predefined interactivity may lead to error messages. You may run into similar errors for autofill buttons which may be pulling data from components that are excluded. \n", "\n", @@ -780,7 +1014,11 @@ { "cell_type": "markdown", "id": "e07c9eca", - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%% md\n" + } + }, "source": [ "# Final words\n", "\n", @@ -814,4 +1052,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file