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

Annotation of /FigKernelPackages/raelib.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : redwards 1.1 # -*- perl -*-
2 :    
3 :     =pod
4 :    
5 :     =head1
6 :    
7 :     Some routines and things that Rob uses. Please feel free to use at will and incorporate into
8 :     your own code or move them into FIG.pm or elsewhere.
9 :    
10 :     =cut
11 :    
12 :     package raelib;
13 :     use strict;
14 :     use FIG;
15 :     my $fig=new FIG;
16 :    
17 :     =head2 pirsfcorrespondance
18 :    
19 :     Generate the pirsf->fig id correspondance. This is only done once and the correspondance file is written.
20 :     This is so that we can easily go back and forth.
21 :    
22 :     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
23 :    
24 :     =cut
25 :    
26 :     sub pirsfcorrespondance {
27 :     my ($self, $from, $to)=@_;
28 :     die "File $from does not exist as called in $0" unless (-e $from);
29 :     open (IN, $from) || die "Can't open $from";
30 :     open (OUT, ">$to") || die "Can't write tot $to";
31 :     while (<IN>) {
32 :     if (/^>/) {print OUT; next}
33 :     chomp;
34 :     my $done;
35 : redwards 1.2 foreach my $peg ($fig->by_alias("uni|$_")) {
36 : redwards 1.1 print OUT $_, "\t", $peg, "\n";
37 :     $done=1;
38 :     }
39 :     unless ($done) {print OUT $_, "\t\n"}
40 :     }
41 :     close IN;
42 :     close OUT;
43 :     }
44 :    
45 :    
46 :     =head2 ss_by_id
47 :    
48 :     Generate a list of subsystems that a peg occurs in. This is a ; separated list.
49 :     This is a wrapper that removes roles and ignores essential things
50 :    
51 :     =cut
52 :    
53 :     sub ss_by_id {
54 :     my ($self, $peg)=@_;
55 :     my $ssout;
56 :     foreach my $ss (sort $fig->subsystems_for_peg($peg))
57 :     {
58 :     next if ($$ss[0] =~ /essential/i); # Ignore the Essential B-subtilis subsystems
59 :     $ssout.=$$ss[0]."; ";
60 :     }
61 :     $ssout =~ s/; $//;
62 :     return $ssout;
63 :     }
64 :    
65 : redwards 1.3 =head2 ss_by_homol
66 :    
67 :     Generate a list of subsystems that homologs of a peg occur in. This is a ; separated list.
68 :     This is also a wrapper around sims and ss, but makes everything unified
69 :    
70 :     =cut
71 :    
72 :     sub ss_by_homol {
73 :     my ($self, $peg)=@_;
74 :     return unless ($peg);
75 :     my ($maxN, $maxP)=(50, 1e-20);
76 :    
77 :     # find the sims
78 :     my @sims=$fig->sims($peg, $maxN, $maxP, 'fig');
79 :    
80 :     # we are only going to keep the best hit for each peg
81 :     # in a subsystem
82 :     my $best_ss_score; my $best_ss_id;
83 :     foreach my $sim (@sims)
84 :     {
85 :     my $simpeg=$$sim[1];
86 :     my $simscore=$$sim[10];
87 :     my @subsys=$fig->subsystems_for_peg($simpeg);
88 :     foreach my $ss (@subsys)
89 :     {
90 :     if (! defined $best_ss_score->{$$ss[0]}) {$best_ss_score->{$$ss[0]}=$simscore; $best_ss_id->{$$ss[0]}=$simpeg}
91 :     elsif ($best_ss_score->{$$ss[0]} > $simscore)
92 :     {
93 :     $best_ss_score->{$$ss[0]}=$simscore;
94 :     $best_ss_id->{$$ss[0]}=$simpeg;
95 :     }
96 :     }
97 :     }
98 :    
99 :     my $ssoutput=join "", (map {"$_ (".$best_ss_id->{$_}."), "} keys %$best_ss_id);
100 :    
101 :     $ssoutput =~ s/, $//;
102 :     return $ssoutput;
103 :     }
104 :    
105 :     =head2 tagvalue
106 :    
107 :     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)
108 :    
109 :     e.g. $values=raelib->tagvalue($peg, "PIRSF"); print join "\n", @$values;
110 :    
111 :     Returns an empty array if no tag/value appropriate.
112 :    
113 :     Just because I use this a lot I don't want to waste rewriting it.
114 :    
115 :     =cut
116 :    
117 :     sub tagvalue {
118 :     my ($self, $peg, $tag)=@_;
119 :     my @return;
120 :     my @attr=$fig->feature_attributes($peg);
121 :     foreach my $attr (@attr) {
122 :     my ($gottag, $val, $link)=@$attr;
123 :     push @return, $val if ($gottag eq $tag);
124 :     }
125 :     return wantarray ? @return : join "; ", @return;
126 :     }
127 : redwards 1.1
128 :    
129 :    
130 :    
131 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3