首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >prolog逻辑门聚合递归优化

prolog逻辑门聚合递归优化
EN

Stack Overflow用户
提问于 2014-06-09 12:40:43
回答 1查看 384关注 0票数 1

我正在尝试实现一个逻辑门类型聚合操作。我在编写一个在合理的时间内执行计算的实现时遇到了困难。我认为我所拥有的是合乎逻辑的,但它是非常缓慢的,我不认为它需要。我认为应该有可能做到这一点,而不使用许多‘查找或削减’。

我有一个大约10,000列和70行的表。行对应于样本,而列对应于探测。表中的每个值要么为1,要么为零(示例中的探测状态)。

多个探针编码一个蛋白质。(多到一个关系),因此我希望使用逻辑OR操作将探测列聚合到蛋白质列。

除此之外,一些蛋白质是蛋白质复合体或蛋白质集合的一部分。蛋白质复合物和蛋白质组除了含有蛋白质外,还可能包含蛋白质复合物或蛋白质组。所以它们可以是一种递归关系。我想把蛋白质集合建模为OR门和蛋白质复合物作为和盖茨。我把蛋白质、protein_sets和复合物统称为“实体”。

所以总的来说,我想要一个谓词,在这里我可以问一个蛋白质或实体在一个能快速工作的样本中是开的还是关的。

如果其他谓词不清楚,那么我可以告诉您它们是做什么的。

代码语言:javascript
复制
protein(Sample, Reactome_Id, State):-
    setof(Sample, Probe^samples(Sample, Probe, ProbeValue), Samples), 
    %sample/3 is a set of facts that correspond to the described table
    member(X, Samples), %used to generate Sample Id's %this seems wasteful 
    protein_reactome_Id_to_Uniprot_Id(Reactome_Id, UniprotId), % a set of facts matching two types of id
    %used to generate uniprot ids
    findall(Value, uniProt_Sample_Probes(UniprotId,X,_,Value),Vs),
    Vs = [_|_],     %Check list is not empty already
    delete(Vs,0,ListOfOnes),
    (ListOfOnes=[]-> (State is 0, write('OFF'));(State is 1,write('ON'))).
    %As this is an or I think I should just be able to find a single 1 and cut for the  on case and if this is not possible to say it is off.

%if a (simple) entity is a protein set and its state is on
%this is a base case where an entity does not have complexs or sets inside it
state_of_entity(Entity,State,Sample):-
    all_children_proteins(Entity), %checks that all children are of type protein
    type(Entity, protein_set),
    child_component(Entity,Child), %generates the children of an entity
    protein(Sample,Child,1),
    State is 1,!.

 %if a (simple) entity is a protein set and it's state if off
 %this is a base case where an entity does not have complexs or sets inside it
 %I find all proteins for a sample, this is a list of values, I delete all the
 %zeros and the remaining list will unify with the empty list.
 state_of_entity(Entity,State,Sample):-
     all_children_proteins(Entity),
     type(Entity, protein_set),
     child_component(Entity,Child),
 bagof(Value, Value^protein(Sample,Child,Value),Vs),
 delete(Vs,0,ListOfOnes),ListOfOnes=[],
 State is 0,!.

%if a (simple) entity is a complex and is off
%this is a base case where an entity does not have complexs or sets inside it
state_of_entity(Entity,State,Sample):-
    all_children_proteins(Entity),
    type(Entity, complex),
    child_component(Entity,Child),
    protein(Sample,Child,0),
    State is 0,!.

%if a (simple) entity is a complex and is on.
%this is a base case where an entity does not have complexs or sets inside it
%I find all protein in a sample, this is a list of values, I delete all the
%zeros and the remaining list will unify with the empty list.
state_of_entity(Entity,State,Sample):-
    all_children_proteins(Entity),
    type(Entity, complex),
    child_component(Entity,Child),
    bagof(Value, Value^protein(Sample,Child,Value),Vs),
    delete(Vs,1,ListOfZeros),ListOfZeros=[],
    State is 1,!.

%if a complex with components is off
%recursive case
state_of_entity(Entity,State,Sample):-
    type(Entity, complex),
    child_component(Entity,Child),
    (state_of_entity(Child,0,Sample);
    protein(Sample,Child,0)), %if it has any proteins as input as well as other      components
    State is 0,!.

%if a complex with components is on
%recursive case
state_of_entity(Entity,State,Sample):-
    type(Entity, complex),
    child_component(Entity,Child),
    bagof(Value, Value^state_of_entity(Child,Value,Sample),Vs),%if it has component inputs
    bagof(Value2, Value2^protein(Sample,Child,Value2),Vs2),%if it has protein inputs
    append(Vs, Vs2, Vs3),
    delete(Vs3,1,ListOfZeros),ListOfZeros=[],%delete all the ones, the list of zeros will be empty if all inputs are on
  State is 1,!.

%if a protein set with components is on
%recursive case
state_of_entity(Entity,State,Sample):-
    type(Entity, protein_set),
    child_component(Entity,Child),
    (state_of_entity(Child,1,Sample);
    protein(Sample,Child,1)), %if it has any proteins as input as well as other entities
    State is 1,!.

%if a protein set with components is off
%recursive case
state_of_entity(Entity,State,Sample):-
    type(Entity, protein_set),
    child_component(Entity,Child),
    bagof(Value, Value^state_of_entity(Child,Value,Sample),Vs), %if it has entity inputs
    bagof(Value2, Value2^protein(Sample,Child,Value2),Vs2), %if it has protein inputs
    append(Vs, Vs2, Vs3), %join the list of inputs together
    delete(Vs3,0,ListOfOnes),ListOfOnes=[], %delete all the zeros, the list of 1's will be empty if all inputs are off
    State is 0,!.

更新--为了使蛋白质比特按我的意愿工作,我最终得到了这个结果。

代码语言:javascript
复制
samples(Samples):-
    setof(Sample_in, Probe^samples(Sample_in, Probe, ProbeValue), Samples).
sample(Sample):-
    once(samples(Samples)), %why do I need this?!
    member(Sample, Samples).

protein_stack(Sample, Reactome_Id, State):-
        (
            protein_reactome_Id_to_Uniprot_Id(Reactome_Id, UniprotId),
            uniProt_Sample_Probes(UniprotId, Sample, Probe, 1),
            !,
            State is 1
        ;
            State is 0
        ).

protein_good(Sample, Reactome_Id,State):-
    sample(Sample), 
    protein_reactome_Id_to_Uniprot_Id(Reactome_Id, _),
    protein_stack(Sample, Reactome_Id,State).
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-09 13:34:06

让我们以protein/3的第一个规则为例。

  • Reactome_IdUniprotId之间的关系是唯一的吗?如果是的话,在setof(Sample ...), member(X, Samples)之前移动它,然后在它后面加一个切口。否则,您将尝试满足setof(...), member(X, Samples)的每个结果。更重要的是,绿色削减在业绩方面有所帮助。
  • 该规则有一个目的,以查看Vs中是否至少有一个1的值。您不应该生成Vs的所有成员,然后搜索值为1,但是当您在满足uniProt_Sample_Probes(UniprotId, X, _, Value)时找到第一个成员时停止。 蛋白质(样品,Reactome_Id,状态):-( protein_reactome_Id_to_Uniprot_Id(Reactome_Id,UniprotId),集合(样品,探针^样品(样品,探针,ProbeValue),样本( X,样品),uniProt_Sample_Probes(UniprotId,X,_,1),!,状态为1,写(‘ON));状态为0,写(‘OFF’)。

其他规则可以使用相同的模式进行优化:

代码语言:javascript
复制
state_of_x(X, State) :- Goal, !, State = 1.
state_of_x(X, State) :- State = 0.

或者,更简洁,

代码语言:javascript
复制
state_of_x(X, 1) :- Goal, !.
state_of_x(X, 0).
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24120534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档