View source: R/quantiseqr_helpers.R
se_to_matrix | R Documentation |
SummarizedExperiment to matrix
se_to_matrix(se, assay = "abundance")
se |
A |
assay |
A character string, specifying the name of the |
A matrix object, containing the TPM values, ready to be used in the
framework of quantiseqr
library("SummarizedExperiment")
library("macrophage")
data("gse", package = "macrophage")
se <- gse
# If using ENSEMBL or Gencode gene annotation, you might want to convert the row names
## in this case, the gene symbols are provided as rowData information
rownames(se) <- rowData(se)$SYMBOL
tpm_matrix <- se_to_matrix(se, assay = "abundance")
## otherwise, you can map the identifiers via
library("org.Hs.eg.db")
library("AnnotationDbi")
se <- gse
# keep the parts before the '.', used in the Gencode annotation
rownames(se) <- substr(rownames(se), 1, 15)
gene_names <- mapIds(org.Hs.eg.db,
keys = rownames(se),
column = "SYMBOL",
keytype = "ENSEMBL")
rownames(se) <- gene_names
# If you require to convert the counts to TPMs by hand, you need a vector of
# gene lengths as well, and then run this simple function on the count matrix
counts_to_tpm <- function(counts, lengths) {
ratio <- counts / lengths
mytpm <- ratio / sum(ratio) * 1e6
return(mytpm)
}
# then run via
# tpmdata <- counts_to_tpm(count_matrix, genelength_vector)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.