Skip to content

Commit

Permalink
ALS-7300: Prepare for Analysis Page in BDC (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 authored Sep 19, 2024
1 parent 53b8b0d commit 109fb92
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/lib/assets/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"apiPage": {
"cards": [
{
"header": "Example Analyses with PIC-SURE page",
"body": "Detailed step-by-step example code that demonstrates how to use PIC-SURE for analysis.",
"header": "Setting Up the PIC-SURE API",
"body": "Step-by-step instructions to get started using the PIC-SURE API",
"link": "/analyze/example"
}
]
Expand All @@ -79,11 +79,11 @@
"btnText": "Start Exploring"
},
{
"title": "Analyze",
"description": "Access data and kickstart your research",
"title": "Prepare for Analysis",
"description": "Use the PIC-SURE API to prepare data for analysis",
"icon": "fa-solid fa-chart-line",
"url": "/analyze",
"btnText": "Go to Analyze"
"btnText": "Prepare for Analysis"
}
],
"stats": ["Variables", "Participants", "Data Sources"]
Expand Down
2 changes: 1 addition & 1 deletion src/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const routes: Route[] = [
},
{
path: '/analyze',
text: 'Analyze',
text: 'Prepare for Analysis',
privilege: [PicsurePrivileges.QUERY, BDCPrivileges.AUTHORIZED_ACCESS],
},
{
Expand Down
57 changes: 35 additions & 22 deletions src/routes/(picsure)/(authorized)/analyze/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@
<title>{branding.applicationName} | API</title>
</svelte:head>

<Content title="Analyze">
<Content title="Prepare for Analysis with the PIC-SURE API">
<section class="flex flex-col gap-8">
<p class="mt-4">
To start your analysis, use the following code to connect to PIC-SURE. Note that you will need
your personal access token below to complete the connection.
The PIC-SURE Application Programming Interface (API) can be used in an analysis environment of
your choice. This API is available in both Python and R coding languages.
</p>
<p>
To connect to the PIC-SURE Application Programming Interface (API), you will need your
personal access token. Copy your token and save as a text file called “token.txt” in the
working directory of your chosen analysis workspace, such as BioData Catalyst Powered by Seven
Bridges or BioData Catalyst Powered by Terra.
</p>
<div class="flex justify-center">
<UserToken />
</div>
<p>
To start your analysis, copy and execute the following code in an analysis environment, such
as BioData Catalyst Powered by Seven Bridges or BioData Catalyst Powered by Terra, to connect
to the PIC-SURE API. Note that you will need your personal access token to complete the
connection.
</p>
<TabGroup class="card p-4">
<Tab bind:group={tabSet} name="python" value={0}>Python</Tab>
Expand All @@ -26,48 +41,46 @@
language="python"
lineNumbers={true}
buttonCopied="Copied!"
code={`# Requires python 3.7 or later
code={`# Requires python 3.6 or later
import sys
import pandas as pd
import matplotlib.pyplot as plt
!{sys.executable} -m pip install --upgrade --force-reinstall git+https://github.com/hms-dbmi/pic-sure-python-adapter-hpds.git
# 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
import PicSureHpdsLib
!{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()
my_token = f.read()
connection = PicSureClient.Client.connect(url = PICSURE_network_URL, token = my_token)`}
bdc = PicSureBdcAdapter.Adapter(PICSURE_network_URL, my_token)`}
></CodeBlock>
{:else if tabSet === 1}
<CodeBlock
language="r"
lineNumbers={true}
code={`# Requires R 3.4 or later
install.packages("devtools")
### 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.
#install.packages("devtools")
Sys.setenv(TAR = "/bin/tar")
options(unzip = "internal")
devtools::install_github("hms-dbmi/pic-sure-r-adapter-hpds", ref="main", force=T, quiet=FALSE)
library(dplyr)
PICSURE_network_URL = "https://nhanes.hms.harvard.edu/picsure"
PICSURE_network_URL = "https://picsure.biodatacatalyst.nhlbi.nih.gov/picsure"
token_file <- "token.txt"
token <- scan(token_file, what = "character")
session <- picsure::bdc.initializeSession(PICSURE_network_URL, token)
session <- picsure::bdc.setResource(session = session)`}
session <- picsure::bdc.setResource(session = session, resourceName = "AUTH")`}
></CodeBlock>
{/if}
</svelte:fragment>
</TabGroup>
<p>
Copy your personal access token and save as a text file called “token.txt” in the same working
directory to execute the code above.
</p>
<div class="flex justify-center">
<UserToken />
</div>
</section>
<section id="info-cards" class="w-full flex flex-wrap flex-row justify-center mt-6">
{#each branding.apiPage.cards as card}
Expand Down
26 changes: 19 additions & 7 deletions src/routes/(picsure)/(authorized)/analyze/example/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,30 @@

<h4 class="font-medium mt-8">1. Set up your analysis workspace</h4>
<p>
First, you will need to set up your analysis workspace. This can be done locally or in a
cloud computing environment. Examples of how to programmatically access the PIC-SURE API
with Python or R are publicly available. These include Jupyter notebooks and RStudio files,
which you can access on the <a
First, you will need to set up your analysis workspace. This can be done in one of the
BioData Catalyst cloud computing environments, Seven Bridges or Terra. Examples of how to
programmatically access the PIC-SURE API with Python or R are publicly available. These
include Jupyter notebooks and RStudio files, which you can access on the
<a
class="anchor"
href="https://github.com/hms-dbmi/Access-to-Data-using-PIC-SURE-API/"
href="https://github.com/hms-dbmi/Access-to-Data-using-PIC-SURE-API/tree/master/NHLBI_BioData_Catalyst"
target="_blank">GitHub repository</a
>
</p>
<p>
The PIC-SURE team recommends starting with the PIC-SURE_101 example code. You can clone this
GitHub repository to your analysis workspace or set up a new file.
The PIC-SURE team recommends starting with the PIC-SURE_101 example code. You can access
these files in the
<a
class="anchor"
href="https://platform.sb.biodatacatalyst.nhlbi.nih.gov/u/biodatacatalyst/data-export-from-the-pic-sure-ui"
target="_blank">Data Export from the PIC-SURE UI Seven Bridges Public Project</a
>
or using one of the
<a
class="anchor"
href="https://terra.biodatacatalyst.nhlbi.nih.gov/#workspaces?tab=public&filter=pic-sure"
target="_blank">PIC-SURE Workspaces on Terra</a
>
</p>

<h4 class="font-medium mt-8">2. Get your Personal Access Token</h4>
Expand Down

0 comments on commit 109fb92

Please sign in to comment.