希望这可以用python实现!我在同一个数据上使用了两个集群程序,现在两个都有了一个集群文件。我重新格式化了文件,使它们看起来像这样:
Cluster 0:
Brucellaceae(10)
Brucella(10)
abortus(1)
canis(1)
ceti(1)
inopinata(1)
melitensis(1)
microti(1)
neotomae(1)
ovis(1)
pinnipedialis(1)
suis(1)
Cluster 1:
Streptomycetaceae(28)
Streptomyces(28)
achromogenes(1)
albaduncus(1)
anthocyanicus(1)
etc.
这些文件包含细菌种类信息。所以我有了簇数(0),然后在它的正下方是布鲁氏菌科(brucellae)和这个家族中的细菌数量(10)。下面是在该科中发现的属(名称后接编号,布鲁氏菌属(10)),最后是每个属的物种(abortus(1)),等等。在
我的问题:我有两个这样格式化的文件,我想写一个程序来寻找两者之间的差异。唯一的问题是两个程序以不同的方式聚集,因此两个群集可能是相同的,即使实际的“簇号”不同(因此一个文件中的簇1的内容可能与另一个文件中的簇43相匹配,唯一不同的是实际的簇号)。所以我需要一些东西来忽略簇号,集中在簇的内容上。在
有什么方法可以比较这两个文件来检查它们的区别吗?有可能吗?任何想法都将不胜感激!在
给予:
这是你需要的吗?在
^{pr2}$要了解差异:
印刷品
我在评论中看到了很多不同的答案,为了帮助您,我将给您一个非常非常简单的脚本实现,您可以从中开始。在
请注意,这个并不能回答您的全部问题,而是在评论中为您指出一个方向。在
通常,如果你没有经验,我会建议你去读一读Python(无论如何我都会这么做,我会在答案的底部加上一些链接)
去玩好玩的东西吧!:)
我在没有任何花哨的东西和python2.7.2的情况下,尽可能地编写了这篇愚蠢而过于简单的文章 您可以将这个文件复制到
.py
文件中,然后直接从命令行python bacteria.py
运行它。在希望这有点帮助,如果您有任何问题,请随时访问我们的Python聊天室!:)
你必须写一些代码来解析文件。如果你忽略了聚类,你应该能够根据缩进区分科、属和种。在
定义named tuple的最简单方法是:
在这个对象的实例中,您可以这样做:
^{pr2}$解析器应该逐行读取文件,并设置族和属。如果它找到了一个物种,它应该在一个列表中添加一个细菌
一旦您有了每个文件或集群中所有细菌的列表,您可以从所有细菌中进行选择,如下所示:
相关问题 更多 >
编程相关推荐