samtools根据坐标提取子bam加速

2018-12-21  本文已影响35人  因地制宜的生信达人

samtools根据坐标提取子bam加速

本来是准备用

samtools view -h test_marked_fixed.bam  -L test.sort.bed 

但是发现速度实在是太慢了,所以我稍微取巧了。

cat indel.sort.bed |perl -alne '{system("samtools view -h test_marked_fixed.bam $F[0]:$F[1]-$F[2]|samtools sort -O bam -@ 5  -o $F[0]_$F[1]_$F[2].bam - ")}'
samtools merge test.bam *.bam

如果有多个bam,也可以使用批处理,如下:

ls ../alignment/*.bam |while read id;
do (export id=$id;
cat indel.sort.bed | perl -alne '{system("samtools view -h  $ENV{\"id\"} $F[0]:$F[1]-$F[2]|samtools sort -O bam -@ 5   -o tmp/$F[0]_$F[1]_$F[2].bam - ; ")}';
samtools merge $(basename $id "_marked_fixed.bam")_small.bam tmp/*.bam);
done

ls *_small.bam |xargs -i samtools index {}
上一篇 下一篇

猜你喜欢

热点阅读