Skip to content

Instantly share code, notes, and snippets.

@mtmorgan
Last active October 6, 2021 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtmorgan/308820eaffe5ab76faac12bb10327802 to your computer and use it in GitHub Desktop.
Save mtmorgan/308820eaffe5ab76faac12bb10327802 to your computer and use it in GitHub Desktop.
Script used during Human Cell Atlas presentation, 2021-10-06
##
## Preliminiaries: install infrasctructure and required packages
##
## We've got to be using a least R version 4.1
my_R_version <-
numeric_version(paste(R.Version()[c("major", "minor")], collapse = "."))
stopifnot(my_R_version >= "4.1")
## install pre-requisites for package installation
prerequisites <- c("remotes", "BiocManager", "futile.logger")
prerequisites <-
prerequisites[!prerequisites %in% rownames(installed.packages())]
install.packages(prerequisites, repos = "https://cran.r-project.org")
## install the 'devel' version of the hca package; may be prompted to
## update out-of-date packages
BiocManager::install("Bioconductor/hca")
pkgs <- "LoomExperiment"
pkgs <- pkgs[!pkgs %in% rownames(installed.packages())]
BiocManager::install(pkgs)
##
## The HCA Data Portal
##
suppressPackageStartupMessages({
library(hca)
library(dplyr)
})
## all projects
projects <- projects()
projects
## filter on the `projects` object -- title of interest
projects |>
filter(grepl("development of the blood", projectTitle)) |>
glimpse()
## filter on 'facets' of the data: what facets are avaiable?
projects_facets()
projects_facets() |>
filter(endsWith(facet, "Organ"))
## What values values are available within the 'specimenOrgan' facet?
projects_facets("specimenOrgan")
## find all studies of the liver
filter <- filters(
specimenOrgan = list(is = "liver")
)
projects(filter)
## I want more information about these studies!
tbl <- projects(filter, as = "tibble_expanded")
names(tbl)
## I want as many donors as possible
tbl |>
select(projectId, projects.projectTitle, donorOrganisms.donorCount)
tbl |>
filter(donorOrganisms.donorCount > 5)
##
## Loom files
##
## discovery and retrieval
## one experiment, loom files from the DCP/2 analysis pipeline,
## including post-processing (combine across samples; 'sparse'
## representation) step
filter <- filters(
projectId = list(is = "4d6f6c96-2a83-43d8-8fe1-0f53bffd4674"),
fileSource = list(is = "DCP/2 Analysis"),
fileFormat = list(is = "loom"),
workflow = list(is = "optimus_post_processing_v1.0.0")
)
loom_file_path <-
files(filter) |> # find files matching filter
files_download() # download (and cache) to local disk
## import into R
suppressPackageStartupMessages({
library(LoomExperiment)
})
loom <- LoomExperiment::import(loom_file_path)
loom
## add biological annotations
loom_annotated <- optimus_loom_annotation(loom)
table(loom_annotated$input_id, loom_annotated$donor_organism.sex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment