requireNamespace("knitr") knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
In this example, we're going to explore the capabilities of the phenotype matrix services using the gorr
package.
First load the gorr
package, the tidyverse
package is recommended in general, but not required for this example
library(gorr) library(magrittr) # pipe library(tibble)
First we'll need to establish a connection to our API services. To do that we'll need to call platform_connect
and provide it with the relevant parameters pointing to the phenotype-catalog-service, i.e. api_key
and project
:
conn <- platform_connect(api_key = Sys.getenv("GOR_API_KEY"), project = Sys.getenv("GOR_API_PROJECT")) conn
If everything goes as planned, we'll have a conn
object to pass into subsequent functions.
Let's start by listing available phenotypes in project with "Cases" as one of its tags
recipe_tag = "Cases" phenos<- get_phenotypes(conn, any_tags = recipe_tag, limit = 20) phenos[1:3]
The results come back as a vector
of phenotypes
phenos_subset_names <- sample(names(phenos),5) phenos_subset_names
We initialize an empty phenotype matrix object by running get_phenotype_matrix
optionally passing the base
variable.
pheno_matrix <- get_phenotype_matrix() class(pheno_matrix) pheno_matrix
To add phenotype/s to the phenotype matrix we use either phemat_add_phenotype
for adding a single phenotype to the matrix or phemat_add_phenotypes
to add multiples.
Note that these methods do not have the same input arguments
phemat_add_phenotype(name, phenotype_matrix, missing_value, label)
phemat_add_phenotypes(names, phenotype_matrix, missing_value)
pheno_matrix <- phemat_add_phenotypes(phenos_subset_names, pheno_matrix, missing_value = '-99')
print(paste("pheno_matrix class:", class(pheno_matrix))) print(paste("pheno_matrix content:", paste(names(pheno_matrix), collapse = ", "))) print(paste("pheno_matrix phenotypes:", paste(names(pheno_matrix$phenotypes), collapse = ", ")))
rm_pheno <- names(pheno_matrix$phenotypes)[1] paste("Removing phenotype:", rm_pheno) pheno_matrix <- phemat_remove_phenotype(name=rm_pheno, pheno_matrix) pheno_matrix
Lastly, let's fetch a phenotype from the project. We'll use the first listed
pheno_data <- get_data(pheno_matrix, conn)
print(pheno_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.