R/get_ctd.R

Defines functions get_ctd

Documented in get_ctd

#' Import precomputed CellTypeDatasets
#'
#' Import CellTypeDatasets (CTD) generated by
#' \href{https://github.com/NathanSkene/EWCE}{EWCE}.
#' \itemize{
#' \item{"ctd_AIBS"\cr}{CTD file derived from adult human cortex 
#' scRNA-seq data collected by the Allen Institute for Brain Science (AIBS) 
#' Note that this CTD used an early release of the AIBS data that only included
#' samples from human Medial Temporal Gyrus (MTG).
#' \cr Reference: \doi{10.1038/s41586-019-1506-7}\cr
#' \href{https://portal.brain-map.org/atlases-and-data/rnaseq/data-files-2018}{
#' Allen Brain Institute website}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_allAIBS"\cr}{CTD file derived from adult human cortex 
#' scRNA-seq data collected by the Allen Institute for Brain Science (AIBS) 
#' Note that this CTD used an later release of the AIBS data that included
#' samples from multiple human brain regions.
#' \cr Reference: \doi{10.1038/s41586-019-1506-7}\cr
#' \href{https://portal.brain-map.org/atlases-and-data/rnaseq/data-files-2018}{
#' Allen Brain Institute website}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_allKI"\cr}{CTD file with cortex, hippocampus,
#' hypothalamus and midbrain.
#' \cr Reference: \doi{10.1038/s41588-018-0129-5}\cr
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_BlueLake2018_FrontalCortexOnly"\cr}{
#' CTD file with data from humans.
#' \cr Reference: \doi{10.1038/nbt.4038}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_BlueLake2018_VisualCortexOnly"\cr}{
#' CTD file with data from humans.
#' \cr Reference: \doi{10.1038/nbt.4038}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_Saunders"\cr}{
#' CTD file with data from humans.
#' \cr Reference: \doi{10.1016/j.cell.2018.07.028}\cr  
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_DescartesHuman"\cr}{
#' CTD file with scRNA-seq data from human embryo across multiple organ systems.
#' \cr Reference: \doi{10.1126/science.aba7721}\cr 
#' \href{https://descartes.brotmanbaty.org/bbi/human-gene-expression-during-development/}{
#' Source}
#' }
#' \item{"ctd_DRONC_human"\cr}{
#' CTD file with DRONC-seq data from humans.
#' \cr Reference: \doi{10.1038/nmeth.4407}\cr  
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_DRONC_mouse"\cr}{
#' CTD file with Tasic data from mouse.
#' \cr Reference: \doi{10.1038/nmeth.4407}\cr  
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Reference}
#' }
#' \item{"ctd_DivSeq"\cr}{
#' CTD file with DivSeq data.
#' \cr Reference: \doi{10.1126/science.aad7038}\cr
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_Tasic"\cr}{
#' CTD file with Tasic data.
#' \cr Reference: \doi{10.1038/nn.4216}\cr
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_Zeisel2016"\cr}{
#' CTD file with data from adult mouse hippocampus.
#' \cr Reference: \doi{10.1126/science.aaa1934}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_Zeisel2018"\cr}{
#' CTD file with data from juvenile mouse central nervous system atlas.
#' \cr Reference: \doi{10.1016/j.cell.2018.06.021}\cr 
#' \href{http://www.hjerling-leffler-lab.org/data/scz_singlecell/}{Source}
#' }
#' \item{"ctd_LaManno2020"\cr}{
#' CTD file with data from developing mouse central nervous system atlas.
#' \cr Reference: \doi{10.1038/s41586-021-03775-x}\cr 
#' \href{http://mousebrain.org/development/downloads.html}{Source}
#' }
#' \item{"ctd_Aerts2018"\cr}{
#' CTD file with data from aging fly central nervous system atlas.
#' \cr Reference: \doi{10.1016/j.cell.2018.05.057}\cr
#' \href{https://scope.aertslab.org/}{Source}
#' }
#' \item{"ctd_FlyCellAtlas"\cr}{
#' CTD file with data from adult fly whole-body atlas
#'  (a.k.a the FlyCellAtlas).
#' \cr Reference: \doi{10.1126/science.abk2432}\cr
#' \href{https://www.flycellatlas.org/#data}{Source}
#' }
#' \item{"ctd_Raj2018"\cr}{
#' CTD file with data from juvenile zebrafish central nervous system atlas.
#' \cr Reference: \doi{10.1038/nbt.4103}\cr 
#' \href{https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE105010}{Source}
#' }
#' \item{"ctd_Raj2020"\cr}{
#' CTD file with data from developing zebrafish central nervous system atlas.
#' \cr Reference: \doi{10.1016/j.neuron.2020.09.023}\cr  
#' \href{https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE158142}{Source}
#' }
#' \item{"ctd_Farnsworth2020"\cr}{
#' CTD file with data from developing zebrafish central nervous system atlas.
#' \cr Reference: \doi{10.1016/j.ydbio.2019.11.008}\cr  
#' \href{http://cells.ucsc.edu/?ds=zebrafish-dev}{Source}
#' }
#' \item{"ctd_TabulaMuris_facs"\cr}{
#' CTD file with data from adult mouse whole-body atlas.
#' Uses the Smart-seq2 (FACS) subset of the data and covers a greater number 
#' of cell-types than the Droplet version.
#' \cr Reference: \doi{10.1038/s41586-018-0590-4}\cr   
#' \href{https://tabula-muris.ds.czbiohub.org/}{Source}
#' }
#' \item{"ctd_TabulaMuris_droplet"\cr}{
#' CTD file with data from adult mouse whole-body atlas.
#' Uses the Droplet subset of the data 
#' \cr Reference: \doi{10.1038/s41586-018-0590-4}\cr   
#' \href{https://tabula-muris.ds.czbiohub.org/}{Source}
#' }
#' \item{"ctd_TabulaMurisSenis" (Under construction)\cr}{
#' CTD file with data from aging adult mouse whole-body atlas.
#' \cr Reference: \doi{10.1038/s41586-020-2496-1}\cr
#' \href{https://tabula-muris-senis.ds.czbiohub.org/}{Source}
#' }
#' \item{"ctd_Avalos2019"\cr}{
#' CTD file with data from developing fly central nervous system atlas.
#' \cr Reference: \doi{10.7554/eLife.50354}\cr 
#' \href{https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE134722}{Source}
#' }
#' \item{"ctd_NonHumanPrimateCellAtlas"\cr}{
#' CTD file with data from adult monkey whole-body atlas.
#' \cr Reference: \doi{10.1038/s41586-022-04587-3}\cr 
#' \href{https://db.cngb.org/nhpca/download}{Source}
#' }
#' \item{"ctd_DescartesMouse"\cr}{
#' CTD file with data from the Descartes developing mouse whole-body atlas.
#' \cr Reference: \doi{10.1038/s41586-019-0969-x}\cr 
#' \href{https://oncoscape.v3.sttrcancer.org/atlas.gs.washington.edu.mouse.rna}{
#' Source}
#' }
#' }
#' @param ctd_name Name of one or more CellTypeDatset objects to import.
#' @param storage_dir Folder in which to save the CellTypeDatset.
#' @inheritParams piggyback::pb_upload
#' @returns CellTypeDataset object, or a named list of CellTypeDataset objects.
#' @export
#' @importFrom tools R_user_dir
#' @importFrom stats setNames
#' @importFrom stringr str_split
#' @importFrom gh gh_token
#' @examples
#' ctd <- MAGMA.Celltyping::get_ctd("ctd_AIBS")
get_ctd <- function(ctd_name = c(
                        "ctd_AIBS",
                        "ctd_allKI",
                        "ctd_BlueLake2018_FrontalCortexOnly",
                        "ctd_BlueLake2018_VisualCortexOnly", 
                        "ctd_DivSeq",
                        "ctd_DRONC_human",
                        "ctd_DRONC_mouse",
                        "ctd_Saunders",
                        "ctd_Tasic",
                        "ctd_Zeisel2015",
                        "ctd_Zeisel2018",
                        "ctd_TabulaMuris_facs",
                        "ctd_TabulaMuris_droplet",
                        "ctd_Aerts2018",
                        "ctd_FlyCellAtlas",
                        "ctd_Avalos2019",
                        "ctd_DescartesHuman",  
                        "ctd_DescartesMouse",
                        "ctd_HumanCellLandscape",
                        "ctd_Jiang2021",
                        "ctd_NonHumanPrimateCellAtlas",
                        "ctd_Raj2018",
                        "ctd_Raj2018",
                        "ctd_Farnsworth2020"
                    ),
                    tag = "v2.0.8",
                    .token = gh::gh_token(),
                    storage_dir = tools::R_user_dir(
                        package = "MAGMA.Celltyping",
                        which = "cache"
                    )) {
    
    requireNamespace("piggyback")
    #### Check that files exist on Releases ####
    files <- piggyback::pb_list(repo = "neurogenomics/MAGMA_Celltyping",
                                tag = tag,
                                .token = .token)
    files$name <- stringr::str_split(files$file_name,"\\.",
                                     simplify = TRUE)[,1] 
    files <- files[files$name %in% ctd_name,] 
    ctd_dict <- stats::setNames(files$file_name, files$name)
    if(length(ctd_dict)==0) stop("No matching CTD files found.")
    #### Download files ####
    messager("Downloading",length(ctd_name),"CellTypeDataset file(s).")
    ctd_list <- lapply(ctd_dict, function(x){
               tmp <- get_data(
                   fname = x,
                   tag = tag,
                   .token = .token,
                   storage_dir = storage_dir
               )
               #### Import the data ####
               if(grepl('\\.rds$',tmp,ignore.case = TRUE)){
                   obj <- readRDS(tmp)
               } else if(grepl('\\.rda$|\\.rdata',tmp,ignore.case = TRUE)){
                   obj <- load_rdata(tmp)
               } 
               return(obj)
    })
    if(length(ctd_name)==1) ctd_list <- ctd_list[[1]]
    return(ctd_list)
}
NathanSkene/MAGMA_Celltyping documentation built on Aug. 21, 2023, 8:55 a.m.