Output the results of samtools flagstat of 180 bam files in one text file
2
0
Entering edit mode
4.9 years ago
Hann ▴ 110

Hello,

I have 180 bam files that I wanna see the mapping rate. I am running a for loop in files, and using samtools flagstat to get the stats, I want to have the output results for all the files in one text file with the file name so it would be something like this:

>M883.rgroup.bam
88168368 + 0 in total (QC-passed reads + QC-failed reads)
1695365 + 0 secondary
0 + 0 supplementary
55252515 + 0 duplicates
88168368 + 0 mapped (100.00% : N/A)
86473003 + 0 paired in sequencing
43227447 + 0 read1
43245556 + 0 read2
79991062 + 0 properly paired (92.50% : N/A)
85979751 + 0 with itself and mate mapped
493252 + 0 singletons (0.57% : N/A)
5058236 + 0 with mate mapped to a different chr
5058236 + 0 with mate mapped to a different chr (mapQ>=5)
>L33r4.rgroup.bam
.......
.....etc

I am running a for loop as the following:

    for i in $(ls bam_files/*.bam); do temp=${i/.bam/.txt}; out=${temp/bam_files/stat}; samtools flagstat $i > $out & done

But this give the output for each bam file in a text file, therefore I will have 180 text files

Thanks

for loop shell alignment genome • 3.7k views
ADD COMMENT
1
Entering edit mode
4.9 years ago
( for i in bam_files/*.bam ; do samtools flagstat $i ; done) > out.txt
ADD COMMENT
0
Entering edit mode
4.9 years ago
Hann ▴ 110

One option is to concatenate all files together after the for loop finishes.

grep "" *.txt > all_files

This won't give a 'header', but it prefixes every line with the filename.

ADD COMMENT

Login before adding your answer.

Traffic: 1982 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6