合并sam文件
The samtools merge
can merge bam files while it can not work for sam files.
samtools merge
可以合并bam 文件,而不能用于sam文件。
How to merge sam files on Linux?
如何在Linux上合并sam文件?
According to the sam format specification, header lines start with @
, while alignment lines do not. So you can use grep
to merge sam files as follows efficiently.
根据sam格式规范 ,标题行以@
开头 ,而对齐行则不是。 因此,您可以使用grep
如下有效地合并sam文件。
Assume the header is from 0.sam, the files to be merged are 0.sam, 1.sam and 2.sam, and the merged output sam file is out.sam.
假设标头来自0.sam,要合并的文件为0.sam,1.sam和2.sam,并且合并的输出sam文件为out.sam。
header=0.sam
files="0.sam 1.sam 2.sam"
output=out.sam
(grep ^@ $header; for f in $files; do grep -v ^@ $f; done) > $output
It should be much faster than the way of “convert sams to bams, merge bams by samtools merge
, convert bam to sam”.
它应该比“将sam转换为bam,通过samtools merge
bam,将bam转换为sam”的方式快得多。
翻译自: https://www.systutorials.com/how-to-merge-sam-files-on-linux/
合并sam文件