Convert transcripts to genes
Source:R/AllGenerics.R
, R/convertTranscriptsToGenes-methods.R
convertTranscriptsToGenes.Rd
Convert transcripts to genes
Usage
convertTranscriptsToGenes(object, ...)
# S4 method for Matrix
convertTranscriptsToGenes(object, tx2gene, aggregate = TRUE)
# S4 method for SummarizedExperiment
convertTranscriptsToGenes(object)
# S4 method for character
convertTranscriptsToGenes(object, tx2gene)
# S4 method for matrix
convertTranscriptsToGenes(object, tx2gene, aggregate = TRUE)
Arguments
- object
Object.
- tx2gene
TxToGene
. Transcript-to-gene mappings.- aggregate
logical(1)
. For objects supportingdim()
, aggregate counts to gene level and collapse the matrix.- ...
Additional arguments.
Value
character
:factor
. Genes in the values, transcripts in the names.matrix
,Matrix
,SummarizedExperiment
: Object containing counts collapsed to gene level by default (seeaggregate
argument).
Note
For objects containing a count matrix, the object rows will be
collapsed to gene level using aggregate()
. This applies to our
SummarizedExperiment
method.
Updated 2021-09-13.
Examples
data(SummarizedExperiment_transcripts, package = "AcidTest")
txse <- SummarizedExperiment_transcripts
object <- txse
t2g <- TxToGene(object)
print(t2g)
#> TxToGene with 6 rows and 2 columns
#> txId geneId
#> <character> <character>
#> ENST00000371584.8 ENST00000371584.8 ENSG00000000419.12
#> ENST00000371588.9 ENST00000371588.9 ENSG00000000419.12
#> ENST00000413082.1 ENST00000413082.1 ENSG00000000419.12
#> ENST00000494424.1 ENST00000494424.1 ENSG00000000003.15
#> ENST00000496771.5 ENST00000496771.5 ENSG00000000003.15
#> ENST00000612152.4 ENST00000612152.4 ENSG00000000003.15
transcripts <- rownames(object)
print(transcripts)
#> [1] "ENST00000494424.1" "ENST00000496771.5" "ENST00000612152.4"
#> [4] "ENST00000371584.8" "ENST00000371588.9" "ENST00000413082.1"
## character ====
## Returns as factor.
x <- convertTranscriptsToGenes(transcripts, tx2gene = t2g)
print(x)
#> ENST00000494424.1 ENST00000496771.5 ENST00000612152.4 ENST00000371584.8
#> ENSG00000000003.15 ENSG00000000003.15 ENSG00000000003.15 ENSG00000000419.12
#> ENST00000371588.9 ENST00000413082.1
#> ENSG00000000419.12 ENSG00000000419.12
#> Levels: ENSG00000000003.15 ENSG00000000419.12
str(x)
#> Factor w/ 2 levels "ENSG00000000003.15",..: 1 1 1 2 2 2
#> - attr(*, "names")= chr [1:6] "ENST00000494424.1" "ENST00000496771.5" "ENST00000612152.4" "ENST00000371584.8" ...
## matrix ====
## Note that transcript IDs currently must be in the rows.
counts <- counts(object)
print(counts)
#> sample1 sample2 sample3 sample4
#> ENST00000494424.1 1 2 3 4
#> ENST00000496771.5 5 6 7 8
#> ENST00000612152.4 9 10 11 12
#> ENST00000371584.8 13 14 15 16
#> ENST00000371588.9 17 18 19 20
#> ENST00000413082.1 21 22 23 24
## Aggregate to gene level.
x <- convertTranscriptsToGenes(counts, tx2gene = t2g, aggregate = TRUE)
print(x)
#> sample1 sample2 sample3 sample4
#> ENSG00000000003.15 15 18 21 24
#> ENSG00000000419.12 51 54 57 60
colSums(x)
#> sample1 sample2 sample3 sample4
#> 66 72 78 84
## Simply map to rownames.
x <- convertTranscriptsToGenes(counts, tx2gene = t2g, aggregate = FALSE)
print(x)
#> sample1 sample2 sample3 sample4
#> ENSG00000000003.15 1 2 3 4
#> ENSG00000000003.15 5 6 7 8
#> ENSG00000000003.15 9 10 11 12
#> ENSG00000000419.12 13 14 15 16
#> ENSG00000000419.12 17 18 19 20
#> ENSG00000000419.12 21 22 23 24
colSums(x)
#> sample1 sample2 sample3 sample4
#> 66 72 78 84
## SummarizedExperiment ====
x <- convertTranscriptsToGenes(object)
print(x)
#> class: SummarizedExperiment
#> dim: 2 4
#> metadata(0):
#> assays(1): counts
#> rownames(2): ENSG00000000003.15 ENSG00000000419.12
#> rowData names(0):
#> colnames(4): sample1 sample2 sample3 sample4
#> colData names(0):