Question: Output the results of samtools flagstat of 180 bam files in one text file
0
gravatar for haneenih7
7 months ago by
haneenih770
KAUST
haneenih770 wrote:

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

shell for loop alignment genome • 258 views
ADD COMMENTlink modified 7 months ago by Pierre Lindenbaum129k • written 7 months ago by haneenih770
1
gravatar for Pierre Lindenbaum
7 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum129k wrote:
( for i in bam_files/*.bam ; do samtools flagstat $i ; done) > out.txt
ADD COMMENTlink written 7 months ago by Pierre Lindenbaum129k
0
gravatar for haneenih7
7 months ago by
haneenih770
KAUST
haneenih770 wrote:

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 COMMENTlink written 7 months ago by haneenih770
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1528 users visited in the last hour