This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get the statistics of bowtie alignment into a file?

Hi,

I'm using bowite for alignment with the following script:

${bowtie_source}  --best  --sam ${ref_genome} ${fastq_file} | ${samtools}  view -bS - |  ${samtools} sort -o ${target_dir}/${sample_name}.bam

and on the terminal I get the statistics:

# reads processed: 12641952
# reads with at least one reported alignment: 5914379 (46.78%)
# reads that failed to align: 5352269 (42.34%)
# reads with alignments suppressed due to -m: 1375304 (10.88%)
Reported 5914379 alignments

Anyone know how to get this statistics into a text file, plus maybe more statistics that can be extracted besides what is printed on the terminal?

chip-seq bowtie

Bella_p, I just noticed something: You're using ${samtools} and ${bowtie_source}, not samtools and bowtie. Why is that?

2 answers

Redirect standard error and standard out to a file to capture things printed to screen.

You can use other programs like Qualimap and BamUtils to get additional statistics from BAM files.

Edit: Since @Ram pointed out that the first link may have confusing reference to 2 standing in for to in headers of sections here is a staid Stackoverflow version.

The first link has weird text. Are they using 2 as a stand-in for to? It's crazy seeing such usage on a popular website.

@Bella_p: The sub-headers in the tldp site have text that goes std### 2 file and so on. Please mentally substitute each 2 with a to when you read those sub-headers. It has nothing to do with the actual 2 in that context, which is the file descriptor for stderr (usage like 2>)

To clarify @genomax's correct answer, the output the OP wants to save is stderr. Therefore, to save it to a file you can use 2> stats.file, e.g.

${bowtie_source}  --best  --sam ${ref_genome} ${fastq_file} 2> stats.file | ${samtools}  view -bS - |  ${samtools} sort -o ${target_dir}/${sample_name}.bam

Log in to answer this question.