samtools notes

bam2sam

-h: include header in SAM output
-O: Specify output format (SAM, BAM, CRAM)
-S: input format is auto-detected

samtools view -h test.bam -O SAM -o test.sam 

sam2bam

samtools view -S -O BAM test.sam  -o test.bam

sam2fastq

-c: compression level
-@: threads
-t: copy RG, BC and QT tags to the FASTQ header line

~/miniconda3/bin/samtools fastq test.sam -c 6 -@ 10 -1 reads_1.fq.gz -2 reads_2.fq.gz

bam2fastq

~/miniconda3/bin/samtools fastq test.bam -c 6 -@ 10 -1 reads_1.fq.gz -2 reads_2.fq.gz

samtools fasta  -F 4 test.sam  -@ 20 -1 mapped_reads_1.fa -2 mapped_reads_2.fa

extract FLAG

# from sam
~/miniconda3/bin/samtools view -S -O BAM -f 4 test.sam -o unmapped.bam
~/miniconda3/bin/samtools view -S -O SAM -f 4 test.sam -o unmapped.sam
~/miniconda3/bin/samtools fastq -c 6 -@ 10 -f 4  test.sam -1 reads_unmapped_1.fq.gz -2 reads_unmapped_2.fq.gz

# from bam
~/miniconda3/bin/samtools view -S -O BAM -f 4 test.bam -o unmapped.bam
~/miniconda3/bin/samtools view -S -O SAM -f 4 test.bam -o unmapped.sam
~/miniconda3/bin/samtools fastq -c 6 -@ 10 -f 4  test.bam -1 reads_unmapped_1.fq.gz -2 reads_unmapped_2.fq.gz

generate text files with alignment regions

COLUMNS=200
COLUMNS=$COLUMNS ~/miniconda3/bin/samtools tview -d T -p chr1:1000 sorted.bam hap1_chrom.fa 

Reference

https://en.wikipedia.org/wiki/Pileup_format
https://www.samformat.info/sam-format-flag

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容