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

View of /FigKernelPackages/raelib.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.4 - (download) (as text) (annotate)
Fri Feb 11 21:26:25 2005 UTC (14 years, 11 months ago) by redwards
Branch: MAIN
Changes since 1.3: +40 -0 lines
Additions to raelib

# -*- 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 features_on_contig

 Returns a reference to an array containing all the features on a contig in a genome.

 my $arrayref=$rae->features_on_contig($genome, $contig);

 foreach my $peg (@{$rae->features_on_contig($genome, $contig)}) {
  ... blah blah ...

 returns undef if contig is not a part of genome or there is nothing to return, otherwise returns a list of pegs
 v. experimental and guaranteed not to work!


sub features_on_contig {
 my ($self, $genome, $contig)=@_;
 # were this in FIG.pm you'd use this line:
 #my $rdbH = $self->db_handle;

 my $rdbH = $fig->db_handle;
 my $relational_db_response=$rdbH->SQL('SELECT id FROM features WHERE  (genome = \'' . $genome . '\' AND  location ~* \'' . $contig . '\')');
 # this is complicated. A reference to an array of references to arrays, and we only want the first element. 
 # simplify.
 my @results;
 foreach my $res (@$relational_db_response) {push @results, $res->[0]}
 return \@results;

=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