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

Annotation of /FigKernelPackages/Observation.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : mkubal 1.1 package Observation;
2 :    
3 : paczian 1.54 #use lib '/vol/ontologies';
4 : mkubal 1.19 use DBMaster;
5 : mkubal 1.34 use Data::Dumper;
6 : mkubal 1.19
7 : mkubal 1.1 require Exporter;
8 : parrello 1.59 @EXPORT_OK = qw(get_objects get_sims_objects);
9 : mkubal 1.1
10 : paczian 1.44 use WebColors;
11 : paczian 1.52 use WebConfig;
12 : paczian 1.44
13 : arodri7 1.16 use FIG_Config;
14 : arodri7 1.74 use LWP::Simple;
15 : mkubal 1.30 #use strict;
16 : arodri7 1.16 #use warnings;
17 : arodri7 1.9 use HTML;
18 : arodri7 1.55 use FFs;
19 : mkubal 1.1
20 :     1;
21 :    
22 :     =head1 NAME
23 :    
24 :     Observation -- A presentation layer for observations in SEED.
25 :    
26 :     =head1 DESCRIPTION
27 :    
28 :     The SEED environment contains various sources of information for sequence features. The purpose of this library is to provide a
29 :     single interface to this data.
30 :    
31 :     The data can be used to display information for a given sequence feature (protein or other, but primarily information is computed for proteins).
32 :    
33 :     =cut
34 :    
35 :     =head1 BACKGROUND
36 :    
37 :     =head2 Data incorporated in the Observations
38 :    
39 :     As the goal of this library is to provide an integrated view, we combine diverse sources of evidence.
40 :    
41 :     =head3 SEED core evidence
42 :    
43 :     The core SEED data structures provided by FIG.pm. These are Similarities, BBHs and PCHs.
44 :    
45 :     =head3 Attribute based Evidence
46 :    
47 :     We use the SEED attribute infrastructure to store information computed by a variety of computational procedures.
48 :    
49 :     These are e.g. InterPro hits via InterProScan (ipr), NCBI Conserved Domain Database Hits via PSSM(cdd),
50 :     PFAM hits via HMM(pfam), SignalP results(signalp), and various others.
51 :    
52 :     =head1 METHODS
53 :    
54 :     The public methods this package provides are listed below:
55 :    
56 :    
57 : mkubal 1.24 =head3 context()
58 :    
59 :     Returns close or diverse for purposes of displaying genomic context
60 : mkubal 1.1
61 :     =cut
62 :    
63 : mkubal 1.24 sub context {
64 : mkubal 1.1 my ($self) = @_;
65 :    
66 : mkubal 1.24 return $self->{context};
67 : mkubal 1.1 }
68 :    
69 : mkubal 1.24 =head3 rows()
70 : mkubal 1.1
71 : mkubal 1.24 each row in a displayed table
72 : mkubal 1.1
73 : mkubal 1.24 =cut
74 :    
75 :     sub rows {
76 :     my ($self) = @_;
77 :    
78 :     return $self->{rows};
79 :     }
80 :    
81 :     =head3 acc()
82 :    
83 :     A valid accession or remote ID (in the style of a db_xref) or a valid local ID (FID) in case this is supported.
84 : mkubal 1.1
85 :     =cut
86 :    
87 : mkubal 1.24 sub acc {
88 : mkubal 1.1 my ($self) = @_;
89 : mkubal 1.24 return $self->{acc};
90 : mkubal 1.1 }
91 :    
92 : arodri7 1.40 =head3 query()
93 :    
94 :     The query id
95 :    
96 :     =cut
97 :    
98 :     sub query {
99 :     my ($self) = @_;
100 :     return $self->{query};
101 :     }
102 :    
103 :    
104 : mkubal 1.1 =head3 class()
105 :    
106 :     The class of evidence (required). This is usually simply the name of the tool or the name of the SEED data structure.
107 :     B<Please note> the connection of class and display_method and URL.
108 : mkubal 1.7
109 : mkubal 1.1 Current valid classes are:
110 :    
111 :     =over 9
112 :    
113 : arodri7 1.9 =item IDENTICAL (seq)
114 :    
115 : mkubal 1.3 =item SIM (seq)
116 : mkubal 1.1
117 : mkubal 1.3 =item BBH (seq)
118 : mkubal 1.1
119 : mkubal 1.3 =item PCH (fc)
120 : mkubal 1.1
121 : mkubal 1.3 =item FIGFAM (seq)
122 : mkubal 1.1
123 : mkubal 1.3 =item IPR (dom)
124 : mkubal 1.1
125 : mkubal 1.3 =item CDD (dom)
126 : mkubal 1.1
127 : mkubal 1.3 =item PFAM (dom)
128 : mkubal 1.1
129 : mkubal 1.12 =item SIGNALP_CELLO_TMPRED (loc)
130 : mkubal 1.1
131 : mkubal 1.20 =item PDB (seq)
132 :    
133 : mkubal 1.3 =item TMHMM (loc)
134 : mkubal 1.1
135 : mkubal 1.3 =item HMMTOP (loc)
136 : mkubal 1.1
137 :     =back
138 :    
139 :     =cut
140 :    
141 :     sub class {
142 :     my ($self) = @_;
143 :    
144 :     return $self->{class};
145 :     }
146 :    
147 :     =head3 type()
148 :    
149 :     The type of evidence (required).
150 :    
151 :     Where type is one of the following:
152 :    
153 :     =over 8
154 :    
155 :     =item seq=Sequence similarity
156 :    
157 :     =item dom=domain based match
158 :    
159 :     =item loc=Localization of the feature
160 :    
161 :     =item fc=Functional coupling.
162 :    
163 :     =back
164 :    
165 :     =cut
166 :    
167 :     sub type {
168 :     my ($self) = @_;
169 :    
170 : arodri7 1.26 return $self->{type};
171 : mkubal 1.1 }
172 :    
173 :     =head3 start()
174 :    
175 :     Start of hit in query sequence.
176 :    
177 :     =cut
178 :    
179 :     sub start {
180 :     my ($self) = @_;
181 :    
182 :     return $self->{start};
183 :     }
184 :    
185 :     =head3 end()
186 :    
187 :     End of the hit in query sequence.
188 :    
189 :     =cut
190 :    
191 :     sub stop {
192 :     my ($self) = @_;
193 :    
194 :     return $self->{stop};
195 :     }
196 :    
197 : arodri7 1.11 =head3 start()
198 :    
199 :     Start of hit in query sequence.
200 :    
201 :     =cut
202 :    
203 :     sub qstart {
204 :     my ($self) = @_;
205 :    
206 :     return $self->{qstart};
207 :     }
208 :    
209 :     =head3 qstop()
210 :    
211 :     End of the hit in query sequence.
212 :    
213 :     =cut
214 :    
215 :     sub qstop {
216 :     my ($self) = @_;
217 :    
218 :     return $self->{qstop};
219 :     }
220 :    
221 :     =head3 hstart()
222 :    
223 :     Start of hit in hit sequence.
224 :    
225 :     =cut
226 :    
227 :     sub hstart {
228 :     my ($self) = @_;
229 :    
230 :     return $self->{hstart};
231 :     }
232 :    
233 :     =head3 end()
234 :    
235 :     End of the hit in hit sequence.
236 :    
237 :     =cut
238 :    
239 :     sub hstop {
240 :     my ($self) = @_;
241 :    
242 :     return $self->{hstop};
243 :     }
244 :    
245 :     =head3 qlength()
246 :    
247 :     length of the query sequence in similarities
248 :    
249 :     =cut
250 :    
251 :     sub qlength {
252 :     my ($self) = @_;
253 :    
254 :     return $self->{qlength};
255 :     }
256 :    
257 :     =head3 hlength()
258 :    
259 :     length of the hit sequence in similarities
260 :    
261 :     =cut
262 :    
263 :     sub hlength {
264 :     my ($self) = @_;
265 :    
266 :     return $self->{hlength};
267 :     }
268 :    
269 : mkubal 1.1 =head3 evalue()
270 :    
271 :     E-value or P-Value if present.
272 :    
273 :     =cut
274 :    
275 :     sub evalue {
276 :     my ($self) = @_;
277 :    
278 :     return $self->{evalue};
279 :     }
280 :    
281 :     =head3 score()
282 :    
283 :     Score if present.
284 :    
285 :     =cut
286 :    
287 :     sub score {
288 :     my ($self) = @_;
289 :     return $self->{score};
290 :     }
291 :    
292 : mkubal 1.12 =head3 display()
293 : mkubal 1.1
294 : mkubal 1.12 will be different for each type
295 : mkubal 1.1
296 :     =cut
297 :    
298 : mkubal 1.7 sub display {
299 : mkubal 1.1
300 : mkubal 1.7 die "Abstract Method Called\n";
301 : mkubal 1.1
302 :     }
303 :    
304 : mkubal 1.24 =head3 display_table()
305 : mkubal 1.7
306 : mkubal 1.24 will be different for each type
307 : mkubal 1.1
308 : mkubal 1.24 =cut
309 : mkubal 1.1
310 : mkubal 1.24 sub display_table {
311 :    
312 :     die "Abstract Table Method Called\n";
313 : mkubal 1.1
314 :     }
315 :    
316 :     =head3 get_objects()
317 :    
318 :     This is the B<REAL WORKHORSE> method of this Package.
319 :    
320 :     =cut
321 :    
322 :     sub get_objects {
323 : arodri7 1.67 my ($self,$fid,$fig,$parameters,$scope) = @_;
324 : paczian 1.44
325 : mkubal 1.7 my $objects = [];
326 :     my @matched_datasets=();
327 : mkubal 1.1
328 : mkubal 1.7 # call function that fetches attribute based observations
329 :     # returns an array of arrays of hashes
330 :    
331 : mkubal 1.24 if($scope){
332 :     get_cluster_observations($fid,\@matched_datasets,$scope);
333 : mkubal 1.7 }
334 :     else{
335 :     my %domain_classes;
336 : arodri7 1.28 my @attributes = $fig->get_attributes($fid);
337 : arodri7 1.74 #$domain_classes{'CDD'} = 1;
338 : arodri7 1.41 $domain_classes{'PFAM'} = 1;
339 :     get_identical_proteins($fid,\@matched_datasets,$fig);
340 :     get_attribute_based_domain_observations($fid,\%domain_classes,\@matched_datasets,\@attributes,$fig);
341 : arodri7 1.67 get_sims_observations($fid,\@matched_datasets,$fig,$parameters);
342 : arodri7 1.41 get_functional_coupling($fid,\@matched_datasets,$fig);
343 :     get_attribute_based_location_observations($fid,\@matched_datasets,\@attributes,$fig);
344 :     get_pdb_observations($fid,\@matched_datasets,\@attributes,$fig);
345 : mkubal 1.1 }
346 : mkubal 1.7
347 :     foreach my $dataset (@matched_datasets) {
348 :     my $object;
349 :     if($dataset->{'type'} eq "dom"){
350 :     $object = Observation::Domain->new($dataset);
351 :     }
352 : arodri7 1.41 elsif($dataset->{'class'} eq "PCH"){
353 : arodri7 1.9 $object = Observation::FC->new($dataset);
354 :     }
355 : arodri7 1.41 elsif ($dataset->{'class'} eq "IDENTICAL"){
356 : arodri7 1.9 $object = Observation::Identical->new($dataset);
357 :     }
358 : arodri7 1.41 elsif ($dataset->{'class'} eq "SIGNALP_CELLO_TMPRED"){
359 : mkubal 1.12 $object = Observation::Location->new($dataset);
360 :     }
361 : arodri7 1.41 elsif ($dataset->{'class'} eq "SIM"){
362 : arodri7 1.10 $object = Observation::Sims->new($dataset);
363 :     }
364 : arodri7 1.41 elsif ($dataset->{'class'} eq "CLUSTER"){
365 : arodri7 1.15 $object = Observation::Cluster->new($dataset);
366 :     }
367 : arodri7 1.41 elsif ($dataset->{'class'} eq "PDB"){
368 : mkubal 1.20 $object = Observation::PDB->new($dataset);
369 :     }
370 :    
371 : mkubal 1.7 push (@$objects, $object);
372 : mkubal 1.1 }
373 : mkubal 1.7
374 :     return $objects;
375 : mkubal 1.1
376 :     }
377 :    
378 : parrello 1.70 =head3 get_attributes
379 : mkubal 1.61 provides layer of abstraction between tools and underlying access method to Attribute Server
380 :     =cut
381 :    
382 :     sub get_attributes{
383 :     my ($self,$fig,$search_set,$search_term,$value_array_ref) = @_;
384 :     my @attributes = $fig->get_attributes($search_set,$search_term,@$value_array_ref);
385 :     return @attributes;
386 :     }
387 :    
388 : arodri7 1.58 =head3 get_sims_objects()
389 :    
390 :     This is the B<REAL WORKHORSE> method of this Package.
391 :    
392 :     =cut
393 :    
394 :     sub get_sims_objects {
395 :     my ($self,$fid,$fig,$parameters) = @_;
396 :    
397 :     my $objects = [];
398 :     my @matched_datasets=();
399 :    
400 :     # call function that fetches attribute based observations
401 :     # returns an array of arrays of hashes
402 :     get_sims_observations($fid,\@matched_datasets,$fig,$parameters);
403 :    
404 :     foreach my $dataset (@matched_datasets) {
405 :     my $object;
406 :     if ($dataset->{'class'} eq "SIM"){
407 :     $object = Observation::Sims->new($dataset);
408 :     }
409 :     push (@$objects, $object);
410 :     }
411 :     return $objects;
412 :     }
413 :    
414 :    
415 : arodri7 1.28 =head3 display_housekeeping
416 :     This method returns the housekeeping data for a given peg in a table format
417 :    
418 :     =cut
419 :     sub display_housekeeping {
420 : arodri7 1.41 my ($self,$fid,$fig) = @_;
421 :     my $content = [];
422 :     my $row = [];
423 : arodri7 1.28
424 : arodri7 1.66 my $org_name = "Data not available";
425 :     if ( $fig->org_of($fid)){
426 :     $org_name = $fig->org_of($fid);
427 :     }
428 : arodri7 1.45 my $org_id = $fig->genome_of($fid);
429 : arodri7 1.28 my $function = $fig->function_of($fid);
430 : arodri7 1.41 #my $taxonomy = $fig->taxonomy_of($org_id);
431 :     my $length = $fig->translation_length($fid);
432 :    
433 :     push (@$row, $org_name);
434 :     push (@$row, $fid);
435 :     push (@$row, $length);
436 :     push (@$row, $function);
437 :    
438 :     # initialize the table for commentary and annotations
439 :     #$content .= qq(<b>My Sequence Data</b><br><table border="0">);
440 :     #$content .= qq(<tr width=15%><td >FIG ID</td><td>$fid</td></tr>\n);
441 :     #$content .= qq(<tr width=15%><td >Organism Name</td><td>$org_name</td></tr>\n);
442 :     #$content .= qq(<tr><td width=15%>Taxonomy</td><td>$taxonomy</td></tr>\n);
443 :     #$content .= qq(<tr width=15%><td>Function</td><td>$function</td></tr>\n);
444 :     #$content .= qq(<tr width=15%><td>Sequence Length</td><td>$length aa</td></tr>\n);
445 :     #$content .= qq(</table><p>\n);
446 :    
447 :     push(@$content, $row);
448 : arodri7 1.28
449 :     return ($content);
450 :     }
451 :    
452 :     =head3 get_sims_summary
453 :     This method uses as input the similarities of a peg and creates a tree view of their taxonomy
454 :    
455 :     =cut
456 :    
457 :     sub get_sims_summary {
458 : arodri7 1.53 my ($observation, $dataset, $fig) = @_;
459 : arodri7 1.28 my %families;
460 : arodri7 1.53 my $taxes = $fig->taxonomy_list();
461 :    
462 : arodri7 1.42 foreach my $thing (@$dataset) {
463 : arodri7 1.53 my ($id, $evalue);
464 :     if ($thing =~ /fig\|/){
465 :     $id = $thing;
466 :     $evalue = -1;
467 :     }
468 :     else{
469 :     next if ($thing->class ne "SIM");
470 :     $id = $thing->acc;
471 :     $evalue = $thing->evalue;
472 :     }
473 : arodri7 1.42 next if ($id !~ /fig\|/);
474 :     next if ($fig->is_deleted_fid($id));
475 : arodri7 1.53
476 : arodri7 1.42 my $genome = $fig->genome_of($id);
477 : arodri7 1.45 #my ($genome1) = ($genome) =~ /(.*)\./;
478 : arodri7 1.53 my $taxonomy = $taxes->{$genome};
479 : arodri7 1.28 my $parent_tax = "Root";
480 : arodri7 1.38 my @currLineage = ($parent_tax);
481 : arodri7 1.53 push (@{$families{figs}{$parent_tax}}, $id);
482 :     my $level = 2;
483 : arodri7 1.69
484 : arodri7 1.68 foreach my $tax (split(/\; /, $taxonomy),$id){
485 : arodri7 1.69 next if ($tax eq $parent_tax);
486 :     push (@{$families{children}{$parent_tax}}, $tax) if ($tax ne $parent_tax);
487 :     push (@{$families{figs}{$tax}}, $id) if ($tax ne $parent_tax);
488 :     $families{level}{$tax} = $level;
489 :     push (@currLineage, $tax);
490 :     $families{parent}{$tax} = $parent_tax;
491 :     $families{lineage}{$tax} = join(";", @currLineage);
492 :     if (defined ($families{evalue}{$tax})){
493 :     if ($evalue < $families{evalue}{$tax}){
494 :     $families{evalue}{$tax} = $evalue;
495 :     $families{color}{$tax} = &get_taxcolor($evalue);
496 : arodri7 1.39 }
497 : arodri7 1.69 }
498 :     else{
499 :     $families{evalue}{$tax} = $evalue;
500 :     $families{color}{$tax} = &get_taxcolor($evalue);
501 :     }
502 :    
503 :     $parent_tax = $tax;
504 :     $level++;
505 : arodri7 1.28 }
506 :     }
507 :    
508 :     foreach my $key (keys %{$families{children}}){
509 :     $families{count}{$key} = @{$families{children}{$key}};
510 :    
511 :     my %saw;
512 :     my @out = grep(!$saw{$_}++, @{$families{children}{$key}});
513 :     $families{children}{$key} = \@out;
514 :     }
515 : arodri7 1.53
516 :     return \%families;
517 : arodri7 1.28 }
518 :    
519 : mkubal 1.1 =head1 Internal Methods
520 :    
521 :     These methods are not meant to be used outside of this package.
522 :    
523 :     B<Please do not use them outside of this package!>
524 :    
525 :     =cut
526 :    
527 : arodri7 1.39 sub get_taxcolor{
528 :     my ($evalue) = @_;
529 :     my $color;
530 : arodri7 1.53 if ($evalue == -1){ $color = "black"; }
531 :     elsif (($evalue <= 1e-170) && ($evalue >= 0)){ $color = "#FF2000"; }
532 : arodri7 1.39 elsif (($evalue <= 1e-120) && ($evalue > 1e-170)){ $color = "#FF3300"; }
533 :     elsif (($evalue <= 1e-90) && ($evalue > 1e-120)){ $color = "#FF6600"; }
534 :     elsif (($evalue <= 1e-70) && ($evalue > 1e-90)){ $color = "#FF9900"; }
535 :     elsif (($evalue <= 1e-40) && ($evalue > 1e-70)){ $color = "#FFCC00"; }
536 :     elsif (($evalue <= 1e-20) && ($evalue > 1e-40)){ $color = "#FFFF00"; }
537 :     elsif (($evalue <= 1e-5) && ($evalue > 1e-20)){ $color = "#CCFF00"; }
538 :     elsif (($evalue <= 1) && ($evalue > 1e-5)){ $color = "#66FF00"; }
539 :     elsif (($evalue <= 10) && ($evalue > 1)){ $color = "#00FF00"; }
540 :     else{ $color = "#6666FF"; }
541 :     return ($color);
542 :     }
543 :    
544 :    
545 : mkubal 1.7 sub get_attribute_based_domain_observations{
546 :    
547 :     # we read a FIG ID and a reference to an array (of arrays of hashes, see above)
548 : arodri7 1.41 my ($fid,$domain_classes,$datasets_ref,$attributes_ref,$fig) = (@_);
549 : arodri7 1.66 my $seen = {};
550 : arodri7 1.28 foreach my $attr_ref (@$attributes_ref) {
551 : mkubal 1.7 my $key = @$attr_ref[1];
552 :     my @parts = split("::",$key);
553 :     my $class = $parts[0];
554 : arodri7 1.50 my $name = $parts[1];
555 : arodri7 1.66 next if ($seen->{$name});
556 :     $seen->{$name}++;
557 : arodri7 1.56 #next if (($class eq "PFAM") && ($name !~ /interpro/));
558 : arodri7 1.50
559 : mkubal 1.7 if($domain_classes->{$parts[0]}){
560 :     my $val = @$attr_ref[2];
561 : mkubal 1.8 if($val =~/^(\d+\.\d+|0\.0);(\d+)-(\d+)/){
562 : mkubal 1.7 my $raw_evalue = $1;
563 : mkubal 1.8 my $from = $2;
564 :     my $to = $3;
565 : mkubal 1.7 my $evalue;
566 : arodri7 1.50 if(($raw_evalue =~/(\d+)\.(\d+)/) && ($class ne "PFAM")){
567 : mkubal 1.7 my $part2 = 1000 - $1;
568 :     my $part1 = $2/100;
569 :     $evalue = $part1."e-".$part2;
570 :     }
571 : arodri7 1.50 elsif(($raw_evalue =~/(\d+)\.(\d+)/) && ($class eq "PFAM")){
572 : arodri7 1.75 #$evalue=$raw_evalue;
573 :     my $part2 = 1000 - $1;
574 :     my $part1 = $2/100;
575 :     $evalue = $part1."e-".$part2;
576 :    
577 : arodri7 1.50 }
578 : mkubal 1.7 else{
579 : mkubal 1.8 $evalue = "0.0";
580 : mkubal 1.7 }
581 : arodri7 1.66
582 : mkubal 1.7 my $dataset = {'class' => $class,
583 :     'acc' => $key,
584 :     'type' => "dom" ,
585 :     'evalue' => $evalue,
586 :     'start' => $from,
587 : mkubal 1.24 'stop' => $to,
588 :     'fig_id' => $fid,
589 :     'score' => $raw_evalue
590 : mkubal 1.7 };
591 :    
592 :     push (@{$datasets_ref} ,$dataset);
593 :     }
594 :     }
595 :     }
596 :     }
597 : mkubal 1.12
598 :     sub get_attribute_based_location_observations{
599 :    
600 : arodri7 1.41 my ($fid,$datasets_ref, $attributes_ref,$fig) = (@_);
601 :     #my $fig = new FIG;
602 : mkubal 1.12
603 : mkubal 1.30 my $location_attributes = ['SignalP','CELLO','TMPRED','Phobius'];
604 : mkubal 1.12
605 : arodri7 1.26 my $dataset = {'type' => "loc",
606 :     'class' => 'SIGNALP_CELLO_TMPRED',
607 :     'fig_id' => $fid
608 :     };
609 :    
610 : arodri7 1.28 foreach my $attr_ref (@$attributes_ref){
611 : mkubal 1.12 my $key = @$attr_ref[1];
612 : mkubal 1.30 next if (($key !~ /SignalP/) && ($key !~ /CELLO/) && ($key !~ /TMPRED/) && ($key !~/Phobius/) );
613 : mkubal 1.12 my @parts = split("::",$key);
614 :     my $sub_class = $parts[0];
615 :     my $sub_key = $parts[1];
616 :     my $value = @$attr_ref[2];
617 :     if($sub_class eq "SignalP"){
618 :     if($sub_key eq "cleavage_site"){
619 :     my @value_parts = split(";",$value);
620 :     $dataset->{'cleavage_prob'} = $value_parts[0];
621 :     $dataset->{'cleavage_loc'} = $value_parts[1];
622 :     }
623 :     elsif($sub_key eq "signal_peptide"){
624 :     $dataset->{'signal_peptide_score'} = $value;
625 :     }
626 :     }
627 : mkubal 1.30
628 : mkubal 1.12 elsif($sub_class eq "CELLO"){
629 :     $dataset->{'cello_location'} = $sub_key;
630 :     $dataset->{'cello_score'} = $value;
631 :     }
632 : mkubal 1.30
633 :     elsif($sub_class eq "Phobius"){
634 :     if($sub_key eq "transmembrane"){
635 :     $dataset->{'phobius_tm_locations'} = $value;
636 :     }
637 :     elsif($sub_key eq "signal"){
638 :     $dataset->{'phobius_signal_location'} = $value;
639 :     }
640 :     }
641 :    
642 : mkubal 1.12 elsif($sub_class eq "TMPRED"){
643 : arodri7 1.26 my @value_parts = split(/\;/,$value);
644 : mkubal 1.12 $dataset->{'tmpred_score'} = $value_parts[0];
645 :     $dataset->{'tmpred_locations'} = $value_parts[1];
646 :     }
647 :     }
648 :    
649 :     push (@{$datasets_ref} ,$dataset);
650 :    
651 :     }
652 :    
653 : mkubal 1.20 =head3 get_pdb_observations() (internal)
654 :    
655 :     This methods sets the type and class for pdb observations
656 :    
657 :     =cut
658 :    
659 :     sub get_pdb_observations{
660 : arodri7 1.41 my ($fid,$datasets_ref, $attributes_ref,$fig) = (@_);
661 : mkubal 1.20
662 : arodri7 1.41 #my $fig = new FIG;
663 : mkubal 1.20
664 : arodri7 1.28 foreach my $attr_ref (@$attributes_ref){
665 : mkubal 1.20 my $key = @$attr_ref[1];
666 : arodri7 1.28 next if ( ($key !~ /PDB/));
667 : mkubal 1.20 my($key1,$key2) =split("::",$key);
668 :     my $value = @$attr_ref[2];
669 :     my ($evalue,$location) = split(";",$value);
670 :    
671 :     if($evalue =~/(\d+)\.(\d+)/){
672 :     my $part2 = 1000 - $1;
673 :     my $part1 = $2/100;
674 :     $evalue = $part1."e-".$part2;
675 :     }
676 :    
677 :     my($start,$stop) =split("-",$location);
678 :    
679 :     my $url = @$attr_ref[3];
680 :     my $dataset = {'class' => 'PDB',
681 :     'type' => 'seq' ,
682 :     'acc' => $key2,
683 :     'evalue' => $evalue,
684 :     'start' => $start,
685 : mkubal 1.24 'stop' => $stop,
686 :     'fig_id' => $fid
687 : mkubal 1.20 };
688 :    
689 :     push (@{$datasets_ref} ,$dataset);
690 :     }
691 :     }
692 :    
693 : arodri7 1.15 =head3 get_cluster_observations() (internal)
694 :    
695 :     This methods sets the type and class for cluster observations
696 :    
697 :     =cut
698 :    
699 :     sub get_cluster_observations{
700 : mkubal 1.24 my ($fid,$datasets_ref,$scope) = (@_);
701 : arodri7 1.15
702 : arodri7 1.16 my $dataset = {'class' => 'CLUSTER',
703 : mkubal 1.24 'type' => 'fc',
704 :     'context' => $scope,
705 :     'fig_id' => $fid
706 : arodri7 1.16 };
707 : arodri7 1.15 push (@{$datasets_ref} ,$dataset);
708 :     }
709 :    
710 :    
711 : mkubal 1.3 =head3 get_sims_observations() (internal)
712 :    
713 :     This methods retrieves sims fills the internal data structures.
714 :    
715 :     =cut
716 :    
717 :     sub get_sims_observations{
718 : arodri7 1.58 my ($fid,$datasets_ref,$fig,$parameters) = (@_);
719 : mkubal 1.3
720 : arodri7 1.62 my ($max_sims, $max_expand, $max_eval, $sim_order, $db_filter, $sim_filters);
721 : arodri7 1.67 if ( (defined $parameters->{flag}) && ($parameters->{flag})){
722 : arodri7 1.58 $max_sims = $parameters->{max_sims};
723 :     $max_expand = $parameters->{max_expand};
724 :     $max_eval = $parameters->{max_eval};
725 :     $db_filter = $parameters->{db_filter};
726 : arodri7 1.62 $sim_filters->{ sort_by } = $parameters->{sim_order};
727 :     #$sim_order = $parameters->{sim_order};
728 : arodri7 1.58 $group_by_genome = 1 if (defined ($parameters->{group_genome}));
729 :     }
730 : arodri7 1.67 elsif ( (defined $parameters->{sims_db}) && ($parameters->{sims_db} eq 'all')){
731 :     $max_sims = 50;
732 :     $max_expand = 5;
733 :     $max_eval = 1e-5;
734 :     $db_filter = "all";
735 :     $sim_filters->{ sort_by } = 'id';
736 :     }
737 : arodri7 1.58 else{
738 :     $max_sims = 50;
739 :     $max_expand = 5;
740 :     $max_eval = 1e-5;
741 :     $db_filter = "figx";
742 : arodri7 1.62 $sim_filters->{ sort_by } = 'id';
743 :     #$sim_order = "id";
744 : arodri7 1.58 }
745 :    
746 : parrello 1.59 my($id, $genome, @genomes, %sims);
747 : arodri7 1.77 # my @tmp= $fig->sims($fid,$max_sims,$max_eval,$db_filter,$max_expand,$sim_filters);
748 :     my @tmp= $fig->sims($fid,1000000,$max_eval,$db_filter,$max_expand,$sim_filters);
749 : arodri7 1.58 @tmp = grep { !($_->id2 =~ /^fig\|/ and $fig->is_deleted_fid($_->id2)) } @tmp;
750 : mkubal 1.4 my ($dataset);
751 : arodri7 1.26
752 : arodri7 1.58 if ($group_by_genome){
753 :     # Collect all sims from genome with the first occurance of the genome:
754 :     foreach $sim ( @tmp ){
755 :     $id = $sim->id2;
756 :     $genome = ($id =~ /^fig\|(\d+\.\d+)\.peg\.\d+/) ? $1 : $id;
757 :     if (! defined( $sims{ $genome } ) ) { push @genomes, $genome }
758 :     push @{ $sims{ $genome } }, $sim;
759 :     }
760 :     @tmp = map { @{ $sims{$_} } } @genomes;
761 :     }
762 : arodri7 1.66
763 :     my $seen_sims={};
764 : arodri7 1.77 my $count=1;
765 : arodri7 1.58 foreach my $sim (@tmp){
766 : arodri7 1.77
767 : arodri7 1.26 my $hit = $sim->[1];
768 : arodri7 1.66 next if ($seen_sims->{$hit});
769 : arodri7 1.77 next if ($hit =~ /nmpdr\||gnl\|md5\|/);
770 : arodri7 1.66 $seen_sims->{$hit}++;
771 : arodri7 1.77
772 :     last if ($count>$max_sims);
773 :     $count++;
774 :    
775 : arodri7 1.11 my $percent = $sim->[2];
776 : mkubal 1.4 my $evalue = $sim->[10];
777 : arodri7 1.11 my $qfrom = $sim->[6];
778 :     my $qto = $sim->[7];
779 :     my $hfrom = $sim->[8];
780 :     my $hto = $sim->[9];
781 :     my $qlength = $sim->[12];
782 :     my $hlength = $sim->[13];
783 :     my $db = get_database($hit);
784 :     my $func = $fig->function_of($hit);
785 : arodri7 1.66 my $organism;
786 :     if ($fig->org_of($hit)){
787 :     $organism = $fig->org_of($hit);
788 :     }
789 :     else{
790 :     $organism = "Data not available";
791 :     }
792 : arodri7 1.11
793 : arodri7 1.10 $dataset = {'class' => 'SIM',
794 : arodri7 1.40 'query' => $sim->[0],
795 : arodri7 1.10 'acc' => $hit,
796 : arodri7 1.11 'identity' => $percent,
797 : arodri7 1.10 'type' => 'seq',
798 :     'evalue' => $evalue,
799 : arodri7 1.11 'qstart' => $qfrom,
800 :     'qstop' => $qto,
801 :     'hstart' => $hfrom,
802 :     'hstop' => $hto,
803 :     'database' => $db,
804 :     'organism' => $organism,
805 :     'function' => $func,
806 :     'qlength' => $qlength,
807 : mkubal 1.24 'hlength' => $hlength,
808 :     'fig_id' => $fid
809 : arodri7 1.10 };
810 :    
811 :     push (@{$datasets_ref} ,$dataset);
812 : mkubal 1.3 }
813 :     }
814 :    
815 : arodri7 1.11 =head3 get_database (internal)
816 :     This method gets the database association from the sequence id
817 :    
818 :     =cut
819 :    
820 :     sub get_database{
821 :     my ($id) = (@_);
822 :    
823 :     my ($db);
824 : arodri7 1.58 if ($id =~ /^fig\|/) { $db = "SEED" }
825 : arodri7 1.11 elsif ($id =~ /^gi\|/) { $db = "NCBI" }
826 : arodri7 1.58 elsif ($id =~ /^gb\|/) { $db = "GenBank" }
827 : arodri7 1.11 elsif ($id =~ /^^[NXYZA]P_/) { $db = "RefSeq" }
828 : arodri7 1.58 elsif ($id =~ /^ref\|/) { $db = "RefSeq" }
829 : arodri7 1.11 elsif ($id =~ /^sp\|/) { $db = "SwissProt" }
830 :     elsif ($id =~ /^uni\|/) { $db = "UniProt" }
831 :     elsif ($id =~ /^tigr\|/) { $db = "TIGR" }
832 :     elsif ($id =~ /^pir\|/) { $db = "PIR" }
833 : arodri7 1.28 elsif (($id =~ /^kegg\|/) || ($id =~ /Spy/)) { $db = "KEGG" }
834 :     elsif ($id =~ /^tr\|/) { $db = "TrEMBL" }
835 : arodri7 1.11 elsif ($id =~ /^eric\|/) { $db = "ASAP" }
836 :     elsif ($id =~ /^img\|/) { $db = "JGI" }
837 : arodri7 1.58 elsif ($id =~ /^pdb\|/) { $db = "PDB" }
838 :     elsif ($id =~ /^img\|/) { $db = "IMG" }
839 :     elsif ($id =~ /^cmr\|/) { $db = "CMR" }
840 :     elsif ($id =~ /^dbj\|/) { $db = "DBJ" }
841 : arodri7 1.11
842 :     return ($db);
843 :    
844 :     }
845 :    
846 : mkubal 1.24
847 : arodri7 1.5 =head3 get_identical_proteins() (internal)
848 :    
849 :     This methods retrieves sims fills the internal data structures.
850 :    
851 :     =cut
852 :    
853 :     sub get_identical_proteins{
854 :    
855 : arodri7 1.41 my ($fid,$datasets_ref,$fig) = (@_);
856 :     #my $fig = new FIG;
857 : mkubal 1.24 my $funcs_ref;
858 : arodri7 1.5
859 :     my @maps_to = grep { $_ ne $fid and $_ !~ /^xxx/ } map { $_->[0] } $fig->mapped_prot_ids($fid);
860 :     foreach my $id (@maps_to) {
861 :     my ($tmp, $who);
862 : arodri7 1.33 if (($id ne $fid) && ($tmp = $fig->function_of($id))) {
863 : arodri7 1.11 $who = &get_database($id);
864 : mkubal 1.24 push(@$funcs_ref, [$id,$who,$tmp]);
865 : arodri7 1.5 }
866 :     }
867 :    
868 : mkubal 1.24 my $dataset = {'class' => 'IDENTICAL',
869 :     'type' => 'seq',
870 :     'fig_id' => $fid,
871 :     'rows' => $funcs_ref
872 :     };
873 :    
874 :     push (@{$datasets_ref} ,$dataset);
875 :    
876 : arodri7 1.5
877 :     }
878 :    
879 : arodri7 1.6 =head3 get_functional_coupling() (internal)
880 :    
881 :     This methods retrieves the functional coupling of a protein given a peg ID
882 :    
883 :     =cut
884 :    
885 :     sub get_functional_coupling{
886 :    
887 : arodri7 1.41 my ($fid,$datasets_ref,$fig) = (@_);
888 :     #my $fig = new FIG;
889 : arodri7 1.6 my @funcs = ();
890 :    
891 :     # initialize some variables
892 :     my($sc,$neigh);
893 :    
894 :     # set default parameters for coupling and evidence
895 :     my ($bound,$sim_cutoff,$coupling_cutoff) = (5000, 1.0e-10, 4);
896 :    
897 :     # get the fc data
898 : arodri7 1.71 my @fc_data = $fig->coupling_and_evidence($fid,$bound,$sim_cutoff,$coupling_cutoff);
899 : arodri7 1.6
900 :     # retrieve data
901 :     my @rows = map { ($sc,$neigh) = @$_;
902 :     [$sc,$neigh,scalar $fig->function_of($neigh)]
903 :     } @fc_data;
904 :    
905 : mkubal 1.24 my $dataset = {'class' => 'PCH',
906 :     'type' => 'fc',
907 :     'fig_id' => $fid,
908 :     'rows' => \@rows
909 :     };
910 :    
911 :     push (@{$datasets_ref} ,$dataset);
912 : arodri7 1.9
913 : arodri7 1.6 }
914 : arodri7 1.5
915 : mkubal 1.1 =head3 new (internal)
916 :    
917 :     Instantiate a new object.
918 :    
919 :     =cut
920 :    
921 :     sub new {
922 : mkubal 1.7 my ($class,$dataset) = @_;
923 :    
924 :     my $self = { class => $dataset->{'class'},
925 : mkubal 1.24 type => $dataset->{'type'},
926 :     fig_id => $dataset->{'fig_id'},
927 :     score => $dataset->{'score'},
928 : arodri7 1.10 };
929 : mkubal 1.7
930 :     bless($self,$class);
931 : mkubal 1.1
932 :     return $self;
933 :     }
934 :    
935 : arodri7 1.11 =head3 identity (internal)
936 :    
937 :     Returns the % identity of the similar sequence
938 :    
939 :     =cut
940 :    
941 :     sub identity {
942 :     my ($self) = @_;
943 :    
944 :     return $self->{identity};
945 :     }
946 :    
947 : mkubal 1.24 =head3 fig_id (internal)
948 :    
949 :     =cut
950 :    
951 :     sub fig_id {
952 :     my ($self) = @_;
953 :     return $self->{fig_id};
954 :     }
955 :    
956 : mkubal 1.1 =head3 feature_id (internal)
957 :    
958 :    
959 :     =cut
960 :    
961 :     sub feature_id {
962 :     my ($self) = @_;
963 :    
964 :     return $self->{feature_id};
965 :     }
966 : arodri7 1.5
967 :     =head3 id (internal)
968 :    
969 :     Returns the ID of the identical sequence
970 :    
971 :     =cut
972 :    
973 :     sub id {
974 :     my ($self) = @_;
975 :    
976 :     return $self->{id};
977 :     }
978 :    
979 :     =head3 organism (internal)
980 :    
981 :     Returns the organism of the identical sequence
982 :    
983 :     =cut
984 :    
985 :     sub organism {
986 :     my ($self) = @_;
987 :    
988 :     return $self->{organism};
989 :     }
990 :    
991 : arodri7 1.9 =head3 function (internal)
992 :    
993 :     Returns the function of the identical sequence
994 :    
995 :     =cut
996 :    
997 :     sub function {
998 :     my ($self) = @_;
999 :    
1000 :     return $self->{function};
1001 :     }
1002 :    
1003 : arodri7 1.5 =head3 database (internal)
1004 :    
1005 :     Returns the database of the identical sequence
1006 :    
1007 :     =cut
1008 :    
1009 :     sub database {
1010 :     my ($self) = @_;
1011 :    
1012 :     return $self->{database};
1013 :     }
1014 :    
1015 : mkubal 1.20 ############################################################
1016 :     ############################################################
1017 :     package Observation::PDB;
1018 :    
1019 :     use base qw(Observation);
1020 :    
1021 :     sub new {
1022 :    
1023 :     my ($class,$dataset) = @_;
1024 :     my $self = $class->SUPER::new($dataset);
1025 :     $self->{acc} = $dataset->{'acc'};
1026 :     $self->{evalue} = $dataset->{'evalue'};
1027 :     $self->{start} = $dataset->{'start'};
1028 :     $self->{stop} = $dataset->{'stop'};
1029 :     bless($self,$class);
1030 :     return $self;
1031 :     }
1032 :    
1033 :     =head3 display()
1034 :    
1035 :     displays data stored in best_PDB attribute and in Ontology server for given PDB id
1036 :    
1037 :     =cut
1038 :    
1039 :     sub display{
1040 : arodri7 1.41 my ($self,$gd,$fig) = @_;
1041 : mkubal 1.20
1042 : mkubal 1.24 my $fid = $self->fig_id;
1043 : paczian 1.52 my $dbmaster = DBMaster->new(-database =>'Ontology',
1044 : arodri7 1.74 -host => $WebConfig::DBHOST,
1045 :     -user => $WebConfig::DBUSER,
1046 :     -password => $WebConfig::DBPWD);
1047 : mkubal 1.20
1048 :     my $acc = $self->acc;
1049 :    
1050 :     my ($pdb_description,$pdb_source,$pdb_ligand);
1051 :     my $pdb_objs = $dbmaster->pdb->get_objects( { 'id' => $acc } );
1052 :     if(!scalar(@$pdb_objs)){
1053 :     $pdb_description = "not available";
1054 :     $pdb_source = "not available";
1055 :     $pdb_ligand = "not available";
1056 :     }
1057 :     else{
1058 :     my $pdb_obj = $pdb_objs->[0];
1059 :     $pdb_description = $pdb_obj->description;
1060 :     $pdb_source = $pdb_obj->source;
1061 :     $pdb_ligand = $pdb_obj->ligand;
1062 :     }
1063 : arodri7 1.6
1064 : mkubal 1.20 my $lines = [];
1065 :     my $line_data = [];
1066 :     my $line_config = { 'title' => "PDB hit for $fid",
1067 : paczian 1.47 'hover_title' => 'PDB',
1068 : mkubal 1.20 'short_title' => "best PDB",
1069 :     'basepair_offset' => '1' };
1070 :    
1071 : arodri7 1.41 #my $fig = new FIG;
1072 : mkubal 1.20 my $seq = $fig->get_translation($fid);
1073 :     my $fid_stop = length($seq);
1074 :    
1075 :     my $fid_element_hash = {
1076 :     "title" => $fid,
1077 :     "start" => '1',
1078 :     "end" => $fid_stop,
1079 :     "color"=> '1',
1080 :     "zlayer" => '1'
1081 :     };
1082 :    
1083 :     push(@$line_data,$fid_element_hash);
1084 :    
1085 :     my $links_list = [];
1086 :     my $descriptions = [];
1087 :    
1088 :     my $name;
1089 :     $name = {"title" => 'id',
1090 :     "value" => $acc};
1091 :     push(@$descriptions,$name);
1092 :    
1093 :     my $description;
1094 :     $description = {"title" => 'pdb description',
1095 :     "value" => $pdb_description};
1096 :     push(@$descriptions,$description);
1097 :    
1098 :     my $score;
1099 :     $score = {"title" => "score",
1100 :     "value" => $self->evalue};
1101 :     push(@$descriptions,$score);
1102 :    
1103 :     my $start_stop;
1104 :     my $start_stop_value = $self->start."_".$self->stop;
1105 :     $start_stop = {"title" => "start-stop",
1106 :     "value" => $start_stop_value};
1107 :     push(@$descriptions,$start_stop);
1108 :    
1109 :     my $source;
1110 :     $source = {"title" => "source",
1111 :     "value" => $pdb_source};
1112 :     push(@$descriptions,$source);
1113 :    
1114 :     my $ligand;
1115 :     $ligand = {"title" => "pdb ligand",
1116 :     "value" => $pdb_ligand};
1117 :     push(@$descriptions,$ligand);
1118 :    
1119 :     my $link;
1120 :     my $link_url ="http://www.rcsb.org/pdb/explore/explore.do?structureId=".$acc;
1121 :    
1122 :     $link = {"link_title" => $acc,
1123 :     "link" => $link_url};
1124 :     push(@$links_list,$link);
1125 :    
1126 :     my $pdb_element_hash = {
1127 :     "title" => "PDB homology",
1128 :     "start" => $self->start,
1129 :     "end" => $self->stop,
1130 :     "color"=> '6',
1131 :     "zlayer" => '3',
1132 :     "links_list" => $links_list,
1133 :     "description" => $descriptions};
1134 :    
1135 :     push(@$line_data,$pdb_element_hash);
1136 :     $gd->add_line($line_data, $line_config);
1137 :    
1138 :     return $gd;
1139 :     }
1140 :    
1141 :     1;
1142 : arodri7 1.11
1143 : arodri7 1.9 ############################################################
1144 :     ############################################################
1145 :     package Observation::Identical;
1146 :    
1147 :     use base qw(Observation);
1148 :    
1149 :     sub new {
1150 :    
1151 :     my ($class,$dataset) = @_;
1152 :     my $self = $class->SUPER::new($dataset);
1153 : mkubal 1.24 $self->{rows} = $dataset->{'rows'};
1154 :    
1155 : arodri7 1.9 bless($self,$class);
1156 :     return $self;
1157 :     }
1158 :    
1159 : mkubal 1.24 =head3 display_table()
1160 : arodri7 1.6
1161 :     If available use the function specified here to display the "raw" observation.
1162 :     This code will display a table for the identical protein
1163 :    
1164 :    
1165 : arodri7 1.9 B<Please note> that URL linked to in display_method() is an external component and needs to added to the code for every class of evi
1166 :     dence.
1167 : arodri7 1.6
1168 :     =cut
1169 :    
1170 :    
1171 : mkubal 1.24 sub display_table{
1172 : arodri7 1.41 my ($self,$fig) = @_;
1173 : mkubal 1.24
1174 : arodri7 1.41 #my $fig = new FIG;
1175 : mkubal 1.24 my $fid = $self->fig_id;
1176 :     my $rows = $self->rows;
1177 :     my $cgi = new CGI;
1178 : arodri7 1.6 my $all_domains = [];
1179 :     my $count_identical = 0;
1180 : arodri7 1.9 my $content;
1181 : mkubal 1.24 foreach my $row (@$rows) {
1182 :     my $id = $row->[0];
1183 :     my $who = $row->[1];
1184 :     my $assignment = $row->[2];
1185 : arodri7 1.66 my $organism = "Data not available";
1186 :     if ($fig->org_of($id)){
1187 :     $organism = $fig->org_of($id);
1188 :     }
1189 : arodri7 1.9 my $single_domain = [];
1190 : mkubal 1.24 push(@$single_domain,$who);
1191 : redwards 1.83 push(@$single_domain,$self->get_url_for_id($id));
1192 : mkubal 1.24 push(@$single_domain,$organism);
1193 :     push(@$single_domain,$assignment);
1194 : arodri7 1.9 push(@$all_domains,$single_domain);
1195 : mkubal 1.24 $count_identical++;
1196 : arodri7 1.6 }
1197 :    
1198 :     if ($count_identical >0){
1199 : arodri7 1.9 $content = $all_domains;
1200 : arodri7 1.6 }
1201 :     else{
1202 : arodri7 1.9 $content = "<p>This PEG does not have any essentially identical proteins</p>";
1203 : arodri7 1.6 }
1204 :     return ($content);
1205 :     }
1206 : mkubal 1.7
1207 : redwards 1.83 sub get_url_for_id {
1208 :     my ($self, $id) = @_;
1209 :    
1210 :     my $copy = $id;
1211 :     if ($copy =~ s/^kegg\|//) {
1212 :     return "<a href='http://www.genome.jp/dbget-bin/www_bget?$copy'>$id</a>";
1213 :     }
1214 :     elsif ($copy =~ s/^sp\|//) {
1215 :     return "<a href='http://www.uniprot.org/entry/$copy'>$id</a>";
1216 :     }
1217 :     elsif ($copy =~ s/^tr\|//) {
1218 :     return "<a href='http://www.uniprot.org/entry/$copy'>$id</a>";
1219 :     }
1220 :     elsif ($copy =~ s/^uni\|//) {
1221 :     return "<a href='http://www.uniprot.org/entry/$copy'>$id</a>";
1222 :     }
1223 :     elsif ($copy =~ s/^gi\|//) {
1224 :     return "<a href='http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&id=$copy'>$id</a>";
1225 :     }
1226 :     elsif ($copy =~ s/^ref\|//) {
1227 :     return "<a href='http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&id=$copy'>$id</a>";
1228 :     }
1229 :     elsif ($copy =~ s/^gb\|//) {
1230 :     return "<a href='http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=protein&id=$copy'>$id</a>";
1231 :     }
1232 :     elsif ($copy =~ s/^cmr\|// or $copy =~ s/^tigrcmr\|//) {
1233 :     return "<a href='http://cmr.tigr.org/tigr-scripts/CMR/shared/GenePage.cgi?locus=$copy'>$id</a>";
1234 :     }
1235 :     elsif ($copy =~ /^fig\|/) {
1236 :     return "<a href='http://seed-viewer.theseed.org/linkin.cgi?id=$id'>$id</a>";
1237 :     }
1238 :     elsif ($copy =~ s/^img\|//) {
1239 :     return "<a href='http://img.jgi.doe.gov/cgi-bin/pub/main.cgi?section=GeneDetail&page=geneDetail&gene_oid=$copy'>$id</a>";
1240 :     }
1241 :     else {
1242 :     return $id;
1243 :     }
1244 :    
1245 :     }
1246 :    
1247 :    
1248 :    
1249 : arodri7 1.9 1;
1250 :    
1251 :     #########################################
1252 :     #########################################
1253 :     package Observation::FC;
1254 :     1;
1255 :    
1256 :     use base qw(Observation);
1257 :    
1258 :     sub new {
1259 :    
1260 :     my ($class,$dataset) = @_;
1261 :     my $self = $class->SUPER::new($dataset);
1262 : mkubal 1.24 $self->{rows} = $dataset->{'rows'};
1263 : arodri7 1.9
1264 :     bless($self,$class);
1265 :     return $self;
1266 :     }
1267 :    
1268 : mkubal 1.24 =head3 display_table()
1269 : arodri7 1.9
1270 :     If available use the function specified here to display the "raw" observation.
1271 :     This code will display a table for the identical protein
1272 :    
1273 :    
1274 :     B<Please note> that URL linked to in display_method() is an external component and needs to added to the code for every class of evi
1275 :     dence.
1276 :    
1277 :     =cut
1278 :    
1279 : mkubal 1.24 sub display_table {
1280 : arodri7 1.9
1281 : arodri7 1.41 my ($self,$dataset,$fig) = @_;
1282 : mkubal 1.24 my $fid = $self->fig_id;
1283 :     my $rows = $self->rows;
1284 :     my $cgi = new CGI;
1285 : arodri7 1.9 my $functional_data = [];
1286 :     my $count = 0;
1287 :     my $content;
1288 :    
1289 : mkubal 1.24 foreach my $row (@$rows) {
1290 : arodri7 1.9 my $single_domain = [];
1291 :     $count++;
1292 :    
1293 :     # construct the score link
1294 : mkubal 1.24 my $score = $row->[0];
1295 :     my $toid = $row->[1];
1296 : paczian 1.44 my $link = $cgi->url(-relative => 1) . "?page=Annotation&feature=$fid";
1297 :     my $sc_link = "<a href='$link'>$score</a>";
1298 : arodri7 1.9
1299 :     push(@$single_domain,$sc_link);
1300 : mkubal 1.24 push(@$single_domain,$row->[1]);
1301 :     push(@$single_domain,$row->[2]);
1302 : arodri7 1.9 push(@$functional_data,$single_domain);
1303 :     }
1304 :    
1305 :     if ($count >0){
1306 :     $content = $functional_data;
1307 :     }
1308 :     else
1309 :     {
1310 :     $content = "<p>This PEG does not have any functional coupling</p>";
1311 :     }
1312 :     return ($content);
1313 :     }
1314 :    
1315 :    
1316 :     #########################################
1317 :     #########################################
1318 : mkubal 1.7 package Observation::Domain;
1319 :    
1320 :     use base qw(Observation);
1321 :    
1322 :     sub new {
1323 :    
1324 :     my ($class,$dataset) = @_;
1325 :     my $self = $class->SUPER::new($dataset);
1326 :     $self->{evalue} = $dataset->{'evalue'};
1327 :     $self->{acc} = $dataset->{'acc'};
1328 :     $self->{start} = $dataset->{'start'};
1329 :     $self->{stop} = $dataset->{'stop'};
1330 :    
1331 :     bless($self,$class);
1332 :     return $self;
1333 :     }
1334 :    
1335 :     sub display {
1336 :     my ($thing,$gd) = @_;
1337 :     my $lines = [];
1338 : arodri7 1.27 # my $line_config = { 'title' => $thing->acc,
1339 :     # 'short_title' => $thing->type,
1340 :     # 'basepair_offset' => '1' };
1341 : mkubal 1.7 my $color = "4";
1342 :    
1343 :     my $line_data = [];
1344 :     my $links_list = [];
1345 :     my $descriptions = [];
1346 : mkubal 1.19
1347 :     my $db_and_id = $thing->acc;
1348 :     my ($db,$id) = split("::",$db_and_id);
1349 : arodri7 1.41
1350 : paczian 1.52 my $dbmaster = DBMaster->new(-database =>'Ontology',
1351 :     -host => $WebConfig::DBHOST,
1352 :     -user => $WebConfig::DBUSER,
1353 :     -password => $WebConfig::DBPWD);
1354 : mkubal 1.7
1355 : mkubal 1.19 my ($name_title,$name_value,$description_title,$description_value);
1356 : arodri7 1.74
1357 :     if($db =~ /PFAM/){
1358 :     my $new_id;
1359 :     if ($id =~ /_/){
1360 :     ($new_id) = ($id) =~ /(.*?)_/;
1361 : mkubal 1.19 }
1362 :     else{
1363 : arodri7 1.74 $new_id = $id;
1364 : mkubal 1.19 }
1365 : arodri7 1.74
1366 : arodri7 1.50 my $pfam_objs = $dbmaster->pfam->get_objects( { 'id' => $new_id } );
1367 : arodri7 1.41 if(!scalar(@$pfam_objs)){
1368 :     $name_title = "name";
1369 :     $name_value = "not available";
1370 :     $description_title = "description";
1371 :     $description_value = "not available";
1372 :     }
1373 :     else{
1374 :     my $pfam_obj = $pfam_objs->[0];
1375 : arodri7 1.50 $name_title = "name";
1376 :     $name_value = $pfam_obj->term;
1377 : arodri7 1.41 #$description_title = "description";
1378 :     #$description_value = $pfam_obj->description;
1379 :     }
1380 :     }
1381 :    
1382 :     my $short_title = $thing->acc;
1383 :     $short_title =~ s/::/ - /ig;
1384 : arodri7 1.50 my $new_short_title=$short_title;
1385 :     if ($short_title =~ /interpro/){
1386 :     ($new_short_title) = ($short_title) =~ /(.*?)_/;
1387 :     }
1388 : arodri7 1.41 my $line_config = { 'title' => $name_value,
1389 : paczian 1.47 'hover_title', => 'Domain',
1390 : arodri7 1.50 'short_title' => $new_short_title,
1391 : arodri7 1.27 'basepair_offset' => '1' };
1392 : mkubal 1.7
1393 : mkubal 1.19 my $name;
1394 : arodri7 1.50 my ($new_id) = ($id) =~ /(.*?)_/;
1395 : arodri7 1.41 $name = {"title" => $db,
1396 : arodri7 1.50 "value" => $new_id};
1397 : mkubal 1.19 push(@$descriptions,$name);
1398 :    
1399 : arodri7 1.41 # my $description;
1400 :     # $description = {"title" => $description_title,
1401 :     # "value" => $description_value};
1402 :     # push(@$descriptions,$description);
1403 : mkubal 1.7
1404 :     my $score;
1405 :     $score = {"title" => "score",
1406 :     "value" => $thing->evalue};
1407 :     push(@$descriptions,$score);
1408 :    
1409 : arodri7 1.41 my $location;
1410 :     $location = {"title" => "location",
1411 :     "value" => $thing->start . " - " . $thing->stop};
1412 :     push(@$descriptions,$location);
1413 :    
1414 : mkubal 1.7 my $link_id;
1415 : arodri7 1.41 if ($thing->acc =~/::(.*)/){
1416 : mkubal 1.7 $link_id = $1;
1417 :     }
1418 :    
1419 :     my $link;
1420 : mkubal 1.12 my $link_url;
1421 : arodri7 1.74 # if ($thing->class eq "CDD"){$link_url = "http://0-www.ncbi.nlm.nih.gov.library.vu.edu.au:80/Structure/cdd/cddsrv.cgi?uid=$link_id"}
1422 :     if($thing->class eq "PFAM"){$link_url = "http://pfam.sanger.ac.uk/family?acc=$link_id"}
1423 : mkubal 1.12 else{$link_url = "NO_URL"}
1424 :    
1425 : mkubal 1.7 $link = {"link_title" => $thing->acc,
1426 : mkubal 1.12 "link" => $link_url};
1427 : mkubal 1.7 push(@$links_list,$link);
1428 :    
1429 :     my $element_hash = {
1430 : arodri7 1.41 "title" => $name_value,
1431 : mkubal 1.7 "start" => $thing->start,
1432 :     "end" => $thing->stop,
1433 :     "color"=> $color,
1434 :     "zlayer" => '2',
1435 :     "links_list" => $links_list,
1436 :     "description" => $descriptions};
1437 :    
1438 :     push(@$line_data,$element_hash);
1439 :     $gd->add_line($line_data, $line_config);
1440 :    
1441 :     return $gd;
1442 :    
1443 :     }
1444 : arodri7 1.28
1445 :     sub display_table {
1446 :     my ($self,$dataset) = @_;
1447 :     my $cgi = new CGI;
1448 :     my $data = [];
1449 :     my $count = 0;
1450 :     my $content;
1451 : arodri7 1.74 my $seen = {};
1452 : arodri7 1.28
1453 :     foreach my $thing (@$dataset) {
1454 :     next if ($thing->type !~ /dom/);
1455 :     my $single_domain = [];
1456 :     $count++;
1457 :    
1458 :     my $db_and_id = $thing->acc;
1459 :     my ($db,$id) = split("::",$db_and_id);
1460 :    
1461 : paczian 1.52 my $dbmaster = DBMaster->new(-database =>'Ontology',
1462 :     -host => $WebConfig::DBHOST,
1463 :     -user => $WebConfig::DBUSER,
1464 :     -password => $WebConfig::DBPWD);
1465 : arodri7 1.28
1466 :     my ($name_title,$name_value,$description_title,$description_value);
1467 : arodri7 1.74
1468 :     my $new_id;
1469 :     if($db =~ /PFAM/){
1470 :     if ($id =~ /_/){
1471 :     ($new_id) = ($id) =~ /(.*?)_/;
1472 : arodri7 1.28 }
1473 :     else{
1474 : arodri7 1.74 $new_id = $id;
1475 : arodri7 1.28 }
1476 : arodri7 1.74
1477 :     next if ($seen->{$new_id});
1478 :     $seen->{$new_id}=1;
1479 :    
1480 : arodri7 1.51 my $pfam_objs = $dbmaster->pfam->get_objects( { 'id' => $new_id } );
1481 : arodri7 1.74 # print STDERR "VALUES: " . $pfam_objs . "\n";
1482 : arodri7 1.51 if(!scalar(@$pfam_objs)){
1483 :     $name_title = "name";
1484 :     $name_value = "not available";
1485 :     $description_title = "description";
1486 :     $description_value = "not available";
1487 :     }
1488 :     else{
1489 :     my $pfam_obj = $pfam_objs->[0];
1490 :     $name_title = "name";
1491 :     $name_value = $pfam_obj->term;
1492 :     #$description_title = "description";
1493 :     #$description_value = $pfam_obj->description;
1494 :     }
1495 :     }
1496 : arodri7 1.28
1497 :     my $location = $thing->start . " - " . $thing->stop;
1498 :    
1499 :     push(@$single_domain,$db);
1500 : arodri7 1.74 push(@$single_domain,$new_id);
1501 : arodri7 1.28 push(@$single_domain,$name_value);
1502 :     push(@$single_domain,$location);
1503 :     push(@$single_domain,$thing->evalue);
1504 :     push(@$single_domain,$description_value);
1505 :     push(@$data,$single_domain);
1506 :     }
1507 :    
1508 :     if ($count >0){
1509 :     $content = $data;
1510 :     }
1511 :     else
1512 :     {
1513 :     $content = "<p>This PEG does not have any similarities to domains</p>";
1514 :     }
1515 :     }
1516 :    
1517 : mkubal 1.7
1518 : arodri7 1.10 #########################################
1519 :     #########################################
1520 : mkubal 1.12 package Observation::Location;
1521 :    
1522 :     use base qw(Observation);
1523 :    
1524 :     sub new {
1525 :    
1526 :     my ($class,$dataset) = @_;
1527 :     my $self = $class->SUPER::new($dataset);
1528 :     $self->{cleavage_prob} = $dataset->{'cleavage_prob'};
1529 :     $self->{cleavage_loc} = $dataset->{'cleavage_loc'};
1530 :     $self->{signal_peptide_score} = $dataset->{'signal_peptide_score'};
1531 :     $self->{cello_location} = $dataset->{'cello_location'};
1532 :     $self->{cello_score} = $dataset->{'cello_score'};
1533 :     $self->{tmpred_score} = $dataset->{'tmpred_score'};
1534 :     $self->{tmpred_locations} = $dataset->{'tmpred_locations'};
1535 : mkubal 1.30 $self->{phobius_signal_location} = $dataset->{'phobius_signal_location'};
1536 :     $self->{phobius_tm_locations} = $dataset->{'phobius_tm_locations'};
1537 : mkubal 1.12
1538 :     bless($self,$class);
1539 :     return $self;
1540 :     }
1541 :    
1542 : mkubal 1.36 sub display_cello {
1543 : arodri7 1.45 my ($thing) = @_;
1544 : mkubal 1.36 my $html;
1545 :     my $cello_location = $thing->cello_location;
1546 :     my $cello_score = $thing->cello_score;
1547 :     if($cello_location){
1548 : arodri7 1.40 $html .= "<p><font type=verdana size=-2>Subcellular location prediction: $cello_location, score: $cello_score</font> </p>";
1549 :     #$html .= "<p>CELLO score: $cello_score </p>";
1550 : mkubal 1.36 }
1551 :     return ($html);
1552 :     }
1553 :    
1554 : mkubal 1.12 sub display {
1555 : arodri7 1.41 my ($thing,$gd,$fig) = @_;
1556 : mkubal 1.12
1557 : mkubal 1.24 my $fid = $thing->fig_id;
1558 : arodri7 1.41 #my $fig= new FIG;
1559 : mkubal 1.12 my $length = length($fig->get_translation($fid));
1560 :    
1561 :     my $cleavage_prob;
1562 :     if($thing->cleavage_prob){$cleavage_prob = $thing->cleavage_prob;}
1563 :     my ($cleavage_loc_begin,$cleavage_loc_end) = split("-",$thing->cleavage_loc);
1564 :     my $signal_peptide_score = $thing->signal_peptide_score;
1565 :     my $cello_location = $thing->cello_location;
1566 :     my $cello_score = $thing->cello_score;
1567 :     my $tmpred_score = $thing->tmpred_score;
1568 :     my @tmpred_locations = split(",",$thing->tmpred_locations);
1569 :    
1570 : mkubal 1.30 my $phobius_signal_location = $thing->phobius_signal_location;
1571 :     my @phobius_tm_locations = split(",",$thing->phobius_tm_locations);
1572 :    
1573 : mkubal 1.12 my $lines = [];
1574 :    
1575 :     #color is
1576 : arodri7 1.28 my $color = "6";
1577 : mkubal 1.36
1578 :    
1579 : arodri7 1.28
1580 : parrello 1.70 # if($cello_location){
1581 :     # my $cello_descriptions = [];
1582 :     # my $line_data =[];
1583 :     #
1584 :     # my $line_config = { 'title' => 'Localization Evidence',
1585 :     # 'short_title' => 'CELLO',
1586 :     # 'hover_title' => 'Localization',
1587 :     # 'basepair_offset' => '1' };
1588 :     #
1589 :     # my $description_cello_location = {"title" => 'Best Cello Location',
1590 :     # "value" => $cello_location};
1591 :     #
1592 :     # push(@$cello_descriptions,$description_cello_location);
1593 :     #
1594 :     # my $description_cello_score = {"title" => 'Cello Score',
1595 :     # "value" => $cello_score};
1596 :     #
1597 :     # push(@$cello_descriptions,$description_cello_score);
1598 :     #
1599 :     # my $element_hash = {
1600 :     # "title" => "CELLO",
1601 :     # "color"=> $color,
1602 :     # "start" => "1",
1603 :     # "end" => $length + 1,
1604 :     # "zlayer" => '1',
1605 :     # "description" => $cello_descriptions};
1606 :     #
1607 :     # push(@$line_data,$element_hash);
1608 :     # $gd->add_line($line_data, $line_config);
1609 :     # }
1610 :     #
1611 :     # $color = "2";
1612 :     # if($tmpred_score){
1613 :     # my $line_data =[];
1614 :     # my $line_config = { 'title' => 'Localization Evidence',
1615 :     # 'short_title' => 'Transmembrane',
1616 :     # 'basepair_offset' => '1' };
1617 :     #
1618 :     # foreach my $tmpred (@tmpred_locations){
1619 :     # my $descriptions = [];
1620 :     # my ($begin,$end) =split("-",$tmpred);
1621 :     # my $description_tmpred_score = {"title" => 'TMPRED score',
1622 :     # "value" => $tmpred_score};
1623 :     #
1624 :     # push(@$descriptions,$description_tmpred_score);
1625 :     #
1626 :     # my $element_hash = {
1627 :     # "title" => "transmembrane location",
1628 :     # "start" => $begin + 1,
1629 :     # "end" => $end + 1,
1630 :     # "color"=> $color,
1631 :     # "zlayer" => '5',
1632 :     # "type" => 'box',
1633 :     # "description" => $descriptions};
1634 :     #
1635 :     # push(@$line_data,$element_hash);
1636 :     #
1637 :     # }
1638 :     # $gd->add_line($line_data, $line_config);
1639 :     # }
1640 : arodri7 1.28
1641 : mkubal 1.12
1642 : mkubal 1.30 if((scalar(@phobius_tm_locations) > 0) || $phobius_signal_location){
1643 :     my $line_data =[];
1644 : arodri7 1.40 my $line_config = { 'title' => 'Localization Evidence, Transmembrane and Signal Peptide',
1645 :     'short_title' => 'TM and SP',
1646 : paczian 1.48 'hover_title' => 'Localization',
1647 : mkubal 1.30 'basepair_offset' => '1' };
1648 :    
1649 :     foreach my $tm_loc (@phobius_tm_locations){
1650 :     my $descriptions = [];
1651 : arodri7 1.40 my $description_phobius_tm_locations = {"title" => 'transmembrane location',
1652 : mkubal 1.30 "value" => $tm_loc};
1653 :     push(@$descriptions,$description_phobius_tm_locations);
1654 :    
1655 :     my ($begin,$end) =split("-",$tm_loc);
1656 :    
1657 :     my $element_hash = {
1658 : arodri7 1.40 "title" => "Phobius",
1659 : mkubal 1.30 "start" => $begin + 1,
1660 :     "end" => $end + 1,
1661 :     "color"=> '6',
1662 :     "zlayer" => '4',
1663 :     "type" => 'bigbox',
1664 :     "description" => $descriptions};
1665 :    
1666 :     push(@$line_data,$element_hash);
1667 :    
1668 :     }
1669 :    
1670 :     if($phobius_signal_location){
1671 :     my $descriptions = [];
1672 :     my $description_phobius_signal_location = {"title" => 'Phobius Signal Location',
1673 :     "value" => $phobius_signal_location};
1674 :     push(@$descriptions,$description_phobius_signal_location);
1675 :    
1676 :    
1677 :     my ($begin,$end) =split("-",$phobius_signal_location);
1678 :     my $element_hash = {
1679 :     "title" => "phobius signal locations",
1680 :     "start" => $begin + 1,
1681 :     "end" => $end + 1,
1682 :     "color"=> '1',
1683 :     "zlayer" => '5',
1684 :     "type" => 'box',
1685 :     "description" => $descriptions};
1686 :     push(@$line_data,$element_hash);
1687 :     }
1688 :    
1689 :     $gd->add_line($line_data, $line_config);
1690 :     }
1691 :    
1692 : arodri7 1.28
1693 : parrello 1.70 # $color = "1";
1694 :     # if($signal_peptide_score){
1695 :     # my $line_data = [];
1696 :     # my $descriptions = [];
1697 :     #
1698 :     # my $line_config = { 'title' => 'Localization Evidence',
1699 :     # 'short_title' => 'SignalP',
1700 :     # 'hover_title' => 'Localization',
1701 :     # 'basepair_offset' => '1' };
1702 :     #
1703 :     # my $description_signal_peptide_score = {"title" => 'signal peptide score',
1704 :     # "value" => $signal_peptide_score};
1705 :     #
1706 :     # push(@$descriptions,$description_signal_peptide_score);
1707 :     #
1708 :     # my $description_cleavage_prob = {"title" => 'cleavage site probability',
1709 :     # "value" => $cleavage_prob};
1710 :     #
1711 :     # push(@$descriptions,$description_cleavage_prob);
1712 :     #
1713 :     # my $element_hash = {
1714 :     # "title" => "SignalP",
1715 :     # "start" => $cleavage_loc_begin - 2,
1716 :     # "end" => $cleavage_loc_end + 1,
1717 :     # "type" => 'bigbox',
1718 :     # "color"=> $color,
1719 :     # "zlayer" => '10',
1720 :     # "description" => $descriptions};
1721 :     #
1722 :     # push(@$line_data,$element_hash);
1723 :     # $gd->add_line($line_data, $line_config);
1724 :     # }
1725 : mkubal 1.12
1726 : arodri7 1.40
1727 : mkubal 1.12 return ($gd);
1728 :    
1729 :     }
1730 :    
1731 :     sub cleavage_loc {
1732 :     my ($self) = @_;
1733 :    
1734 :     return $self->{cleavage_loc};
1735 :     }
1736 :    
1737 :     sub cleavage_prob {
1738 :     my ($self) = @_;
1739 :    
1740 :     return $self->{cleavage_prob};
1741 :     }
1742 :    
1743 :     sub signal_peptide_score {
1744 :     my ($self) = @_;
1745 :    
1746 :     return $self->{signal_peptide_score};
1747 :     }
1748 :    
1749 :     sub tmpred_score {
1750 :     my ($self) = @_;
1751 :    
1752 :     return $self->{tmpred_score};
1753 :     }
1754 :    
1755 :     sub tmpred_locations {
1756 :     my ($self) = @_;
1757 :    
1758 :     return $self->{tmpred_locations};
1759 :     }
1760 :    
1761 :     sub cello_location {
1762 :     my ($self) = @_;
1763 :    
1764 :     return $self->{cello_location};
1765 :     }
1766 :    
1767 :     sub cello_score {
1768 :     my ($self) = @_;
1769 :    
1770 :     return $self->{cello_score};
1771 :     }
1772 :    
1773 : mkubal 1.30 sub phobius_signal_location {
1774 :     my ($self) = @_;
1775 :     return $self->{phobius_signal_location};
1776 :     }
1777 :    
1778 :     sub phobius_tm_locations {
1779 :     my ($self) = @_;
1780 :     return $self->{phobius_tm_locations};
1781 :     }
1782 :    
1783 :    
1784 : mkubal 1.12
1785 :     #########################################
1786 :     #########################################
1787 : arodri7 1.10 package Observation::Sims;
1788 :    
1789 :     use base qw(Observation);
1790 :    
1791 :     sub new {
1792 :    
1793 :     my ($class,$dataset) = @_;
1794 :     my $self = $class->SUPER::new($dataset);
1795 : arodri7 1.11 $self->{identity} = $dataset->{'identity'};
1796 : arodri7 1.10 $self->{acc} = $dataset->{'acc'};
1797 : arodri7 1.40 $self->{query} = $dataset->{'query'};
1798 : arodri7 1.10 $self->{evalue} = $dataset->{'evalue'};
1799 : arodri7 1.11 $self->{qstart} = $dataset->{'qstart'};
1800 :     $self->{qstop} = $dataset->{'qstop'};
1801 :     $self->{hstart} = $dataset->{'hstart'};
1802 :     $self->{hstop} = $dataset->{'hstop'};
1803 :     $self->{database} = $dataset->{'database'};
1804 :     $self->{organism} = $dataset->{'organism'};
1805 :     $self->{function} = $dataset->{'function'};
1806 :     $self->{qlength} = $dataset->{'qlength'};
1807 :     $self->{hlength} = $dataset->{'hlength'};
1808 : arodri7 1.10
1809 :     bless($self,$class);
1810 :     return $self;
1811 :     }
1812 :    
1813 : arodri7 1.25 =head3 display()
1814 :    
1815 :     If available use the function specified here to display a graphical observation.
1816 :     This code will display a graphical view of the similarities using the genome drawer object
1817 :    
1818 :     =cut
1819 :    
1820 :     sub display {
1821 : arodri7 1.58 my ($self,$gd,$thing,$fig,$base_start,$in_subs,$cgi) = @_;
1822 : arodri7 1.25
1823 : arodri7 1.58 # declare variables
1824 :     my $window_size = $gd->window_size;
1825 :     my $peg = $thing->acc;
1826 :     my $query_id = $thing->query;
1827 :     my $organism = $thing->organism;
1828 :     my $abbrev_name = $fig->abbrev($organism);
1829 :     if (!$organism){
1830 :     $organism = $peg;
1831 :     $abbrev_name = $peg;
1832 :     }
1833 :     my $genome = $fig->genome_of($peg);
1834 :     my ($org_tax) = ($genome) =~ /(.*)\./;
1835 :     my $function = $thing->function;
1836 :     my $query_start = $thing->qstart;
1837 :     my $query_stop = $thing->qstop;
1838 :     my $hit_start = $thing->hstart;
1839 :     my $hit_stop = $thing->hstop;
1840 :     my $ln_query = $thing->qlength;
1841 :     my $ln_hit = $thing->hlength;
1842 : paczian 1.81 my $query_color = match_color($query_start, $query_stop, abs($query_stop-$query_start)+1, 1);
1843 :     my $hit_color = match_color($hit_start, $hit_stop, abs($query_stop-$query_start)+1, 1);
1844 : arodri7 1.58
1845 :     my $tax_link = "http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=" . $org_tax;
1846 :    
1847 :     # hit sequence title
1848 :     my $line_config = { 'title' => "$organism [$org_tax]",
1849 :     'short_title' => "$abbrev_name",
1850 :     'title_link' => '$tax_link',
1851 : arodri7 1.60 'basepair_offset' => '0',
1852 :     'no_middle_line' => '1'
1853 : arodri7 1.58 };
1854 :    
1855 :     # query sequence title
1856 :     my $replace_id = $peg;
1857 :     $replace_id =~ s/\|/_/ig;
1858 :     my $anchor_name = "anchor_". $replace_id;
1859 :     my $query_config = { 'title' => "Query",
1860 :     'short_title' => "Query",
1861 :     'title_link' => "changeSimsLocation('$replace_id', 1)",
1862 : arodri7 1.60 'basepair_offset' => '0',
1863 :     'no_middle_line' => '1'
1864 : arodri7 1.58 };
1865 :     my $line_data = [];
1866 :     my $query_data = [];
1867 :    
1868 :     my $element_hash;
1869 :     my $hit_links_list = [];
1870 :     my $hit_descriptions = [];
1871 :     my $query_descriptions = [];
1872 :    
1873 :     # get sequence information
1874 :     # evidence link
1875 :     my $evidence_link;
1876 :     if ($peg =~ /^fig\|/){
1877 : arodri7 1.66 $evidence_link = "?page=Annotation&feature=".$peg;
1878 : arodri7 1.41 }
1879 : arodri7 1.58 else{
1880 :     my $db = &Observation::get_database($peg);
1881 :     my ($link_id) = ($peg) =~ /\|(.*)/;
1882 :     $evidence_link = &HTML::alias_url($link_id, $db);
1883 :     #print STDERR "LINK: $db $evidence_link";
1884 :     }
1885 :     my $link = {"link_title" => $peg,
1886 :     "link" => $evidence_link};
1887 :     push(@$hit_links_list,$link) if ($evidence_link);
1888 :    
1889 :     # subsystem link
1890 :     my $subs = $in_subs->{$peg} if (defined $in_subs->{$peg});
1891 :     my @subsystems;
1892 :     foreach my $array (@$subs){
1893 :     my $subsystem = $$array[0];
1894 :     push(@subsystems,$subsystem);
1895 :     my $link = {"link" => "?page=Subsystems&subsystem=$subsystem",
1896 :     "link_title" => $subsystem};
1897 :     push(@$hit_links_list,$link);
1898 :     }
1899 :    
1900 :     # blast alignment
1901 :     $link = {"link_title" => "view blast alignment",
1902 :     "link" => "$FIG_Config::cgi_url/seedviewer.cgi?page=ToolResult&tool=bl2seq&peg1=$query_id&peg2=$peg"};
1903 :     push (@$hit_links_list,$link) if ($peg =~ /^fig\|/);
1904 :    
1905 :     # description data
1906 :     my $description_function;
1907 :     $description_function = {"title" => "function",
1908 :     "value" => $function};
1909 :     push(@$hit_descriptions,$description_function);
1910 :    
1911 :     # subsystem description
1912 :     my $ss_string = join (",", @subsystems);
1913 :     $ss_string =~ s/_/ /ig;
1914 :     my $description_ss = {"title" => "subsystems",
1915 :     "value" => $ss_string};
1916 :     push(@$hit_descriptions,$description_ss);
1917 :    
1918 :     # location description
1919 :     # hit
1920 :     my $description_loc;
1921 :     $description_loc = {"title" => "Hit Location",
1922 :     "value" => $hit_start . " - " . $hit_stop};
1923 :     push(@$hit_descriptions, $description_loc);
1924 :    
1925 :     $description_loc = {"title" => "Sequence Length",
1926 :     "value" => $ln_hit};
1927 :     push(@$hit_descriptions, $description_loc);
1928 :    
1929 :     # query
1930 :     $description_loc = {"title" => "Hit Location",
1931 :     "value" => $query_start . " - " . $query_stop};
1932 :     push(@$query_descriptions, $description_loc);
1933 :    
1934 :     $description_loc = {"title" => "Sequence Length",
1935 :     "value" => $ln_query};
1936 :     push(@$query_descriptions, $description_loc);
1937 :    
1938 :    
1939 :    
1940 :     # evalue score description
1941 :     my $evalue = $thing->evalue;
1942 :     while ($evalue =~ /-0/)
1943 :     {
1944 :     my ($chunk1, $chunk2) = split(/-/, $evalue);
1945 :     $chunk2 = substr($chunk2,1);
1946 :     $evalue = $chunk1 . "-" . $chunk2;
1947 :     }
1948 :    
1949 :     my $color = &color($evalue);
1950 :     my $description_eval = {"title" => "E-Value",
1951 :     "value" => $evalue};
1952 :     push(@$hit_descriptions, $description_eval);
1953 :     push(@$query_descriptions, $description_eval);
1954 :    
1955 :     my $identity = $self->identity;
1956 :     my $description_identity = {"title" => "Identity",
1957 :     "value" => $identity};
1958 :     push(@$hit_descriptions, $description_identity);
1959 :     push(@$query_descriptions, $description_identity);
1960 :    
1961 :    
1962 :     my $number = $base_start + ($query_start-$hit_start);
1963 :     #print STDERR "START: $number";
1964 :     $element_hash = {
1965 :     "title" => $query_id,
1966 :     "start" => $base_start,
1967 :     "end" => $base_start+$ln_query,
1968 :     "type"=> 'box',
1969 :     "color"=> $color,
1970 :     "zlayer" => "2",
1971 :     "links_list" => $query_links_list,
1972 :     "description" => $query_descriptions
1973 :     };
1974 :     push(@$query_data,$element_hash);
1975 :    
1976 :     $element_hash = {
1977 :     "title" => $query_id . ': HIT AREA',
1978 :     "start" => $base_start + $query_start,
1979 :     "end" => $base_start + $query_stop,
1980 :     "type"=> 'smallbox',
1981 :     "color"=> $query_color,
1982 :     "zlayer" => "3",
1983 :     "links_list" => $query_links_list,
1984 :     "description" => $query_descriptions
1985 :     };
1986 :     push(@$query_data,$element_hash);
1987 :    
1988 :     $gd->add_line($query_data, $query_config);
1989 : arodri7 1.25
1990 : arodri7 1.41
1991 : arodri7 1.58 $element_hash = {
1992 : arodri7 1.41 "title" => $peg,
1993 : arodri7 1.58 "start" => $base_start + ($query_start-$hit_start),
1994 :     "end" => $base_start + (($query_start-$hit_start)+$ln_hit),
1995 : arodri7 1.41 "type"=> 'box',
1996 :     "color"=> $color,
1997 :     "zlayer" => "2",
1998 : arodri7 1.58 "links_list" => $hit_links_list,
1999 :     "description" => $hit_descriptions
2000 : arodri7 1.41 };
2001 : arodri7 1.58 push(@$line_data,$element_hash);
2002 :    
2003 :     $element_hash = {
2004 :     "title" => $peg . ': HIT AREA',
2005 :     "start" => $base_start + $query_start,
2006 :     "end" => $base_start + $query_stop,
2007 :     "type"=> 'smallbox',
2008 :     "color"=> $hit_color,
2009 :     "zlayer" => "3",
2010 :     "links_list" => $hit_links_list,
2011 :     "description" => $hit_descriptions
2012 :     };
2013 :     push(@$line_data,$element_hash);
2014 :    
2015 :     $gd->add_line($line_data, $line_config);
2016 :    
2017 :     my $breaker = [];
2018 :     my $breaker_hash = {};
2019 :     my $breaker_config = { 'no_middle_line' => "1" };
2020 :    
2021 :     push (@$breaker, $breaker_hash);
2022 :     $gd->add_line($breaker, $breaker_config);
2023 :    
2024 : arodri7 1.25 return ($gd);
2025 :     }
2026 :    
2027 : mkubal 1.34 =head3 display_domain_composition()
2028 :    
2029 :     If available use the function specified here to display a graphical observation of the CDD(later Pfam or selected) domains that occur in the set of similar proteins
2030 :    
2031 :     =cut
2032 :    
2033 :     sub display_domain_composition {
2034 : arodri7 1.41 my ($self,$gd,$fig) = @_;
2035 : mkubal 1.34
2036 : arodri7 1.45 #$fig = new FIG;
2037 : mkubal 1.34 my $peg = $self->acc;
2038 :    
2039 :     my $line_data = [];
2040 :     my $links_list = [];
2041 :     my $descriptions = [];
2042 :    
2043 :     my @domain_query_results =$fig->get_attributes($peg,"CDD");
2044 : arodri7 1.45 #my @domain_query_results = ();
2045 : mkubal 1.34 foreach $dqr (@domain_query_results){
2046 :     my $key = @$dqr[1];
2047 :     my @parts = split("::",$key);
2048 :     my $db = $parts[0];
2049 :     my $id = $parts[1];
2050 :     my $val = @$dqr[2];
2051 :     my $from;
2052 :     my $to;
2053 :     my $evalue;
2054 :    
2055 :     if($val =~/^(\d+\.\d+|0\.0);(\d+)-(\d+)/){
2056 :     my $raw_evalue = $1;
2057 :     $from = $2;
2058 :     $to = $3;
2059 :     if($raw_evalue =~/(\d+)\.(\d+)/){
2060 :     my $part2 = 1000 - $1;
2061 :     my $part1 = $2/100;
2062 :     $evalue = $part1."e-".$part2;
2063 :     }
2064 :     else{
2065 :     $evalue = "0.0";
2066 :     }
2067 :     }
2068 :    
2069 : paczian 1.52 my $dbmaster = DBMaster->new(-database =>'Ontology',
2070 :     -host => $WebConfig::DBHOST,
2071 :     -user => $WebConfig::DBUSER,
2072 :     -password => $WebConfig::DBPWD);
2073 : mkubal 1.34 my ($name_value,$description_value);
2074 :    
2075 :     if($db eq "CDD"){
2076 :     my $cdd_objs = $dbmaster->cdd->get_objects( { 'id' => $id } );
2077 :     if(!scalar(@$cdd_objs)){
2078 :     $name_title = "name";
2079 :     $name_value = "not available";
2080 :     $description_title = "description";
2081 :     $description_value = "not available";
2082 :     }
2083 :     else{
2084 :     my $cdd_obj = $cdd_objs->[0];
2085 :     $name_value = $cdd_obj->term;
2086 :     $description_value = $cdd_obj->description;
2087 :     }
2088 :     }
2089 :    
2090 :     my $domain_name;
2091 :     $domain_name = {"title" => "name",
2092 : arodri7 1.45 "value" => $name_value};
2093 : mkubal 1.34 push(@$descriptions,$domain_name);
2094 :    
2095 :     my $description;
2096 :     $description = {"title" => "description",
2097 :     "value" => $description_value};
2098 :     push(@$descriptions,$description);
2099 :    
2100 :     my $score;
2101 :     $score = {"title" => "score",
2102 :     "value" => $evalue};
2103 :     push(@$descriptions,$score);
2104 :    
2105 :     my $link_id = $id;
2106 :     my $link;
2107 :     my $link_url;
2108 :     if ($db eq "CDD"){$link_url = "http://0-www.ncbi.nlm.nih.gov.library.vu.edu.au:80/Structure/cdd/cddsrv.cgi?uid=$link_id"}
2109 : arodri7 1.53 elsif($db eq "PFAM"){$link_url = "http://pfam.sanger.ac.uk/family?acc=$link_id"}
2110 : mkubal 1.34 else{$link_url = "NO_URL"}
2111 :    
2112 :     $link = {"link_title" => $name_value,
2113 :     "link" => $link_url};
2114 :     push(@$links_list,$link);
2115 :    
2116 :     my $domain_element_hash = {
2117 :     "title" => $peg,
2118 :     "start" => $from,
2119 :     "end" => $to,
2120 :     "type"=> 'box',
2121 :     "zlayer" => '4',
2122 :     "links_list" => $links_list,
2123 :     "description" => $descriptions
2124 :     };
2125 :    
2126 :     push(@$line_data,$domain_element_hash);
2127 :    
2128 :     #just one CDD domain for now, later will add option for multiple domains from selected DB
2129 :     last;
2130 :     }
2131 :    
2132 :     my $line_config = { 'title' => $peg,
2133 : paczian 1.47 'hover_title' => 'Domain',
2134 : mkubal 1.34 'short_title' => $peg,
2135 :     'basepair_offset' => '1' };
2136 : arodri7 1.45
2137 : mkubal 1.34 $gd->add_line($line_data, $line_config);
2138 :    
2139 :     return ($gd);
2140 :    
2141 :     }
2142 :    
2143 : mkubal 1.24 =head3 display_table()
2144 : arodri7 1.10
2145 :     If available use the function specified here to display the "raw" observation.
2146 :     This code will display a table for the similarities protein
2147 :    
2148 :     B<Please note> that URL linked to in display_method() is an external component and needs to added to the code for every class of evidence.
2149 :    
2150 :     =cut
2151 :    
2152 : mkubal 1.24 sub display_table {
2153 : arodri7 1.60 my ($self,$dataset, $show_columns, $query_fid, $fig, $application, $cgi) = @_;
2154 :     my ($count, $data, $content, %box_column, $subsystems_column, $evidence_column, %e_identical, $function_color, @ids);
2155 :    
2156 :     my $scroll_list;
2157 :     foreach my $col (@$show_columns){
2158 :     push (@$scroll_list, $col->{key});
2159 :     }
2160 : arodri7 1.53
2161 : arodri7 1.60 push (@ids, $query_fid);
2162 : arodri7 1.10 foreach my $thing (@$dataset) {
2163 : arodri7 1.28 next if ($thing->class ne "SIM");
2164 :     push (@ids, $thing->acc);
2165 :     }
2166 :    
2167 : arodri7 1.60 $lineages = $fig->taxonomy_list() if (grep /lineage/, @$scroll_list);
2168 :     my @attributes = $fig->get_attributes(\@ids) if ( (grep /evidence/, @$scroll_list) || (grep /(pfam|mw)/, @$scroll_list) );
2169 : arodri7 1.35
2170 :     # get the column for the subsystems
2171 : arodri7 1.69 $subsystems_column = &get_subsystems_column(\@ids,$fig,$cgi,'hash');
2172 : arodri7 1.35
2173 :     # get the column for the evidence codes
2174 : arodri7 1.69 $evidence_column = &get_evidence_column(\@ids, \@attributes, $fig, $cgi, 'hash');
2175 : arodri7 1.35
2176 :     # get the column for pfam_domain
2177 : arodri7 1.60 $pfam_column = &get_attrb_column(\@ids, \@attributes, $fig, $cgi, 'pfam', 'PFAM', 'hash') if (grep /^pfam$/, @$scroll_list);
2178 :    
2179 :     # get the column for molecular weight
2180 :     $mw_column = &get_attrb_column(\@ids, \@attributes, $fig, $cgi, 'mw', 'molecular_weight', 'hash') if (grep /^mw$/, @$scroll_list);
2181 :    
2182 :     # get the column for organism's habitat
2183 :     my $habitat_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'habitat', 'Habitat', 'hash') if (grep /^habitat$/, @$scroll_list);
2184 :    
2185 :     # get the column for organism's temperature optimum
2186 :     my $temperature_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'temperature', 'Optimal_Temperature', 'hash') if (grep /^temperature$/, @$scroll_list);
2187 : arodri7 1.41
2188 : arodri7 1.60 # get the column for organism's temperature range
2189 :     my $temperature_range_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'temp_range', 'Temperature_Range', 'hash') if (grep /^temp_range$/, @$scroll_list);
2190 :    
2191 :     # get the column for organism's oxygen requirement
2192 :     my $oxygen_req_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'oxygen', 'Oxygen_Requirement', 'hash') if (grep /^oxygen$/, @$scroll_list);
2193 :    
2194 :     # get the column for organism's pathogenicity
2195 :     my $pathogenic_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'pathogenic', 'Pathogenic', 'hash') if (grep /^pathogenic$/, @$scroll_list);
2196 :    
2197 :     # get the column for organism's pathogenicity host
2198 :     my $pathogenic_in_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'pathogenic_in', 'Pathogenic_In', 'hash') if (grep /^pathogenic_in$/, @$scroll_list);
2199 :    
2200 :     # get the column for organism's salinity
2201 :     my $salinity_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'salinity', 'Salinity', 'hash') if (grep /^salinity$/, @$scroll_list);
2202 :    
2203 :     # get the column for organism's motility
2204 :     my $motility_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'motility', 'Motility', 'hash') if (grep /^motility$/, @$scroll_list);
2205 :    
2206 :     # get the column for organism's gram stain
2207 :     my $gram_stain_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'gram_stain', 'Gram_Stain', 'hash') if (grep /^gram_stain$/, @$scroll_list);
2208 :    
2209 :     # get the column for organism's endospores
2210 :     my $endospores_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'endospores', 'Endospores', 'hash') if (grep /^endospores$/, @$scroll_list);
2211 :    
2212 :     # get the column for organism's shape
2213 :     my $shape_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'shape', 'Shape', 'hash') if (grep /^shape$/, @$scroll_list);
2214 :    
2215 :     # get the column for organism's disease
2216 :     my $disease_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'disease', 'Disease', 'hash') if (grep /^disease$/, @$scroll_list);
2217 :    
2218 :     # get the column for organism's disease
2219 :     my $gc_content_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'gc_content', 'GC_Content', 'hash') if (grep /^gc_content$/, @$scroll_list);
2220 :    
2221 :     # get the column for transmembrane domains
2222 :     my $transmembrane_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'transmembrane', 'Phobius::transmembrane', 'hash') if (grep /^transmembrane$/, @$scroll_list);
2223 :    
2224 :     # get the column for similar to human
2225 :     my $similar_to_human_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'similar_to_human', 'similar_to_human', 'hash') if (grep /^similar_to_human$/, @$scroll_list);
2226 :    
2227 :     # get the column for signal peptide
2228 :     my $signal_peptide_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'signal_peptide', 'Phobius::signal', 'hash') if (grep /^signal_peptide$/, @$scroll_list);
2229 :    
2230 :     # get the column for transmembrane domains
2231 :     my $isoelectric_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'isoelectric', 'isoelectric_point', 'hash') if (grep /^isoelectric$/, @$scroll_list);
2232 :    
2233 :     # get the column for conserved neighborhood
2234 :     my $cons_neigh_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'conserved_neighborhood', undef, 'hash') if (grep /^conserved_neighborhood$/, @$scroll_list);
2235 :    
2236 :     # get the column for cellular location
2237 :     my $cell_location_column = &get_attrb_column(\@ids, undef, $fig, $cgi, 'cellular_location', 'PSORT::', 'hash') if (grep /^isoelectric$/, @$scroll_list);
2238 :    
2239 :     # get the aliases
2240 :     my $alias_col;
2241 :     if ( (grep /asap_id/, @$scroll_list) || (grep /ncbi_id/, @$scroll_list) ||
2242 :     (grep /refseq_id/, @$scroll_list) || (grep /swissprot_id/, @$scroll_list) ||
2243 :     (grep /uniprot_id/, @$scroll_list) || (grep /tigr_id/, @$scroll_list) ||
2244 :     (grep /kegg_id/, @$scroll_list) || (grep /pir_id/, @$scroll_list) ||
2245 :     (grep /trembl_id/, @$scroll_list) || (grep /jgi_id/, @$scroll_list) ) {
2246 :     $alias_col = &get_db_aliases(\@ids,$fig,'all',$cgi,'hash');
2247 :     }
2248 :    
2249 : arodri7 1.58 # get the colors for the function cell
2250 :     my $functions = $fig->function_of_bulk(\@ids,1);
2251 : arodri7 1.60 $functional_color = &get_function_color_cell($functions, $fig);
2252 : arodri7 1.58 my $query_function = $fig->function_of($query_fid);
2253 :    
2254 : arodri7 1.60 my %e_identical = &get_essentially_identical($query_fid,$dataset,$fig);
2255 : arodri7 1.31
2256 : olson 1.57 my $figfam_data = &FIG::get_figfams_data();
2257 : arodri7 1.55 my $figfams = new FFs($figfam_data);
2258 : arodri7 1.66 my $same_genome_flag = 0;
2259 : arodri7 1.53
2260 : arodri7 1.58 my $func_color_offset=0;
2261 : arodri7 1.60 unshift(@$dataset, $query_fid);
2262 : arodri7 1.66 for (my $thing_count=0;$thing_count<scalar @$dataset;$thing_count++){
2263 :     # foreach my $thing ( @$dataset){
2264 :     my $thing = $dataset->[$thing_count];
2265 :     my $next_thing = $dataset->[$thing_count+1] if (defined $dataset->[$thing_count+1]);
2266 :     my ($id, $taxid, $iden, $ln1,$ln2,$b1,$b2,$e1,$e2,$d1,$d2,$color1,$color2,$reg1,$reg2, $next_org);
2267 : arodri7 1.60 if ($thing eq $query_fid){
2268 :     $id = $thing;
2269 :     $taxid = $fig->genome_of($id);
2270 :     $organism = $fig->genus_species($taxid);
2271 :     $current_function = $fig->function_of($id);
2272 :     }
2273 :     else{
2274 :     next if ($thing->class ne "SIM");
2275 :    
2276 :     $id = $thing->acc;
2277 :     $evalue = $thing->evalue;
2278 :     $taxid = $fig->genome_of($id);
2279 :     $iden = $thing->identity;
2280 :     $organism= $thing->organism;
2281 :     $ln1 = $thing->qlength;
2282 : paczian 1.82 if ($ln1 < 1) { $ln1 = 1; }
2283 : arodri7 1.60 $ln2 = $thing->hlength;
2284 : paczian 1.82 if ($ln2 < 1) { $ln2 = 1; }
2285 : arodri7 1.60 $b1 = $thing->qstart;
2286 :     $e1 = $thing->qstop;
2287 :     $b2 = $thing->hstart;
2288 :     $e2 = $thing->hstop;
2289 :     $d1 = abs($e1 - $b1) + 1;
2290 :     $d2 = abs($e2 - $b2) + 1;
2291 :     $color1 = match_color( $b1, $e1, $ln1 );
2292 :     $color2 = match_color( $b2, $e2, $ln2 );
2293 :     $reg1 = {'data'=> "$b1-$e1 (<b>$d1/$ln1</b>)", 'highlight' => $color1};
2294 :     $reg2 = {'data'=> "$b2-$e2 (<b>$d2/$ln2</b>)", 'highlight' => $color2};
2295 :     $current_function = $thing->function;
2296 : arodri7 1.66 $next_org = $next_thing->organism if (defined $next_thing);
2297 : arodri7 1.60 }
2298 :    
2299 : arodri7 1.77 next if ($id =~ /nmpdr\||gnl\|md5\|/);
2300 :    
2301 : arodri7 1.10 my $single_domain = [];
2302 :     $count++;
2303 :    
2304 : arodri7 1.58 # organisms cell
2305 :     my ($org, $org_color) = $fig->org_and_color_of($id);
2306 : arodri7 1.66
2307 :     my $org_cell;
2308 :     if ( ($next_org ne $organism) && ($same_genome_flag == 0) ){
2309 :     $org_cell = { 'data' => $organism, 'highlight' => $org_color};
2310 :     }
2311 :     elsif ($next_org eq $organism){
2312 :     $org_cell = { 'data' => "<b>" . $organism . "</b>", 'highlight' => $org_color};
2313 :     $same_genome_flag = 1;
2314 :     }
2315 :     elsif ($same_genome_flag == 1){
2316 :     $org_cell = { 'data' => "<b>" . $organism . "</b>", 'highlight' => $org_color};
2317 :     $same_genome_flag = 0;
2318 :     }
2319 : arodri7 1.11
2320 : arodri7 1.58 # checkbox cell
2321 : arodri7 1.60 my ($box_cell,$tax, $radio_cell);
2322 : arodri7 1.29 my $field_name = "tables_" . $id;
2323 : arodri7 1.58 my $pair_name = "visual_" . $id;
2324 :     my $cell_name = "cell_". $id;
2325 :     my $replace_id = $id;
2326 :     $replace_id =~ s/\|/_/ig;
2327 : arodri7 1.60 my $white = '#ffffff';
2328 :     $white = '#999966' if ($id eq $query_fid);
2329 :     $org_color = '#999966' if ($id eq $query_fid);
2330 : arodri7 1.58 my $anchor_name = "anchor_". $replace_id;
2331 : arodri7 1.66 my $checked = "";
2332 :     #$checked = "checked" if ($id eq $query_fid);
2333 : arodri7 1.77 # if ($id =~ /^fig\|/){
2334 : arodri7 1.66 my $box = qq~<a name="$anchor_name"></a><input type="checkbox" name="seq" value="$id" id="$field_name" onClick="VisualCheckPair('$field_name', '$pair_name','$cell_name');" $checked>~;
2335 : arodri7 1.58 $box_cell = { 'data'=>$box, 'highlight'=>$org_color};
2336 : arodri7 1.77 $tax = $fig->genome_of($id) if ($id =~ /^fig\|/);
2337 :     # }
2338 :     # else{
2339 :     # my $box = qq(<a name="$anchor_name"></a>);
2340 :     # $box_cell = { 'data'=>$box, 'highlight'=>$org_color};
2341 :     # }
2342 : arodri7 1.58
2343 : arodri7 1.68 # create the radio cell for any sequence, not just fig ids
2344 : arodri7 1.72 my $radio = qq(<input type="radio" name="function_select" value="$current_function" id="$field_name" onClick="clearText('new_text_function')">);
2345 : arodri7 1.68 $radio_cell = { 'data'=>$radio, 'highlight'=>$white};
2346 :    
2347 : arodri7 1.31 # get the linked fig id
2348 : arodri7 1.58 my $anchor_link = "graph_" . $replace_id;
2349 : arodri7 1.76
2350 :     my $fig_data;
2351 :     if ($id =~ /^fig\|/)
2352 :     {
2353 :     $fig_data = "<table><tr><td><a href='?page=Annotation&feature=$id'>$id</a></td>" . "&nbsp;" x 2;
2354 :     }
2355 :     else
2356 :     {
2357 :     my $url_link = &HTML::set_prot_links($cgi,$id);
2358 :     $fig_data = "<table><tr><td>$url_link</td>". "&nbsp;" x 2;
2359 :     }
2360 : parrello 1.70 $fig_data .= qq(<td><img height='10px' width='20px' src='$FIG_Config::cgi_url/Html/anchor_alignment.png' alt='View Graphic View of Alignment' onClick='changeSimsLocation("$anchor_link", 0)'/></td></tr></table>);
2361 : arodri7 1.58 my $fig_col = {'data'=> $fig_data,
2362 : arodri7 1.60 'highlight'=>$white};
2363 :    
2364 :     $replace_id = $peg;
2365 :     $replace_id =~ s/\|/_/ig;
2366 :     $anchor_name = "anchor_". $replace_id;
2367 :     my $query_config = { 'title' => "Query",
2368 :     'short_title' => "Query",
2369 :     'title_link' => "changeSimsLocation('$replace_id')",
2370 :     'basepair_offset' => '0'
2371 :     };
2372 : arodri7 1.58
2373 :     # function cell
2374 :     my $function_cell_colors = {0=>"#ffffff", 1=>"#eeccaa", 2=>"#ffaaaa",
2375 :     3=>"#ffcc66", 4=>"#ffff00", 5=>"#aaffaa",
2376 :     6=>"#bbbbff", 7=>"#ffaaff", 8=>"#dddddd"};
2377 : arodri7 1.60
2378 :     my $function_color;
2379 :     if ( (defined($functional_color->{$query_function})) && ($functional_color->{$query_function} == 1) ){
2380 :     $function_color = $function_cell_colors->{ $functional_color->{$current_function} - $func_color_offset};
2381 :     }
2382 :     else{
2383 :     $function_color = $function_cell_colors->{ $functional_color->{$current_function}};
2384 :     }
2385 : arodri7 1.58 my $function_cell;
2386 :     if ($current_function){
2387 :     if ($current_function eq $query_function){
2388 :     $function_cell = {'data'=>$current_function, 'highlight'=>$function_cell_colors->{0}};
2389 :     $func_color_offset=1;
2390 :     }
2391 :     else{
2392 : arodri7 1.60 $function_cell = {'data'=>$current_function,'highlight' => $function_color};
2393 : arodri7 1.58 }
2394 : arodri7 1.31 }
2395 : arodri7 1.58 else{
2396 :     $function_cell = {'data'=>$current_function,'highlight' => "#dddddd"};
2397 : arodri7 1.28 }
2398 : arodri7 1.58
2399 : arodri7 1.60 if ($id eq $query_fid){
2400 :     push (@$single_domain, $box_cell, {'data'=>qq~<i>Query Sequence: </i>~ . qq~<b>$id</b>~ , 'highlight'=>$white}, {'data'=> 'n/a', 'highlight'=>$white},
2401 :     {'data'=>'n/a', 'highlight'=>$white}, {'data'=>'n/a', 'highlight'=>$white}, {'data'=>'n/a', 'highlight'=>$white},
2402 : arodri7 1.69 {'data' => $organism, 'highlight'=> $white}, {'data'=>$current_function, 'highlight'=>$white},
2403 :     {'data'=>$subsystems_column->{$id},'highlight'=>$white},
2404 :     {'data'=>$evidence_column->{$id},'highlight'=>$white}); # permanent columns
2405 : arodri7 1.60 }
2406 :     else{
2407 :     push (@$single_domain, $box_cell, $fig_col, {'data'=> $evalue, 'highlight'=>"#ffffff"},
2408 : arodri7 1.69 {'data'=>"$iden\%", 'highlight'=>"#ffffff"}, $reg1, $reg2, $org_cell, $function_cell,
2409 :     {'data'=>$subsystems_column->{$id},'highlight'=>"#ffffff"},
2410 :     {'data'=>$evidence_column->{$id},'highlight'=>"#ffffff"}); # permanent columns
2411 :    
2412 : arodri7 1.60 }
2413 :    
2414 :     if ( ( $application->session->user) ){
2415 : paczian 1.64 my $user = $application->session->user;
2416 : paczian 1.79 if ($user && $user->has_right(undef, 'annotate', 'genome')) {
2417 : arodri7 1.60 push (@$single_domain,$radio_cell);
2418 : paczian 1.64 }
2419 : arodri7 1.60 }
2420 :    
2421 : arodri7 1.55 my ($ff) = $figfams->families_containing_peg($id);
2422 :    
2423 : arodri7 1.60 foreach my $col (@$scroll_list){
2424 :     if ($id eq $query_fid) { $highlight_color = "#999966"; }
2425 :     else { $highlight_color = "#ffffff"; }
2426 :    
2427 : arodri7 1.69 if ($col =~ /pfam/) {push(@$single_domain,{'data'=>$pfam_column->{$id},'highlight'=>$highlight_color});}
2428 : arodri7 1.60 elsif ($col =~ /mw/) {push(@$single_domain,{'data'=>$mw_column->{$id},'highlight'=>$highlight_color});}
2429 :     elsif ($col =~ /habitat/) {push(@$single_domain,{'data'=>$habitat_column->{$id},'highlight'=>$highlight_color});}
2430 :     elsif ($col =~ /temperature/) {push(@$single_domain,{'data'=>$temperature_column->{$id},'highlight'=>$highlight_color});}
2431 :     elsif ($col =~ /temp_range/) {push(@$single_domain,{'data'=>$temperature_range_column->{$id},'highlight'=>$highlight_color});}
2432 :     elsif ($col =~ /oxygen/) {push(@$single_domain,{'data'=>$oxygen_req_column->{$id},'highlight'=>$highlight_color});}
2433 :     elsif ($col =~ /^pathogenic$/) {push(@$single_domain,{'data'=>$pathogenic_column->{$id},'highlight'=>$highlight_color});}
2434 :     elsif ($col =~ /^pathogenic_in$/) {push(@$single_domain,{'data'=>$pathogenic_in_column->{$id},'highlight'=>$highlight_color});}
2435 :     elsif ($col =~ /salinity/) {push(@$single_domain,{'data'=>$salinity_column->{$id},'highlight'=>$highlight_color});}
2436 :     elsif ($col =~ /motility/) {push(@$single_domain,{'data'=>$motility_column->{$id},'highlight'=>$highlight_color});}
2437 :     elsif ($col =~ /gram_stain/) {push(@$single_domain,{'data'=>$gram_stain_column->{$id},'highlight'=>$highlight_color});}
2438 :     elsif ($col =~ /endospores/) {push(@$single_domain,{'data'=>$endospores_column->{$id},'highlight'=>$highlight_color});}
2439 :     elsif ($col =~ /shape/) {push(@$single_domain,{'data'=>$shape_column->{$id},'highlight'=>$highlight_color});}
2440 :     elsif ($col =~ /disease/) {push(@$single_domain,{'data'=>$disease_column->{$id},'highlight'=>$highlight_color});}
2441 :     elsif ($col =~ /gc_content/) {push(@$single_domain,{'data'=>$gc_content_column->{$id},'highlight'=>$highlight_color});}
2442 :     elsif ($col =~ /transmembrane/) {push(@$single_domain,{'data'=>$transmembrane_column->{$id},'highlight'=>$highlight_color});}
2443 :     elsif ($col =~ /signal_peptide/) {push(@$single_domain,{'data'=>$signal_peptide_column->{$id},'highlight'=>$highlight_color});}
2444 :     elsif ($col =~ /isoelectric/) {push(@$single_domain,{'data'=>$isoelectric_column->{$id},'highlight'=>$highlight_color});}
2445 : arodri7 1.66 elsif ($col =~ /conerved_neighborhood/) {push(@$single_domain,{'data'=>$cons_neigh_column->{$id},'highlight'=>$highlight_color});}
2446 : arodri7 1.60 elsif ($col =~ /cellular_location/) {push(@$single_domain,{'data'=>$cell_location_column->{$id},'highlight'=>$highlight_color});}
2447 :     elsif ($col =~ /ncbi_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"NCBI"},'highlight'=>$highlight_color});}
2448 :     elsif ($col =~ /refseq_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"RefSeq"},'highlight'=>$highlight_color});}
2449 :     elsif ($col =~ /swissprot_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"SwissProt"},'highlight'=>$highlight_color});}
2450 :     elsif ($col =~ /uniprot_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"UniProt"},'highlight'=>$highlight_color});}
2451 :     elsif ($col =~ /tigr_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"TIGR"},'highlight'=>$highlight_color});}
2452 :     elsif ($col =~ /pir_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"PIR"},'highlight'=>$highlight_color});}
2453 :     elsif ($col =~ /kegg_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"KEGG"},'highlight'=>$highlight_color});}
2454 :     elsif ($col =~ /trembl_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"TrEMBL"},'highlight'=>$highlight_color});}
2455 :     elsif ($col =~ /asap_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"ASAP"},'highlight'=>$highlight_color});}
2456 :     elsif ($col =~ /jgi_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"JGI"},'highlight'=>$highlight_color});}
2457 :     elsif ($col =~ /lineage/) {push(@$single_domain,{'data'=>$lineages->{$tax},'highlight'=>$highlight_color});}
2458 :     elsif ($col =~ /figfam/) {push(@$single_domain,{'data'=>"<a href='?page=FigFamViewer&figfam=" . $ff . "' target='_new'>" . $ff . "</a>",'highlight'=>$highlight_color});}
2459 : arodri7 1.32 }
2460 : arodri7 1.10 push(@$data,$single_domain);
2461 :     }
2462 : arodri7 1.26 if ($count >0 ){
2463 :     $content = $data;
2464 : arodri7 1.10 }
2465 : arodri7 1.26 else{
2466 : arodri7 1.10 $content = "<p>This PEG does not have any similarities</p>";
2467 :     }
2468 : arodri7 1.60 shift(@$dataset);
2469 : arodri7 1.10 return ($content);
2470 :     }
2471 : arodri7 1.11
2472 : arodri7 1.69
2473 :     =head3 display_figfam_table()
2474 :    
2475 :     If available use the function specified here to display the "raw" observation.
2476 :     This code will display a table for the similarities protein
2477 :    
2478 :     B<Please note> that URL linked to in display_method() is an external component and needs to added to the code for every class of evidence.
2479 :    
2480 :     =cut
2481 :    
2482 :     sub display_figfam_table {
2483 :     my ($self,$ids, $show_columns, $fig, $application, $cgi) = @_;
2484 :     my ($count, $data, $content, %box_column, $subsystems_column, $evidence_column, %e_identical, $function_color, @ids);
2485 :    
2486 :     my $scroll_list;
2487 :     foreach my $col (@$show_columns){
2488 :     push (@$scroll_list, $col->{key});
2489 :     }
2490 :    
2491 :     $lineages = $fig->taxonomy_list() if (grep /lineage/, @$scroll_list);
2492 :     my @attributes = $fig->get_attributes($ids) if ( (grep /evidence/, @$scroll_list) || (grep /(pfam|mw)/, @$scroll_list) );
2493 :    
2494 :     # get the column for the subsystems
2495 :     $subsystems_column = &get_subsystems_column($ids,$fig,$cgi,'hash');
2496 :    
2497 :     # get the column for the evidence codes
2498 :     $evidence_column = &get_evidence_column($ids, \@attributes, $fig, $cgi, 'hash') if (grep /^evidence$/, @$scroll_list);
2499 :    
2500 :     # get the column for pfam_domain
2501 :     $pfam_column = &get_attrb_column($ids, \@attributes, $fig, $cgi, 'pfam', 'PFAM', 'hash') if (grep /^pfam$/, @$scroll_list);
2502 :    
2503 :     # get the column for molecular weight
2504 :     $mw_column = &get_attrb_column($ids, \@attributes, $fig, $cgi, 'mw', 'molecular_weight', 'hash') if (grep /^mw$/, @$scroll_list);
2505 :    
2506 :     # get the column for organism's habitat
2507 :     my $habitat_column = &get_attrb_column($ids, undef, $fig, $cgi, 'habitat', 'Habitat', 'hash') if (grep /^habitat$/, @$scroll_list);
2508 :    
2509 :     # get the column for organism's temperature optimum
2510 :     my $temperature_column = &get_attrb_column($ids, undef, $fig, $cgi, 'temperature', 'Optimal_Temperature', 'hash') if (grep /^temperature$/, @$scroll_list);
2511 :    
2512 :     # get the column for organism's temperature range
2513 :     my $temperature_range_column = &get_attrb_column($ids, undef, $fig, $cgi, 'temp_range', 'Temperature_Range', 'hash') if (grep /^temp_range$/, @$scroll_list);
2514 :    
2515 :     # get the column for organism's oxygen requirement
2516 :     my $oxygen_req_column = &get_attrb_column($ids, undef, $fig, $cgi, 'oxygen', 'Oxygen_Requirement', 'hash') if (grep /^oxygen$/, @$scroll_list);
2517 :    
2518 :     # get the column for organism's pathogenicity
2519 :     my $pathogenic_column = &get_attrb_column($ids, undef, $fig, $cgi, 'pathogenic', 'Pathogenic', 'hash') if (grep /^pathogenic$/, @$scroll_list);
2520 :    
2521 :     # get the column for organism's pathogenicity host
2522 :     my $pathogenic_in_column = &get_attrb_column($ids, undef, $fig, $cgi, 'pathogenic_in', 'Pathogenic_In', 'hash') if (grep /^pathogenic_in$/, @$scroll_list);
2523 :    
2524 :     # get the column for organism's salinity
2525 :     my $salinity_column = &get_attrb_column($ids, undef, $fig, $cgi, 'salinity', 'Salinity', 'hash') if (grep /^salinity$/, @$scroll_list);
2526 :    
2527 :     # get the column for organism's motility
2528 :     my $motility_column = &get_attrb_column($ids, undef, $fig, $cgi, 'motility', 'Motility', 'hash') if (grep /^motility$/, @$scroll_list);
2529 :    
2530 :     # get the column for organism's gram stain
2531 :     my $gram_stain_column = &get_attrb_column($ids, undef, $fig, $cgi, 'gram_stain', 'Gram_Stain', 'hash') if (grep /^gram_stain$/, @$scroll_list);
2532 :    
2533 :     # get the column for organism's endospores
2534 :     my $endospores_column = &get_attrb_column($ids, undef, $fig, $cgi, 'endospores', 'Endospores', 'hash') if (grep /^endospores$/, @$scroll_list);
2535 :    
2536 :     # get the column for organism's shape
2537 :     my $shape_column = &get_attrb_column($ids, undef, $fig, $cgi, 'shape', 'Shape', 'hash') if (grep /^shape$/, @$scroll_list);
2538 :    
2539 :     # get the column for organism's disease
2540 :     my $disease_column = &get_attrb_column($ids, undef, $fig, $cgi, 'disease', 'Disease', 'hash') if (grep /^disease$/, @$scroll_list);
2541 :    
2542 :     # get the column for organism's disease
2543 :     my $gc_content_column = &get_attrb_column($ids, undef, $fig, $cgi, 'gc_content', 'GC_Content', 'hash') if (grep /^gc_content$/, @$scroll_list);
2544 :    
2545 :     # get the column for transmembrane domains
2546 :     my $transmembrane_column = &get_attrb_column($ids, undef, $fig, $cgi, 'transmembrane', 'Phobius::transmembrane', 'hash') if (grep /^transmembrane$/, @$scroll_list);
2547 :    
2548 :     # get the column for similar to human
2549 :     my $similar_to_human_column = &get_attrb_column($ids, undef, $fig, $cgi, 'similar_to_human', 'similar_to_human', 'hash') if (grep /^similar_to_human$/, @$scroll_list);
2550 :    
2551 :     # get the column for signal peptide
2552 :     my $signal_peptide_column = &get_attrb_column($ids, undef, $fig, $cgi, 'signal_peptide', 'Phobius::signal', 'hash') if (grep /^signal_peptide$/, @$scroll_list);
2553 :    
2554 :     # get the column for transmembrane domains
2555 :     my $isoelectric_column = &get_attrb_column($ids, undef, $fig, $cgi, 'isoelectric', 'isoelectric_point', 'hash') if (grep /^isoelectric$/, @$scroll_list);
2556 :    
2557 :     # get the column for conserved neighborhood
2558 :     my $cons_neigh_column = &get_attrb_column($ids, undef, $fig, $cgi, 'conserved_neighborhood', undef, 'hash') if (grep /^conserved_neighborhood$/, @$scroll_list);
2559 :    
2560 :     # get the column for cellular location
2561 :     my $cell_location_column = &get_attrb_column($ids, undef, $fig, $cgi, 'cellular_location', 'PSORT::', 'hash') if (grep /^isoelectric$/, @$scroll_list);
2562 :    
2563 :     # get the aliases
2564 :     my $alias_col;
2565 :     if ( (grep /asap_id/, @$scroll_list) || (grep /ncbi_id/, @$scroll_list) ||
2566 :     (grep /refseq_id/, @$scroll_list) || (grep /swissprot_id/, @$scroll_list) ||
2567 :     (grep /uniprot_id/, @$scroll_list) || (grep /tigr_id/, @$scroll_list) ||
2568 :     (grep /kegg_id/, @$scroll_list) || (grep /pir_id/, @$scroll_list) ||
2569 :     (grep /trembl_id/, @$scroll_list) || (grep /jgi_id/, @$scroll_list) ) {
2570 :     $alias_col = &get_db_aliases($ids,$fig,'all',$cgi,'hash');
2571 :     }
2572 :    
2573 :     foreach my $id ( @$ids){
2574 :     my $current_function = $fig->function_of($id);
2575 :     my $organism = $fig->org_of($id);
2576 :     my $single_domain = [];
2577 :    
2578 : arodri7 1.76 # organisms cell comehere2
2579 : arodri7 1.69 my ($org, $org_color) = $fig->org_and_color_of($id);
2580 :     my $org_cell = { 'data' => $organism, 'highlight' => $org_color};
2581 :    
2582 :     # get the linked fig id
2583 : arodri7 1.76 my $fig_data;
2584 :     if ($id =~ /^fig\|/)
2585 :     {
2586 :     $fig_data = "<a href='?page=Annotation&feature=$id'>$id</a>";
2587 :     }
2588 :     else
2589 :     {
2590 :     my $url_link = &HTML::set_prot_links($cgi,$id);
2591 :     $fig_data = "<table><tr><td>$url_link</td>". "&nbsp;" x 2;
2592 :     }
2593 :    
2594 : arodri7 1.69 my $fig_col = {'data'=> $fig_data,
2595 :     'highlight'=>"#ffffff"};
2596 : arodri7 1.80
2597 :     # get sequence length
2598 :     my $length_col = {'data'=> $fig->translation_length($id),
2599 :     'highlight'=>"#ffffff"};
2600 :    
2601 : arodri7 1.69 # function cell
2602 :     $function_cell = {'data'=>$current_function, 'highlight'=> "#ffffff"};
2603 :    
2604 :     # insert data
2605 : arodri7 1.80 push (@$single_domain, $fig_col, $length_col, $org_cell, {'data'=>$subsystems_column->{$id},'highlight'=>"#ffffff"}, $function_cell);
2606 : arodri7 1.69
2607 :     foreach my $col (@$scroll_list){
2608 :     my $highlight_color = "#ffffff";
2609 :    
2610 :     if ($col =~ /evidence/) {push(@$single_domain,{'data'=>$evidence_column->{$id},'highlight'=>$highlight_color});}
2611 :     elsif ($col =~ /pfam/) {push(@$single_domain,{'data'=>$pfam_column->{$id},'highlight'=>$highlight_color});}
2612 :     elsif ($col =~ /mw/) {push(@$single_domain,{'data'=>$mw_column->{$id},'highlight'=>$highlight_color});}
2613 :     elsif ($col =~ /habitat/) {push(@$single_domain,{'data'=>$habitat_column->{$id},'highlight'=>$highlight_color});}
2614 :     elsif ($col =~ /temperature/) {push(@$single_domain,{'data'=>$temperature_column->{$id},'highlight'=>$highlight_color});}
2615 :     elsif ($col =~ /temp_range/) {push(@$single_domain,{'data'=>$temperature_range_column->{$id},'highlight'=>$highlight_color});}
2616 :     elsif ($col =~ /oxygen/) {push(@$single_domain,{'data'=>$oxygen_req_column->{$id},'highlight'=>$highlight_color});}
2617 :     elsif ($col =~ /^pathogenic$/) {push(@$single_domain,{'data'=>$pathogenic_column->{$id},'highlight'=>$highlight_color});}
2618 :     elsif ($col =~ /^pathogenic_in$/) {push(@$single_domain,{'data'=>$pathogenic_in_column->{$id},'highlight'=>$highlight_color});}
2619 :     elsif ($col =~ /salinity/) {push(@$single_domain,{'data'=>$salinity_column->{$id},'highlight'=>$highlight_color});}
2620 :     elsif ($col =~ /motility/) {push(@$single_domain,{'data'=>$motility_column->{$id},'highlight'=>$highlight_color});}
2621 :     elsif ($col =~ /gram_stain/) {push(@$single_domain,{'data'=>$gram_stain_column->{$id},'highlight'=>$highlight_color});}
2622 :     elsif ($col =~ /endospores/) {push(@$single_domain,{'data'=>$endospores_column->{$id},'highlight'=>$highlight_color});}
2623 :     elsif ($col =~ /shape/) {push(@$single_domain,{'data'=>$shape_column->{$id},'highlight'=>$highlight_color});}
2624 :     elsif ($col =~ /disease/) {push(@$single_domain,{'data'=>$disease_column->{$id},'highlight'=>$highlight_color});}
2625 :     elsif ($col =~ /gc_content/) {push(@$single_domain,{'data'=>$gc_content_column->{$id},'highlight'=>$highlight_color});}
2626 :     elsif ($col =~ /transmembrane/) {push(@$single_domain,{'data'=>$transmembrane_column->{$id},'highlight'=>$highlight_color});}
2627 :     elsif ($col =~ /signal_peptide/) {push(@$single_domain,{'data'=>$signal_peptide_column->{$id},'highlight'=>$highlight_color});}
2628 :     elsif ($col =~ /isoelectric/) {push(@$single_domain,{'data'=>$isoelectric_column->{$id},'highlight'=>$highlight_color});}
2629 :     elsif ($col =~ /conerved_neighborhood/) {push(@$single_domain,{'data'=>$cons_neigh_column->{$id},'highlight'=>$highlight_color});}
2630 :     elsif ($col =~ /cellular_location/) {push(@$single_domain,{'data'=>$cell_location_column->{$id},'highlight'=>$highlight_color});}
2631 :     elsif ($col =~ /ncbi_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"NCBI"},'highlight'=>$highlight_color});}
2632 :     elsif ($col =~ /refseq_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"RefSeq"},'highlight'=>$highlight_color});}
2633 :     elsif ($col =~ /swissprot_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"SwissProt"},'highlight'=>$highlight_color});}
2634 :     elsif ($col =~ /uniprot_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"UniProt"},'highlight'=>$highlight_color});}
2635 :     elsif ($col =~ /tigr_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"TIGR"},'highlight'=>$highlight_color});}
2636 :     elsif ($col =~ /pir_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"PIR"},'highlight'=>$highlight_color});}
2637 :     elsif ($col =~ /kegg_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"KEGG"},'highlight'=>$highlight_color});}
2638 :     elsif ($col =~ /trembl_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"TrEMBL"},'highlight'=>$highlight_color});}
2639 :     elsif ($col =~ /asap_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"ASAP"},'highlight'=>$highlight_color});}
2640 :     elsif ($col =~ /jgi_id/) {push(@$single_domain,{'data'=>$alias_col->{$id}->{"JGI"},'highlight'=>$highlight_color});}
2641 :     elsif ($col =~ /lineage/) {push(@$single_domain,{'data'=>$lineages->{$tax},'highlight'=>$highlight_color});}
2642 :     elsif ($col =~ /figfam/) {push(@$single_domain,{'data'=>"<a href='?page=FigFamViewer&figfam=" . $ff . "' target='_new'>" . $ff . "</a>",'highlight'=>$highlight_color});}
2643 :     }
2644 :     push(@$data,$single_domain);
2645 :     }
2646 :    
2647 :     $content = $data;
2648 :     return ($content);
2649 :     }
2650 :    
2651 : arodri7 1.29 sub get_box_column{
2652 :     my ($ids) = @_;
2653 :     my %column;
2654 :     foreach my $id (@$ids){
2655 :     my $field_name = "tables_" . $id;
2656 :     my $pair_name = "visual_" . $id;
2657 : arodri7 1.58 my $cell_name = "cell_" . $id;
2658 :     $column{$id} = qq(<input type=checkbox name=seq value="$id" id="$field_name" onClick="VisualCheckPair('$field_name', '$pair_name', '$cell_name');">);
2659 : arodri7 1.29 }
2660 :     return (%column);
2661 :     }
2662 :    
2663 : arodri7 1.60 sub get_figfam_column{
2664 :     my ($ids, $fig, $cgi) = @_;
2665 :     my $column;
2666 :    
2667 :     my $figfam_data = &FIG::get_figfams_data();
2668 :     my $figfams = new FFs($figfam_data);
2669 :    
2670 :     foreach my $id (@$ids){
2671 : arodri7 1.74 my ($ff);
2672 :     if ($id =~ /\.peg\./){
2673 :     ($ff) = $figfams->families_containing_peg($id);
2674 :     }
2675 : arodri7 1.60 if ($ff){
2676 :     push (@$column, "<a href='?page=FigFamViewer&figfam=" . $ff . "' target='_new'>" . $ff . "</a>");
2677 :     }
2678 :     else{
2679 :     push (@$column, " ");
2680 :     }
2681 :     }
2682 :    
2683 :     return $column;
2684 :     }
2685 :    
2686 : arodri7 1.29 sub get_subsystems_column{
2687 : arodri7 1.60 my ($ids,$fig,$cgi,$returnType) = @_;
2688 : arodri7 1.29
2689 : arodri7 1.78 my %in_subs = $fig->subsystems_for_pegs($ids,1);
2690 : arodri7 1.60 my ($column, $ss);
2691 : arodri7 1.29 foreach my $id (@$ids){
2692 : arodri7 1.32 my @in_sub = @{$in_subs{$id}} if (defined $in_subs{$id});
2693 :     my @subsystems;
2694 : paczian 1.81 if (scalar(@in_sub)) {
2695 :     foreach my $array (@in_sub){
2696 :     my $ss_name = $array->[0];
2697 :     $ss_name =~ s/_/ /ig;
2698 :     push (@subsystems, "-" . $ss_name);
2699 : arodri7 1.32 }
2700 :     my $in_sub_line = join ("<br>", @subsystems);
2701 : arodri7 1.60 $ss->{$id} = $in_sub_line;
2702 : arodri7 1.29 } else {
2703 : arodri7 1.60 $ss->{$id} = "None added";
2704 : arodri7 1.29 }
2705 : arodri7 1.60 push (@$column, $ss->{$id});
2706 :     }
2707 :    
2708 :     if ($returnType eq 'hash') { return $ss; }
2709 :     elsif ($returnType eq 'array') { return $column; }
2710 :     }
2711 :    
2712 :     sub get_lineage_column{
2713 :     my ($ids, $fig, $cgi) = @_;
2714 :    
2715 :     my $lineages = $fig->taxonomy_list();
2716 :    
2717 :     foreach my $id (@$ids){
2718 :     my $genome = $fig->genome_of($id);
2719 :     if ($lineages->{$genome}){
2720 :     # push (@$column, qq~<table style='border-style:hidden;'><tr><td style='background-color: #ffffff;'>~ . $lineages->{$genome} . qq~</td></tr</table>~);
2721 :     push (@$column, $lineages->{$genome});
2722 :     }
2723 :     else{
2724 :     push (@$column, " ");
2725 :     }
2726 : arodri7 1.29 }
2727 : arodri7 1.60 return $column;
2728 : arodri7 1.29 }
2729 :    
2730 : arodri7 1.58 sub match_color {
2731 :     my ( $b, $e, $n , $rgb) = @_;
2732 :     my ( $l, $r ) = ( $e > $b ) ? ( $b, $e ) : ( $e, $b );
2733 :     my $hue = 5/6 * 0.5*($l+$r)/$n - 1/12;
2734 :     my $cov = ( $r - $l + 1 ) / $n;
2735 :     my $sat = 1 - 10 * $cov / 9;
2736 :     my $br = 1;
2737 :     if ($rgb){
2738 :     return html2rgb( rgb2html( hsb2rgb( $hue, $sat, $br ) ) );
2739 :     }
2740 :     else{
2741 :     rgb2html( hsb2rgb( $hue, $sat, $br ) );
2742 :     }
2743 :     }
2744 :    
2745 :     sub hsb2rgb {
2746 :     my ( $h, $s, $br ) = @_;
2747 :     $h = 6 * ($h - floor($h));
2748 :     if ( $s > 1 ) { $s = 1 } elsif ( $s < 0 ) { $s = 0 }
2749 :     if ( $br > 1 ) { $br = 1 } elsif ( $br < 0 ) { $br = 0 }
2750 :     my ( $r, $g, $b ) = ( $h <= 3 ) ? ( ( $h <= 1 ) ? ( 1, $h, 0 )
2751 :     : ( $h <= 2 ) ? ( 2 - $h, 1, 0 )
2752 :     : ( 0, 1, $h - 2 )
2753 :     )
2754 :     : ( ( $h <= 4 ) ? ( 0, 4 - $h, 1 )
2755 :     : ( $h <= 5 ) ? ( $h - 4, 0, 1 )
2756 :     : ( 1, 0, 6 - $h )
2757 :     );
2758 :     ( ( $r * $s + 1 - $s ) * $br,
2759 :     ( $g * $s + 1 - $s ) * $br,
2760 :     ( $b * $s + 1 - $s ) * $br
2761 :     )
2762 :     }
2763 :    
2764 :     sub html2rgb {
2765 :     my ($hex) = @_;
2766 :     my ($r,$g,$b) = ($hex) =~ /^\#(\w\w)(\w\w)(\w\w)/;
2767 :     my $code = { 'A'=>10, 'B'=>11, 'C'=>12, 'D'=>13, 'E'=>14, 'F'=>15,
2768 :     1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9};
2769 :    
2770 :     my @R = split(//, $r);
2771 :     my @G = split(//, $g);
2772 :     my @B = split(//, $b);
2773 :    
2774 :     my $red = ($code->{uc($R[0])}*16)+$code->{uc($R[1])};
2775 :     my $green = ($code->{uc($G[0])}*16)+$code->{uc($G[1])};
2776 :     my $blue = ($code->{uc($B[0])}*16)+$code->{uc($B[1])};
2777 :    
2778 :     my $rgb = [$red, $green, $blue];
2779 :     return $rgb;
2780 :    
2781 :     }
2782 :    
2783 :     sub rgb2html {
2784 :     my ( $r, $g, $b ) = @_;
2785 :     if ( $r > 1 ) { $r = 1 } elsif ( $r < 0 ) { $r = 0 }
2786 :     if ( $g > 1 ) { $g = 1 } elsif ( $g < 0 ) { $g = 0 }
2787 :     if ( $b > 1 ) { $b = 1 } elsif ( $b < 0 ) { $b = 0 }
2788 :     sprintf("#%02x%02x%02x", int(255.999*$r), int(255.999*$g), int(255.999*$b) )
2789 :     }
2790 :    
2791 :     sub floor {
2792 :     my $x = $_[0];
2793 :     defined( $x ) || return undef;
2794 :     ( $x >= 0 ) || ( int($x) == $x ) ? int( $x ) : -1 - int( - $x )
2795 :     }
2796 :    
2797 :     sub get_function_color_cell{
2798 :     my ($functions, $fig) = @_;
2799 :    
2800 :     # figure out the quantity of each function
2801 :     my %hash;
2802 :     foreach my $key (keys %$functions){
2803 :     my $func = $functions->{$key};
2804 :     $hash{$func}++;
2805 :     }
2806 :    
2807 :     my %func_colors;
2808 :     my $count = 1;
2809 :     foreach my $key (sort {$hash{$b}<=>$hash{$a}} keys %hash){
2810 :     $func_colors{$key}=$count;
2811 :     $count++;
2812 :     }
2813 :    
2814 :     return \%func_colors;
2815 :     }
2816 :    
2817 : arodri7 1.31 sub get_essentially_identical{
2818 : arodri7 1.41 my ($fid,$dataset,$fig) = @_;
2819 :     #my $fig = new FIG;
2820 :    
2821 : arodri7 1.31 my %id_list;
2822 : arodri7 1.41 #my @maps_to = grep { $_ ne $fid and $_ !~ /^xxx/ } map { $_->[0] } $fig->mapped_prot_ids($fid);
2823 : arodri7 1.31
2824 : arodri7 1.41 foreach my $thing (@$dataset){
2825 :     if($thing->class eq "IDENTICAL"){
2826 :     my $rows = $thing->rows;
2827 :     my $count_identical = 0;
2828 :     foreach my $row (@$rows) {
2829 :     my $id = $row->[0];
2830 :     if (($id ne $fid) && ($fig->function_of($id))) {
2831 :     $id_list{$id} = 1;
2832 :     }
2833 :     }
2834 :     }
2835 : arodri7 1.31 }
2836 : arodri7 1.41
2837 :     # foreach my $id (@maps_to) {
2838 :     # if (($id ne $fid) && ($fig->function_of($id))) {
2839 :     # $id_list{$id} = 1;
2840 :     # }
2841 :     # }
2842 : arodri7 1.31 return(%id_list);
2843 :     }
2844 :    
2845 :    
2846 : arodri7 1.29 sub get_evidence_column{
2847 : arodri7 1.60 my ($ids,$attributes,$fig,$cgi,$returnType) = @_;
2848 :     my ($column, $code_attributes);
2849 :    
2850 :     if (! defined $attributes) {
2851 :     my @attributes_array = $fig->get_attributes($ids);
2852 :     $attributes = \@attributes_array;
2853 :     }
2854 : arodri7 1.29
2855 : arodri7 1.41 my @codes = grep { $_->[1] =~ /^evidence_code/i } @$attributes;
2856 : arodri7 1.29 foreach my $key (@codes){
2857 : arodri7 1.60 push (@{$code_attributes->{$key->[0]}}, $key);
2858 : arodri7 1.29 }
2859 :    
2860 :     foreach my $id (@$ids){
2861 :     # add evidence code with tool tip
2862 :     my $ev_codes=" &nbsp; ";
2863 :    
2864 : arodri7 1.60 my @codes = @{$code_attributes->{$id}} if (defined @{$code_attributes->{$id}});
2865 : arodri7 1.41 my @ev_codes = ();
2866 :     foreach my $code (@codes) {
2867 :     my $pretty_code = $code->[2];
2868 :     if ($pretty_code =~ /;/) {
2869 :     my ($cd, $ss) = split(";", $code->[2]);
2870 : arodri7 1.65 if ($cd =~ /ilit|dlit/){
2871 :     my ($type,$pubmed_id) = ($cd) =~ /(.*?)\((.*)\)/;
2872 :     my $publink = &HTML::alias_url($pubmed_id,'PMID');
2873 :     $cd = $type . "(<a href='" . $publink . "'>" . $pubmed_id . "</a>)";
2874 :     }
2875 : arodri7 1.41 $ss =~ s/_/ /g;
2876 :     $pretty_code = $cd;# . " in " . $ss;
2877 :     }
2878 :     push(@ev_codes, $pretty_code);
2879 :     }
2880 : arodri7 1.60
2881 : arodri7 1.29 if (scalar(@ev_codes) && $ev_codes[0]) {
2882 :     my $ev_code_help=join("<br />", map {&HTML::evidence_codes_explain($_)} @ev_codes);
2883 :     $ev_codes = $cgi->a(
2884 :     {
2885 :     id=>"evidence_codes", onMouseover=>"javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this, 'Evidence Codes', '$ev_code_help', ''); this.tooltip.addHandler(); return false;"}, join("<br />", @ev_codes));
2886 :     }
2887 : arodri7 1.60
2888 :     if ($returnType eq 'hash') { $column->{$id}=$ev_codes; }
2889 :     elsif ($returnType eq 'array') { push (@$column, $ev_codes); }
2890 : arodri7 1.29 }
2891 : arodri7 1.60 return $column;
2892 : arodri7 1.29 }
2893 :    
2894 : arodri7 1.60 sub get_attrb_column{
2895 :     my ($ids, $attributes, $fig, $cgi, $colName, $attrbName, $returnType) = @_;
2896 :    
2897 :     my ($column, %code_attributes, %attribute_locations);
2898 : paczian 1.52 my $dbmaster = DBMaster->new(-database =>'Ontology',
2899 : arodri7 1.60 -host => $WebConfig::DBHOST,
2900 :     -user => $WebConfig::DBUSER,
2901 :     -password => $WebConfig::DBPWD);
2902 :    
2903 :     if ($colName eq "pfam"){
2904 :     if (! defined $attributes) {
2905 :     my @attributes_array = $fig->get_attributes($ids);
2906 :     $attributes = \@attributes_array;
2907 :     }
2908 : arodri7 1.33
2909 : arodri7 1.60 my @codes = grep { $_->[1] =~ /^$attrbName/i } @$attributes;
2910 :     foreach my $key (@codes){
2911 :     my $name = $key->[1];
2912 :     if ($name =~ /_/){
2913 :     ($name) = ($key->[1]) =~ /(.*?)_/;
2914 :     }
2915 :     push (@{$code_attributes{$key->[0]}}, $name);
2916 :     push (@{$attribute_location{$key->[0]}{$name}}, $key->[2]);
2917 :     }
2918 :    
2919 :     foreach my $id (@$ids){
2920 :     # add pfam code
2921 :     my $pfam_codes=" &nbsp; ";
2922 :     my @pfam_codes = "";
2923 :     my %description_codes;
2924 :    
2925 :     if ($id =~ /^fig\|\d+\.\d+\.peg\.\d+$/) {
2926 : redwards 1.84 my @ncodes = @{$code_attributes{$id}} if (@{$code_attributes{$id}});
2927 : arodri7 1.60 @pfam_codes = ();
2928 :    
2929 :     # get only unique values
2930 :     my %saw;
2931 :     foreach my $key (@ncodes) {$saw{$key}=1;}
2932 :     @ncodes = keys %saw;
2933 :    
2934 :     foreach my $code (@ncodes) {
2935 :     my @parts = split("::",$code);
2936 :     my $pfam_link = "<a href=http://pfam.sanger.ac.uk/family?acc=" . $parts[1] . ">$parts[1]</a>";
2937 :    
2938 : arodri7 1.74 # # get the locations for the domain
2939 :     # my @locs;
2940 :     # foreach my $part (@{$attribute_location{$id}{$code}}){
2941 :     # my ($loc) = ($part) =~ /\;(.*)/;
2942 :     # push (@locs,$loc);
2943 :     # }
2944 :     # my %locsaw;
2945 :     # foreach my $key (@locs) {$locsaw{$key}=1;}
2946 :     # @locs = keys %locsaw;
2947 :     #
2948 :     # my $locations = join (", ", @locs);
2949 :     #
2950 : arodri7 1.60 if (defined ($description_codes{$parts[1]})){
2951 : arodri7 1.74 push(@pfam_codes, "$parts[1]");
2952 : arodri7 1.60 }
2953 :     else {
2954 :     my $description = $dbmaster->pfam->get_objects( { 'id' => $parts[1] } );
2955 :     $description_codes{$parts[1]} = $description->[0]->{term};
2956 : arodri7 1.74 push(@pfam_codes, "$pfam_link");
2957 : arodri7 1.60 }
2958 :     }
2959 :    
2960 :     if ($returnType eq 'hash') { $column->{$id} = join("<br><br>", @pfam_codes); }
2961 :     elsif ($returnType eq 'array') { push (@$column, join("<br><br>", @pfam_codes)); }
2962 :     }
2963 : arodri7 1.41 }
2964 : arodri7 1.33 }
2965 : arodri7 1.60 elsif ($colName eq 'cellular_location'){
2966 :     if (! defined $attributes) {
2967 :     my @attributes_array = $fig->get_attributes($ids);
2968 :     $attributes = \@attributes_array;
2969 :     }
2970 : arodri7 1.33
2971 : arodri7 1.60 my @codes = grep { $_->[1] =~ /^$attrbName/i } @$attributes;
2972 :     foreach my $key (@codes){
2973 :     my ($loc) = ($key->[1]) =~ /::(.*)/;
2974 :     my ($new_loc, @all);
2975 :     @all = split (//, $loc);
2976 :     my $count = 0;
2977 :     foreach my $i (@all){
2978 :     if ( ($i eq uc($i)) && ($count > 0) ){
2979 :     $new_loc .= " " . $i;
2980 :     }
2981 :     else{
2982 :     $new_loc .= $i;
2983 : arodri7 1.40 }
2984 : arodri7 1.60 $count++;
2985 :     }
2986 :     push (@{$code_attributes{$key->[0]}}, [$new_loc, $key->[2]]);
2987 :     }
2988 :    
2989 :     foreach my $id (@$ids){
2990 :     my (@values, $entry);
2991 :     #@values = (" ");
2992 : redwards 1.84 if (@{$code_attributes{$id}}){
2993 : arodri7 1.60 my @ncodes = @{$code_attributes{$id}};
2994 :     foreach my $code (@ncodes){
2995 :     push (@values, $code->[0] . ", " . $code->[1]);
2996 :     }
2997 :     }
2998 :     else{
2999 :     @values = ("Not available");
3000 :     }
3001 : arodri7 1.41
3002 : arodri7 1.60 if ($returnType eq 'hash') { $column->{$id} = join ("<BR>", @values); }
3003 :     elsif ($returnType eq 'array') { push (@$column, join ("<BR>", @values)); }
3004 :     }
3005 :     }
3006 :     elsif ( ($colName eq 'mw') || ($colName eq 'transmembrane') || ($colName eq 'similar_to_human') ||
3007 :     ($colName eq 'signal_peptide') || ($colName eq 'isoelectric') ){
3008 :     if (! defined $attributes) {
3009 :     my @attributes_array = $fig->get_attributes($ids);
3010 :     $attributes = \@attributes_array;
3011 :     }
3012 :    
3013 :     my @codes = grep { $_->[1] =~ /^$attrbName/i } @$attributes;
3014 :     foreach my $key (@codes){
3015 :     push (@{$code_attributes{$key->[0]}}, $key->[2]);
3016 :     }
3017 :    
3018 :     foreach my $id (@$ids){
3019 :     my (@values, $entry);
3020 :     #@values = (" ");
3021 : redwards 1.84 if (@{$code_attributes{$id}}){
3022 : arodri7 1.60 my @ncodes = @{$code_attributes{$id}};
3023 :     foreach my $code (@ncodes){
3024 :     push (@values, $code);
3025 : arodri7 1.33 }
3026 :     }
3027 : arodri7 1.60 else{
3028 :     @values = ("Not available");
3029 :     }
3030 :    
3031 :     if ($returnType eq 'hash') { $column->{$id} = join ("<BR>", @values); }
3032 :     elsif ($returnType eq 'array') { push (@$column, join ("<BR>", @values)); }
3033 :     }
3034 :     }
3035 :     elsif ( ($colName eq 'habitat') || ($colName eq 'temperature') || ($colName eq 'temp_range') ||
3036 :     ($colName eq 'oxygen') || ($colName eq 'pathogenic') || ($colName eq 'pathogenic_in') ||
3037 :     ($colName eq 'salinity') || ($colName eq 'motility') || ($colName eq 'gram_stain') ||
3038 :     ($colName eq 'endospores') || ($colName eq 'shape') || ($colName eq 'disease') ||
3039 :     ($colName eq 'gc_content') ) {
3040 :     if (! defined $attributes) {
3041 :     my @attributes_array = $fig->get_attributes(undef,$attrbName);
3042 :     $attributes = \@attributes_array;
3043 :     }
3044 :    
3045 :     my $genomes_with_phenotype;
3046 :     foreach my $attribute (@$attributes){
3047 :     my $genome = $attribute->[0];
3048 :     $genomes_with_phenotype->{$genome} = $attribute->[2];
3049 : arodri7 1.33 }
3050 :    
3051 : arodri7 1.60 foreach my $id (@$ids){
3052 :     my $genome = $fig->genome_of($id);
3053 :     my @values = (' ');
3054 :     if (defined $genomes_with_phenotype->{$genome}){
3055 :     push (@values, $genomes_with_phenotype->{$genome});
3056 :     }
3057 :     if ($returnType eq 'hash') { $column->{$id} = join ("<BR>", @values); }
3058 :     elsif ($returnType eq 'array') { push (@$column, join ("<BR>", @values)); }
3059 :     }
3060 : arodri7 1.33 }
3061 : arodri7 1.60
3062 :     return $column;
3063 : arodri7 1.33 }
3064 : mkubal 1.12
3065 : arodri7 1.74 sub get_aclh_aliases {
3066 :     my ($ids,$fig,$db,$cgi,$returnType) = @_;
3067 :     my $db_array;
3068 :    
3069 :     my $id_line = join (",", @$ids);
3070 :     my $aclh_url = "http://clearinghouse.nmpdr.org/aclh.cgi?page=SearchResults&raw_dump=1&query=" . $id_line;
3071 :    
3072 :    
3073 :     }
3074 :    
3075 :     sub get_id_aliases {
3076 :     my ($id, $fig) = @_;
3077 :     my $aliases = {};
3078 :    
3079 :     my $org = $fig->org_of($id);
3080 :     my $url = "http://clearinghouse.nmpdr.org/aclh.cgi?page=SearchResults&raw_dump=1&query=$id";
3081 :     if ( my $form = &LWP::Simple::get($url) ) {
3082 :     my ($block) = ($form) =~ /<pre>(.*)<\/pre>/s;
3083 :     foreach my $line (split /\n/, $block){
3084 :     my @values = split /\t/, $line;
3085 :     next if ($values[3] eq "Expert");
3086 :     if (($values[1] =~ /$org/) || ($org =~ /$values[1]/) && (! defined $aliases->{$values[4]}) ){
3087 :     $aliases->{$values[4]} = $values[0];
3088 :     }
3089 :     }
3090 :     }
3091 :    
3092 :     return $aliases;
3093 :     }
3094 : arodri7 1.31
3095 : arodri7 1.60 sub get_db_aliases {
3096 :     my ($ids,$fig,$db,$cgi,$returnType) = @_;
3097 :     my $db_array;
3098 : arodri7 1.41 my $all_aliases = $fig->feature_aliases_bulk($ids);
3099 :     foreach my $id (@$ids){
3100 : arodri7 1.74 # my @all_aliases = grep { $_ ne $id and $_ !~ /^xxx/ } map { $_->[0] } $fig->mapped_prot_ids($id);
3101 :     my $id_org = $fig->org_of($id);
3102 :    
3103 : arodri7 1.41 foreach my $alias (@{$$all_aliases{$id}}){
3104 : arodri7 1.74 # foreach my $alias (@all_aliases){
3105 : arodri7 1.41 my $id_db = &Observation::get_database($alias);
3106 : arodri7 1.60 next if ( ($id_db ne $db) && ($db ne 'all') );
3107 :     next if ($aliases->{$id}->{$db});
3108 : arodri7 1.74 my $alias_org = $fig->org_of($alias);
3109 :     # if (($id ne $peg) && ( ($alias_org =~ /$id_org/) || ($id_org =~ /$alias_org/)) ) {
3110 :     #push(@funcs, [$id,$id_db,$tmp]);
3111 :     $aliases->{$id}->{$id_db} = &HTML::set_prot_links($cgi,$alias);
3112 :     # }
3113 : arodri7 1.28 }
3114 : arodri7 1.60 if (!defined( $aliases->{$id}->{$db})){
3115 :     $aliases->{$id}->{$db} = " ";
3116 :     }
3117 :     #push (@$db_array, {'data'=> $aliases->{$id}->{$db},'highlight'=>"#ffffff"});
3118 :     push (@$db_array, $aliases->{$id}->{$db});
3119 : arodri7 1.28 }
3120 : arodri7 1.74
3121 : arodri7 1.60 if ($returnType eq 'hash') { return $aliases; }
3122 :     elsif ($returnType eq 'array') { return $db_array; }
3123 : arodri7 1.28 }
3124 :    
3125 : arodri7 1.60
3126 :    
3127 : arodri7 1.33 sub html_enc { $_ = $_[0]; s/\&/&amp;/g; s/\>/&gt;/g; s/\</&lt;/g; $_ }
3128 :    
3129 : arodri7 1.26 sub color {
3130 : paczian 1.44 my ($evalue) = @_;
3131 :     my $palette = WebColors::get_palette('vitamins');
3132 : arodri7 1.26 my $color;
3133 : paczian 1.44 if ($evalue <= 1e-170){ $color = $palette->[0]; }
3134 :     elsif (($evalue <= 1e-120) && ($evalue > 1e-170)){ $color = $palette->[1]; }
3135 :     elsif (($evalue <= 1e-90) && ($evalue > 1e-120)){ $color = $palette->[2]; }
3136 :     elsif (($evalue <= 1e-70) && ($evalue > 1e-90)){ $color = $palette->[3]; }
3137 :     elsif (($evalue <= 1e-40) && ($evalue > 1e-70)){ $color = $palette->[4]; }
3138 :     elsif (($evalue <= 1e-20) && ($evalue > 1e-40)){ $color = $palette->[5]; }
3139 :     elsif (($evalue <= 1e-5) && ($evalue > 1e-20)){ $color = $palette->[6]; }
3140 :     elsif (($evalue <= 1) && ($evalue > 1e-5)){ $color = $palette->[7]; }
3141 :     elsif (($evalue <= 10) && ($evalue > 1)){ $color = $palette->[8]; }
3142 :     else{ $color = $palette->[9]; }
3143 : arodri7 1.26 return ($color);
3144 :     }
3145 : arodri7 1.13
3146 :    
3147 :     ############################
3148 :     package Observation::Cluster;
3149 :    
3150 :     use base qw(Observation);
3151 :    
3152 :     sub new {
3153 :    
3154 :     my ($class,$dataset) = @_;
3155 :     my $self = $class->SUPER::new($dataset);
3156 : mkubal 1.24 $self->{context} = $dataset->{'context'};
3157 : arodri7 1.13 bless($self,$class);
3158 :     return $self;
3159 :     }
3160 :    
3161 :     sub display {
3162 : arodri7 1.41 my ($self,$gd,$selected_taxonomies,$taxes,$sims_array,$fig) = @_;
3163 : mkubal 1.24
3164 : arodri7 1.53 $taxes = $fig->taxonomy_list();
3165 :    
3166 : mkubal 1.24 my $fid = $self->fig_id;
3167 :     my $compare_or_coupling = $self->context;
3168 :     my $gd_window_size = $gd->window_size;
3169 : arodri7 1.41 my $range = $gd_window_size;
3170 : mkubal 1.14 my $all_regions = [];
3171 : arodri7 1.38 my $gene_associations={};
3172 : arodri7 1.13
3173 :     #get the organism genome
3174 : mkubal 1.14 my $target_genome = $fig->genome_of($fid);
3175 : arodri7 1.38 $gene_associations->{$fid}->{"organism"} = $target_genome;
3176 :     $gene_associations->{$fid}->{"main_gene"} = $fid;
3177 :     $gene_associations->{$fid}->{"reverse_flag"} = 0;
3178 : arodri7 1.13
3179 :     # get location of the gene
3180 :     my $data = $fig->feature_location($fid);
3181 :     my ($contig, $beg, $end);
3182 : arodri7 1.22 my %reverse_flag;
3183 : arodri7 1.13
3184 :     if ($data =~ /(.*)_(\d+)_(\d+)$/){
3185 :     $contig = $1;
3186 :     $beg = $2;
3187 :     $end = $3;
3188 :     }
3189 :    
3190 : arodri7 1.22 my $offset;
3191 : arodri7 1.13 my ($region_start, $region_end);
3192 :     if ($beg < $end)
3193 :     {
3194 : arodri7 1.41 $region_start = $beg - ($range);
3195 :     $region_end = $end+ ($range);
3196 : arodri7 1.22 $offset = ($2+(($3-$2)/2))-($gd_window_size/2);
3197 : arodri7 1.13 }
3198 :     else
3199 :     {
3200 : arodri7 1.41 $region_start = $end-($range);
3201 :     $region_end = $beg+($range);
3202 : arodri7 1.22 $offset = ($3+(($2-$3)/2))-($gd_window_size/2);
3203 : arodri7 1.25 $reverse_flag{$target_genome} = $fid;
3204 : arodri7 1.38 $gene_associations->{$fid}->{"reverse_flag"} = 1;
3205 : arodri7 1.21 }
3206 : arodri7 1.13
3207 :     # call genes in region
3208 : arodri7 1.16 my ($target_gene_features, $reg_beg, $reg_end) = $fig->genes_in_region($target_genome, $contig, $region_start, $region_end);
3209 : arodri7 1.42 #foreach my $feat (@$target_gene_features){
3210 :     # push (@$all_regions, $feat) if ($feat =~ /peg/);
3211 :     #}
3212 : mkubal 1.14 push(@$all_regions,$target_gene_features);
3213 : arodri7 1.16 my (@start_array_region);
3214 : arodri7 1.22 push (@start_array_region, $offset);
3215 : mkubal 1.14
3216 :     my %all_genes;
3217 :     my %all_genomes;
3218 : arodri7 1.42 foreach my $feature (@$target_gene_features){
3219 :     #if ($feature =~ /peg/){
3220 :     $all_genes{$feature} = $fid; $gene_associations->{$feature}->{"main_gene"}=$fid;
3221 :     #}
3222 :     }
3223 :    
3224 : arodri7 1.41 my @selected_sims;
3225 : arodri7 1.16
3226 : arodri7 1.40 if ($compare_or_coupling eq "sims"){
3227 : arodri7 1.37 # get the selected boxes
3228 : arodri7 1.38 my @selected_taxonomy = @$selected_taxonomies;
3229 : arodri7 1.37
3230 :     # get the similarities and store only the ones that match the lineages selected
3231 : arodri7 1.41 if (@selected_taxonomy > 0){
3232 :     foreach my $sim (@$sims_array){
3233 :     next if ($sim->class ne "SIM");
3234 :     next if ($sim->acc !~ /fig\|/);
3235 : arodri7 1.37
3236 : arodri7 1.41 #my $genome = $fig->genome_of($sim->[1]);
3237 :     my $genome = $fig->genome_of($sim->acc);
3238 : arodri7 1.45 #my ($genome1) = ($genome) =~ /(.*)\./;
3239 : arodri7 1.53 my $lineage = $taxes->{$genome};
3240 :     #my $lineage = $fig->taxonomy_of($fig->genome_of($genome));
3241 : arodri7 1.38 foreach my $taxon(@selected_taxonomy){
3242 :     if ($lineage =~ /$taxon/){
3243 : arodri7 1.41 #push (@selected_sims, $sim->[1]);
3244 :     push (@selected_sims, $sim->acc);
3245 : arodri7 1.38 }
3246 : arodri7 1.37 }
3247 :     }
3248 :     }
3249 : arodri7 1.40 else{
3250 :     my $simcount = 0;
3251 : arodri7 1.41 foreach my $sim (@$sims_array){
3252 :     next if ($sim->class ne "SIM");
3253 :     next if ($sim->acc !~ /fig\|/);
3254 :    
3255 :     push (@selected_sims, $sim->acc);
3256 : arodri7 1.40 $simcount++;
3257 :     last if ($simcount > 4);
3258 :     }
3259 :     }
3260 : arodri7 1.16
3261 : arodri7 1.41 my %saw;
3262 :     @selected_sims = grep(!$saw{$_}++, @selected_sims);
3263 :    
3264 : arodri7 1.37 # get the gene context for the sorted matches
3265 :     foreach my $sim_fid(@selected_sims){
3266 :     #get the organism genome
3267 :     my $sim_genome = $fig->genome_of($sim_fid);
3268 : arodri7 1.38 $gene_associations->{$sim_fid}->{"organism"} = $sim_genome;
3269 :     $gene_associations->{$sim_fid}->{"main_gene"} = $sim_fid;
3270 :     $gene_associations->{$sim_fid}->{"reverse_flag"} = 0;
3271 : arodri7 1.37
3272 :     # get location of the gene
3273 :     my $data = $fig->feature_location($sim_fid);
3274 :     my ($contig, $beg, $end);
3275 :    
3276 :     if ($data =~ /(.*)_(\d+)_(\d+)$/){
3277 :     $contig = $1;
3278 :     $beg = $2;
3279 :     $end = $3;
3280 :     }
3281 :    
3282 :     my $offset;
3283 :     my ($region_start, $region_end);
3284 :     if ($beg < $end)
3285 :     {
3286 : arodri7 1.41 $region_start = $beg - ($range/2);
3287 :     $region_end = $end+($range/2);
3288 : arodri7 1.38 $offset = ($beg+(($end-$beg)/2))-($gd_window_size/2);
3289 : arodri7 1.37 }
3290 :     else
3291 :     {
3292 : arodri7 1.41 $region_start = $end-($range/2);
3293 :     $region_end = $beg+($range/2);
3294 : arodri7 1.38 $offset = ($end+(($beg-$end)/2))-($gd_window_size/2);
3295 :     $reverse_flag{$sim_genome} = $sim_fid;
3296 :     $gene_associations->{$sim_fid}->{"reverse_flag"} = 1;
3297 : arodri7 1.37 }
3298 :    
3299 :     # call genes in region
3300 :     my ($sim_gene_features, $reg_beg, $reg_end) = $fig->genes_in_region($sim_genome, $contig, $region_start, $region_end);
3301 :     push(@$all_regions,$sim_gene_features);
3302 :     push (@start_array_region, $offset);
3303 : arodri7 1.38 foreach my $feature (@$sim_gene_features){ $all_genes{$feature} = $sim_fid;$gene_associations->{$feature}->{"main_gene"}=$sim_fid;}
3304 :     $all_genomes{$sim_genome} = 1;
3305 : arodri7 1.16 }
3306 : mkubal 1.14
3307 :     }
3308 : arodri7 1.41
3309 : arodri7 1.42 #print STDERR "START CLUSTER OF GENES IN COMP REGION: " . `date`;
3310 : arodri7 1.38 # cluster the genes
3311 :     my @all_pegs = keys %all_genes;
3312 :     my $color_sets = &cluster_genes($fig,\@all_pegs,$fid);
3313 : arodri7 1.42 #print STDERR "END CLUSTER OF GENES IN COMP REGION: ". `date`;
3314 : arodri7 1.78 my %in_subs = $fig->subsystems_for_pegs(\@all_pegs,1);
3315 : arodri7 1.21
3316 : mkubal 1.14 foreach my $region (@$all_regions){
3317 :     my $sample_peg = @$region[0];
3318 :     my $region_genome = $fig->genome_of($sample_peg);
3319 :     my $region_gs = $fig->genus_species($region_genome);
3320 : arodri7 1.18 my $abbrev_name = $fig->abbrev($region_gs);
3321 : arodri7 1.45 #my ($genome1) = ($region_genome) =~ /(.*?)\./;
3322 : arodri7 1.53 my $lineage = $taxes->{$region_genome};
3323 :     #my $lineage = $fig->taxonomy_of($region_genome);
3324 : arodri7 1.40 #$region_gs .= "Lineage:$lineage";
3325 : arodri7 1.16 my $line_config = { 'title' => $region_gs,
3326 : arodri7 1.18 'short_title' => $abbrev_name,
3327 : arodri7 1.16 'basepair_offset' => '0'
3328 :     };
3329 :    
3330 : arodri7 1.22 my $offsetting = shift @start_array_region;
3331 : arodri7 1.16
3332 : arodri7 1.40 my $second_line_config = { 'title' => "$lineage",
3333 : arodri7 1.25 'short_title' => "",
3334 : arodri7 1.38 'basepair_offset' => '0',
3335 :     'no_middle_line' => '1'
3336 : arodri7 1.25 };
3337 :    
3338 : mkubal 1.14 my $line_data = [];
3339 : arodri7 1.25 my $second_line_data = [];
3340 :    
3341 :     # initialize variables to check for overlap in genes
3342 :     my ($prev_start, $prev_stop, $prev_fig, $second_line_flag);
3343 :     my $major_line_flag = 0;
3344 :     my $prev_second_flag = 0;
3345 :    
3346 : arodri7 1.16 foreach my $fid1 (@$region){
3347 : arodri7 1.25 $second_line_flag = 0;
3348 : mkubal 1.14 my $element_hash;
3349 :     my $links_list = [];
3350 :     my $descriptions = [];
3351 : arodri7 1.38
3352 :     my $color = $color_sets->{$fid1};
3353 : arodri7 1.26
3354 : arodri7 1.18 # get subsystem information
3355 :     my $function = $fig->function_of($fid1);
3356 : paczian 1.44 my $url_link = "?page=Annotation&feature=".$fid1;
3357 : arodri7 1.18
3358 :     my $link;
3359 :     $link = {"link_title" => $fid1,
3360 :     "link" => $url_link};
3361 :     push(@$links_list,$link);
3362 :    
3363 : arodri7 1.41 my @subs = @{$in_subs{$fid1}} if (defined $in_subs{$fid1});
3364 :     my @subsystems;
3365 :     foreach my $array (@subs){
3366 :     my $subsystem = $$array[0];
3367 :     my $ss = $subsystem;
3368 :     $ss =~ s/_/ /ig;
3369 :     push (@subsystems, $ss);
3370 : arodri7 1.18 my $link;
3371 : paczian 1.44 $link = {"link" => "?page=Subsystems&subsystem=$subsystem",
3372 : arodri7 1.41 "link_title" => $ss};
3373 : arodri7 1.18 push(@$links_list,$link);
3374 :     }
3375 : arodri7 1.41
3376 :     if ($fid1 eq $fid){
3377 :     my $link;
3378 :     $link = {"link_title" => "Annotate this sequence",
3379 :     "link" => "$FIG_Config::cgi_url/seedviewer.cgi?page=Commentary"};
3380 :     push (@$links_list,$link);
3381 :     }
3382 :    
3383 : arodri7 1.18 my $description_function;
3384 :     $description_function = {"title" => "function",
3385 :     "value" => $function};
3386 :     push(@$descriptions,$description_function);
3387 :    
3388 :     my $description_ss;
3389 : arodri7 1.41 my $ss_string = join (", ", @subsystems);
3390 : arodri7 1.18 $description_ss = {"title" => "subsystems",
3391 :     "value" => $ss_string};
3392 :     push(@$descriptions,$description_ss);
3393 :    
3394 : arodri7 1.16
3395 :     my $fid_location = $fig->feature_location($fid1);
3396 : mkubal 1.14 if($fid_location =~/(.*)_(\d+)_(\d+)$/){
3397 :     my($start,$stop);
3398 : arodri7 1.22 $start = $2 - $offsetting;
3399 :     $stop = $3 - $offsetting;
3400 : arodri7 1.25
3401 :     if ( (($prev_start) && ($prev_stop) ) &&
3402 :     ( ($start < $prev_start) || ($start < $prev_stop) ||
3403 :     ($stop < $prev_start) || ($stop < $prev_stop) )){
3404 :     if (($second_line_flag == 0) && ($prev_second_flag == 0)) {
3405 :     $second_line_flag = 1;
3406 :     $major_line_flag = 1;
3407 :     }
3408 :     }
3409 :     $prev_start = $start;
3410 :     $prev_stop = $stop;
3411 :     $prev_fig = $fid1;
3412 :    
3413 : arodri7 1.58 if ((defined($reverse_flag{$region_genome})) && ($reverse_flag{$region_genome} eq $all_gnes{$fid1})){
3414 : arodri7 1.22 $start = $gd_window_size - $start;
3415 :     $stop = $gd_window_size - $stop;
3416 :     }
3417 :    
3418 : arodri7 1.41 my $title = $fid1;
3419 :     if ($fid1 eq $fid){
3420 :     $title = "My query gene: $fid1";
3421 :     }
3422 :    
3423 : mkubal 1.14 $element_hash = {
3424 : arodri7 1.41 "title" => $title,
3425 : mkubal 1.14 "start" => $start,
3426 :     "end" => $stop,
3427 :     "type"=> 'arrow',
3428 :     "color"=> $color,
3429 : arodri7 1.18 "zlayer" => "2",
3430 :     "links_list" => $links_list,
3431 :     "description" => $descriptions
3432 : mkubal 1.14 };
3433 : arodri7 1.25
3434 :     # if there is an overlap, put into second line
3435 :     if ($second_line_flag == 1){ push(@$second_line_data,$element_hash); $prev_second_flag = 1;}
3436 :     else{ push(@$line_data,$element_hash); $prev_second_flag = 0;}
3437 : arodri7 1.41
3438 :     if ($fid1 eq $fid){
3439 :     $element_hash = {
3440 :     "title" => 'Query',
3441 :     "start" => $start,
3442 :     "end" => $stop,
3443 :     "type"=> 'bigbox',
3444 :     "color"=> $color,
3445 :     "zlayer" => "1"
3446 :     };
3447 :    
3448 :     # if there is an overlap, put into second line
3449 :     if ($second_line_flag == 1){ push(@$second_line_data,$element_hash); $prev_second_flag = 1;}
3450 :     else{ push(@$line_data,$element_hash); $prev_second_flag = 0;}
3451 :     }
3452 : mkubal 1.14 }
3453 :     }
3454 :     $gd->add_line($line_data, $line_config);
3455 : arodri7 1.40 $gd->add_line($second_line_data, $second_line_config); # if ($major_line_flag == 1);
3456 : mkubal 1.14 }
3457 : arodri7 1.41 return ($gd, \@selected_sims);
3458 : mkubal 1.14 }
3459 :    
3460 : arodri7 1.38 sub cluster_genes {
3461 :     my($fig,$all_pegs,$peg) = @_;
3462 :     my(%seen,$i,$j,$k,$x,$cluster,$conn,$pegI,$red_set);
3463 :    
3464 :     my @color_sets = ();
3465 :    
3466 :     $conn = &get_connections_by_similarity($fig,$all_pegs);
3467 :    
3468 :     for ($i=0; ($i < @$all_pegs); $i++) {
3469 :     if ($all_pegs->[$i] eq $peg) { $pegI = $i }
3470 :     if (! $seen{$i}) {
3471 :     $cluster = [$i];
3472 :     $seen{$i} = 1;
3473 :     for ($j=0; ($j < @$cluster); $j++) {
3474 :     $x = $conn->{$cluster->[$j]};
3475 :     foreach $k (@$x) {
3476 :     if (! $seen{$k}) {
3477 :     push(@$cluster,$k);
3478 :     $seen{$k} = 1;
3479 :     }
3480 :     }
3481 :     }
3482 :    
3483 :     if ((@$cluster > 1) || ($cluster->[0] eq $pegI)) {
3484 :     push(@color_sets,$cluster);
3485 :     }
3486 :     }
3487 :     }
3488 :     for ($i=0; ($i < @color_sets) && (! &in($pegI,$color_sets[$i])); $i++) {}
3489 :     $red_set = $color_sets[$i];
3490 :     splice(@color_sets,$i,1);
3491 :     @color_sets = sort { @$b <=> @$a } @color_sets;
3492 :     unshift(@color_sets,$red_set);
3493 :    
3494 :     my $color_sets = {};
3495 :     for ($i=0; ($i < @color_sets); $i++) {
3496 :     foreach $x (@{$color_sets[$i]}) {
3497 :     $color_sets->{$all_pegs->[$x]} = $i;
3498 :     }
3499 :     }
3500 :     return $color_sets;
3501 :     }
3502 :    
3503 :     sub get_connections_by_similarity {
3504 :     my($fig,$all_pegs) = @_;
3505 :     my($i,$j,$tmp,$peg,%pos_of);
3506 :     my($sim,%conn,$x,$y);
3507 :    
3508 :     for ($i=0; ($i < @$all_pegs); $i++) {
3509 :     $tmp = $fig->maps_to_id($all_pegs->[$i]);
3510 :     push(@{$pos_of{$tmp}},$i);
3511 :     if ($tmp ne $all_pegs->[$i]) {
3512 :     push(@{$pos_of{$all_pegs->[$i]}},$i);
3513 :     }
3514 :     }
3515 :    
3516 :     foreach $y (keys(%pos_of)) {
3517 : arodri7 1.41 $x = $pos_of{$y};
3518 : arodri7 1.38 for ($i=0; ($i < @$x); $i++) {
3519 :     for ($j=$i+1; ($j < @$x); $j++) {
3520 :     push(@{$conn{$x->[$i]}},$x->[$j]);
3521 :     push(@{$conn{$x->[$j]}},$x->[$i]);
3522 :     }
3523 :     }
3524 :     }
3525 :    
3526 :     for ($i=0; ($i < @$all_pegs); $i++) {
3527 : arodri7 1.42 foreach $sim ($fig->sims($all_pegs->[$i],500,10,"raw")) {
3528 : arodri7 1.38 if (defined($x = $pos_of{$sim->id2})) {
3529 :     foreach $y (@$x) {
3530 :     push(@{$conn{$i}},$y);
3531 :     }
3532 :     }
3533 :     }
3534 :     }
3535 :     return \%conn;
3536 :     }
3537 :    
3538 :     sub in {
3539 :     my($x,$xL) = @_;
3540 :     my($i);
3541 :    
3542 :     for ($i=0; ($i < @$xL) && ($x != $xL->[$i]); $i++) {}
3543 :     return ($i < @$xL);
3544 :     }
3545 : arodri7 1.41
3546 :     #############################################
3547 :     #############################################
3548 :     package Observation::Commentary;
3549 :    
3550 :     use base qw(Observation);
3551 :    
3552 :     =head3 display_protein_commentary()
3553 :    
3554 :     =cut
3555 :    
3556 :     sub display_protein_commentary {
3557 :     my ($self,$dataset,$mypeg,$fig) = @_;
3558 :    
3559 :     my $all_rows = [];
3560 :     my $content;
3561 :     #my $fig = new FIG;
3562 :     my $cgi = new CGI;
3563 :     my $count = 0;
3564 :     my $peg_array = [];
3565 : arodri7 1.60 my ($evidence_column, $subsystems_column, %e_identical);
3566 : arodri7 1.41
3567 :     if (@$dataset != 1){
3568 :     foreach my $thing (@$dataset){
3569 :     if ($thing->class eq "SIM"){
3570 :     push (@$peg_array, $thing->acc);
3571 :     }
3572 :     }
3573 :     # get the column for the evidence codes
3574 : arodri7 1.60 $evidence_column = &Observation::Sims::get_evidence_column($peg_array, undef, $fig, $cgi, 'hash');
3575 : arodri7 1.41
3576 :     # get the column for the subsystems
3577 : arodri7 1.60 $subsystems_column = &Observation::Sims::get_subsystems_column($peg_array,$fig, $cgi, 'array');
3578 : arodri7 1.41
3579 :     # get essentially identical seqs
3580 :     %e_identical = &Observation::Sims::get_essentially_identical($mypeg,$dataset,$fig);
3581 :     }
3582 :     else{
3583 :     push (@$peg_array, @$dataset);
3584 :     }
3585 :    
3586 :     my $selected_sims = [];
3587 :     foreach my $id (@$peg_array){
3588 :     last if ($count > 10);
3589 :     my $row_data = [];
3590 :     my ($set, $org, $ss, $ev, $function, $function_cell, $id_cell);
3591 : arodri7 1.66 if ($fig->org_of($id)){
3592 :     $org = $fig->org_of($id);
3593 :     }
3594 :     else{
3595 :     $org = "Data not available";
3596 :     }
3597 : arodri7 1.41 $function = $fig->function_of($id);
3598 :     if ($mypeg ne $id){
3599 : paczian 1.47 $function_cell = "<input type='radio' name='function' id='$id' value='$function' onClick=\"clearText('setAnnotation');\">&nbsp;&nbsp;$function";
3600 :     $id_cell .= "<a href='?page=Annotation&feature=$id'>$id</a>"; # &HTML::set_prot_links($cgi,$id);
3601 : arodri7 1.41 if (defined($e_identical{$id})) { $id_cell .= "*";}
3602 :     }
3603 :     else{
3604 :     $function_cell = "&nbsp;&nbsp;$function";
3605 : paczian 1.47 $id_cell = "<input type='checkbox' name='peg' id='peg$count' value='$id' checked='true'>";
3606 :     $id_cell .= "<a href='?page=Annotation&feature=$id'>$id</a>"; # &HTML::set_prot_links($cgi,$id);
3607 : arodri7 1.41 }
3608 :    
3609 :     push(@$row_data,$id_cell);
3610 :     push(@$row_data,$org);
3611 : arodri7 1.60 push(@$row_data, $subsystems_column->{$id}) if ($mypeg ne $id);
3612 :     push(@$row_data, $evidence_column->{$id}) if ($mypeg ne $id);
3613 : arodri7 1.41 push(@$row_data, $fig->translation_length($id));
3614 :     push(@$row_data,$function_cell);
3615 :     push(@$all_rows,$row_data);
3616 :     push (@$selected_sims, $id);
3617 :     $count++;
3618 :     }
3619 :    
3620 :     if ($count >0){
3621 :     $content = $all_rows;
3622 :     }
3623 :     else{
3624 :     $content = "<p>This PEG does not have enough similarities to change the commentary</p>";
3625 :     }
3626 :     return ($content,$selected_sims);
3627 :     }
3628 :    
3629 :     sub display_protein_history {
3630 :     my ($self, $id,$fig) = @_;
3631 :     my $all_rows = [];
3632 :     my $content;
3633 :    
3634 :     my $cgi = new CGI;
3635 :     my $count = 0;
3636 :     foreach my $feat ($fig->feature_annotations($id)){
3637 :     my $row = [];
3638 :     my $col1 = $feat->[2];
3639 :     my $col2 = $feat->[1];
3640 :     #my $text = "<pre>" . $feat->[3] . "<\pre>";
3641 :     my $text = $feat->[3];
3642 :    
3643 :     push (@$row, $col1);
3644 :     push (@$row, $col2);
3645 :     push (@$row, $text);
3646 :     push (@$all_rows, $row);
3647 :     $count++;
3648 :     }
3649 :     if ($count > 0){
3650 :     $content = $all_rows;
3651 :     }
3652 :     else {
3653 :     $content = "There is no history for this PEG";
3654 :     }
3655 :    
3656 :     return($content);
3657 :     }
3658 : arodri7 1.58

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3