Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mmRmeta/R/add.expression.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
18 lines (16 sloc)
1.15 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Add Gene Expression | |
#' @description This function adds the gene expression values to each "case_id" of a gene in the data frame. It uses the expressionmatrix from organ_data. | |
#' @param cancer_data A large list created by multimodalR | |
#' @param nested_metadata A list of data frames made by >make.nested.metadata< | |
#' @param key Character or integer - Column name or index of unique identifier of nested_metadata, default = "case_id" | |
#' @importFrom magrittr %>% | |
#' @examples | |
#' lungMetaExpression <- add.expression(lungXY, lungMetaExpression) | |
#' @return Returns the same list but with data franes containing the expression values in a new colummn. | |
add.expression <- function(cancer_data, nested_metadata, key = "case_id") { #nested_metadata = List of metadata for each gene | |
for (gene in names(nested_metadata)) { | |
geneExpression <- cancer_data$Expressionmatrix[gene, c(nested_metadata[[gene]][[key]])] %>% as.numeric #[genename, case_id from the matrix] | |
nested_metadata[[gene]]$expression <- geneExpression #add the expression values to the data.table | |
} | |
return(nested_metadata) | |
} |