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

View of /FigKernelPackages/raelib.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.3 - (download) (as text) (annotate)
Wed Feb 2 01:07:44 2005 UTC (14 years, 11 months ago) by redwards
Branch: MAIN
Changes since 1.2: +62 -1 lines
Minor changes to ubsys.cgi  (mainly commenting) and raelib adding tagvalue

# -*- perl -*-



 Some routines and things that Rob uses. Please feel free to use at will and incorporate into
 your own code or move them into FIG.pm or elsewhere.


package raelib;
use strict;
use FIG;
my $fig=new FIG;

=head2 pirsfcorrespondance

 Generate the pirsf->fig id correspondance. This is only done once and the correspondance file is written.
 This is so that we can easily go back and forth.

 The correspondance has PIR ID \t FIG ID\n, and is probably based on ftp://ftp.pir.georgetown.edu/pir_databases/pirsf/data/pirsfinfo.dat


sub pirsfcorrespondance { 
 my ($self, $from, $to)=@_;
 die "File $from does not exist as called in $0" unless (-e $from);
 open (IN, $from) || die "Can't open $from";
 open (OUT, ">$to") || die "Can't write tot $to";
 while (<IN>) {
  if (/^>/) {print OUT; next}
  my $done;
  foreach my $peg ($fig->by_alias("uni|$_")) {
   print OUT $_, "\t", $peg, "\n";
  unless ($done) {print OUT $_, "\t\n"}
 close IN;
 close OUT;

=head2 ss_by_id

 Generate a list of subsystems that a peg occurs in. This is a ; separated list.
 This is a wrapper that removes roles and ignores essential things


sub ss_by_id { 
 my ($self, $peg)=@_;
 my $ssout;
 foreach my $ss (sort $fig->subsystems_for_peg($peg)) 
  next if ($$ss[0] =~ /essential/i); # Ignore the Essential B-subtilis subsystems
  $ssout.=$$ss[0]."; ";
 $ssout =~ s/; $//;
 return $ssout;

=head2 ss_by_homol

 Generate a list of subsystems that homologs of a peg occur in. This is a ; separated list.
 This is also a wrapper around sims and ss, but makes everything unified


sub ss_by_homol {
 my ($self, $peg)=@_;
 return unless ($peg);
 my ($maxN, $maxP)=(50, 1e-20);

 # find the sims
 my @sims=$fig->sims($peg, $maxN, $maxP, 'fig');

 # we are only going to keep the best hit for each peg
 # in a subsystem
 my $best_ss_score; my $best_ss_id;
 foreach my $sim (@sims)
  my $simpeg=$$sim[1];
  my $simscore=$$sim[10];
  my @subsys=$fig->subsystems_for_peg($simpeg);
  foreach my $ss (@subsys)
   if (! defined $best_ss_score->{$$ss[0]}) {$best_ss_score->{$$ss[0]}=$simscore; $best_ss_id->{$$ss[0]}=$simpeg}
   elsif ($best_ss_score->{$$ss[0]} > $simscore)

 my $ssoutput=join "", (map {"$_ (".$best_ss_id->{$_}."), "} keys %$best_ss_id);

 $ssoutput =~ s/, $//;
 return $ssoutput;

=head2 tagvalue

 This will just check for tag value pairs and return either an array of values or a single ; separated list (if called as a scalar)
 e.g. $values=raelib->tagvalue($peg, "PIRSF"); print join "\n", @$values;
 Returns an empty array if no tag/value appropriate.

 Just because I use this a lot I don't want to waste rewriting it. 


sub tagvalue {
 my ($self, $peg, $tag)=@_;
 my @return;
 my @attr=$fig->feature_attributes($peg);
 foreach my $attr (@attr) { 
  my ($gottag, $val, $link)=@$attr;
  push @return, $val if ($gottag eq $tag);
 return wantarray ? @return : join "; ", @return;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3