diff --git a/src/lib/assets/codeBlocks.json b/src/lib/assets/codeBlocks.json new file mode 100644 index 00000000..2a97c4c8 --- /dev/null +++ b/src/lib/assets/codeBlocks.json @@ -0,0 +1,10 @@ +{ + "bdcPythonExport": "# Requires python 3.7 or later\nimport sys\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\n# BDC Powered by Terra users uncomment the following line to specify package install location\n# sys.path.insert(0, r\"/home/jupyter/.local/lib/python3.7/site-packages\")\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-client.git\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-adapter-hpds.git\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-biodatacatalyst-python-adapter-hpds.git\n\nimport PicSureClient\nimport PicSureBdcAdapter\n\ntoken_file = \"token.txt\"\nwith open(token_file, \"r\") as f:\n my_token = f.read()\n\nbdc = PicSureBdcAdapter.Adapter(\"https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure\", my_token)\n\nresource = bdc.useResource('02e23f52-f354-4e8b-992c-d37c8b9ba140')\n\nqueryID = <>\n\nresults = resource.retrieveQueryResults(queryID)\n\nfrom io import StringIO\ndf_UI = pd.read_csv(StringIO(results), low_memory=False)\ndf_UI.head() # View top 5 rows of dataframe", + "bdcRExport": "# Requires R 3.4 or later\n### Uncomment this code if you are not using the PIC-SURE environment in *BDC-Seven Bridges*, or if you do not have all the necessary dependencies installed.\n#install.packages(\"devtools\")\n\nSys.setenv(TAR = \"/bin/tar\")\noptions(unzip = \"internal\")\ndevtools::install_github(\"hms-dbmi/pic-sure-r-adapter-hpds\", ref=\"main\", force=T, quiet=FALSE)\nlibrary(dplyr)\n\ntoken_file <- \"token.txt\"\ntoken <- scan(token_file, what = \"character\")\n\nsession <- picsure::bdc.initializeSession(\"https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure\", token)\nsession <- picsure::bdc.setResource(session = session, resourceName = \"AUTH\")\n\nqueryID <- \"526c318d-4a0c-4937-9baa-e21042a0e444\"\nresults <- picsure::getResultByQueryUUID(session, queryID)\nhead(results) # View top 5 rows of dataframe", + "bdcPythonAPI": "# Requires python 3.6 or later\nimport sys\nimport pandas as pd\nimport matplotlib.pyplot as plt\n# BDC Powered by Terra users uncomment the following line to specify package install location\n# sys.path.insert(0, r\"/home/jupyter/.local/lib/python3.7/site-packages\")\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-client.git\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-adapter-hpds.git\n!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-biodatacatalyst-python-adapter-hpds.git\nimport PicSureClient\nimport PicSureBdcAdapter\n# Set up connection to PIC-SURE API\nPICSURE_network_URL = \"https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure\"\ntoken_file = \"token.txt\"\n\nwith open(token_file, \"r\") as f:\n my_token = f.read()\n\nbdc = PicSureBdcAdapter.Adapter(PICSURE_network_URL, my_token)", + "bdcRAPI": "# Requires R 3.4 or later\n### Uncomment this code if you are not using the PIC-SURE environment in *BDC-Seven Bridges*, or if you do not have all the necessary dependencies installed.\n#install.packages(\"devtools\")\nSys.setenv(TAR = \"/bin/tar\")\noptions(unzip = \"internal\")\ndevtools::install_github(\"hms-dbmi/pic-sure-r-adapter-hpds\", ref=\"main\", force=T, quiet=FALSE)\nlibrary(dplyr)\nPICSURE_network_URL = \"https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure\"\ntoken_file <- \"token.txt\"\ntoken <- scan(token_file, what = \"character\")\nsession <- picsure::bdc.initializeSession(PICSURE_network_URL, token)\nsession <- picsure::bdc.setResource(session = session, resourceName = \"AUTH\")", + "basePythonExport": "Code not set", + "baseRExport": "Code not set", + "basePythonAPI": "Code not set", + "baseRAPI": "Code not set" +} diff --git a/src/lib/components/explorer/export/ExportStepper.svelte b/src/lib/components/explorer/export/ExportStepper.svelte index 5dfe93cb..0d7c09b0 100644 --- a/src/lib/components/explorer/export/ExportStepper.svelte +++ b/src/lib/components/explorer/export/ExportStepper.svelte @@ -20,6 +20,7 @@ import { createDatasetName } from '$lib/services/datasets'; import CardButton from '$lib/components/buttons/CardButton.svelte'; import type { ExpectedResultType } from '$lib/models/query/Query.ts'; + import codeBlocks from '$lib/assets/codeBlocks.json'; export let query: QueryRequestInterface; export let showTreeStep = false; @@ -321,55 +322,13 @@ language="python" lineNumbers={true} buttonCopied="Copied!" - code={`# Requires python 3.7 or later -import sys -import pandas as pd -import matplotlib.pyplot as plt -# BDC Powered by Terra users uncomment the following line to specify package install location -# sys.path.insert(0, r"/home/jupyter/.local/lib/python3.7/site-packages") -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-client.git -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-adapter-hpds.git -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-biodatacatalyst-python-adapter-hpds.git -import PicSureHpdsLib -import PicSureClient - -PICSURE_network_URL = "https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure" - -token_file = "token.txt" -with open(token_file, "r") as f: - my_token = f.read() - -connection = PicSureClient.Client.connect(url = PICSURE_network_URL, token = my_token) - -queryID = "${datasetId}" - -results = resource.retrieveQueryResults(queryID) - -from io import StringIO -df_UI = pd.read_csv(StringIO(results), low_memory=False)`} + code={codeBlocks?.bdcPythonExport || 'Code not set'} > {:else if tabSet === 1} {:else if tabSet === 2}
diff --git a/src/routes/(picsure)/(authorized)/analyze/+page.svelte b/src/routes/(picsure)/(authorized)/analyze/+page.svelte index 648b21d5..4f27af6a 100644 --- a/src/routes/(picsure)/(authorized)/analyze/+page.svelte +++ b/src/routes/(picsure)/(authorized)/analyze/+page.svelte @@ -3,6 +3,7 @@ import UserToken from '$lib/components/UserToken.svelte'; import { branding } from '$lib/configuration'; import { CodeBlock, Tab, TabGroup } from '@skeletonlabs/skeleton'; + import codeBlocks from '$lib/assets/codeBlocks.json'; let tabSet: number = 0; @@ -53,42 +54,10 @@ language="python" lineNumbers={true} buttonCopied="Copied!" - code={`# Requires python 3.6 or later -import sys -import pandas as pd -import matplotlib.pyplot as plt -# BDC Powered by Terra users uncomment the following line to specify package install location -# sys.path.insert(0, r"/home/jupyter/.local/lib/python3.7/site-packages") -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-client.git -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-adapter-hpds.git -!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-biodatacatalyst-python-adapter-hpds.git -import PicSureClient -import PicSureBdcAdapter -# Set up connection to PIC-SURE API -PICSURE_network_URL = "https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure" -token_file = "token.txt" - -with open(token_file, "r") as f: - my_token = f.read() - -bdc = PicSureBdcAdapter.Adapter(PICSURE_network_URL, my_token)`} + code={codeBlocks?.bdcPythonAPI || 'Code not set'} > {:else if tabSet === 1} - {/if}