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

Diff of /FigKernelPackages/raelib.pm

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

revision 1.4, Fri Feb 11 21:26:25 2005 UTC revision 1.5, Sat Mar 19 17:45:47 2005 UTC
# Line 14  Line 14 
14  use FIG;  use FIG;
15  my $fig=new FIG;  my $fig=new FIG;
16    
17    =head2 new
18    
19    Just instantiate the object and return $self
20    
21    =cut
22    
23    sub new {
24     my $self=shift;
25     return $self
26    }
27    
28    
29    
30    
31  =head2 features_on_contig  =head2 features_on_contig
32    
33   Returns a reference to an array containing all the features on a contig in a genome.   Returns a reference to an array containing all the features on a contig in a genome.
# Line 165  Line 179 
179   return wantarray ? @return : join "; ", @return;   return wantarray ? @return : join "; ", @return;
180  }  }
181    
182    =head2 locations_on_contig
183    
184    Return the locations of a sequence on a contig.
185    
186    This will look for exact matches to a sequence on a contig, and return a reference to an array that has all the locations.
187    
188    my $locations=$raelib->locations_on_contig($genome, $contig, 'GATC', undef);
189    foreach my $bp (@$locations) { ... do something ... }
190    
191    first argument  : genome number
192    second argument : contig name
193    third argument  : sequence to look for
194    fourth argument : beginning position to start looking from (can be undef)
195    fifth argument  : end position to stop looking from (can be undef)
196    sixth argument : check reverse complement (0 or undef will check forward, 1 or true will check rc)
197    
198    Note, the position is calculated before the sequence is rc'd
199    
200    =cut
201    
202    sub locations_on_contig {
203     my ($self, $genome, $contig, $sequence, $from, $to, $check_reverse)=@_;
204     my $return=[];
205    
206     # get the dna sequence of the contig, and make sure it is uppercase
207     my $contig_ln=$fig->contig_ln($genome, $contig);
208     return $return unless ($contig_ln);
209     unless ($from) {$from=1}
210     unless ($to) {$to=$contig_ln}
211     if ($from > $to) {($from, $to)=($to, $from)}
212     my $dna_seq=$fig->dna_seq($genome, $contig."_".$from."_".$to);
213     $dna_seq=uc($dna_seq);
214    
215     # if we want to check the rc, we actually rc the query
216     $sequence=$fig->reverse_comp($sequence) if ($check_reverse);
217     $sequence=uc($sequence);
218    
219     # now find all the matches
220     my $posn=index($dna_seq, $sequence, 0);
221     while ($posn > -1) {
222      push @$return, $posn;
223      $posn=index($dna_seq, $sequence, $posn+1);
224     }
225     return $return;
226    }
227    
228    
229    =head2 scrolling_org_list
230    
231    This is the list from index.cgi, that I call often. It has one minor modification: the value returned is solely the organisms id and does not contain genus_species information. I abstracted this here: 1, so I could call it often, and 2, so I could edit it once.
232    
233    use like this push @$html, $raelib->scrolling_org_list($cgi, $multiple);
234    
235    multiple selections will only be set if $multiple is true
236    
237    =cut
238    
239    sub scrolling_org_list {
240     my ($self, $cgi, $multiple)=@_;
241     unless ($multiple) {$multiple=0}
242    
243     my @display = ( 'All', 'Archaea', 'Bacteria', 'Eucarya', 'Viruses', 'Environmental samples' );
244    
245     #
246     #  Canonical names must match the keywords used in the DBMS.  They are
247     #  defined in compute_genome_counts.pl
248     #
249     my %canonical = (
250            'All'                   =>  undef,
251            'Archaea'               => 'Archaea',
252            'Bacteria'              => 'Bacteria',
253            'Eucarya'               => 'Eukaryota',
254            'Viruses'               => 'Virus',
255            'Environmental samples' => 'Environmental Sample'
256         );
257    
258     my $req_dom = $cgi->param( 'domain' ) || 'All';
259     my @domains = $cgi->radio_group( -name     => 'domain',
260                                         -default  => $req_dom,
261                                         -override => 1,
262                                         -values   => [ @display ]
263                                    );
264    
265     my $n_domain = 0;
266     my %dom_num = map { ( $_, $n_domain++ ) } @display;
267     my $req_dom_num = $dom_num{ $req_dom } || 0;
268    
269     #
270     #  Viruses and Environmental samples must have completeness = All (that is
271     #  how they are in the database).  Otherwise, default is Only "complete".
272     #
273     my $req_comp = ( $req_dom_num > $dom_num{ 'Eucarya' } ) ? 'All'
274                  : $cgi->param( 'complete' ) || 'Only "complete"';
275     my @complete = $cgi->radio_group( -name     => 'complete',
276                                       -default  => $req_comp,
277                                       -override => 1,
278                                        -values   => [ 'All', 'Only "complete"' ]
279                           );
280     #
281     #  Use $fig->genomes( complete, restricted, domain ) to get org list:
282     #
283     my $complete = ( $req_comp =~ /^all$/i ) ? undef : "complete";
284    
285     my $orgs; my $label;
286     @$orgs =  $fig->genomes( $complete, undef, $canonical{ $req_dom } );
287    
288     foreach (@$orgs) {
289       my $gs = $fig->genus_species($_);
290       my $gc=scalar $fig->all_contigs($_);
291       $label->{$_} = "$gs ($_) [$gc contigs]";
292      }
293    
294     @$orgs = sort {$label->{$a} cmp $label->{$b}} @$orgs;
295    
296     my $n_genomes = @$orgs;
297    
298     return (         "<TABLE>\n",
299                      "   <TR>\n",
300                      "      <TD>",
301                      $cgi->scrolling_list( -name   => 'korgs',
302                                            -values => $orgs,
303                                            -labels => $label,
304                                            -size   => 10,
305                                          ), $cgi->br,
306                      "$n_genomes genomes shown ",
307                      $cgi->submit( 'Update List' ), $cgi->reset, $cgi->br,
308                      "      </TD>",
309                      "      <TD>",
310                      join( "<br>", "<b>Domain(s) to show:</b>", @domains), "<br>\n",
311                      join( "<br>", "<b>Completeness?</b>", @complete), "\n",
312                      "</TD>",
313                      "   </TR>\n",
314                      "</TABLE>\n",
315                      $cgi->hr
316            );
317    }
318    
319    
320    
321    
322    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3