{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Wherever the current working directory is move to `~/cerebmodels`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/harshkhilawala/gsoc/demo_ecosystem/cerebmodels/docs/notebooks\r\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/harshkhilawala/gsoc/demo_ecosystem/cerebmodels/docs\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/harshkhilawala/gsoc/demo_ecosystem/cerebmodels\n" ] } ], "source": [ "cd .." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create MockData Instance to generate mock data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from cerebstats.test_mock_data import MockData\n", "MD = MockData()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Reference Dataset Link\n", "datasetlink = \"https://raw.githubusercontent.com/cerebunit/cerebdata/master/expdata/cells/PurkinjeCell/Llinas_Sugimori_1980_soma_restVm.json\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generate mock data files with reference dataset" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mock Data File 1 generated...\n", "Mock Data File 2 generated...\n", "Mock Data File 3 generated...\n", "Mock Data File 4 generated...\n", "Mock Data File 5 generated...\n", "Mock Data File 6 generated...\n", "Mock Data File 7 generated...\n", "Mock Data File 8 generated...\n", "Mock Data File 9 generated...\n", "Mock Data File 10 generated...\n" ] } ], "source": [ "MD.generate_random_data_files(datasetlink, sample_low=-70,sample_high=-48,num_of_files=10)" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "MD.count_files()" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "data6.json\n", "data8.json\n", "data9.json\n", "data1.json\n", "data10.json\n", "data3.json\n", "data2.json\n", "data5.json\n", "data4.json\n", "data7.json\n" ] } ], "source": [ "MD.display_files()" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "# Clear out the files\n", "# MD.clear_files()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load desired Validation Test" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [], "source": [ "from cerebtests.validation_tests.cells.Purkinje import SomaRestingVmTest as srvt" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "# Set the Model in dictionary format with keys \"modelscale\" and \"modelname\"\n", "test_model = {\"modelscale\": \"cells\", \"modelname\": \"PC2003Khaliq\"}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instantiate TestMetrics Object" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "from cerebstats.test_quality import TestMetrics" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "%%capture\n", "TM = TestMetrics(test_model,srvt, alpha=0.05, epsilon=5) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Calculate the Test Metrics" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Running 1 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is normal\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.09515751699998987 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.14974589499999524 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.1355783710000082 seconds ---\n", "Computing score ...\n", "Done.\n", "u0 = -60.67565845798073 mV, u = -59.30909090909091 mV, n = 55\n", "H0: u = u0\n", "Ha: u =/= u0\n", "Test statistic: z = 0.2301124290815077 dimensionless\n", "Assuming H0 is true, p-value = 0.8180044070217465\n", "\n", "\n", "\n", "\n", "Running 2 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.09747960500001795 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.15349269800000798 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.1451948119999997 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -58.0 mV, n = 74\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 2.557448052364024\n", "Assuming H0 is true, p-value = 0.010544330566972694\n", "\n", "\n", "\n", "\n", "Running 3 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is Not skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10171535699998913 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.15931845599999406 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.245789142999996 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -59.0 mV, n = 50\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 1.1825266376236836\n", "Assuming H0 is true, p-value = 0.23699680244648247\n", "\n", "\n", "\n", "\n", "Running 4 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is normal\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10118826100000433 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.15947674100002018 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.258272912999985 seconds ---\n", "Computing score ...\n", "Done.\n", "u0 = -60.67565845798073 mV, u = -58.48 mV, n = 75\n", "H0: u = u0\n", "Ha: u =/= u0\n", "Test statistic: z = 0.33631258385661145 dimensionless\n", "Assuming H0 is true, p-value = 0.7366351615036643\n", "\n", "\n", "\n", "\n", "Running 5 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is normal\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10438432500001227 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.16593286599999146 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.2758500919999847 seconds ---\n", "Computing score ...\n", "Done.\n", "u0 = -60.67565845798073 mV, u = -59.345238095238095 mV, n = 84\n", "H0: u = u0\n", "Ha: u =/= u0\n", "Test statistic: z = 0.20655127348297922 dimensionless\n", "Assuming H0 is true, p-value = 0.8363603176537158\n", "\n", "\n", "\n", "\n", "Running 6 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10099187299999812 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.1577753159999986 seconds ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/envs/py3-cerebmodels/lib/python3.6/site-packages/scipy/stats/stats.py:1604: UserWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=10\n", " \"anyway, n=%i\" % int(n))\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Simulation produce_soma v_restingVm Done.\n", "--- 3.240491643999974 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -60.5 mV, n = 10\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 0.0\n", "Assuming H0 is true, p-value = 1.0\n", "\n", "\n", "\n", "\n", "Running 7 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10715595299998881 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.1680948350000051 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.297033875000011 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -52.0 mV, n = 26\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 3.530090432487313\n", "Assuming H0 is true, p-value = 0.00041541764838159116\n", "\n", "\n", "\n", "\n", "Running 8 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is Not skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10228512500000875 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.16382761399998458 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.2751330160000123 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -60.0 mV, n = 63\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 0.4655350788461547\n", "Assuming H0 is true, p-value = 0.6415483222069057\n", "\n", "\n", "\n", "\n", "Running 9 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is Not normal\n", "dataset is Not skewed\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10897472400000652 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.17115610899998046 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.341652879999998 seconds ---\n", "Computing score ...\n", "Done.\n", "eta0 = -60.67565845798073 mV, eta = -61.5 mV, n = 34\n", "H0: eta = eta0\n", "Ha: eta =/= eta0\n", "Test statistic: z = 1.0172426498607163\n", "Assuming H0 is true, p-value = 0.3090380114196175\n", "\n", "\n", "\n", "\n", "Running 10 of 10 \n", "\n", "\n", "Validate Observation ...\n", "dataset is normal\n", "Validated.\n", "Testing ...\n", "Sim produce_soma v_restingVm starting ...\n", "Simulation produce_voltage_response starting ...\n", "--- 0.10844991900000878 seconds ---\n", "File saving ...\n", "File saved.\n", "Simulation produce_voltage_response Done.\n", "--- 0.16898487199998158 seconds ---\n", "Simulation produce_soma v_restingVm Done.\n", "--- 3.349777137999979 seconds ---\n", "Computing score ...\n", "Done.\n", "u0 = -60.67565845798073 mV, u = -59.215053763440864 mV, n = 93\n", "H0: u = u0\n", "Ha: u =/= u0\n", "Test statistic: z = 0.22850703411968248 dimensionless\n", "Assuming H0 is true, p-value = 0.8192520883327371\n", "\n", "\n", "\n" ] } ], "source": [ "TM.calculate_metrics()" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "TM.get_specificity()" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.8888888888888888" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "TM.get_sensitivity()" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.5" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "TM.get_npv()" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "TM.get_ppv()" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-----------+---------+\n", "| Outcome | Value |\n", "|-----------+---------|\n", "| TP | 8 |\n", "| FP | 0 |\n", "| TN | 1 |\n", "| FN | 1 |\n", "+-----------+---------+\n" ] } ], "source": [ "TM.display_outcomes()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+---------------------------+----------+\n", "| Metric | Value |\n", "|---------------------------+----------|\n", "| Specificity | 1 |\n", "| Sensitivity | 0.888889 |\n", "| Negative Predictive Value | 0.5 |\n", "| Positive Predictive Value | 1 |\n", "+---------------------------+----------+\n" ] } ], "source": [ "TM.display_metrics()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.5.2" } }, "nbformat": 4, "nbformat_minor": 5 }