Skip to content

Instantly share code, notes, and snippets.

@mtmorgan
Last active May 3, 2021 14:40
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/855b303cecd5416ef9402d04ba72e61f to your computer and use it in GitHub Desktop.
Save mtmorgan/855b303cecd5416ef9402d04ba72e61f to your computer and use it in GitHub Desktop.
AnVIL PopUp Workshop week 2 script
if (!"AnVIL" %in% rownames(installed.packages()))
BiocManager::install("AnVIL")
library(AnVIL)
this_workspace = avworkspace()
hca = "featured-workspaces-hca/HCA_Optimus_Pipeline"
thousand_genomes = "anvil-datastorage/1000G-high-coverage-2019"
## AnVIL 'namespace' / 'name' == workspace
avworkspace()
avworkspace(hca)
## DATA TABLE access
avtables()
tbl = avtable("sample")
tbl
tbl %>% count(participant)
## tbl %>% avtable_import()
## second example
avworkspace(thousand_genomes)
avtables()
participant = avtable("participant")
participant
participant %>%
count(POPULATION, sort = TRUE)
avtable("pedigree") %>%
count(Population, Sex) %>%
tidyr::pivot_wider(names_from = "Sex", values_from = "n")
## switch back to the HCA workspace
avworkspace(hca)
## Google buckets
## Copy files from google buckets to persistent disk
tbl = avtable("sample_set")
tbl
dir.create("~/loom")
gsutil_cp(tbl$loom_output_file, "~/loom/") # see also gsutil_rsync()
dir("~/loom")
## workspace bucket -- 'backup' or share persistent disk to workspace bucket
avworkspace(this_workspace)
avbucket() # bucket associated with this workspace
gsutil_ls(avbucket())
avfiles_backup("~/scripts", recursive = TRUE) # see also avfiles_restore()
gsutil_ls(avbucket(), recursive = TRUE)
if (FALSE) {
## update to 'devel' version of the AnVIL package
BiocManager::install("Bioconductor/AnVIL") # do NOT update
# out-of-date packages
## RESTART R, and then...
AnVIL::repositories() # binary Bioconductor and CRAN installations
## install and use LoomExperiment
AnVIL::install("LoomExperiment") # about 40 seconds, rather than
# 10's of minutes
sce = LoomExperiment::import("~/loom/pbmc_human_v3.loom")
}
## advanced -- access AnVIL from outside AnVIL, with google cloud SDK installed
## gcloud_account()
## gcloud_project()
## advanced -- the AnVIL / Terra API
leo = Leonardo()
leo
leo$listDisks()
terra = Terra()
tags(terra, "Workspaces")
wkspc =
terra$listWorkspaces() %>%
flatten() %>%
select(-starts_with("workspace.attributes"))
wkspc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment