{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Collecting git+https://github.com/GMOD/jbrowse-jupyter.git@main\n",
      "  Cloning https://github.com/GMOD/jbrowse-jupyter.git (to revision main) to /private/var/folders/96/hq94_1qd3c9_q87bwqhg05s80000gn/T/pip-req-build-emfgm9s3\n",
      "  Running command git clone --filter=blob:none -q https://github.com/GMOD/jbrowse-jupyter.git /private/var/folders/96/hq94_1qd3c9_q87bwqhg05s80000gn/T/pip-req-build-emfgm9s3\n",
      "  Resolved https://github.com/GMOD/jbrowse-jupyter.git to commit 5a7a753cf3ada2d028992c67ed305e0ea575555b\n",
      "  Preparing metadata (setup.py) ... \u001b[?25ldone\n",
      "\u001b[?25hCollecting dash==2.0.0\n",
      "  Using cached dash-2.0.0-py3-none-any.whl (7.3 MB)\n",
      "Collecting dash-jbrowse>=1.0.1\n",
      "  Using cached dash_jbrowse-1.0.1-py3-none-any.whl (1.1 MB)\n",
      "Requirement already satisfied: flake8>=4.0.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jbrowse-jupyter==1.2.1) (4.0.1)\n",
      "Requirement already satisfied: jupyter_dash>=0.4.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jbrowse-jupyter==1.2.1) (0.4.0)\n",
      "Requirement already satisfied: pandas>=1.1.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jbrowse-jupyter==1.2.1) (1.4.0)\n",
      "Requirement already satisfied: pytest>=6.2.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jbrowse-jupyter==1.2.1) (6.2.5)\n",
      "Requirement already satisfied: dash-table==5.0.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (5.0.0)\n",
      "Requirement already satisfied: flask-compress in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (1.10.1)\n",
      "Requirement already satisfied: dash-core-components==2.0.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (2.0.0)\n",
      "Requirement already satisfied: plotly>=5.0.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (5.3.1)\n",
      "Requirement already satisfied: dash-html-components==2.0.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (2.0.0)\n",
      "Requirement already satisfied: Flask>=1.0.4 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from dash==2.0.0->jbrowse-jupyter==1.2.1) (1.1.2)\n",
      "Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from flake8>=4.0.1->jbrowse-jupyter==1.2.1) (2.8.0)\n",
      "Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from flake8>=4.0.1->jbrowse-jupyter==1.2.1) (0.6.1)\n",
      "Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from flake8>=4.0.1->jbrowse-jupyter==1.2.1) (2.4.0)\n",
      "Requirement already satisfied: ipykernel in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (5.3.4)\n",
      "Requirement already satisfied: ansi2html in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (1.6.0)\n",
      "Requirement already satisfied: retrying in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (1.3.3)\n",
      "Requirement already satisfied: requests in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (2.24.0)\n",
      "Requirement already satisfied: ipython in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (7.19.0)\n",
      "Requirement already satisfied: python-dateutil>=2.8.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pandas>=1.1.5->jbrowse-jupyter==1.2.1) (2.8.1)\n",
      "Requirement already satisfied: numpy>=1.18.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pandas>=1.1.5->jbrowse-jupyter==1.2.1) (1.19.2)\n",
      "Requirement already satisfied: pytz>=2020.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pandas>=1.1.5->jbrowse-jupyter==1.2.1) (2020.1)\n",
      "Requirement already satisfied: packaging in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (20.4)\n",
      "Requirement already satisfied: iniconfig in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (1.1.1)\n",
      "Requirement already satisfied: attrs>=19.2.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (20.3.0)\n",
      "Requirement already satisfied: py>=1.8.2 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (1.9.0)\n",
      "Requirement already satisfied: toml in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (0.10.1)\n",
      "Requirement already satisfied: pluggy<2.0,>=0.12 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pytest>=6.2.5->jbrowse-jupyter==1.2.1) (0.13.1)\n",
      "Requirement already satisfied: click>=5.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from Flask>=1.0.4->dash==2.0.0->jbrowse-jupyter==1.2.1) (7.1.2)\n",
      "Requirement already satisfied: itsdangerous>=0.24 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from Flask>=1.0.4->dash==2.0.0->jbrowse-jupyter==1.2.1) (1.1.0)\n",
      "Requirement already satisfied: Jinja2>=2.10.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from Flask>=1.0.4->dash==2.0.0->jbrowse-jupyter==1.2.1) (2.11.2)\n",
      "Requirement already satisfied: Werkzeug>=0.15 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from Flask>=1.0.4->dash==2.0.0->jbrowse-jupyter==1.2.1) (2.0.2)\n",
      "Requirement already satisfied: tenacity>=6.2.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from plotly>=5.0.0->dash==2.0.0->jbrowse-jupyter==1.2.1) (8.0.1)\n",
      "Requirement already satisfied: six in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from plotly>=5.0.0->dash==2.0.0->jbrowse-jupyter==1.2.1) (1.16.0)\n",
      "Requirement already satisfied: brotli in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from flask-compress->dash==2.0.0->jbrowse-jupyter==1.2.1) (1.0.9)\n",
      "Requirement already satisfied: appnope in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.1.0)\n",
      "Requirement already satisfied: tornado>=4.2 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (6.0.4)\n",
      "Requirement already satisfied: jupyter-client in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (6.1.7)\n",
      "Requirement already satisfied: traitlets>=4.1.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (5.1.1)\n",
      "Requirement already satisfied: pygments in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (2.7.2)\n",
      "Requirement already satisfied: decorator in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (4.4.2)\n",
      "Requirement already satisfied: setuptools>=18.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (59.2.0)\n",
      "Requirement already satisfied: backcall in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.2.0)\n",
      "Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (3.0.8)\n",
      "Requirement already satisfied: jedi>=0.10 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.17.1)\n",
      "Requirement already satisfied: pexpect>4.3 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (4.8.0)\n",
      "Requirement already satisfied: pickleshare in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.7.5)\n",
      "Requirement already satisfied: pyparsing>=2.0.2 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from packaging->pytest>=6.2.5->jbrowse-jupyter==1.2.1) (2.4.7)\n",
      "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from requests->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (1.25.11)\n",
      "Requirement already satisfied: idna<3,>=2.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from requests->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (2.10)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from requests->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (2020.6.20)\n",
      "Requirement already satisfied: chardet<4,>=3.0.2 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from requests->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (3.0.4)\n",
      "Requirement already satisfied: parso<0.8.0,>=0.7.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jedi>=0.10->ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.7.0)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from Jinja2>=2.10.1->Flask>=1.0.4->dash==2.0.0->jbrowse-jupyter==1.2.1) (2.0.1)\n",
      "Requirement already satisfied: ptyprocess>=0.5 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from pexpect>4.3->ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.6.0)\n",
      "Requirement already satisfied: wcwidth in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (0.2.5)\n",
      "Requirement already satisfied: pyzmq>=13 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter-client->ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (19.0.2)\n",
      "Requirement already satisfied: jupyter-core>=4.6.0 in /Users/teresamartinez/opt/anaconda3/lib/python3.8/site-packages (from jupyter-client->ipykernel->jupyter_dash>=0.4.0->jbrowse-jupyter==1.2.1) (4.6.3)\n",
      "Building wheels for collected packages: jbrowse-jupyter\n",
      "  Building wheel for jbrowse-jupyter (setup.py) ... \u001b[?25ldone\n",
      "\u001b[?25h  Created wheel for jbrowse-jupyter: filename=jbrowse_jupyter-1.2.1-py3-none-any.whl size=23012 sha256=dc06962e969611682d804c0be04df525f0ddaf4de081e7ff81ca334a6ad8ef75\n",
      "  Stored in directory: /private/var/folders/96/hq94_1qd3c9_q87bwqhg05s80000gn/T/pip-ephem-wheel-cache-_0jqacx4/wheels/a5/b8/b6/451f32abe96728b448365b4289261b6a436d79dd1ace71c4f1\n",
      "Successfully built jbrowse-jupyter\n",
      "Installing collected packages: dash, dash-jbrowse, jbrowse-jupyter\n",
      "  Attempting uninstall: dash\n",
      "    Found existing installation: dash 2.1.0\n",
      "    Uninstalling dash-2.1.0:\n",
      "      Successfully uninstalled dash-2.1.0\n",
      "  Attempting uninstall: dash-jbrowse\n",
      "    Found existing installation: dash-jbrowse 1.0.0\n",
      "    Uninstalling dash-jbrowse-1.0.0:\n",
      "      Successfully uninstalled dash-jbrowse-1.0.0\n",
      "Successfully installed dash-2.0.0 dash-jbrowse-1.0.1 jbrowse-jupyter-1.2.1\n",
      "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.\n",
      "You should consider upgrading via the '/Users/teresamartinez/opt/anaconda3/bin/python -m pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install git+https://github.com/GMOD/jbrowse-jupyter.git@main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from jbrowse_jupyter import launch, create"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "hg38 = create('LGV', genome='hg38')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "  refName  start  end      name\n0      10    100  175  feature1\n1      10    150  225  feature2\n2      10    200  275  feature3\n3      10    250  325  feature4\n"
     ]
    }
   ],
   "source": [
    "data = {'refName':['10', '10', '10', '10'],\n",
    "        'start':[100, 150, 200, 250],\n",
    "        'end':[175, 225, 275, 325],\n",
    "        'name':['feature1', 'feature2', 'feature3', 'feature4']}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "print(df)\n",
    "hg38.add_df_track(df, 'track_name', track_id=\"df_track_id\", overwrite=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "<IPython.lib.display.IFrame at 0x7fac089d0438>",
      "text/html": "\n        <iframe\n            width=\"100%\"\n            height=\"300\"\n            src=\"http://127.0.0.1:3003/\"\n            frameborder=\"0\"\n            allowfullscreen\n        ></iframe>\n        "
     },
     "metadata": {}
    }
   ],
   "source": [
    "hg38.set_location(\"10:100..350\")\n",
    "hg38.set_default_session(['df_track_id'], False)\n",
    "new_conf = hg38.get_config()\n",
    "launch(new_conf, port=3003)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "tracks = [\n",
    "    (\"https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GCA_000001405.15_GRCh38_full_analysis_set.refseq_annotation.sorted.gff.gz\", \"gff-demo\"),\n",
    "    (\"https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/skbr3/SKBR3_Feb17_GRCh38.sorted.bam\", \"bam-demo\"),\n",
    "    (\"https://s3.amazonaws.com/jbrowse.org/genomes/hg19/skbr3/reads_lr_skbr3.fa_ngmlr-0.2.3_mapped.down.cram\", \"cram-demo\"),\n",
    "    (\"https://hgdownload.cse.ucsc.edu/goldenpath/hg38/phyloP100way/hg38.phyloP100way.bw\", \"bigwig-demo\"),\n",
    "    (\"https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh38/clinvar.vcf.gz\", \"vcf-demo\"),\n",
    "    (\"https://jbrowse.org/genomes/GRCh38/repeats.bb\", \"bigbed\")\n",
    "]\n",
    "for track in tracks:\n",
    "    data = track[0]\n",
    "    track_id = track[1]\n",
    "    hg38.add_track(data, track_id=track_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "<IPython.lib.display.IFrame at 0x7fabc80d3668>",
      "text/html": "\n        <iframe\n            width=\"100%\"\n            height=\"800\"\n            src=\"http://127.0.0.1:8000/\"\n            frameborder=\"0\"\n            allowfullscreen\n        ></iframe>\n        "
     },
     "metadata": {}
    }
   ],
   "source": [
    "# set theme\n",
    "hg38.set_theme(\"#311b92\", \"#0097a7\", \"#f57c00\", \"#d50000\")\n",
    "hg38.set_default_session(['gff-demo', 'bigbed'],False)\n",
    "hg38.set_location(\"1:110654228..110936130\")\n",
    "new_conf2 = hg38.get_config()\n",
    "launch(new_conf2, id=\"test-2\",height=800, dash_comp=\"LGV\", port=8000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.6.13 64-bit ('penv': conda)",
   "metadata": {
    "interpreter": {
     "hash": "008c12275884433fb16330e243da39c752250b643962dc839102136cfd0533c7"
    }
   }
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}