R/getDataValues.R

Defines functions getDataValues

Documented in getDataValues

#' Retrieve the values for a particular patients dataset
#' 
#' Creates a vector of final data values for a particular patient, tumor, and dataset
#' @param patient Patient ID in long form (i.e. Patient300 not P300)
#' @param tumor sf number with sf lower
#' @param dataset name of dataset (i.e. Histology, Amplification, Copy Number, etc)
#' @param type only required if dataset is Histology
#' @param rowSelection only required if dataset is Copy Number, RNAseq, Cell Types, Cancer-associated Processes, or Expansions
#' @param threshold only required if dataset is Amplification
#' @param conversion converts dataset to name of data file, where value is dataset and name is file name (ex c(cn.rds='Copy Number', ))
#' @param tumorDatasetsPath path to datasets
#' @export 

getDataValues <- function(patient, tumor, dataset, type, rowSelection, threshold, conversion, tumorDatasetsPath){
  if (dataset=="Histology"){
    if (type=='BV Hyperplasia'){
      fname <- 'bv_hyper.rds'
    } else {
      fname <- 'per_nec.rds'
    }
  } else {
    fname <-  conversion[[dataset]][1]
  }
  data <- readRDS(file.path(tumorDatasetsPath, patient, tumor, fname))#data has rownames=gene names and colnames=sample names of format PNNNvN
  if (dataset=='Amplification'){
    data <- cn_to_amp(data, threshold)
  }
  if (is.data.frame(data)){ # Handling purity & histology datasets (vector instead of dataframe)
    vector <- as.numeric(data[rowSelection,])
  } else { # All other datasets
    vector <- as.numeric(data)
  }
  names(vector) <- gsub('P[0-9]{3}v', '', names(data))
  return(vector)
}
SRHilz/GliomaAtlas3D documentation built on Nov. 25, 2020, 8:31 p.m.