在轉(zhuǎn)錄組數(shù)據(jù)與參考基因組進(jìn)行比對后,得到sam文件,后續(xù)分析需要將sam轉(zhuǎn)換為bam,這里用到的工具是SAMtools。
序列比對 —— Hisat2 - 簡書 (jianshu.com)
SAMtools的主要功能是讀取、寫出、編輯、查看SAM/BAM/CRAM格式的數(shù)據(jù)文件。
SAMtools官方網(wǎng)站:
http://www.htslib.org/
1.下載安裝
鏈接:
http://www.htslib.org/download/

$ tar -jxvf samtools-1.14.tar.bz2
安裝:
$ cd ~/samtools-1.14
$ ./configure --prefix=/your/path
$ make
$ make install
2. 基礎(chǔ)命令
$ samtools
Program: samtools (Tools for alignments in the SAM format)
Version: 1.14 (using htslib 1.14)
Usage: samtools <command> [options]
Commands:
-- Indexing
dict create a sequence dictionary file
faidx index/extract FASTA
fqidx index/extract FASTQ
index index alignment
-- Editing
calmd recalculate MD/NM tags and '=' bases
fixmate fix mate information
reheader replace BAM header
targetcut cut fosmid regions (for fosmid pool only)
addreplacerg adds or replaces RG tags
markdup mark duplicates
ampliconclip clip oligos from the end of reads
-- File operations
collate shuffle and group alignments by name
cat concatenate BAMs
merge merge sorted alignments
mpileup multi-way pileup
sort sort alignment file
split splits a file by read group
quickcheck quickly check if SAM/BAM/CRAM file appears intact
fastq converts a BAM to a FASTQ
fasta converts a BAM to a FASTA
import Converts FASTA or FASTQ files to SAM/BAM/CRAM
-- Statistics
bedcov read depth per BED region
coverage alignment depth and percent coverage
depth compute the depth
flagstat simple stats
idxstats BAM index stats
phase phase heterozygotes
stats generate stats (former bamcheck)
ampliconstats generate amplicon specific stats
-- Viewing
flags explain BAM flags
tview text alignment viewer
view SAM<->BAM<->CRAM conversion
depad convert padded BAM to unpadded BAM
samples list the samples in a set of SAM/BAM/CRAM files
-- Misc
help [cmd] display this help message or help for [cmd]
version detailed version information
這里看到基礎(chǔ)命令主要分為六個模塊,分別為索引、編輯、文件操作、統(tǒng)計、視圖以及其他。這里想要SAM格式轉(zhuǎn)為BAM格式,主要用到的是Viewing模塊中的view。
3. sam格式轉(zhuǎn)換為bam
說明書:
http://www.htslib.org/workflow/fastq.html
在老版本1.9的samtools中,需要用-s 指定sam文件,1.14中不需要指定。
samtools view命令完成sam轉(zhuǎn)為bam。
3.1 view命令基礎(chǔ)功能
$ samtools view
Usage: samtools view [options] <in.bam>|<in.sam>|<in.cram> [region ...]
Output options:
-b, --bam Output BAM
-C, --cram Output CRAM (requires -T)
-1, --fast Use fast BAM compression (implies --bam)
-u, --uncompressed Uncompressed BAM output (implies --bam)
-h, --with-header Include header in SAM output
-H, --header-only Print SAM header only (no alignments)
--no-header Print SAM alignment records only [default]
-c, --count Print only the count of matching records
-o, --output FILE Write output to FILE [standard output]
-U, --unoutput FILE, --output-unselected FILE
Output reads not selected by filters to FILE
-p, --unmap Set flag to UNMAP on reads not selected
then write to output file.
Input options:
-t, --fai-reference FILE FILE listing reference names and lengths
-M, --use-index Use index and multi-region iterator for regions
--region[s]-file FILE Use index to include only reads overlapping FILE
-X, --customized-index Expect extra index file argument after <in.bam>
Filtering options (Only include in output reads that...):
-L, --target[s]-file FILE ...overlap (BED) regions in FILE
-r, --read-group STR ...are in read group STR
-R, --read-group-file FILE ...are in a read group listed in FILE
-N, --qname-file FILE ...whose read name is listed in FILE
-d, --tag STR1[:STR2] ...have a tag STR1 (with associated value STR2)
-D, --tag-file STR:FILE ...have a tag STR whose value is listed in FILE
-q, --min-MQ INT ...have mapping quality >= INT
-l, --library STR ...are in library STR
-m, --min-qlen INT ...cover >= INT query bases (as measured via CIGAR)
-e, --expr STR ...match the filter expression STR
-f, --require-flags FLAG ...have all of the FLAGs present
-F, --excl[ude]-flags FLAG ...have none of the FLAGs present
-G FLAG EXCLUDE reads with all of the FLAGs present
--subsample FLOAT Keep only FLOAT fraction of templates/read pairs
--subsample-seed INT Influence WHICH reads are kept in subsampling [0]
-s INT.FRAC Same as --subsample 0.FRAC --subsample-seed INT
Processing options:
--add-flags FLAG Add FLAGs to reads
--remove-flags FLAG Remove FLAGs from reads
-x, --remove-tag STR
Comma-separated read tags to strip (repeatable) [null]
--keep-tag STR
Comma-separated read tags to preserve (repeatable) [null].
Equivalent to "-x ^STR"
-B, --remove-B Collapse the backward CIGAR operation
General options:
-?, --help Print long help, including note about region specification
-S Ignored (input format is auto-detected)
--no-PG Do not add a PG line
--input-fmt-option OPT[=VAL]
Specify a single input file format option in the form
of OPTION or OPTION=VALUE
-O, --output-fmt FORMAT[,OPT[=VAL]]...
Specify output format (SAM, BAM, CRAM)
--output-fmt-option OPT[=VAL]
Specify a single output file format option in the form
of OPTION or OPTION=VALUE
-T, --reference FILE
Reference sequence FASTA FILE [null]
-@, --threads INT
Number of additional threads to use [0]
--write-index
Automatically index the output files [off]
--verbosity INT
Set level of verbosity
3.2 格式轉(zhuǎn)換
$ samtools view -@8 -b LPF1_R1_MP.sam > LPF1_R1_MP.bam
-@8:8個線程
-b:輸出格式bam文件 >:輸出文件名
如果是1.9版本的SAMtools可以參考這篇文章:
http://m.itdecent.cn/p/6b7a442d293f
引用轉(zhuǎn)載請注明出處,如有錯誤敬請指出。