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

Annotation of /FigKernelPackages/PinnedRegions.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : dsouza 1.1 # -*- perl -*-
2 :     ########################################################################
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     ########################################################################
18 :    
19 :     package PinnedRegions;
20 :    
21 :     use strict;
22 :     use warnings;
23 :    
24 :     use FIG;
25 : dsouza 1.5 use FigFams;
26 : dsouza 1.1 use FIG_Config;
27 : parrello 1.9 use Tracer;
28 : dsouza 1.1
29 : parrello 1.9 use Time::HiRes qw( usleep gettimeofday tv_interval );
30 : dsouza 1.1
31 :     sub pinned_regions {
32 : paczian 1.16 my($fig, $pin_desc, $fast_color, $sims_from, $map_sz, $add_features, $extended) = @_;
33 : parrello 1.11 Trace("Pinned regions method called.") if T(3);
34 : dsouza 1.1 # Get list of pegs required by the description in $pin_desc
35 : dsouza 1.4 my $pinned_pegs = &expand_peg_list($fig, $pin_desc);
36 : parrello 1.9 Trace("Pinned pegs are " . join(", ", @$pinned_pegs) . ".") if T(3);
37 : parrello 1.11 # Filter out the pegs that don't exist.
38 : dsouza 1.1 # Get regions around pinned pegs -- boundaries, features, etc.
39 :     my $regions = &define_regions($fig, $map_sz, $pinned_pegs);
40 :     # Filter out overlapping regions caused by gene fusions, frame shifts etc. where multiple PEGs
41 :     # are pinned (by similarity or PCH) to the input PEG
42 :     $regions = &filter_regions_1($pin_desc, $regions);
43 :    
44 : dsouza 1.4 # Get information for each feature -- location, strand, function etc.
45 : paczian 1.16 my $feature_data = &feature_data($fig, $regions, $extended);
46 : dsouza 1.1
47 : dsouza 1.3 &add_functional_coupling($fig, $pin_desc, $regions, $feature_data);
48 : paczian 1.16
49 : bartels 1.8 # &add_figfams($fig, $feature_data);
50 : paczian 1.17 &add_subsystem_data($fig, $pin_desc, $feature_data, $extended);
51 : paczian 1.16
52 : parrello 1.9 Trace("Coloring pegs.") if T(3);
53 : dsouza 1.4 # Assign a set number to some PEGs through transitive closure based on similarity, from blast scores
54 : dsouza 1.1 &color_pegs($fig, $pin_desc, $pinned_pegs, $regions, $feature_data, $fast_color, $sims_from);
55 :    
56 :     # Filter out regions which have only a single PEG (the pinned one) colored.
57 : dsouza 1.14 # $regions = &filter_regions_2($pin_desc, $regions, $feature_data);
58 : dsouza 1.1
59 : bartels 1.8 if ( defined( $add_features ) ) {
60 : parrello 1.11 &add_features_to_fdata( $fig, $feature_data, $add_features, $regions );
61 : bartels 1.8 }
62 :    
63 : dsouza 1.1 # Add feature data to the regions to make the final maps
64 :     my $maps = &make_maps($fig, $regions, $feature_data);
65 : paczian 1.16
66 : dsouza 1.1 return $maps;
67 :     }
68 :    
69 :     sub expand_peg_list {
70 :     my($fig, $pin_desc) = @_;
71 :     my @pegs = ();
72 :    
73 :     # Filter for legitimate genome IDS -- should handle deleted organisms and (in NMPDR) non-NMPDR orgs
74 :     my %ok_genome_id = map {$_ => 1} $fig->genomes;
75 :    
76 : dsouza 1.5 # If the user has selected the genomes to be displayed, filter out all other genomes
77 :     if ( @{ $pin_desc->{'show_genomes'} } )
78 :     {
79 : parrello 1.11 # create new %ok_genome_id hash from intersection of selected genomes and legitimate genome IDs
80 :     %ok_genome_id = map {$_ => 1} grep {$ok_genome_id{$_}} @{ $pin_desc->{'show_genomes'} };
81 : dsouza 1.5 }
82 :    
83 : dsouza 1.1 if ( @{ $pin_desc->{'pegs'} } > 1 )
84 :     {
85 : parrello 1.11 # Input already contains list of pegs, no need for expansion
86 :     @pegs = grep {$ok_genome_id{$fig->genome_of($_)}} @{ $pin_desc->{'pegs'} };
87 : dsouza 1.1 }
88 :     else
89 :     {
90 : parrello 1.11 # Get PCH pinned pegs
91 :     my $pch_pinned_pegs = &pch_pinned_pegs($fig, $pin_desc, \%ok_genome_id);
92 : dsouza 1.1
93 : parrello 1.11 $pch_pinned_pegs = &select_pegs($fig, $pin_desc, $pin_desc->{'n_pch_pins'}, $pch_pinned_pegs);
94 : dsouza 1.1
95 : dsouza 1.14 # Get similarity pinned pegs
96 :     my $sim_pegs = &sim_pegs($fig, $pin_desc, \%ok_genome_id);
97 : dsouza 1.1
98 : parrello 1.11 # Remove PCH PEGs (if any) from similarity pinned PEG list
99 :     my %seen = map {$_ => 1} @$pch_pinned_pegs;
100 :     $sim_pegs = [grep {! $seen{$_}} @$sim_pegs];
101 :    
102 :     $sim_pegs = &select_pegs($fig, $pin_desc, $pin_desc->{'n_sims'}, $sim_pegs);
103 :    
104 :     @pegs = ();
105 :    
106 :     # Get input peg
107 :     my $peg = $pin_desc->{'pegs'}[0];
108 :     if ( $pin_desc->{'sort_by'} eq 'phylogeny' )
109 :     {
110 :     # First add input peg, then sort by phylogeny
111 :     @pegs = $fig->sort_fids_by_taxonomy($peg, @$sim_pegs, @$pch_pinned_pegs);
112 :     }
113 : dsouza 1.21 elsif ( $pin_desc->{'sort_by'} eq 'phylogenetic_distance' )
114 : parrello 1.11 {
115 :     # Sort by phylogenetic distance or organism name
116 :     my $g1 = $fig->genome_of($peg);
117 :     @pegs = map {$_->[0] }
118 :     sort {$a->[1] <=> $b->[1] or $a->[2] cmp $b->[2]}
119 :     map {[$_, $fig->crude_estimate_of_distance($g1,$fig->genome_of($_)), $fig->org_of($_)]} @$sim_pegs, @$pch_pinned_pegs;
120 :     # Add input peg at front of list
121 :     unshift @pegs, $peg;
122 :     }
123 : dsouza 1.21 elsif ( $pin_desc->{'sort_by'} eq 'similarity' )
124 :     {
125 :     # Sort by similarity to input peg (first peg in list of arguments)
126 :     @pegs = &sort_pegs_by_similarity($fig, $peg, @$sim_pegs, @$pch_pinned_pegs);
127 :     }
128 : dsouza 1.1 }
129 : dsouza 1.21
130 : dsouza 1.1 return \@pegs
131 :     }
132 :    
133 :     sub pch_pinned_pegs {
134 :     my($fig, $pin_desc, $ok_genome_id) = @_;
135 :    
136 :     my @pegs = ();
137 :    
138 :     if ( $pin_desc->{'n_pch_pins'} > 0 )
139 :     {
140 : parrello 1.11 # Get input peg
141 :     my $peg = $pin_desc->{'pegs'}[0];
142 : dsouza 1.1
143 : parrello 1.11 # Get pegs in pch pin with input peg, and filter out deleted or non-NMPDR organisms
144 :     @pegs = grep {$ok_genome_id->{$fig->genome_of($_)}}
145 :     grep {$_ ne $peg}
146 : dsouza 1.1 map {$_->[0]} $fig->in_pch_pin_with_and_evidence($peg);
147 :     }
148 :    
149 :     return \@pegs;
150 :     }
151 :    
152 :     sub sim_pegs {
153 :     my($fig, $pin_desc, $ok_genome_id) = @_;
154 :    
155 :     # Return a list of PEGS similar to the input PEG, with evalue less than or equal to
156 :     # the user defined similarity cutoff.
157 :     # If the number of sims requested is 0, return the empty list
158 :    
159 :     my $n_sims = $pin_desc->{'n_sims'};
160 :     my $sim_cutoff = $pin_desc->{'sim_cutoff'};
161 :     my @pegs = ();
162 :    
163 :     if ( $n_sims > 0 )
164 :     {
165 : parrello 1.11 my $peg = $pin_desc->{'pegs'}[0];
166 :     my %seen;
167 : paczian 1.15
168 : parrello 1.11 @pegs = grep {$ok_genome_id->{$fig->genome_of($_)}}
169 :     grep {! $seen{$_}++}
170 :     map {$_->[1]} $fig->sims($peg, 10000, $sim_cutoff, "fig");
171 : dsouza 1.1
172 : parrello 1.11 my $n_pegs = @pegs;
173 : dsouza 1.1 }
174 :    
175 :     return \@pegs;
176 :     }
177 :    
178 :     sub select_pegs {
179 :     my($fig, $pin_desc, $n_pegs, $pegs) = @_;
180 :    
181 :     if ( $n_pegs == 0 )
182 :     {
183 : parrello 1.11 return [];
184 : dsouza 1.1 }
185 :    
186 : dsouza 1.3 if ( $pin_desc->{'collapse_close_genomes'} == 1 )
187 : dsouza 1.1 {
188 : parrello 1.11 # The ordering of the PEGs done here is in order to =select= the correct set, the ordering for the
189 :     # display is done later.
190 : dsouza 1.2
191 : parrello 1.11 # To collapse the PEG list, we want to:
192 :     # a. Return at most $n_pegs PEGs,
193 :     # b. include a representative PEG from every genus, subject to a, and
194 :     # c. include a representative PEG from each genus-species, subject to a and b.
195 :     # Individual strains will get represented by a single PEG, chosen arbitrarily.
196 :    
197 :     # The PEG selection is defined by the order of the PEGs. This could be done beter.
198 :    
199 :     my(%seen, @unique_genus, @unique_genus_species);
200 :    
201 :     foreach my $peg ( @$pegs )
202 :     {
203 :     my $org = $fig->org_of($peg);
204 :     # 'org_of' returns undef for deleted PEGs, these need to be omitted from the peg list returned
205 :    
206 :     if ( $org )
207 :     {
208 :     # Use only genus+species to drop strain information
209 :     my($genus, $species) = split(/\s+/, $org);
210 :     my $gs = "$genus $species";
211 :    
212 :     if ( not $seen{$genus}++ )
213 :     {
214 :     # First PEG from this genus, add it to @unique_genus.
215 :     # Mark the genus+species as seen.
216 :     # A subsequent PEG with the same genus and species will be dropped.
217 :     # A subsequent PEG with the same genus but different species will be added to @unique_genus_species.
218 :     $seen{$gs}++;
219 :     push @unique_genus, $peg;
220 :     }
221 :     elsif ( not $seen{$gs}++ )
222 :     {
223 :     # First PEG from this genus+species, add it to @unique_genus_species.
224 :     push @unique_genus_species, $peg;
225 :     }
226 :     }
227 :     }
228 : dsouza 1.1
229 : parrello 1.11 # Keep the unique_genus PEGS at the top, followed by the unique_genus_species
230 :     $pegs = [@unique_genus, @unique_genus_species];
231 : dsouza 1.1 }
232 :    
233 :     # Truncate list if necessary
234 : dsouza 1.3 if ( $n_pegs < @$pegs )
235 : dsouza 1.1 {
236 : parrello 1.11 $#{ $pegs } = $n_pegs - 1;
237 : dsouza 1.1 }
238 :    
239 :     return $pegs;
240 :     }
241 :    
242 : dsouza 1.21 sub sort_pegs_by_similarity {
243 :     my($fig, $input_peg, @other_pegs) = @_;
244 :    
245 :     # Set blast environment variables
246 :     $ENV{"BLASTMAT"} ||= "$FIG_Config::blastmat";
247 :     if ($ENV{"PATH"} !~ /fig\/bin/) { $ENV{"PATH"} = "$FIG_Config::bin:" . $ENV{"PATH"}; }
248 :    
249 :     # Get amino acid sequences
250 :     my $sequences = &get_peg_sequences($fig, [$input_peg, @other_pegs]);
251 :    
252 :     # Write the input peg sequence to a fasta file
253 :     my $input_seq = {$input_peg => $sequences->{$input_peg}};
254 :     my $input_seq_file = "$FIG_Config::temp/input_seq.$$.tmp.fasta";
255 :     &write_seqs_to_file($input_seq, $input_seq_file);
256 :    
257 :     # Write the other peg sequences to a fasta file
258 :     delete $sequences->{$input_peg};
259 :     my $other_seq_file = "$FIG_Config::temp/other_seq.$$.tmp.fasta";
260 :     &write_seqs_to_file($sequences, $other_seq_file);
261 :    
262 :     # Run formatdb
263 :     &formatdb_file($fig, $other_seq_file);
264 :    
265 :     # BLAST input peg sequence against other peg sequences
266 :     # set high evalue cutoff so all hits get reported
267 :     my $cutoff = 10;
268 :     my $hits = &blast_files($fig, $input_seq_file, $other_seq_file, $cutoff);
269 :    
270 :     my @sorted = ($input_peg);
271 :     foreach my $hit ( @$hits )
272 :     {
273 :     # BLAST output is already sorted by similarity
274 :     my($peg2) = (split(/\s+/, $hit))[1];
275 :     push @sorted, $peg2;
276 :     }
277 :    
278 :     return @sorted;
279 :     }
280 :    
281 : dsouza 1.1 sub filter_regions_1 {
282 :     my($pin_desc, $regions) = @_;
283 :     my $new_regions;
284 :    
285 :     # Filter out some overlapping regions caused by gene fusions, frame shifts etc. where multiple PEGs
286 :     # are pinned (by similarity or PCH) to the input PEG
287 :     # Note that all overlaps are NOT eliminated
288 :    
289 :     if ( @{ $pin_desc->{'pegs'} } == 1 )
290 :     {
291 : parrello 1.11 # Input pin description is for a single input peg
292 :     my %seen;
293 :    
294 :     foreach my $region ( @$regions )
295 :     {
296 :     my $pinned_peg = $region->{'pinned_peg'};
297 :    
298 :     # If the pinned peg from a region has already been 'seen', don't
299 :     # add the region into the @$new_regions array
300 :    
301 :     if ( not $seen{$pinned_peg} )
302 :     {
303 :     push @$new_regions, $region;
304 :    
305 :     my $fids = $region->{'features'};
306 :     foreach my $fid ( @$fids )
307 :     {
308 :     $seen{$fid} = 1;
309 :     }
310 :     }
311 :     }
312 : dsouza 1.1 }
313 :     else
314 :     {
315 : parrello 1.11 # input PEGs is a list -- keep all of them
316 :     $new_regions = $regions;
317 : dsouza 1.1 }
318 :    
319 :     return $new_regions;
320 :     }
321 :    
322 :     sub filter_regions_2 {
323 :     my($pin_desc, $regions, $feature_data) = @_;
324 :     my $new_regions;
325 :    
326 :     if ( @{ $pin_desc->{'pegs'} } == 1 )
327 :     {
328 : parrello 1.11 # Input is single peg
329 :     my $input_peg = $pin_desc->{'pegs'}[0];
330 : dsouza 1.1
331 : parrello 1.11 foreach my $region ( @$regions )
332 :     {
333 :     my $fids = $region->{'features'};
334 :     my $n_in_sets = grep {$feature_data->{$_}{'set_number'}} @$fids;
335 :    
336 :     if ( $n_in_sets > 1 or $region->{'pinned_peg'} eq $input_peg )
337 :     {
338 :     # Regions should be displayed only if:
339 :     # a. more than one PEG is in a 'colored set' OR
340 :     # b. the pinned PEG is the input PEG
341 :     push @$new_regions, $region;
342 :     }
343 :     }
344 : dsouza 1.1 }
345 :     else
346 :     {
347 : parrello 1.11 # Input is a list of pegs -- keep all of the regions
348 :     $new_regions = $regions
349 : dsouza 1.1 }
350 :    
351 :     return $new_regions;
352 :     }
353 :    
354 :     sub make_maps {
355 :     my($fig, $regions, $feature_data) = @_;
356 :    
357 :     foreach my $region ( @$regions )
358 :     {
359 : parrello 1.11 my $features = [];
360 :     my $fids = $region->{'features'};
361 : dsouza 1.1
362 : parrello 1.11 foreach my $fid ( @$fids )
363 :     {
364 :     push @$features, $feature_data->{$fid};
365 :     # if ( !( $fid =~ /fig/ ) ) {
366 :     # print STDERR $fid." FIDMAKEMAPS\n";
367 :     # }
368 :     }
369 : dsouza 1.1
370 : parrello 1.11 $region->{'features'} = $features;
371 : dsouza 1.1 }
372 :    
373 :     return $regions;
374 :     }
375 :    
376 :     sub define_regions {
377 :     my($fig, $map_sz, $pinned_pegs) = @_;
378 :    
379 :     # Define the 'region' around the pinned peg, get features, and store some region information
380 :     my $regions = [];
381 :     my $half_map_sz = int($map_sz/2);
382 :    
383 :     foreach my $peg ( @$pinned_pegs )
384 :     {
385 : parrello 1.11 my $genome = $fig->genome_of($peg);
386 :     my $loc = $fig->feature_location($peg);
387 :     # We only proceed if a location was found. Failure to find a location indicates
388 :     # that the feature is deleted.
389 :     if ($loc) {
390 :     my($contig, $beg, $end) = $fig->boundaries_of($loc);
391 :    
392 :     my $region_mid = int(($beg + $end)/2);
393 :     my $region_beg = $region_mid - $half_map_sz;
394 :     my $region_end = $region_mid + $half_map_sz;
395 :    
396 :     my($fids) = $fig->genes_in_region($genome, $contig, $region_beg, $region_end);
397 :    
398 :     my $region = {};
399 :     $region->{'genome_id'} = $fig->genome_of($peg);
400 :     $region->{'org_name'} = $fig->genus_species($region->{'genome_id'});
401 :     $region->{'contig'} = $contig;
402 :     $region->{'beg'} = $region_beg;
403 :     $region->{'mid'} = $region_mid;
404 :     $region->{'end'} = $region_end;
405 :     $region->{'features'} = $fids;
406 :     $region->{'pinned_peg_strand'} = ($beg <= $end)? '+' : '-';
407 :     $region->{'pinned_peg'} = $peg;
408 :    
409 :     push @$regions, $region;
410 :     }
411 : dsouza 1.1 }
412 :    
413 :     return $regions;
414 :     }
415 :    
416 : bartels 1.8 sub add_features_to_fdata {
417 :     my ( $fig, $feature_data, $add_features, $regions ) = @_;
418 :    
419 :     foreach my $region ( @$regions ) {
420 : parrello 1.11 my $new_feats = $add_features->{ $region->{ 'genome_id' } };
421 :     foreach my $nf ( @$new_feats ) {
422 :     if ( $nf->{ 'contig' } eq $region->{ 'contig' } &&
423 :     $nf->{ 'start' } < $region->{ 'end' } &&
424 :     $nf->{ 'start' } > $region->{ 'beg' } ) {
425 :     $feature_data->{ $nf->{ 'name' } } = &new_feature_entry( $fig, $nf->{ 'name' }, $region->{ 'mid' }, $region->{ 'contig' }, $nf->{ 'start' }, $nf->{ 'stop' }, $nf->{ 'type' }, $nf->{ 'function' } );
426 :     push @{ $region->{ 'features' } }, $nf->{ 'name' };
427 :     }
428 :     }
429 : bartels 1.8 }
430 :     }
431 :    
432 :     sub new_feature_entry {
433 :     my ( $fig, $fid, $region_mid, $contig, $beg, $end, $type, $func ) = @_;
434 :    
435 :     if ( !defined( $type ) ) {
436 : parrello 1.11 $type = 'unknown';
437 : bartels 1.8 }
438 :    
439 :     if ( !defined( $func ) ) {
440 : parrello 1.11 $func = '';
441 : bartels 1.8 }
442 :    
443 :     my($left, $right) = sort {$a <=> $b} ($beg, $end);
444 :     my $size = $right - $left + 1;
445 :     my $strand = ($beg <= $end)? '+' : '-';
446 :     my $offset = int(($left + $right)/2) - $region_mid;
447 :     my $offset_beg = $left - $region_mid;
448 :     my $offset_end = $right - $region_mid;
449 :    
450 :     return {
451 : parrello 1.11 'fid' => $fid,
452 :     'type' => $type,
453 :     'contig' => $contig,
454 :     'beg' => $beg,
455 :     'end' => $end,
456 :     'size' => $size,
457 :     'strand' => $strand,
458 :     'offset' => $offset,
459 :     'offset_beg' => $offset_beg,
460 :     'offset_end' => $offset_end,
461 :     'function' => $func,
462 : bartels 1.8 };
463 :     }
464 :    
465 : dsouza 1.1 sub feature_data {
466 : paczian 1.16 my($fig, $regions, $extended) = @_;
467 : dsouza 1.1 my %feature_data;
468 :    
469 :     foreach my $region ( @$regions )
470 :     {
471 : parrello 1.11 my $region_mid = $region->{'mid'};
472 :     my $fids = $region->{'features'};
473 : dsouza 1.1
474 : parrello 1.11 foreach my $fid ( @$fids )
475 :     {
476 :     # Get feature data if this feature has not been seen before, this avoids repeating
477 :     # this step when pegs occur in multiple regions
478 :     if ( not exists $feature_data{$fid} )
479 :     {
480 : paczian 1.16 $feature_data{$fid} = &feature_entry($fig, $fid, $region_mid, $extended);
481 : parrello 1.11 }
482 :     }
483 : dsouza 1.1 }
484 :    
485 : paczian 1.16 if ($extended) {
486 :     # get the evidence codes
487 :     my @all_fids = keys(%feature_data);
488 :     my @codes = grep { $_->[1] =~ /^evidence_code/i } $fig->get_attributes(\@all_fids, 'evidence_code');
489 :     my $pretty_codes = {};
490 :     foreach my $code (@codes) {
491 :     my $pretty_code = $code->[2];
492 :     if ($pretty_code =~ /;/) {
493 :     my ($cd, $ss) = split(";", $code->[2]);
494 :     $pretty_code = $cd;
495 :     }
496 :     $pretty_code =~ s/lit\((\d+)\)/lit\(<a href='http:\/\/www\.ncbi\.nlm\.nih\.gov\/sites\/entrez\?cmd=Retrieve&db=PubMed&list_uids=$1&dopt=AbstractPlus' target=_blank>$1<\/a>\)/;
497 :     push(@{$pretty_codes->{$code->[0]}}, $pretty_code);
498 :     }
499 :     foreach my $entry (keys(%$pretty_codes)) {
500 :     $feature_data{$entry}{'evcodes'} = join(", ", @{$pretty_codes->{$entry}});
501 :     }
502 :     }
503 :    
504 : dsouza 1.1 return \%feature_data;
505 :     }
506 :    
507 :     sub feature_entry {
508 : paczian 1.16 my($fig, $fid, $region_mid, $extended) = @_;
509 : dsouza 1.1
510 :     my $type = $fig->ftype($fid);
511 :     my $loc = $fig->feature_location($fid);
512 :     my($contig, $beg, $end) = $fig->boundaries_of($loc);
513 :     my($left, $right) = sort {$a <=> $b} ($beg, $end);
514 : dsouza 1.3 my $size = $right - $left + 1;
515 : dsouza 1.1 my $strand = ($beg <= $end)? '+' : '-';
516 :     my $offset = int(($left + $right)/2) - $region_mid;
517 :     my $offset_beg = $left - $region_mid;
518 :     my $offset_end = $right - $region_mid;
519 :     my $func = scalar $fig->function_of($fid) || '';
520 :    
521 : paczian 1.16 my $retval = { 'fid' => $fid,
522 :     'type' => $type,
523 :     'contig' => $contig,
524 :     'beg' => $beg,
525 :     'end' => $end,
526 :     'size' => $size,
527 :     'strand' => $strand,
528 :     'offset' => $offset,
529 :     'offset_beg' => $offset_beg,
530 :     'offset_end' => $offset_end,
531 :     'function' => $func };
532 :     if ($extended) {
533 :     my $aliases = $fig->feature_aliases($fid) || '';
534 :     $retval->{aliases} = $aliases;
535 :     }
536 :    
537 :     return $retval;
538 : dsouza 1.1 }
539 :    
540 : dsouza 1.3 sub add_functional_coupling {
541 :     my($fig, $pin_desc, $regions, $feature_data) = @_;
542 :    
543 :     my $fc_cutoff = defined($pin_desc->{'fc_cutoff'})? $pin_desc->{'fc_cutoff'} : 4;
544 :    
545 :     foreach my $region ( @$regions )
546 :     {
547 : parrello 1.11 my $pin = $region->{'pinned_peg'};
548 :     my @pegs = grep {$feature_data->{$_}{'type'} eq 'peg'} @{ $region->{'features'} };
549 : dsouza 1.3
550 : parrello 1.11 foreach my $couple ( $fig->coupled_to_batch(@pegs) )
551 :     {
552 :     my($peg1, $peg2, $sc) = @$couple;
553 :    
554 :     if ( $peg1 eq $pin and $sc >= $fc_cutoff )
555 :     {
556 :     $feature_data->{$peg2}{'fc_score'} = $sc;
557 : paczian 1.15 $feature_data->{$peg2}{'fc_pin'} = $peg1;
558 : parrello 1.11 }
559 :     }
560 : dsouza 1.3 }
561 :     }
562 :    
563 : dsouza 1.5 sub add_figfams {
564 :     my($fig, $feature_data) = @_;
565 :    
566 : dsouza 1.6 # Get FigFams directory from config file
567 : olson 1.10 my $figfam_dir = $fig->get_figfams_data();
568 : dsouza 1.5
569 : dsouza 1.6 # Check if FigFams directory is defined and exists on current machine
570 :     if ( defined($figfam_dir) and (-d $figfam_dir) )
571 : dsouza 1.5 {
572 : parrello 1.11 # Get all PEG IDs
573 :     my @pegs = grep {$feature_data->{$_}{'type'} eq 'peg'} keys %$feature_data;
574 :     # Get $figfams object
575 :     my $figfams = new FigFams($fig, $figfam_dir);
576 :     # Get FigFam family ID for @pegs
577 :     my $figfam = $figfams->families_containing_peg_bulk(\@pegs);
578 :     # Get hash of FigFam ID to family function
579 :     my $family_function = $figfams->family_functions();
580 :    
581 :     # Some FigFams (the ones that are not subsystem related) have the FigFam ID in the family function.
582 :     # This results in the popup displaying the ID twice, so one should be removed.
583 :    
584 :     my %figfam_text;
585 :     foreach my $fid ( keys %$feature_data )
586 :     {
587 :     if ( $figfam->{$fid} )
588 :     {
589 :     my $figfam_id = $figfam->{$fid};
590 :     if ( ! exists $figfam_text{$figfam_id} ) {
591 :     if ( $family_function->{$figfam_id} =~ /^FIG\d+/ ) {
592 :     $figfam_text{$figfam_id} = $family_function->{$figfam_id};
593 :     } else {
594 :     $figfam_text{$figfam_id} = $figfam_id . ': ' . $family_function->{$figfam_id};
595 :     }
596 :     }
597 : dsouza 1.7
598 : parrello 1.11 # Add FigFam information to hash -- to go into the popup text
599 :     $feature_data->{$fid}{'figfam'} = $figfam_text{$figfam_id};
600 :     }
601 :     }
602 : dsouza 1.5 }
603 :     }
604 :    
605 : dsouza 1.3 sub add_subsystem_data {
606 : paczian 1.17 my($fig, $pin_desc, $feature_data, $extended) = @_;
607 : dsouza 1.14
608 :     # Get subsystem_information for =all= pegs
609 :    
610 : paczian 1.16 my @fids = keys(%$feature_data);
611 :     my %ssdata = $fig->subsystems_for_pegs_complete(\@fids);
612 :     my @subsystems = ();
613 :     foreach my $p (keys(%ssdata)) {
614 :     foreach my $entry (@{$ssdata{$p}}) {
615 :     push(@subsystems, [ $entry->[0], $entry->[1], $entry->[2], $p ]);
616 :     }
617 :     }
618 : paczian 1.17 unless ($extended) {
619 : paczian 1.19 @subsystems = grep { $fig->usable_subsystem($_->[0]) } @subsystems;
620 : paczian 1.18 @subsystems = grep { $fig->is_exchangable_subsystem($_->[0]) } @subsystems;
621 : paczian 1.17 }
622 : paczian 1.16
623 : dsouza 1.14 my %peg_to_ss;
624 : paczian 1.16 foreach my $rec ( @subsystems ) {
625 :     my($ss_name, $role, $variant, $fid) = @$rec;
626 :     $ss_name =~ s/_/ /g;
627 :    
628 :     if ( $variant eq '0' ) {
629 :     # no subsystem
630 : paczian 1.19 if ($extended) {
631 :     my $ss_text = "$ss_name (not yet classified for this organism)";
632 : paczian 1.20 $peg_to_ss{$fid}{$ss_name} = $ss_text;
633 : paczian 1.19 }
634 : paczian 1.16 } elsif ( $variant eq '-1' or $variant eq '*-1' ) {
635 :     # subsystem not functional in this organism
636 :     my $ss_text = "$ss_name (classified 'not active' in this organism)";
637 : paczian 1.20 $peg_to_ss{$fid}{$ss_name} = $ss_text;
638 : paczian 1.16 } else {
639 :     $peg_to_ss{$fid}{$ss_name} = 1;
640 : dsouza 1.14 }
641 :     }
642 :    
643 : dsouza 1.3 # Count number of occurences of each subsystem
644 :     my %ss_count;
645 : dsouza 1.14 foreach my $fid ( keys %peg_to_ss )
646 : dsouza 1.3 {
647 : dsouza 1.14 foreach my $ss ( keys %{ $peg_to_ss{$fid} } )
648 :     {
649 :     $ss_count{$ss}++;
650 :     }
651 : dsouza 1.3 }
652 :    
653 :     # Sort subsystems based on count and create hash with unique index for each subsystem where
654 :     # lower indices correspond to higher number of occurences of the subsystem.
655 :     my %ss_index;
656 :     my $index = 0;
657 :     foreach my $ss ( sort {$ss_count{$b} <=> $ss_count{$a} or $a cmp $b} keys %ss_count )
658 :     {
659 : parrello 1.11 $ss_index{$ss} = ++$index;
660 : dsouza 1.3 }
661 :    
662 :     # Add subsystem information for pegs in subsystems
663 :     foreach my $fid ( keys %peg_to_ss )
664 :     {
665 : paczian 1.20 my @subsystems;
666 :     foreach my $key (keys(%{$peg_to_ss{$fid}})) {
667 :     if ($peg_to_ss{$fid}{$key} ne "1") {
668 :     push(@subsystems, [ $peg_to_ss{$fid}{$key}, $ss_index{$key} ]);
669 :     } else {
670 :     push(@subsystems, [ $key, $ss_index{$key} ]);
671 :     }
672 :     }
673 : parrello 1.11
674 :     if ( @subsystems )
675 :     {
676 : paczian 1.20 $feature_data->{$fid}{'subsystems'} = [sort {$a->[1] <=> $b->[1]} @subsystems];
677 : parrello 1.11 }
678 : dsouza 1.3 }
679 :     }
680 :    
681 : dsouza 1.1 sub color_pegs {
682 :     my($fig, $pin_desc, $pinned_pegs, $regions, $feature_data, $fast_color, $sims_from) = @_;
683 :    
684 :     # Run blastp and get connected pegs
685 :     my $blast_hit = {};
686 :     my $color_sim_cutoff = $pin_desc->{'color_sim_cutoff'};
687 :    
688 :     if ( $sims_from eq 'blast' )
689 :     {
690 : parrello 1.11 $blast_hit = &blast_hits($fig, $regions, $feature_data, $fast_color, $color_sim_cutoff);
691 : dsouza 1.1 }
692 :     else
693 :     {
694 : parrello 1.11 $blast_hit = &blast_hits_from_sims($fig, $regions, $feature_data, $fast_color, $color_sim_cutoff);
695 : dsouza 1.1 }
696 :    
697 :     # Assign set numbers to pegs based on blast scores
698 :     my $color_sets = &partition_pegs($blast_hit);
699 :    
700 :     # Sort peg sets to that a) larger sets have smaller set numbers, and
701 :     # b) sets closer to the pinned peg have smaller set numbers
702 : dsouza 1.4 $color_sets = &sort_color_sets($pin_desc, $pinned_pegs, $color_sets, $feature_data);
703 : dsouza 1.1
704 :     # Add color set number into $feature_data
705 :     for (my $i = 0; $i < @$color_sets; $i++)
706 :     {
707 : parrello 1.11 # Use an index that starts at 1 (matches with coloring index)
708 :     my $n = $i + 1;
709 :     foreach my $peg ( @{ $color_sets->[$i] } )
710 :     {
711 :     $feature_data->{$peg}{'set_number'} = $n;
712 :    
713 :     # If this is the pinned set, set the 'color' to 'red'
714 :     if ( $n == 1 )
715 :     {
716 :     $feature_data->{$peg}{'color'} = 'red';
717 :     }
718 :     }
719 : dsouza 1.1 }
720 :     }
721 :    
722 :     sub sort_color_sets {
723 :     my($pin_desc, $pinned_pegs, $color_sets, $feature_data) = @_;
724 :    
725 : dsouza 1.3 # Find the color set containing the set of pinned pegs, i.e. the set containing the input peg.
726 :     # If the input peg is found (or if input is a list of pegs, returned value is the array index for the
727 :     # set.
728 :     # If the input peg is not found, the returned value is an reference to an array containing the input peg.
729 :     my $set = &pinned_set($pin_desc, $pinned_pegs, $color_sets);
730 : dsouza 1.1
731 : dsouza 1.3 my $pinned_color_set;
732 :     if ( $set =~ /^\d+$/ )
733 :     {
734 : parrello 1.11 # Splice out the color set containing the input peg
735 :     ($pinned_color_set) = splice(@$color_sets,$set,1);
736 : dsouza 1.3 }
737 :     else
738 :     {
739 : parrello 1.11 $pinned_color_set = $set;
740 : dsouza 1.3 }
741 : dsouza 1.1
742 : dsouza 1.3 # Add offset (summed distance from
743 :     my @color_sets = map {[$_, &offset($_, $feature_data)]} @$color_sets;
744 : dsouza 1.1 # Sort the remaining color sets based on:
745 :     # a. size (number of pegs) and
746 :     # b. offset from mid-point of region
747 :     @$color_sets = map {$_->[0]}
748 :     sort {@{$b->[0]} <=> @{$a->[0]} or $a->[1] <=> $b->[1]}
749 : dsouza 1.3 # sort {$a->[1] <=> $b->[1] or @{$b->[0]} <=> @{$a->[0]}}
750 : dsouza 1.1 map {[$_, &offset($_, $feature_data)]} @$color_sets;
751 :    
752 :     # Add the set of pinned pegs at the front of the returned list so that it gets colored red
753 :     return [$pinned_color_set, @$color_sets];
754 :     }
755 :    
756 : dsouza 1.3 sub pinned_set {
757 : dsouza 1.1 my($pin_desc, $pinned_pegs, $color_sets) = @_;
758 :    
759 : dsouza 1.3 # Returns an integer if the input is a peg-list or if the input peg is in a set.
760 :     # Returns the input peg (as an array reference) if the input peg is not in a set.
761 :    
762 : dsouza 1.1 if ( @{ $pin_desc->{'pegs'} } == 1 )
763 :     {
764 : parrello 1.11 # Get input peg if it exists -- the set containing this peg should be colored red
765 :     my $peg = $pin_desc->{'pegs'}[0];
766 : dsouza 1.1
767 : parrello 1.11 # Iterate through the color sets until you find the set containing the input peg
768 :     for (my $i = 0; $i < @$color_sets; $i++)
769 :     {
770 :     foreach my $peg2 ( @{ $color_sets->[$i] } )
771 :     {
772 :     if ( $peg2 eq $peg )
773 :     {
774 :     # Return the set index
775 :     return $i;
776 :     }
777 :     }
778 :     }
779 : dsouza 1.1
780 : parrello 1.11 # The input peg may not be in a set if there is only one region or the coloring cutoff is very stringent.
781 :     return [$peg];
782 : dsouza 1.1 }
783 :     else
784 :     {
785 : parrello 1.11 # Input is a peg-list, which may be split into multiple sets -- the largest will be called the
786 :     # "pinned" set.
787 : parrello 1.12 my $i;
788 :     my $max_count = 0;
789 : parrello 1.11 my %pinned = map {$_ => 1} @$pinned_pegs;
790 :    
791 :     for (my $j = 0; $j < @$color_sets; $j++)
792 :     {
793 :     # count how many pinned pegs are found in each set
794 : parrello 1.12 my $count = scalar(grep {$pinned{$_}} @{ $color_sets->[$j] }) || 0;
795 : parrello 1.11
796 :     if ( $max_count < $count )
797 :     {
798 :     # Keep track of the set having the largest number of pinned pegs
799 :     $max_count = $count;
800 :     $i = $j;
801 :     }
802 :     }
803 : dsouza 1.1
804 : parrello 1.11 return $i;
805 : dsouza 1.1 }
806 :     }
807 :    
808 :     sub offset {
809 :     my($set, $feature_data) = @_;
810 :    
811 :     my $offset;
812 :     foreach my $peg ( @$set )
813 :     {
814 : parrello 1.11 $offset += abs($feature_data->{$peg}{'offset'});
815 : dsouza 1.1 }
816 : dsouza 1.3
817 :     return sprintf("%.2f", $offset/@$set);
818 : dsouza 1.1 }
819 :    
820 :     sub partition_pegs {
821 :     my($blast_hit) = @_;
822 :    
823 :     my %seen;
824 :     my $sets = [];
825 :    
826 :     # Iterate through the pegs with blast hits in arbitrary order
827 :     foreach my $peg1 ( keys %$blast_hit )
828 :     {
829 : parrello 1.11 # If it has not been 'seen' (and placed in a set) use it as the seed for a set
830 :     if ( not $seen{$peg1} )
831 :     {
832 :     my $set = [$peg1];
833 :    
834 :     # Mark $peg1 as seen
835 :     $seen{$peg1} = 1;
836 :    
837 :     # Grow set through transitive closure -- note that @$set keeps growing
838 :     for (my $i = 0; $i < @$set; $i++)
839 :     {
840 :     $peg1 = $set->[$i];
841 :    
842 :     # Iterate through blast hits
843 :     foreach my $peg2 ( keys %{ $blast_hit->{$peg1} } )
844 :     {
845 :     # If $peg2 has not been seen, put it in the set, and mark it as seen
846 :     if ( not exists $seen{$peg2} )
847 :     {
848 :     push @$set, $peg2;
849 :     $seen{$peg2} = 1;
850 :     }
851 :     }
852 :     }
853 :    
854 :     # Add the new set to the set of sets
855 :     push @$sets, $set;
856 :     }
857 : dsouza 1.1 }
858 :    
859 :     return $sets;
860 :     }
861 :    
862 :     sub blast_hits {
863 :     my($fig, $regions, $feature_data, $fast_color, $color_sim_cutoff) = @_;
864 :    
865 :     # Set blast environment variables
866 :     $ENV{"BLASTMAT"} ||= "$FIG_Config::blastmat";
867 :     if ($ENV{"PATH"} !~ /fig\/bin/) { $ENV{"PATH"} = "$FIG_Config::bin:" . $ENV{"PATH"}; }
868 :    
869 :     # Get amino acid sequences
870 : dsouza 1.21 my @pegs = grep {$feature_data->{$_}{'type'} eq 'peg'} keys %$feature_data;
871 :     my $sequences = &get_peg_sequences($fig, \@pegs);
872 : dsouza 1.1
873 :     # Write the entire set of sequences to a fasta file
874 :     my $all_seqs_file = "$FIG_Config::temp/all_seqs.$$.tmp.fasta";
875 :     &write_seqs_to_file($sequences, $all_seqs_file);
876 :    
877 :     # Run formatdb
878 :     &formatdb_file($fig, $all_seqs_file);
879 :    
880 :     # If $fast_color == 0, the complete blast of all vs. all sequences is performed
881 :     # Otherwise, instead of all vs. all, the sequences from a single pinned peg region
882 :     # is blasted against all sequences. If any of the hits are better than a given cutoff
883 :     # ($cutoff_2), the pegs hit are deemed to be 'done', i.e. it is assumed that blasting this
884 :     # peg will not yield additional information for forming the peg sets. These 'done' pegs
885 :     # are then omitted from the blast when the sequences from the region they belong to
886 :     # is blasted.
887 :     my %blast_hit;
888 :     if ( $fast_color )
889 :     {
890 : parrello 1.11 my $cutoff_2 = $color_sim_cutoff * 1e-20;
891 :     my %done_with;
892 : dsouza 1.1
893 : parrello 1.11 foreach my $region ( @$regions )
894 :     {
895 :     # Iterate through each region
896 :     my $fids = $region->{'features'};
897 :    
898 :     # Build up a hash of peg sequences which are not 'done_with'
899 :     my %region_seqs;
900 :     foreach my $peg ( grep {$feature_data->{$_}{'type'} eq 'peg'} @$fids )
901 :     {
902 :     if ( $sequences->{$peg} and not $done_with{$peg} )
903 :     {
904 :     $region_seqs{$peg} = $sequences->{$peg};
905 :     }
906 :     }
907 :    
908 :     if ( scalar keys %region_seqs )
909 :     {
910 :     # Write the region sequences to a file
911 :     my $region_seqs_file = "$FIG_Config::temp/region_seqs.$$.tmp.fasta";
912 :     &write_seqs_to_file(\%region_seqs, $region_seqs_file);
913 :    
914 :     # BLAST the region sequences against all other sequences
915 :     my $hits = &blast_files($fig, $region_seqs_file, $all_seqs_file, $color_sim_cutoff);
916 :    
917 :     # Build up hash of blast hits
918 :     foreach my $hit ( @$hits )
919 :     {
920 :     my($peg1, $peg2, $sc) = (split(/\s+/, $hit))[0,1,10];
921 :    
922 :     if ( $peg1 ne $peg2 )
923 :     {
924 :     $blast_hit{$peg1}{$peg2} = 1;
925 :     $blast_hit{$peg2}{$peg1} = 1;
926 :    
927 :     # If the blast score is less than the chosen cutoff, mark $peg2 as 'done_with' so
928 :     # that it will not be blasted with it's region sequences
929 :     if ( $sc <= $cutoff_2 )
930 :     {
931 :     $done_with{$peg2} = 1;
932 :     }
933 :     }
934 :     }
935 :     }
936 :     }
937 : dsouza 1.1 }
938 :     else
939 :     {
940 : parrello 1.11 # BLAST sequence file against itself
941 :     my $hits = &blast_files($fig, $all_seqs_file, $all_seqs_file, $color_sim_cutoff);
942 : dsouza 1.1
943 : parrello 1.11 # Build up hash of blast hits
944 :     foreach my $hit ( @$hits )
945 :     {
946 :     my($peg1, $peg2, $sc) = (split(/\s+/, $hit))[0,1,10];
947 :    
948 :     if ( $peg1 ne $peg2 )
949 :     {
950 :     $blast_hit{$peg1}{$peg2} = 1;
951 :     $blast_hit{$peg2}{$peg1} = 1;
952 :     }
953 :     }
954 : dsouza 1.1 }
955 :    
956 :     return \%blast_hit;
957 :     }
958 :    
959 :     sub blast_hits_from_sims {
960 :     my($fig, $regions, $feature_data, $fast_color, $color_sim_cutoff) = @_;
961 :    
962 :     my %blast_hit;
963 :    
964 :     my $maxN = 2000;
965 :     my $maxP = $color_sim_cutoff;
966 :     my $select = 'fig';
967 :     my $max_expand = '';
968 :     my $filters = '';
969 :    
970 :     # Create a hash of all pegs
971 :     my %region_peg = map {$_ => 1} grep {$feature_data->{$_}{'type'} eq 'peg'} keys %$feature_data;
972 :    
973 :     if ( $fast_color == 1 )
974 :     {
975 : parrello 1.11 my $cutoff_2 = $color_sim_cutoff * 1e-20;
976 :     my %done_with;
977 : dsouza 1.1
978 : parrello 1.11 # Iterate through each peg
979 :     foreach my $peg1 ( keys %region_peg )
980 :     {
981 :     # Skip the 'done_with' pegs
982 :     next if ($done_with{$peg1});
983 :    
984 :     my @sims = $fig->sims($peg1, $maxN, $maxP, $select, $max_expand, $filters);
985 :    
986 :     foreach my $sim ( grep {$region_peg{$_->[1]} and $_->[1] ne $peg1} @sims )
987 :     {
988 :     my($peg2, $sc) = @$sim[1,10];
989 :    
990 :     $blast_hit{$peg1}{$peg2} = 1;
991 :     $blast_hit{$peg2}{$peg1} = 1;
992 :    
993 :     # If the blast score is less than the chosen cutoff, mark $peg2 as 'done_with' so
994 :     # that it will not be blasted with it's region sequences
995 :     if ( $sc <= $cutoff_2 )
996 :     {
997 :     $done_with{$peg2} = 1;
998 :     }
999 :     }
1000 :     }
1001 : dsouza 1.1 }
1002 :     else
1003 :     {
1004 : parrello 1.11 # Iterate through each peg
1005 :     foreach my $peg1 ( keys %region_peg )
1006 :     {
1007 :     my @sims = $fig->sims($peg1, $maxN, $maxP, $select, $max_expand, $filters);
1008 :    
1009 :     foreach my $peg2 ( map {$_->[1]} grep {$region_peg{$_->[1]} and $_->[1] ne $peg1} @sims )
1010 :     {
1011 :     $blast_hit{$peg1}{$peg2} = 1;
1012 :     $blast_hit{$peg2}{$peg1} = 1;
1013 :     }
1014 :     }
1015 : dsouza 1.1 }
1016 :    
1017 :     return \%blast_hit;
1018 :     }
1019 :    
1020 :     sub blast_files {
1021 :     my($fig, $input, $database, $cutoff) = @_;
1022 : dsouza 1.22 my($cmd, @args);
1023 : dsouza 1.1
1024 : dsouza 1.22 # change to using blat
1025 :     my $blat = `which blat`;
1026 :     if ( $blat )
1027 :     {
1028 :     chomp $blat;
1029 :     $cmd = $blat;
1030 :     my $out_file = "$FIG_Config::temp/$$.blat.out";
1031 :     @args = ('-prot', '-out=blast8', $database, $input, $out_file);
1032 :     system($cmd, @args) == 0 or die "could not run blat";
1033 :    
1034 :     open(OUT, "<$out_file") or die "could not open file '$out_file': $!";
1035 :     my @blat_out_all = <OUT>;
1036 :     close(OUT);
1037 :     unlink $out_file;
1038 :    
1039 :     my @blat_out;
1040 :     foreach my $hit ( @blat_out_all )
1041 :     {
1042 :     my($evalue) = (split(/\s+/, $hit))[10];
1043 :     if ( $evalue <= $cutoff )
1044 :     {
1045 :     push @blat_out, $hit;
1046 :     }
1047 :     }
1048 :     return \@blat_out;
1049 :     }
1050 :     else
1051 :     {
1052 :     $cmd = "$FIG_Config::ext_bin/blastall";
1053 :     @args = ('-p', 'blastp', '-i', $input, '-d', $database, '-m', 8, '-e', $cutoff);
1054 :     my @blast_out = $fig->run_gathering_output($cmd, @args);
1055 :     return \@blast_out;
1056 :     }
1057 : dsouza 1.1 }
1058 :    
1059 :     sub formatdb_file {
1060 :     my($fig, $file) = @_;
1061 :    
1062 :     my $cmd = "$FIG_Config::ext_bin/formatdb -i $file -p T";
1063 :     $fig->run($cmd);
1064 :     }
1065 :    
1066 :     sub write_seqs_to_file {
1067 :     my($seq, $fasta_file) = @_;
1068 :    
1069 :     open(FASTA, ">$fasta_file") or die "could not create FASTA file '$fasta_file': $!";
1070 :     foreach my $peg ( keys %$seq )
1071 :     {
1072 : parrello 1.11 print FASTA ">$peg\n$seq->{$peg}\n";
1073 : dsouza 1.1 }
1074 :     close(FASTA) or die "could not close file FASTA file '$fasta_file': $!";
1075 :     }
1076 :    
1077 :     sub get_peg_sequences {
1078 : dsouza 1.21 my($fig, $pegs) = @_;
1079 : dsouza 1.1 my %sequences;
1080 :    
1081 :     # Iterate over each peg
1082 : dsouza 1.21 foreach my $peg ( @$pegs )
1083 : dsouza 1.1 {
1084 : parrello 1.11 my $seq = $fig->get_translation($peg);
1085 : dsouza 1.1
1086 : parrello 1.11 if ( $seq )
1087 :     {
1088 :     $sequences{$peg} = $seq;
1089 :     }
1090 :     else
1091 :     {
1092 :     print STDERR "could not get sqeuence for $peg\n";
1093 :     }
1094 : dsouza 1.1 }
1095 :    
1096 :     return \%sequences;
1097 :     }
1098 :    
1099 :    
1100 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3