R/seurat.R

get_seurat_mappings <- function(mappings){
     return(mappings[sapply(mappings, function(x){x@type == "seurat"})])
}


write_seurat_file <- function(seurat_object, path){
    saveRDS(seurat_object, path)
}


write_the_seurat <- function(process, seurat_object){
    seurat_outputs <- get_seurat_mappings(process@output)
    count = length(seurat_outputs)
 
    if( count == 1)
    {
        outp <- seurat_outputs[[1]]
        write_seurat_file(seurat_object, outp@path)       
    }
    else if (count == 0) 
    {
        stop("No output of type \"seurat\" exists in the output file mapping")  
    }
    else
    {
        stop( stringr::str_interp(
          "Only a single output file mapping of type \"seurat\" is allowed but ${seurat_input_count} are present."
        ))
    }
}


read_seurat_file <- function(path){
    seurat_object <- readRDS(path)
    return(seurat_object)
}


read_the_seurat <- function(process)
{
    seurat_inputs <- get_seurat_mappings(process@input)
    seurat_input_count = length(seurat_inputs)
 
    if( seurat_input_count == 1)
    {
        inp <- seurat_inputs[[1]]
        return(read_seurat_file(inp@path))
    }
    else if (seurat_input_count == 0) 
    {
        stop("No input of type \"seurat\" exists in the input file mapping")  
    }
    else
    {
        stop( stringr::str_interp(
          "Only a single input file mapping of type \"seurat\" is allowed but ${seurat_input_count} are present."
        ))
    }

    return(NULL)
}
FASTGenomics/fastgenomicsR documentation built on June 26, 2019, 12:38 p.m.