Processing Salmon Output Files with tximport
TL;DR
Tools like Salmon and Kallisto are fast and accurate expression quantification software. However, unlike simple count data, the processing and use cases for their output are diverse. This article summarizes Salmon's output file quant.sf and how to process it using tximport.
quant.sf
quant.sf is a tab-separated file with the following five columns:
According to the official docs (Ver 1.40), these values are defined as follows:
| Name | Definition |
|---|---|
| Name | The transcript name, taken from the FASTA header line |
| Length | The length of the transcript in bases |
| EffectiveLength | The effective length that accounts for fragment distribution, sequence-specific bias, and gc-fragment bias. Used in TPM calculation, etc. |
| TPM | TPM in its proper sense. Using this value for downstream analysis is recommended |
| NumReads | The number of reads mapped to the transcript by Salmon |
Reading Files with tximport
You can read quant.sf files with tximport.
Suppose the Salmon output is stored in directories with an _exp suffix:
Exporting tximport Contents to CSV
Continuing from the workspace above. While the data has been loaded, you need to extract the desired components.
You can check what is inside a tximport object with names(tximportObject):
The contents are:
- abundance: TPM
- counts: NumReads
- length: EffectiveLength
- countsFromAbundance:
"no","scaledTPM","lengthScaledTPM"or"dtuScaledTPM"
The default for countsFromAbundance is "no".
To complicate matters, scaledTPM, lengthScaledTPM, and dtuScaledTPM are different from TPM. They are count-like values obtained as follows:
Instead of counting from NumReads, these values are computed from the abundance (TPM in this case) and then scaled by library size. The xxxxTPM name indicates TPM-derived values, and treating them as actual TPM values is not appropriate.
For reference, the scaling methods are as follows. Also, for each sample, the sum of tximportObject$counts equals the total NumReads.
| Name | Method |
|---|---|
no | simple sum |
scaledTPM | scaled by library size |
lengthScaledTPM | scaled by library size adjusted for mean transcript length |
dtuScaledTPM | scaled by library size adjusted for median transcript length |
dtuScaledTPM is reportedly the best scaling method for Differential Transcript Usage (DTU) analysis. These scaled values, or the raw counts, are used for Differential Expression Gene (DEG) analysis and similar analyses.
To export as CSV:
How to Handle DEG Analysis
For 3' tagged RNA-seq, incorporating transcript length would actually introduce an unwanted correction, so it is better to use the raw count values without countsFromAbundance.
However, for standard full-transcript-length RNA-seq, correcting for transcript length reportedly yields better results.
Below are slightly modified versions of code from the official docs, kept here as a reference.
edgeR
DESeq2
Looking at DESeq2's DESeqDataSetFromTximport:
So, if you use countAbundance = "scaledTPM", it should be fine to export to CSV and then load it directly.
Thoughts
The scaledTPM variants are confusing.
I have never used limma-voom -- I wonder what advantages it offers.