forked from alexwjung/CancerRisk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #1 from alexwjung/main
-
Showing
10 changed files
with
2,676 additions
and
63 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IGcSfiuEl2Vo","executionInfo":{"status":"ok","timestamp":1683283387141,"user_tz":-120,"elapsed":7423,"user":{"displayName":"Alexander Jung","userId":"15821513848078905412"}},"outputId":"e0917769-8d32-4089-f7ca-f41178484f31"},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (5.13.1)\n","Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly) (8.2.2)\n"]}],"source":["!pip3 install plotly"]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"6yu1jxDvnf00","executionInfo":{"status":"ok","timestamp":1683283490045,"user_tz":-120,"elapsed":102909,"user":{"displayName":"Alexander Jung","userId":"15821513848078905412"}},"outputId":"e50655f1-7fac-4801-83a7-7f6981e8fbf7"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},{"cell_type":"code","source":["## Custom Modules\n","#=======================================================================================================================\n","import sys\n","import os \n","import tqdm\n","import h5py\n","\n","import time\n","import pickle\n","import numpy as np \n","import pandas as pd \n","\n","import plotly.graph_objects as go \n","import plotly.express as px\n","\n","import matplotlib as mpl\n","import matplotlib.pyplot as plt\n","\n","ROOT_DIR = '/content/drive/MyDrive/tmp/plots/'\n","\n","\n","dd_theta = pd.read_csv(ROOT_DIR + 'theta.csv')\n","\n","disease_ref = np.load(ROOT_DIR + 'disease_codes.npy', allow_pickle=True)\n","disease_ref = disease_ref[:, 1]\n","\n","events = ['oesophagus', 'stomach', 'colorectal', 'liver',\n"," 'pancreas', 'lung', 'melanoma', 'breast', 'cervix_uteri',\n"," 'corpus_uteri', 'ovary', 'prostate', 'testis', 'kidney',\n"," 'bladder', 'brain', 'thyroid', 'non_hodgkin_lymphoma', 'multiple_myeloma', 'AML', 'other', 'death']\n","\n","\n","Events = ['Oesophagus', 'Stomach', 'Colorectal', 'Liver',\n"," 'Pancreas', 'Lung', 'Melanoma', 'Breast', 'Cervix uteri',\n"," 'Corpus Uteri', 'Ovary', 'Prostate', 'Testis', 'Kidney',\n"," 'Bladder', 'Brain', 'Thyroid', 'Non Hodgkin Lymphoma', 'Multiple Myeloma', 'AML']\n","\n","gene_names = np.asarray([jj+ii for jj in Events for ii in [' First Degree', ' All', ' Multiple', ' Early']])\n","\n","bth_names = np.asarray(['Alcoholic', 'Smoker', 'High Blood Pressure', 'Low Blood Pressure', 'Height', 'Weight', 'Age at first Birth'])\n","\n","names = np.concatenate((disease_ref, gene_names, bth_names))\n","\n","colormap= np.asarray(['#1E90FF', '#BFEFFF', '#191970', '#87CEFA', '#008B8B', '#946448', '#421a01', '#6e0b3c', \n"," '#9370DB', '#7A378B', '#CD6090', '#006400', '#5ebd70', '#f8d64f', '#EEAD0E', '#f8d6cf',\n"," '#CDCB50', '#CD6600', '#FF8C69', '#8f0000', '#b3b3b3', '#454545'])\n","\n","for cc in range(22):\n"," print(cc, events[cc])\n","\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"RZ7h07l2mtzX","executionInfo":{"status":"ok","timestamp":1683283491888,"user_tz":-120,"elapsed":1848,"user":{"displayName":"Alexander Jung","userId":"15821513848078905412"}},"outputId":"21dcda12-62fd-4fdf-bd31-16c82ca95774"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["0 oesophagus\n","1 stomach\n","2 colorectal\n","3 liver\n","4 pancreas\n","5 lung\n","6 melanoma\n","7 breast\n","8 cervix_uteri\n","9 corpus_uteri\n","10 ovary\n","11 prostate\n","12 testis\n","13 kidney\n","14 bladder\n","15 brain\n","16 thyroid\n","17 non_hodgkin_lymphoma\n","18 multiple_myeloma\n","19 AML\n","20 other\n","21 death\n"]}]},{"cell_type":"code","execution_count":4,"metadata":{"tags":[],"id":"QaBBCwxYl2Vs","executionInfo":{"status":"ok","timestamp":1683283538544,"user_tz":-120,"elapsed":2,"user":{"displayName":"Alexander Jung","userId":"15821513848078905412"}}},"outputs":[],"source":["theta = np.exp(np.asarray(dd_theta.iloc[:, np.arange(2, 62, 3)]))\n","theta_lower = np.exp(np.asarray(dd_theta.iloc[:, np.arange(3, 63, 3)]))\n","theta_upper = np.exp(np.asarray(dd_theta.iloc[:, np.arange(4, 64, 3)]))\n","\n","y = np.arange(theta.shape[0])"]},{"cell_type":"code","source":["import plotly.graph_objects as go \n","fig = go.Figure()\n","n=300\n","for cc in range(20):\n"," fig.add_trace(go.Scatter(\n"," x=theta[:, cc],\n"," y=names, \n"," mode=\"markers\",\n"," marker_color=colormap[cc], \n"," name=Events[cc],\n"," customdata=pd.DataFrame({'l': theta_lower[:, cc], \n"," 'u': theta_upper[:, cc], \n"," 'e': np.repeat(Events[cc], theta.shape[0]) }),\n"," hovertemplate='<b>Cancer: </b>: %{customdata[2]}<br>' + \n"," '<b>Var: </b>: %{y}<br>' + \n"," '<b>HR</b>: %{x:.2f} [%{customdata[0]:.2f}, %{customdata[1]:.2f}]<br>' + \n"," '<extra></extra>'\n"," ))\n","\n","fig.update_xaxes(title_text=\"Hazard Ratio \", type=\"log\", gridcolor='#acacad')\n","fig.update_yaxes(gridcolor='#acacad')\n","\n","\n","fig.update_layout(\n"," paper_bgcolor='rgba(0,0,0,0)',\n"," plot_bgcolor='rgba(0,0,0,0)',\n"," width=1200,\n"," height=950,\n"," \n",")\n","\n","fig.write_html(ROOT_DIR + 'dexp.html')"],"metadata":{"id":"flTGpgBlzTdA","executionInfo":{"status":"ok","timestamp":1683285477768,"user_tz":-120,"elapsed":624,"user":{"displayName":"Alexander Jung","userId":"15821513848078905412"}}},"execution_count":43,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AW3ySBaml2V0"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"vNykD7Cgl2V1"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"czHbTrItl2V2"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"leMrvnYql2V2"},"outputs":[],"source":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} |