samtools常用命令详解

转载自:https://www.cnblogs.com/emanlee/p/4316581.html

samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml
samtools是一个用于操作sam和bam文件的工具合集。包含有许多命令。以下是常用命令的介绍

1. view

view命令的主要功能是:将sam文件转换成bam文件;然后对bam文件进行各种操作,比如数据的排序(不属于本命令的功能)和提取(这些操作 是对bam文件进行的,因而当输入为sam文件的时候,不能进行该操作);最后将排序或提取得到的数据输出为bam或sam(默认的)格式。

bam文件优点:bam文件为二进制文件,占用的磁盘空间比sam文本文件小;利用bam二进制文件的运算速度快。

view命令中,对sam文件头部的输入(-t或-T)和输出(-h)是单独的一些参数来控制的。

Usage: samtools view [options] | [region1 [...]]
默认情况下不加 region,则是输出所有的 region.

Options: -b       output BAM
                  默认下输出是 SAM 格式文件,该参数设置输出 BAM 格式
         -h       print header for the SAM output
                  默认下输出的 sam 格式文件不带 header,该参数设定输出sam文件时带 header 信息
         -H       print header only (no alignments)
         -S       input is SAM
                  默认下输入是 BAM 文件,若是输入是 SAM 文件,则最好加该参数,否则有时候会报错。
         -u       uncompressed BAM output (force -b)
                  该参数的使用需要有-b参数,能节约时间,但是需要更多磁盘空间。
         -c       Instead of printing the alignments, only count them and print the 
                  total number. All filter options, such as ‘-f’, ‘-F’ and ‘-q’ , 
                  are taken into account.
         -1       fast compression (force -b)
         -x       output FLAG in HEX (samtools-C specific)
         -X       output FLAG in string (samtools-C specific)
         -c       print only the count of matching records
         -L FILE  output alignments overlapping the input BED FILE [null]
         -t FILE  list of reference names and lengths (force -S) [null]
                  使用一个list文件来作为header的输入
         -T FILE  reference sequence file (force -S) [null]
                  使用序列fasta文件作为header的输入
         -o FILE  output file name [stdout]
         -R FILE  list of read groups to be outputted [null]
         -f INT   required flag, 0 for unset [0]
         -F INT   filtering flag, 0 for unset [0] 
                  Skip alignments with bits present in INT [0]
                  数字4代表该序列没有比对到参考序列上
                  数字8代表该序列的mate序列没有比对到参考序列上
         -q INT   minimum mapping quality [0]
         -l STR   only output reads in library STR [null]
         -r STR   only output reads in read group STR [null]
         -s FLOAT fraction of templates to subsample; integer part as seed [-1]
         -?       longer help

继续阅读“samtools常用命令详解”

Cufflinks中的gffread工具

Cufflinks的gffread工具提供了一些其它的用途,在这里做个笔记,方便以后查询。

1. GTF与GFF间的格式转换

#gff to gtf 
gffread my.gff3 -T -o my.gtf 

#gtf to gff 
gffread my.gtf -o- > my.gff3

2. 利用GTF注释文件从基因组上提取转录本或CDS序列

# 获取转录本序列 
gffread transcripts.gtf –g genome.fa –w transcripts.output.fa 

# 获取CDS序列 
gffread transcripts.gtf –g genome.fa -x cds.output.fa 

# 获取蛋白序列 
gffread transcripts.gtf –g genome.fa -y protein.output.fa

安装Trinity 2.8.4

需要组装下转录组,因此找了个当前版本为2.8.4的Trinity。这里记录下安装中遇到的一些问题。仅供同样遇到的朋友们参考。

  • Ubuntu下直接安装Trinity。
sudo apt install trinityrnaseq

在Ubuntu 18.04 LTS下之间安装的Trinity是2.5版本的,会遇到找不到seqtk-trinity找不到的问题。在Trinity的Github可以找到seqtk-trinity的代码,编译安装或许可以解决,但我没有去尝试。装了一下seqtk,但是里面没有seqtk-trinity。不知道是源里的版本旧,还是压根就没有。

继续阅读“安装Trinity 2.8.4”