R/get_example_magma_files.R

Defines functions get_example_magma_files

Documented in get_example_magma_files

#' Get example MAGMA files 
#' 
#' Get example MAGMA files generated by 
#' \link[MAGMA.Celltyping]{map_snps_to_genes}.
#' 
#' @param storage_dir Directory to store files in. 
#' @inheritParams import_magma_files
#' 
#' @keywords internal
get_example_magma_files <- function(file_types,
                                    storage_dir = tempdir(),
                                    nested = FALSE,
                                    verbose = TRUE){
    
    messager("Using built-in example files: ieu-a-298.tsv.gz.35UP.10DOWN",
             v=verbose)
    magma_dir <-  system.file("extdata/MAGMA_Files/ieu-a-298", 
                              package = "MAGMA.Celltyping")
    local_files <- list.files(magma_dir, full.names = TRUE)
    local_files <- grep(paste(file_types,collapse = "|"),
                        local_files, value = TRUE)
    ## Copy to tempdir and rename to include up/down info 
    ## which MAGMA.Celltyping requires 
    tmpdir <- file.path(storage_dir,"MAGMA_Files",
                        "ieu-a-298.tsv.gz.35UP.10DOWN") 
    tmpdir <- fix_path(tmpdir)
    dir.create(tmpdir, recursive = TRUE, showWarnings = FALSE)
    temp_paths <-  file.path(tmpdir, gsub("ieu-a-298",
                                          "ieu-a-298.tsv.gz.35UP.10DOWN",
                                          basename(local_files)))
    temp_paths <- fix_path(temp_paths)
    out <- file.copy(local_files, temp_paths) 
    #### Name each file ####
    names(temp_paths) <- ifelse(
        grepl("\\.genes\\.out$",temp_paths),"genes.out",
        ifelse(grepl("\\.genes\\.raw$",temp_paths),"genes.raw",NA))
    temp_paths <- list("ieu-a-298"=temp_paths) 
    if(isFALSE(nested)) temp_paths <- unlist(temp_paths)
    return(temp_paths)
}
NathanSkene/MAGMA_Celltyping documentation built on Oct. 11, 2024, 7:19 a.m.