如何用 freebayes call SNP

时间:2023-03-10 01:51:38
如何用 freebayes call SNP

1,软件介绍

FreeBayes is a Bayesian genetic variant detector designed to find small polymorphisms, specifically SNPs (single-nucleotide polymorphisms), indels (insertions and deletions),

MNPs (multi-nucleotide polymorphisms), and complex events (composite insertion and substitution events) smaller than the length of a short-read sequencing alignment.

FreeBayes is haplotype-based, in the sense that it calls variants based on the literal sequences of reads aligned to a particular target, not their precise alignment.

This model is a straightforward generalization of previous ones (e.g. PolyBayes, samtools, GATK) which detect or report variants based on alignments.

This method avoids one of the core problems with alignment-based variant detection--- that identical sequences may have multiple possible alignments.

haplotype: 单倍型。一个染色单体里具有统计学关联性的一类SNPs.   基因在一条染色体上的组合为haplotype

freebayse 不仅call SNPs , INDELs,还有

MNPs(multi-nucleotide polymorphisms), 连续两个snp位点,如ref为AT, alt为CG

Complex events(composite insetion and substitution events)

所有的结果为:

五中基本类型:'snp','ins','del','mnp','complex',

'snp,snp',   和ref不同的碱基有两个,比如ref为A, alt为T,G 并且这两个的数量都是显著的。但是对于杂合二倍体来说是可能的。举个例子,参考基因组某位点是A, 比对的reads中有两种情况,C和G, 这应该就是snp,snp。其他的这种情况以此类推。

默认的--ploidy就是 dploid, by default all samples are assumed to be diploid。

除了以上五种,还有杂合二倍体可能出现的一下几种情况:(但是这种情况占的比例非常小,因为从进化的角度来看,一个位点两个都突变的概率就很小。杂合度和遗传距离有关,遗传距离越远杂合度就高,遗传距离越近,纯合度越高。一般超过百分之一的杂合度就肯定是杂种了。粳稻和粳稻之间01肯定比粳稻和籼稻之间的01少!!)

'ins,snp', 'ins,ins', 'ins,mnp',

'del,mnp', 'del,del', 'del,snp', 'del,ins'

'mnp,snp', 'mnp,mnp',

'complex,complex',  'complex,del', 'complex,snp',  'complex,mnp',  'complex,ins',

软件中几个重要的参数:

--haplotype-length  应该是haplotype中各变异位点之间的距离,比如mnp和complex都应该是haplotype, 如果设置为0的话:mnp肯定是可以call出来, 因为mnp是连续的几个snp,每个snp之间的距离就是0。而complex比较复杂,如果ref和alt对应的碱基个数相等。当设置为0的时候,会被过滤掉, 但是不等的并不会被过滤掉。

如果不想要complex直接用--no-complex(-u)参数,但是这个参数会将complex拆分,比如可能一个complex拆分成了几个snp等等。如果使用--no-mnps(-X)的话也会分成两个snp,但是并不能保证每个snp的准确性。

之前做snp比较没有使用这个两个参数,所以导致相似度很低,以后将这两个参数加上以后再和sam和gatk比较。

--min-alternare-count     应该就是-C 观察到的最少的alt碱基数,这个很不好设置,因为我觉得深度不同,应该设置的值也不同,整个一刀切不好。 假如深度为10 , 你-C设置为2.和深度是100-C设置为2的效果和你想象的结果是不同的,100的时候你也许想着5以下的都别call出来,深度为10的时候,你也许2一下的别call出来。

--min-alternate-fraction 就是-F 下面有解释。

-K --pooled-continuous。 Output all alleles which pass input filters, regardles of genotyping outcome or model.   问一下--pooled-continuous什么意思?

只加-K 结果类型有:

'mnp', 'ins', 'del', 'snp', 'complex'。

'complex,complex', 'complex,del',  'del,mnp',  'del,ins', 'del,del', 'snp,snp', 'complex,snp', 'complex,mnp', 'del,snp', 'mnp,snp', 'ins,ins', 'ins,snp', 'ins,mnp', 'mnp,mnp', 'complex,ins'。

(三种类型)'complex,complex,del',  'del,mnp,snp', 'del,snp,snp',  'del,ins,ins', 'complex,ins,mnp', 'complex,del,ins', 'complex,complex,complex', 'complex,ins,ins',  'del,del,snp', 'complex,ins,snp', 'mnp,snp,snp', 'ins,mnp,snp',  'del,ins,snp', 'complex,complex,mnp', 'mnp,mnp,snp', 'complex,del,del',  'del,del,del', 'ins,ins,snp', 'complex,snp,snp',  'del,del,mnp',  'del,del,ins',  'complex,del,mnp', 'complex,del,snp', 'ins,snp,snp', 'complex,mnp,mnp', 'mnp,mnp,mnp', 'snp,snp,snp', 'ins,ins,mnp', 'del,mnp,mnp',  'complex,complex,snp', 'ins,ins,ins','complex,mnp,snp', 'complex,complex,ins',

(四种类型)'complex,complex,complex,mnp',  'del,del,del,del', 'complex,complex,ins,snp', 'complex,ins,ins,snp', 'complex,del,mnp,snp', 'complex,del,del,snp', 'complex,complex,del,del', 'complex,complex,del,snp', 'complex,mnp,snp,snp', 'complex,ins,ins,ins',

'ins,ins,ins,snp', 'complex,complex,snp,snp', 'complex,complex,complex,snp',  'complex,complex,complex,complex',  'mnp,snp,snp,snp', 'complex,complex,complex,del', 'del,snp,snp,snp',  'complex,complex,mnp,snp','mnp,mnp,snp,snp', 'complex,del,snp,snp','del,del,del,snp'

后面两种类型,在其他模式下是call不出来的,观察了一下结果,对于类型为complex,complex,complex,complex, 比如某个位点的深度为5, 而alt的深度分别为2,1,1,1。 很明显是测序错误或比对错误导致的这种情况。所以不要用这个参数。

--report-monomorphic :

Report even loci which appear to be monomorphic, and report all considered alleles, even those which are not in called genotypes. Loci which do not have any potential alternates have '.' for ALT.

会报告每个位点。虽然这个位点并没有alt base, 基因型为0/0, alt为. 相当于你的参考序列有多长,就有多少个报告位点。。。。慎重考虑是否需要。

-n --use-best-n-alleles N。 Evaluate only the best N SNP alleles, ranked by sum of supporting quality scores.  (Set to 0 to use all; default: all)。 如果将n设置为1,只会call出5中基本类型,其他的都会被滤掉。但是除了滤掉others,这五中基本类型也会减少很多!

下面两张图类型的顺序为: snp, ins, del, mnp, complex, others, total

如何用 freebayes call SNP

上图是没有加n1

如何用 freebayes call SNP

上图是加了n1,  可以看到others没有了,但是其他五中类型都少了很多。查看了一下丢失的位点,并没有发现质量很低,深度很低等情况。。所以这参数还是不要用了,丢太多数据了!问海宝这个参数到底是什么一个概念。

如果将n设置成2, 默认的设置为0(all)结果基本没有区别。

2,安装与使用

服务器已经安装好软件,下面举例说明用法,

参考序列为:

RAP_cDAN.fasta

bam文件为:

LCS173-1.sorted.rmp.rg.bam

LCS173-2.sorted.rmp.rg.bam

LCS173-3.sorted.rmp.rg.bam

RCS173-1.sorted.rmp.rg.bam

RCS173-2.sorted.rmp.rg.bam

RCS173-3.sorted.rmp.rg.bam

这是样本CS173的六组数据,每组bam数据都经过了sort, remove duplicate, add read group 步骤,这几个前期处理数据步骤是必须的。对bam文件的处理

详见本博客其他文章。除了这几步以为,还要对bam文件进行index,即每个bam文件都要有相应的bai文件。数据处理好后,就可以进行call snp了。

命令:

freebayes -f RAP_cDAN.fasta -L bamfile.list > CS173.vcf

其中,-f 后跟参考序列。-L 后面跟纯文本文件,里面就是bam文件的名字,因为文件较多,所以将名字都放到一个文件中。如果你只有一个文件,那直接将

文件名放于参考序列后面就可以了。 > 是进行重定向,即将结果保存到CS173.vcf文件中。

也可以同时call 不同的样本, 只要将不同的样本数据放到bam.list文件中就可以了,注意,不同样本数据的read group必须唯一,不能重复。

当命令结束后,就会得到结果文件,文件中记录了snp的信息。详细的vcf格式说明另见博客文章。

对于bam文件, 可以合并去call, 也可以分开向上面那样去call. 结果是一样的。建议不合并,既然一样, 干嘛多做合并那一步?浪费时间和硬盘空间。freebayse会根据bam的SM将不同的样本分开,和单独call一个样本相比,同时call多个样本的snp,结果文件格式上会有些差别。

Format后面是对各个样本的描述,

如何用 freebayes call SNP

只要某个样本在这个变异位点上有比对情况,就会有相应的信息,但是如果这个位点对于某个样本就没有任何信息,会用点.来代替这个样本在此点的情况。同时在一个文件中展现多个样本,有一个问题,比如info列中的信息,type指的是哪个样的?明明是三个样,为何只有一个类型。

另外ALT列,指的是哪个样的?当三个样的类型是00 01 11 还可以区分,但是如果类型更复杂些,必定是区分不清,下一步研究主要集中在snp。

如何用 freebayes call SNP

这是最简单的使用方法,还有一些参数,如果感兴趣的话可以调试,如-C ,默认值为2,即变异位点处至少有两个和参考碱基不同,才会考虑是snp位点。

假如,此某位点的覆盖度为10,但之后一个和参考碱基不同,剩下9个是一样的,那么这个位点不会被call出。

另一个参数-F (--min-alternate-fraction)默认为0.2 ,即至少有20%的碱基和参考碱基不同才能被call出。假如某位点深度为100,但是只有10个碱基和参考序列不同,是不会被call出的。如果该值设置为0,那么参考序列的每个碱基位点都会被call SNP, 尽管没有,也会用0/0代替。现在有个问题是,加入深度是1000, alt是190, 如果按照默认的,这个位点不会出现在结果中,但很明显这应该是一个杂合位点。因为190个碱基被测错, 并且190个测错的结果都一样,这基本是不可能的。所以这个参数的设置挺重要的,怎么样保留我们需要的snp位点。需要考虑一下,比如考虑DP和测序平均深度?

这主要是考虑到了测序错误,比对错误等原因,才设置下限,目的是提高call snp的准确性。但是要根据你自己的数据情况,假如你用RNA-seq数据研究等位基因特异性表达,

某些位点也许表达量很多,深度达到了1000,其中有100个碱基和参考序列有差别,如果你用默认设置,此时并不能将snp call 出,但这可能是一个很重要的特异表达位点。

所以要根据自己的使用目的来设置参数。

3,更多的例子。

examples:

# call variants assuming a diploid sample

freebayes -f ref.fa aln.bam >var.vcf

# require at least 5 supporting observations to consider a variant

freebayes -f ref.fa -C 5 aln.bam >var.vcf

# use a different ploidy

freebayes -f ref.fa -p 4 aln.bam >var.vcf

# assume a pooled sample with a known number of genome copies

freebayes -f ref.fa -p 20 --pooled-discrete aln.bam >var.vcf

# generate frequency-based calls for all variants passing input thresholds

freebayes -f ref.fa -F 0.01 -C 1 --pooled-continuous aln.bam >var.vcf

# use an input VCF (bgzipped + tabix indexed) to force calls at particular alleles

freebayes -f ref.fa -@ in.vcf.gz aln.bam >var.vcf

# generate long haplotype calls over known variants

freebayes -f ref.fa --haplotype-basis-alleles in.vcf.gz \   --haplotype-length 50 aln.bam

# naive variant calling: simply annotate observation counts of SNPs and indels

freebayes -f ref.fa --haplotype-length 0 --min-alternate-count 1 \    --min-alternate-fraction 0 --pooled-continuous --report-monomorphic >var.vcf

对结果进一步筛选,如qual, DP, AO....

大部分问题是出在那些深度较低的位点。

freebayes 产生的是VCF 4.1, 适用于描述很多样本,当然也可以描述一个样本

在freebayes中,qual 指这个位点是变异位点的概率, 理解为1-P, P 是这个位点是纯合的概率。

ROC receiver-operator characteristic ROC曲线

freebayes可以同时call多个样本:

freebayes isdesigned to be run on many individuals from the same population(e.g. many human individuals)simultaneously.

同时call的好处,1, 能够使结果更加准确。2,最后输出文件一致,更容易下游处理, 如某个位点不同样本的情况。如果单独call, 这个样本在这是纯合就不会显示,但是一起call, 都会显示出来。

不同的样本是根据RG信息来区分的, 注意不同样本他们的group ID 不能一样。

The VCF output will have one column per sample in the input.

3,进一步阅读

https://github.com/ekg/freebayes

在装有freebayes的服务器中 敲击 freebayes -h

By freemao

FAFU.

free_mao@qq.com