18 API Users’ Guide
18.1 ACCEPT API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patients provided in the accept
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("accept", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Python
import json
import requests
url = 'https://prism.peermodelsnetwork.com/route/accept/run'
headers = {'x-prism-auth-user': YOUR_API_KEY}
model_run = requests.post(url, headers=headers,
json = {"func":["prism_model_run"],"model_input":[{"ID": "10001","male": 1,"age": 57,"smoker": 0,"oxygen": 0,"statin": 0,"LAMA": 1,"LABA": 1,"ICS": 1,"FEV1": 51,"BMI": 18,"SGRQ": 63,"LastYrExacCount": 2,"LastYrSevExacCount": 1,"randomized_azithromycin": 0,"randomized_statin": 0,"randomized_LAMA": 0,"randomized_LABA": 0,"randomized_ICS": 0, "random_sampling_N" : 1000, "random_distribution_iteration" : 20000, "calculate_CIs" : "TRUE"}]})
print(model_run)
results = json.loads(model_run.text)
print(results)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"ID": "10001","male": 1,"age": 57,"smoker": 0,"oxygen": 0,"statin": 0,"LAMA": 1,"LABA": 1,"ICS": 1,"FEV1": 51,"BMI": 18,"SGRQ": 63,"LastYrExacCount": 2,"LastYrSevExacCount": 1,"randomized_azithromycin": 0,"randomized_statin": 0,"randomized_LAMA": 0,"randomized_LABA": 0,"randomized_ICS": 0, "random_sampling_N" : 1000, "random_distribution_iteration" : 20000, "calculate_CIs" : "TRUE"}]}' \
https://prism.peermodelsnetwork.com/route/accept/run
18.2 BODE API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the bode
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("bode", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"FEV1": 40,"mMRC": 3,"BMI": 22,"walk": 100}]}' \
https://prism.peermodelsnetwork.com/route/bode/run
18.3 EPIC API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the epicR
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("epic", api_key = YOUR_API_KEY)
results <- model_run(input)
18.4 FEV1 API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the fev1
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("fev1", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"male":1,"age":70,"smoker":1,"FEV1":2.5,"height":1.68,"weight":65}]}' \
https://prism.peermodelsnetwork.com/route/fev1/run
18.5 CVDAnderson API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the cvdanderson
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("cvdanderson", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"age": 33,"gender": 1,"Tchol": 230,"ECG_LVH": 0,"HDLchol": 48, "SBP": 135, "DBP": 88, "diabetes": 1, "smoker": 1, "t": 10}]}' \
https://prism.peermodelsnetwork.com/route/cvdanderson/run
18.6 CHDWilson API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the chdwilson
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("chdwilson", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"age": 55,"gender": 1,"TChol": 250,"LDL": 120,"HDL": 39, "SBP": 146, "DBP": 88, "diabetes": 0, "smoker": 1}]}' \
https://prism.peermodelsnetwork.com/route/chdwilson/run
18.7 CFMortality API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the chdwilson
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("cfmortality", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"male": 0,"age": 57,"fvc": 66.7,"fev1": 47.4,"fev1LastYear": 80.5,"bcepacia": 0,"underweight": 0,"nHosp": 0,"pancreaticInsufficient": 1,"CFRelatedDiabetes": 0,"ageAtDiagnosis": 0.9}]}' \
https://prism.peermodelsnetwork.com/route/cfmortality/run
18.8 QRISK3 API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the QRISK3
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("qrisk3", api_key = YOUR_API_KEY)
results <- model_run(input)
18.9 CODEXCOPD API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the codexcopd
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("codexcopd", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"age":40,"charlson":8,"FEV1":40,"mMRC":3,"exacerbation":2}]}' \
https://prism.peermodelsnetwork.com/route/codexcopd/run
18.10 MMRCEA API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example inputs provided by the modelling team:
library(peermodels)
input <- get_default_input("mmrcea", api_key = YOUR_API_KEY)
input$timeHorizon <- 5
input$discountRate <- 0.015
input$averageFamilyReferred <- 2
input$familyReferredHCP <- 1
input$adherenceIntensiveScreening <- 0.9
input$crcmmrDefReferredHCPIntArm <- 0.3
input$crcmmrDefReferredHCPmmrbrafCompArmVCHA <- 0.3
input$crcmmrDefReferredHCPmmrCompArmVCHA <- 0.08
input$crcmmrDefReferredHCPmmrbrafCompArmVIHA <- 0.08
input$crcmmrDefReferredHCPmmrCompArmOtherHA <- 0.08
input$ecmmrDefReferredHCPIntArm <- 0.8
model_run(input)
18.11 COVIDSEIR API (experimental)
We have recently deployed the Bayesian SEIR model to estimate physical-distancing effects developed by Anderson et al to our cloud infrastructure. The current version of the R package deployed to the PRISM server is covidseir v0.0.0.9006
.
The current implementation of the covidseir
package is experimental and has some limitations, given the computational intensity of the model. Depending on the number of chains
and iterations
, the html
connection might be dropped for calls that more than a dozen minutes.
Currently, fitting the model with default parameters takes about 5 minutes. We are actively working to implement asynchronous support which would email the results back to the user when hours long model runs are requested.
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the covidseir
package:
library(peermodels)
input <- get_default_input("covidseir", api_key = YOUR_API_KEY, bypass_router = T)
names(input)
input$daily_cases
results <- model_run(input)
names(results)
draw_plots()
The same workflow can be used to fit and run the model based on custom data. For example, the code snippet below, automatically downloads latest COVID-19 case numbers for British Columbia, and reruns the simulation using different assumptions.
library(stringr)
library(dplyr)
library(tidyr)
library(readr)
library(lubridate)
library(peermodels)
url <- "https://docs.google.com/spreadsheets/d/1ad7-09_Jn6AxsdkVPE33T-iLfGpPRmd3piXQqFiVeas/export?&format=csv"
CanadaCases <- read_csv(url)
covidCases <- CanadaCases %>% rename (name = "prname") %>% rename (Cases = "numconf") %>% mutate(date=dmy(date)) %>%
filter (name!="Canada") %>% filter (date!=today())
bcCases <- covidCases %>% filter (name == "British Columbia")
connect_to_model("covidseir", api_key = "YDbxcnNHmf4XoteSmCFHKx", bypass_router = T)
input <- get_default_input()
first <- length(bcCases$numtoday)-42+1
last <- length(bcCases$numtoday)
input$daily_cases <- bcCases$numtoday[first:last]
# Example assumed sampling fractions of positive cases:
s1 <- c(rep(0.1, 13), rep(0.2, length(input$daily_cases) - 13))
samp_frac_seg <- c(rep(1, 13), rep(2, length(input$daily_cases) - 13))
s2 <- rep(0.07, length(input$daily_cases)) # Assuming 7\% of positive individuals are hospitalized
input$samp_frac_fixed <- rep(0.1, length(input$daily_cases))
input$fit_iter <- 100
input$chains <- 1
input$f_fixed <- rep(0.1, 90)
results <- model_run(input)
draw_plots()
Cloud Access through Python
Users can use Python to access covidseir
model on the cloud. The simple code snippet below runs the model with default inputs.
import json
import requests
url = 'http://model-covidseir.cp.prism-ubc.linaralabs.com/ocpu/library/covidseirPrism/R/gateway/json'
headers = {'x-prism-auth-user': 'YOUR_API_KEY'}
default_input = requests.post(url, headers=headers,json = {"func":["get_default_input"]})
# json_default_input = json.loads(default_input.json()[0]) # OR:
json_default_input = json.loads(json.loads(default_input.text)[0])
response = requests.post(url, headers=headers,json = {"func":["prism_model_run"], "model_input":json_default_input})
results = json.loads(response.text)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":{"daily_cases":[0,0,1,3,1,8,0,6,5,0,7,7,18,9,22,38,53,45,40,77,76,48,67,78,42,66,67,92,16,70,43,53,55,53,29,26,37,25,45,34,40,35],"obs_model":["NB2","Poisson"],"fit_forecast_days":[0],"time_increment":[0.25],"samp_frac_fixed":[0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],"samp_frac_type":["fixed","estimated","rw","segmented"],"samp_frac_seg":{},"days_back":[45],"R0_prior":[0.9555,0.2],"phi_prior":[1],"f_prior":[0.4,0.2],"e_prior":[0.8,0.05],"samp_frac_prior":[0.4,0.2],"start_decline_prior":[2.7081,0.05],"end_decline_prior":[3.091,0.05],"f_ramp_rate":[0],"rw_sigma":[0.1],"seed":[42],"chains":[1],"fit_iter":[100],"N_pop":[5100000],"pars":{"D":[5],"k1":[0.2],"k2":[1],"q":[0.05],"ud":[0.1],"ur":[0.02],"f0":[1]},"i0_prior":[2.0794,1],"state_0":{"E1_frac":[0.4],"E2_frac":[0.1],"I_frac":[0.5],"Q_num":[0],"R_num":[0],"E1d_frac":[0.4],"E2d_frac":[0.1],"Id_frac":[0.5],"Qd_num":[0],"Rd_num":[0]},"save_state_predictions":[false],"delay_scale":[9.85],"delay_shape":[1.73],"ode_control":[1e-07,1e-06,1000000],"project_forecast_days":[100],"f_fixed_start":[53],"f_fixed":[0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.7,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2],"forecast_iter":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],"return_states":[false],"imported_cases":[0],"imported_window":[1],"f_seg":[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]}
} ' \
http://model-covidseir.cp.prism-ubc.linaralabs.com/ocpu/library/covidseirPrism/R/gateway/json
18.12 PLCOM2012 API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the PLCOM2012
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("PLCOm2012", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"age"=62, "race"="White", "education"=4, "bmi"=27, "copd"=0, "cancer_hist"=0, "family_hist_lung_cancer"=0, "smoking_status"=0, "smoking_intensity"=80, "duration_smoking"=27, "smoking_quit_time"=10}]}' \
https://prism.peermodelsnetwork.com/route/plcom2012/run
18.13 ADO API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the ADO
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("ado", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"fev":65, "mmrc":1, "age":41 }]}' \
http://model-ado.cp.prism-ubc.linaralabs.com/ocpu/library/adoPrism/R/gateway/json
18.14 DOSE API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the DOSE
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("dose", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"mmrc":1, "fev":55, "smoking_status":1, "exacerbation":2}]}' \
http://model-dose.cp.prism-ubc.linaralabs.com/ocpu/library/dosePrism/R/gateway/json
18.15 ISARIC4C API
Cloud Access through R
Users can access models on the Peer Models Network using the peermodels
R package, available on GitHub. The following code snippet illustrates how you can run the model for example patient provided in the ISARIC4C
package:
remotes::install_github (resplab/peermodels)
library(peermodels)
input <- get_default_input("isaric4c", api_key = YOUR_API_KEY)
results <- model_run(input)
Cloud Access through Linux Bash
In Ubuntu, you can call the API with curl
:
curl \
-X POST \
-H "x-prism-auth-user: REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"func":["prism_model_run"],"model_input":[{"age":69, "sex":1, "num_comorbidities":1, "respiratory_rate":25, "admission_oxygen_saturation": 90, "glasgow_coma_scale": 10, "urea": 10, "crp": 70, "func": 0}]}' \
http://model-dose.cp.prism-ubc.linaralabs.com/ocpu/library/isaric4cPrism/R/gateway/json