[Bio] / FigKernelPackages / FIG.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIG.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.588, Mon May 14 16:13:25 2007 UTC revision 1.589, Tue May 15 21:12:18 2007 UTC
# Line 12617  Line 12617 
12617      return ();      return ();
12618  }  }
12619    
12620    =head3 ids_of_compound
12621    
12622    usage: @ids = $fig->ids_of_compound
12623    
12624    Returns a list containing all of the ids assigned to the KEGG compounds.  The list
12625    will be ordered as given by KEGG.
12626    
12627    =cut
12628    
12629    sub ids_of_compound {
12630        my($self,$name) = @_;
12631    
12632        my $rdbH = $self->db_handle;
12633        my $relational_db_response = $rdbH->SQL("SELECT pos,cid FROM comp_name where name = \'$name\'");
12634        if (@$relational_db_response > 0)
12635        {
12636            return map { $_->[1] } sort { $a->[0] <=> $b->[0] } @$relational_db_response;
12637        }
12638        return ();
12639    }
12640    
12641    =head3 ids_of_compound_like_name
12642    
12643    usage: @ids = $fig->ids_of_compound_like_name($name)
12644    
12645    Returns a list containing all of the ids assigned to the KEGG compounds that match $name.  The list
12646    will be ordered as given by KEGG.
12647    
12648    =cut
12649    
12650    sub ids_of_compound_like_name {
12651        my($self,$name) = @_;
12652    
12653        # replace dashes with underscores, which will match any single character in the 'like' clause
12654        $name =~ s/-/_/g;
12655        my $rdbH = $self->db_handle;
12656        my $relational_db_response = $rdbH->SQL("SELECT pos,cid FROM comp_name where name ilike \'$name\'");
12657        if (@$relational_db_response > 0)
12658        {
12659            return map { $_->[1] } sort { $a->[0] <=> $b->[0] } @$relational_db_response;
12660        }
12661        return ();
12662    }
12663    
12664    
12665    
12666  =head3 comp2react  =head3 comp2react
12667    
12668  C<< my @rids = $fig->comp2react($cid); >>  C<< my @rids = $fig->comp2react($cid); >>
# Line 12789  Line 12835 
12835      return 1;      return 1;
12836  }  }
12837    
12838    =head3 reaction_direction
12839    
12840    C<< my $rev = $fig->reaction_direction($rid); >>
12841    
12842    Returns an array of triplets mapping from reactions in the context of maps to reversibility.
12843    
12844    =over 4
12845    
12846    =item rid
12847    
12848    ID of the relevant reaction.
12849    
12850    =item RETURN
12851    
12852    Return C<< B >> if the reaction proceeds in both directions, C<< L >> if it proceeds from right
12853    to left, or C<< R >> if it proceeds from left to right (by convention the "substrates"
12854    are on the left and the "products" are on the right).
12855    
12856    =back
12857    
12858    =cut
12859    
12860    sub reaction_direction {
12861        my ($self, $rid) = @_;
12862        my @results = ();
12863    
12864        my $rdbH = $self->db_handle;
12865        my $relational_db_response = $rdbH->SQL("SELECT rid, mapid, direction FROM reaction_direction where rid = \'$rid\'");
12866    
12867        if (@$relational_db_response > 0)
12868        {
12869            foreach my $res (@$relational_db_response) {
12870                my ($rid, $mapid, $rev)=@$res;
12871                push (@results, [$rid, $mapid, $rev]);
12872            }
12873        }
12874    
12875        return @results;
12876    }
12877    
12878  =head3 reaction2comp  =head3 reaction2comp
12879    
12880  C<< my @tuples = $fig->reaction2comp($rid, $which); >>  C<< my @tuples = $fig->reaction2comp($rid, $which, $paths); >>
12881    
12882  Return the substrates or products for a reaction.  In any event (i.e.,  Return the substrates or products for a reaction.  In any event (i.e.,
12883  whether you ask for substrates or products), you get back a list of  whether you ask for substrates or products), you get back a list of
# Line 12814  Line 12900 
12900  TRUE if the products (right side) should be returned, FALSE if the substrates  TRUE if the products (right side) should be returned, FALSE if the substrates
12901  (left side) should be returned.  (left side) should be returned.
12902    
12903    =item paths
12904    
12905    Optional list of paths to check whether compound is "main"
12906    
12907  =item RETURN  =item RETURN
12908    
12909  Returns a list of 3-tuples. Each tuple contains the ID of a compound, its  Returns a list of 3-tuples. Each tuple contains the ID of a compound, its
12910  stoichiometry, and a flag that is TRUE if the compound is one of the main  stoichiometry, and a flag that is TRUE if the compound is one of the main
12911  participants in the reaction.  participants in the reaction.  If paths are specified, the flag indicates
12912    whether the compound is main in any of the specified paths.
12913    
12914  =back  =back
12915    
12916  =cut  =cut
12917    
12918  sub reaction2comp {  sub reaction2comp {
12919      my($self,$rid,$which) = @_;      my($self,$rid,$which,$paths) = @_;
12920    
12921      my $rdbH = $self->db_handle;      my $rdbH = $self->db_handle;
12922      my $relational_db_response = $rdbH->SQL("SELECT cid,stoich,main FROM reaction_to_compound where rid = \'$rid\' and setn = \'$which\'");      my $relational_db_response_not_main = $rdbH->SQL("SELECT cid,stoich,main FROM reaction_to_compound where rid = \'$rid\' and setn = \'$which\' and main = \'0\'");
12923      if (@$relational_db_response > 0)      my $relational_db_response_main = $rdbH->SQL("SELECT distinct cid,stoich,main FROM reaction_to_compound where rid = \'$rid\' and setn = \'$which\' and main = \'1\'");
12924    
12925        if (@$relational_db_response_not_main > 0 || @$relational_db_response_main > 0)
12926      {      {
12927          return sort { $a->[0] cmp $b->[0] } map { $_->[1] =~ s/\s+//g; $_ } @$relational_db_response;          my @tuples_to_return = @$relational_db_response_not_main;
12928    
12929            if (! $paths || scalar @$paths == 0)
12930            {
12931                push @tuples_to_return, @$relational_db_response_main;
12932      }      }
12933            else
12934            {
12935                my $inner_paths_string = join "','", @$paths;
12936    
12937                foreach my $tuple (@$relational_db_response_main)
12938                {
12939                    my $relational_db_response_main_path = $rdbH->SQL("SELECT cid,stoich,main FROM reaction_to_compound where rid = \'$rid\' and setn = \'$which\' and main = \'1\' and cid = \'$tuple->[0]\' and path in \(\'$inner_paths_string\'\)");
12940    
12941                    push @tuples_to_return, [$tuple->[0], $tuple->[1], @$relational_db_response_main_path > 0 ? "1" : "0"];
12942                }
12943            }
12944    
12945            return sort { $a->[0] cmp $b->[0] } map { $_->[1] =~ s/\s+//g; $_ }  @tuples_to_return;
12946        }
12947    
12948      return ();      return ();
12949  }  }
12950    

Legend:
Removed from v.1.588  
changed lines
  Added in v.1.589

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3