This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Syntax for samtools flagstat on multiple .bam files outputting to .txt file

Hello,

I would like to know appropriate syntax for samtools flagstat on multiple .bam files outputting all to .txt file

alignment

What have you tried?

1 answer

An easy way of doing it is to run samtools flagstat on multiple .bam files and then combine their output together using multiqc
So something like

samtools_stat_commands=()
samtools_stat_log_folder=''
multiqc_folder=''
for i in ${aligned_folder}/*.bam
do
    sample_name=$(basename $i .bam)
    log_file=${samtools_stat_log_folder}/${sample_name}_bamtools_stats.txt
    samtools_stat_command="samtools stats ${i} > ${log_file}"
    samtools_stat_commands[${#samtools_stat_commands[@]}]+=$samtools_stat_command

done

parallel -j 16 ::: "${samtools_stat_commands[@]}"

multiqc $samtools_stat_log_folder -o $multiqc_folder -n samtools_flagstat.html

Log in to answer this question.