For some analyses you might be interested in transforming the counts into RPKMs which you can do with this function.

getRPKM(rse, length_var = "bp_length", mapped_var = NULL)

Arguments

rse

A RangedSummarizedExperiment-class object as downloaded with download_study.

length_var

A length 1 character vector with the column name from rowData(rse) that has the coding length. For gene level objects from recount this is bp_length. If NULL, then it will use width(rowRanges(rse)) which should be used for exon RSEs.

mapped_var

A length 1 character vector with the column name from colData(rse) that has the number of reads mapped. For recount RSE object this would be mapped_read_count. If NULL (default) then it will use the column sums of the counts matrix. The results are different because not all mapped reads are mapped to exonic segments of the genome.

Value

A matrix with the RPKM values.

Details

For gene RSE objects, you will want to specify the length_var because otherwise you will be adjusting for the total gene length instead of the total exonic sequence length of the gene.

See also

Author

Andrew Jaffe, Leonardo Collado-Torres

Examples


## get RPKM matrix
rpkm <- getRPKM(rse_gene_SRP009615)

## You can also get an RPKM matrix after running scale_counts()
## with similar RPKM values
rpkm2 <- getRPKM(scale_counts(rse_gene_SRP009615))
rpkm3 <- getRPKM(scale_counts(rse_gene_SRP009615, by = "mapped_reads"))

summary(rpkm - rpkm2)
#>    SRR387777           SRR387778           SRR387779         
#>  Min.   :-0.538140   Min.   :-0.496618   Min.   :-0.2782572  
#>  1st Qu.:-0.001367   1st Qu.:-0.001441   1st Qu.:-0.0007156  
#>  Median : 0.000000   Median : 0.000000   Median : 0.0000000  
#>  Mean   : 0.001328   Mean   : 0.001216   Mean   : 0.0005080  
#>  3rd Qu.: 0.001639   3rd Qu.: 0.002102   3rd Qu.: 0.0014124  
#>  Max.   : 0.459320   Max.   : 0.412033   Max.   : 0.5638757  
#>    SRR387780           SRR389077            SRR389078        
#>  Min.   :-0.275124   Min.   :-0.3686954   Min.   :-1.762821  
#>  1st Qu.:-0.001091   1st Qu.:-0.0017073   1st Qu.:-0.001882  
#>  Median : 0.000000   Median : 0.0000000   Median : 0.000000  
#>  Mean   : 0.000969   Mean   :-0.0009294   Mean   : 0.001999  
#>  3rd Qu.: 0.001363   3rd Qu.: 0.0014684   3rd Qu.: 0.002319  
#>  Max.   : 0.352192   Max.   : 0.8665052   Max.   : 0.640973  
#>    SRR389079            SRR389080            SRR389081         
#>  Min.   :-0.3599736   Min.   :-0.3056064   Min.   :-0.4041139  
#>  1st Qu.:-0.0021947   1st Qu.:-0.0007341   1st Qu.:-0.0014252  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   :-0.0006854   Mean   : 0.0008586   Mean   :-0.0006136  
#>  3rd Qu.: 0.0015759   3rd Qu.: 0.0010928   3rd Qu.: 0.0007495  
#>  Max.   : 0.3829134   Max.   : 0.2733806   Max.   : 0.3281689  
#>    SRR389082            SRR389083            SRR389084         
#>  Min.   :-0.2330620   Min.   :-0.3047474   Min.   :-0.3486800  
#>  1st Qu.:-0.0004445   1st Qu.:-0.0010143   1st Qu.:-0.0009503  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   : 0.0005996   Mean   :-0.0006126   Mean   :-0.0003374  
#>  3rd Qu.: 0.0007402   3rd Qu.: 0.0006283   3rd Qu.: 0.0004121  
#>  Max.   : 0.2488342   Max.   : 0.4275825   Max.   : 0.3975724  
summary(rpkm - rpkm3)
#>    SRR387777            SRR387778            SRR387779         
#>  Min.   :-0.2136981   Min.   :-0.1968742   Min.   :-2.885e-01  
#>  1st Qu.:-0.0006772   1st Qu.:-0.0005507   1st Qu.:-4.843e-04  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.000e+00  
#>  Mean   :-0.0002927   Mean   : 0.0004231   Mean   :-9.456e-05  
#>  3rd Qu.: 0.0004006   3rd Qu.: 0.0007176   3rd Qu.: 1.540e-04  
#>  Max.   : 0.1130460   Max.   : 0.1770789   Max.   : 1.006e-01  
#>    SRR387780            SRR389077            SRR389078         
#>  Min.   :-0.1577897   Min.   :-0.5299857   Min.   :-0.1891372  
#>  1st Qu.:-0.0004845   1st Qu.:-0.0005405   1st Qu.:-0.0009724  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   :-0.0001782   Mean   : 0.0007128   Mean   :-0.0002439  
#>  3rd Qu.: 0.0004263   3rd Qu.: 0.0006473   3rd Qu.: 0.0004048  
#>  Max.   : 0.1376846   Max.   : 0.2552746   Max.   : 0.3569628  
#>    SRR389079            SRR389080            SRR389081         
#>  Min.   :-0.1176256   Min.   :-0.1430089   Min.   :-0.1853069  
#>  1st Qu.:-0.0006174   1st Qu.:-0.0002933   1st Qu.:-0.0002045  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   : 0.0002104   Mean   : 0.0003596   Mean   : 0.0001303  
#>  3rd Qu.: 0.0007492   3rd Qu.: 0.0003547   3rd Qu.: 0.0004992  
#>  Max.   : 0.1201767   Max.   : 0.1114920   Max.   : 0.1054893  
#>    SRR389082            SRR389083            SRR389084         
#>  Min.   :-0.1564435   Min.   :-1.436e-01   Min.   :-1.010e-01  
#>  1st Qu.:-0.0002348   1st Qu.:-4.315e-04   1st Qu.:-3.699e-05  
#>  Median : 0.0000000   Median : 0.000e+00   Median : 0.000e+00  
#>  Mean   : 0.0003452   Mean   :-1.422e-04   Mean   : 1.435e-04  
#>  3rd Qu.: 0.0002462   3rd Qu.: 9.928e-05   3rd Qu.: 3.646e-04  
#>  Max.   : 0.1086730   Max.   : 9.926e-02   Max.   : 9.869e-02  
summary(rpkm2 - rpkm3)
#>    SRR387777           SRR387778           SRR387779         
#>  Min.   :-0.507532   Min.   :-0.445699   Min.   :-0.8523319  
#>  1st Qu.:-0.001622   1st Qu.:-0.002041   1st Qu.:-0.0014352  
#>  Median : 0.000000   Median : 0.000000   Median : 0.0000000  
#>  Mean   :-0.001621   Mean   :-0.000793   Mean   :-0.0006026  
#>  3rd Qu.: 0.001416   3rd Qu.: 0.001372   3rd Qu.: 0.0007158  
#>  Max.   : 0.422133   Max.   : 0.673697   Max.   : 0.3589322  
#>    SRR387780           SRR389077           SRR389078        
#>  Min.   :-0.461343   Min.   :-1.388253   Min.   :-0.491700  
#>  1st Qu.:-0.001245   1st Qu.:-0.001551   1st Qu.:-0.002401  
#>  Median : 0.000000   Median : 0.000000   Median : 0.000000  
#>  Mean   :-0.001147   Mean   : 0.001642   Mean   :-0.002243  
#>  3rd Qu.: 0.001177   3rd Qu.: 0.001683   3rd Qu.: 0.001885  
#>  Max.   : 0.305930   Max.   : 0.505786   Max.   : 2.119784  
#>    SRR389079            SRR389080            SRR389081         
#>  Min.   :-0.3710228   Min.   :-0.3038938   Min.   :-0.4838542  
#>  1st Qu.:-0.0016096   1st Qu.:-0.0010920   1st Qu.:-0.0007814  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   : 0.0008958   Mean   :-0.0004991   Mean   : 0.0007439  
#>  3rd Qu.: 0.0022193   3rd Qu.: 0.0006149   3rd Qu.: 0.0014597  
#>  Max.   : 0.4049808   Max.   : 0.3143154   Max.   : 0.4810074  
#>    SRR389082            SRR389083            SRR389084         
#>  Min.   :-0.3190688   Min.   :-0.4729762   Min.   :-0.3743508  
#>  1st Qu.:-0.0007932   1st Qu.:-0.0006477   1st Qu.:-0.0004526  
#>  Median : 0.0000000   Median : 0.0000000   Median : 0.0000000  
#>  Mean   :-0.0002543   Mean   : 0.0004705   Mean   : 0.0004809  
#>  3rd Qu.: 0.0005059   3rd Qu.: 0.0010338   3rd Qu.: 0.0009586  
#>  Max.   : 0.3414912   Max.   : 0.2808215   Max.   : 0.3405986