我正在尝试使用多对多映射,找到一个集合的子集映射到另一个集合的特定子集。你知道吗
我有很多基因。每个基因都是一个或多个COG的成员(反之亦然)
我有一组代表酶的短COG,例如COG1,COG273。你知道吗
我想找出它们之间的所有基因集,它们都是酶中每个COG的成员,但没有不必要的重叠(例如,在这种情况下,'gene1和gene6'将是虚假的,因为gene6已经是两个COG的成员)。你知道吗
在这个例子中,答案是:
虽然我可以得到每个COG的所有成员并创建一个“产品”,但这将包含虚假的结果(如上所述),其中的基因多于必需的。你知道吗
我的映射当前包含在一个字典中,其中键是gene ID,值是该gene是其成员的COG ID的列表。但是,我承认这可能不是存储映射的最佳方式。你知道吗
这对你有用吗?注意,既然你说你有一个很短的齿轮集,我继续做嵌套for循环;可能有一些方法可以优化这个。。。你知道吗
为了将来的参考,请张贴任何代码,你已经随着你的问题。你知道吗
输出:
lt=[('gene1','COG1'),('gene1','COG1003'),('gene2','COG2'),('gene3','COG273'),('gene4','COG1'), ('gene5','COG273'),('gene5','COG71'),('gene6','COG1'),('gene6','COG273')]
findGenes('COG1','COG273',lt)
('gene1','gene3')
('gene1','gene5')
('gene4','gene3')
('gene4','gene5')
['gene6']
一个基本攻击:
这对你有用吗?我相信它正确地覆盖了最小集,给出了一个表现良好的例子。请注意,从高端开始,当我们检查最小值时,会防范这样的情况:
我们可以看到我们需要gene3、gene4和gene1或gene2。如果我们从低端淘汰掉gene1,就永远找不到解决方案。如果我们从高端开始,我们将消除gene2,但在主循环的稍后过程中找到解决方案。你知道吗
有可能构造一个这样一种情况,即这种情况存在三方冲突。在这种情况下,我们必须在最小值检查中编写一个额外的循环才能找到所有的值。不过,我想你的数据对我们来说并不是那么糟糕。你知道吗
相关问题 更多 >
编程相关推荐