Samtools flagstat
samtools flagstat EXAMPLE.bam > EXAMPLE.tsv
cat EXAMPLE.tsv
288643764 + 0 in total (QC-passed reads + QC-failed reads)
288352428 + 0 primary
0 + 0 secondary
291336 + 0 supplementary
153911191 + 0 duplicates
153911191 + 0 primary duplicates
288570589 + 0 mapped (99.97% : N/A)
288279253 + 0 primary mapped (99.97% : N/A)
288352428 + 0 paired in sequencing
144176214 + 0 read1
144176214 + 0 read2
287241680 + 0 properly paired (99.61% : N/A)
288249748 + 0 with itself and mate mapped
29505 + 0 singletons (0.01% : N/A)
352742 + 0 with mate mapped to a different chr
275146 + 0 with mate mapped to a different chr (mapQ>=5)
# 批量运行代码:
for f in *.sort.markdup.bam; do
samtools flagstat "$f" > "${f%.sort.markdup.bam}.tsv"
done
# 输出未比对上的 reads 为 FASTQ
samtools fastq -f 4 -F 2304 input.sort.markdup.bam > input.unmapped.fastq
# 提取序列,把这个文件导入BLAST查看导致污染的物种
samtools fastq -f 4 -F 2304 input.sort.markdup.bam > input.unmapped.fastq
从第一行至第十一行分别表示:
- QC pass的reads的数量为2499971,未通过QC的reads数量为0,意味着一共有2499971条reads;
重复reads的数量,QC pass和failed - 比对到参考基因组上的reads数量;
- paired reads数据数量;
- read1的数量;
- read2 的数量;
- 正确地匹配到参考序列的reads数量;
- 一对reads都比对到了参考序列上的数量,但是并不一定比对到同一条染色体上;
- 一对reads中只有一条与参考序列相匹配的数量;
- 一对reads比对到不同染色体的数量;
- 一对reads比对到不同染色体的且比对质量值大于5的数量。
Samtools depth 测序深度统计
# samptools depth: 输出fastq数据比对到染色体的位点深度大于0的深度信息。
# samtools depth -a:输出fastq数据比对到染色体的所有位点的测序深度信息,包含0深度位点。
# samtools depth -aa:输出fasta文件中所有染色体上位点的深度信息,包含fastq数据没有比对到的染色体。
samtools depth test.sorted.bam > depth.txt