指示Python中的种群结构
在Python中,我使用的是。我试图计算在VCF文件中找到的每个SNP的Jost的D值 数据 数据为VCF格式。数据集很小,有2个群体,每个群体100个个体和6个SNP(都在1号染色体上) 每个个体被命名为指示Python中的种群结构,python,dictionary,bioinformatics,biopython,vcf-variant-call-format,Python,Dictionary,Bioinformatics,Biopython,Vcf Variant Call Format,在Python中,我使用的是。我试图计算在VCF文件中找到的每个SNP的Jost的D值 数据 数据为VCF格式。数据集很小,有2个群体,每个群体100个个体和6个SNP(都在1号染色体上) 每个个体被命名为Pp.Ii,其中p是它所属的人口指数,i是个体指数 代码 我的困难在于人口结构的具体化。这是我的审判 ### Read the vcf file ### vcf = egglib.io.VcfParser("MyData.vcf") ### Create the `St
Pp.Ii
,其中p
是它所属的人口指数,i
是个体指数
代码
我的困难在于人口结构的具体化。这是我的审判
### Read the vcf file ###
vcf = egglib.io.VcfParser("MyData.vcf")
### Create the `Structure` object ###
# Dictionary for a given cluster. There is only one cluster.
dcluster = {}
# Loop through each population
for popIndex in [0,1]:
# dictionnary for a given population. There are two populations
dpop = {}
# Loop through each individual
for IndIndex in range(popIndex * 100,(popIndex + 1) * 100):
# A single list to define an individual
dpop[IndIndex] = [IndIndex*2, IndIndex*2 + 1]
dcluster[popIndex] = dpop
struct = {0: dcluster}
### Define the population structure ###
Structure = egglib.stats.make_structure(struct, None)
### Configurate the 'ComputeStats' object ###
cs = egglib.stats.ComputeStats()
cs.configure(only_diallelic=False)
cs.add_stats('Dj') # Jost's D
### Isolate a SNP ###
vcf.next()
site = egglib.stats.site_from_vcf(vcf)
### Calculate Jost's D ###
cs.process_site(site, struct=Structure)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/egglib/stats/_cstats.py", line 431, in process_site
self._frq.process_site(site, struct=struct)
File "/Library/Python/2.7/site-packages/egglib/stats/_freq.py", line 159, in process_site
if sum(struct) != site._obj.get_ning(): raise ValueError, 'invalid structure (sample size is required to match)'
ValueError: invalid structure (sample size is required to match)
###读取vcf文件###
vcf=egglib.io.VcfParser(“MyData.vcf”)
###创建'Structure'对象###
#给定集群的字典。只有一个集群。
dcluster={}
#循环遍历每个种群
对于[0,1]中的popIndex:
#特定人群的用语。有两种人群
dpop={}
#循环通过每个人
对于范围内的Index(popIndex*100,(popIndex+1)*100):
#用于定义个人的单个列表
dpop[index]=[index*2,index*2+1]
dcluster[popIndex]=dpop
结构={0:dcluster}
###界定人口结构###
Structure=egglib.stats.make_结构(struct,None)
###配置“ComputeStats”对象###
cs=egglib.stats.ComputeStats()
cs.configure(仅\u diallelic=False)
cs.添加统计数据(“Dj”)#Jost's D
###分离单核苷酸多态性###
vcf.next()
site=egglib.stats.site_from_vcf(vcf)
###计算约斯特D###
cs.过程现场(现场,结构=结构)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/Library/Python/2.7/site packages/egglib/stats/_cstats.py”,第431行,进程中的站点
self.\u frq.process\u site(site,struct=struct)
文件“/Library/Python/2.7/site packages/egglib/stats/_freq.py”,第159行,进程中站点
如果和(结构)!=站点。_obj.get_ning():raise VALUE ERROR,“无效结构(需要匹配样本大小)”
ValueError:结构无效(需要匹配样本大小)
文件表明
[Structure object]是一个包含两个项的元组,每个项都是dict。第一个表示ingroup,第二个表示outgroup
ingroup字典本身就是一个包含更多字典的字典,每个群体一个字典。每个集群字典都是一个总体字典,总体本身由一个字典表示。人口词典也是个人词典。幸运的是,个人由列表表示
单个列表包含属于该个体的所有样本的索引。对于单倍体数据,个体将是一个项目列表。在其他情况下,所有单独的列表都需要有相同数量的项目(一致的倍性)。请注意,如果倍性不止一个,则没有任何东西强制将给定个体的样本分组到原始数据中
ingroup字典的键是标识每个集群的标签。在集群字典中,键是填充标签。最后,在人口字典中,键是单独的标签
第二个字典表示outgroup。它的结构更简单:它有单独的标签作为键,相应的样本索引列表作为值。外组字典类似于任何内组填充字典。倍性需要与所有组内和组外个体相匹配
但我没弄明白。提供的示例是针对fasta格式的,我不理解如何将逻辑扩展到VCF格式。有两个错误
第一个错误
函数make_structure
返回结构对象,但不将其保存在stats
中。因此,您必须保存此输出并将其用于函数process\u站点
Structure = egglib.stats.make_structure(struct, None)
第二个错误
结构对象必须指定单倍体。因此,将字典创建为
dcluster = {}
for popIndex in [0,1]:
dpop = {}
for IndIndex in range(popIndex * 100,(popIndex + 1) * 100):
dpop[IndIndex] = [IndIndex]
dcluster[popIndex] = dpop
struct = {0: dcluster}
有两个错误
第一个错误
函数make_structure
返回结构对象,但不将其保存在stats
中。因此,您必须保存此输出并将其用于函数process\u站点
Structure = egglib.stats.make_structure(struct, None)
第二个错误
结构对象必须指定单倍体。因此,将字典创建为
dcluster = {}
for popIndex in [0,1]:
dpop = {}
for IndIndex in range(popIndex * 100,(popIndex + 1) * 100):
dpop[IndIndex] = [IndIndex]
dcluster[popIndex] = dpop
struct = {0: dcluster}