[Bio] / SubsystemEditor / WebPage / ShowVariants.pm Repository:
ViewVC logotype

Diff of /SubsystemEditor/WebPage/ShowVariants.pm

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

revision 1.2, Fri Aug 31 20:43:46 2007 UTC revision 1.9, Fri May 23 21:45:02 2008 UTC
# Line 21  Line 21 
21    
22    $self->application->register_component(  'Table', 'ShowVariantsTable'  );    $self->application->register_component(  'Table', 'ShowVariantsTable'  );
23    $self->application->register_component(  'Table', 'FRTable'  );    $self->application->register_component(  'Table', 'FRTable'  );
24      $self->application->register_component( 'Table', 'VarDescTable'  );
25      $self->application->register_component( 'Info', 'CommentInfo');
26  }  }
27    
28  sub require_javascript {  sub require_javascript {
# Line 35  Line 37 
37  sub output {  sub output {
38    my ( $self ) = @_;    my ( $self ) = @_;
39    
40    my $can_alter = 1;    my $can_alter = 0;
41      my $user = $self->application->session->user;
42    
43    my $fig = new FIG;    my $fig = new FIG;
44    my $cgi = $self->application->cgi;    my $cgi = $self->application->cgi;
45    
46    my $name = $cgi->param( 'subsystem' );    my $name = $cgi->param( 'subsystem' );
47    my $ssname = $name;    my $ssname = $name;
48      $name = uri_unescape( $name );
49    $ssname =~ s/\_/ /g;    $ssname =~ s/\_/ /g;
50    
51      my $esc_name = uri_escape($name);
52    
53      my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );
54      my $ppoapplication = $dbmaster->Backend->init( { name => 'SubsystemEditor' } );
55    
56      # get a seeduser #
57      my $seeduser = '';
58      if ( defined( $user ) && ref( $user ) ) {
59        my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
60                                                                 name => 'SeedUser',
61                                                                 application => $ppoapplication } );
62        if ( defined( $preferences->[0] ) ) {
63          $seeduser = $preferences->[0]->value();
64        }
65      }
66    
67      if ( $user && $user->has_right( $self->application, 'edit', 'subsystem', $name ) ) {
68        $can_alter = 1;
69        $fig->set_user( $seeduser );
70      }
71    
72    ######################    ######################
73    # Construct the menu #    # Construct the menu #
74    ######################    ######################
# Line 51  Line 76 
76    my $menu = $self->application->menu();    my $menu = $self->application->menu();
77    
78    # Build nice tab menu here    # Build nice tab menu here
79    $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$name" );    $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$esc_name" );
80    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$esc_name" );
81    $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );    $menu->add_category( 'Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$esc_name" );
82    $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );    $menu->add_category( 'Illustrations', "SubsysEditor.cgi?page=ShowIllustrations&subsystem=$esc_name" );
83    $menu->add_category( 'Subsystem Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );    $menu->add_category( 'Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$esc_name" );
84    $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );    $menu->add_category( 'Show Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$esc_name" );
85      $menu->add_category( 'Show Connections', "SubsysEditor.cgi?page=ShowTree&subsystem=$esc_name" );
86    
87    
88    ##############################    ##############################
# Line 72  Line 98 
98      return $content;      return $content;
99    }    }
100    
101    my ( $datahash, $subsystem ) = get_data( $fig, $name );    $content .= $self->start_form();
102    
103      #### 100x100 ####
104      if ( defined( $cgi->param( 'on100x100' ) ) ) {
105        $cgi->param( 'hundred_hundred', 1 );
106      }
107      if ( defined( $cgi->param( 'off100x100' ) ) ) {
108        $cgi->param( 'hundred_hundred', 0 );
109      }
110    
111    
112      if ( !defined( $cgi->param( 'hundred_hundred' ) ) || $cgi->param( 'hundred_hundred' ) != 1 ) {
113        $content .= $cgi->submit( -name => "on100x100", -value => "Show only 100x100" );
114      }
115      else {
116        $content .= $cgi->submit( -name => "off100x100", -value => "Show all genomes" );
117      }
118    
119      my $subsystem = $fig->get_subsystem( $name );
120    
121      my $datahash = get_data( $fig, $cgi, $subsystem );
122    
123    my $application = $self->application;    my $application = $self->application;
124    
125    if ( $cgi->param( 'set_variants' ) ) {    if ( $cgi->param( 'set_variants' ) ) {
126      $comment .= '<BR>';      $comment .= '<BR>';
127      $comment .= set_variants( $cgi, $fig, $name, $subsystem, $application, $datahash );      $comment .= set_variants( $cgi, $fig, $name, $subsystem, $application, $datahash );
128      ( $datahash, $subsystem ) = get_data( $fig, $name );      $datahash = get_data( $fig, $cgi, $subsystem );
129      }
130      elsif ( $cgi->param( 'addsave_variants' ) ) {
131        my @varcodes = $cgi->param( 'VARIANT' );
132        my @vardescs = $cgi->param( 'VARIANTDESC' );
133        my %varhash;
134    
135        for ( my $i = 0; $i < scalar( @varcodes ); $i++ ) {
136    
137          if ( $varcodes[$i] eq '' ) {
138            if ( $vardescs[$i] ne '' ) {
139              $comment .= "No Variant Code given for description ".$vardescs[$i].", so this variant could not be saved.<BR>\n";
140            }
141            next;
142          }
143          if ( defined( $varhash{ $varcodes[$i] } ) ) {
144            $comment .= "Variant ".$varcodes[$i]." already has the description ".$varhash{ $varcodes[$i] }.", so description ".$vardescs[$i]." was ignored.<BR>\n";
145            next;
146          }
147    
148          $varhash{ $varcodes[$i] } = $vardescs[$i];
149        }
150        my $newvarcode = $cgi->param( 'NEWVARIANT' );
151        my $newvardesc = $cgi->param( 'NEWVARIANTDESC' );
152        if ( defined( $newvarcode ) && $newvarcode ne '' && defined( $newvardesc ) && $newvardesc ne '' ) {
153          if ( $newvarcode eq '' ) {
154            if ( $newvarcode ne '' ) {
155              $comment .= "No Variant Code given for description $newvardesc, so this variant could not be saved.<BR>\n";
156            }
157          }
158          elsif ( defined( $varhash{ $newvarcode } ) ) {
159            $comment .= "Variant $newvarcode already has the description $newvardesc, so description $newvardesc was ignored.<BR>\n";
160          }
161          else {
162            $varhash{ $newvarcode } = $newvardesc;
163          }
164    }    }
165    
166    $content .= show_variants( $self, $cgi, $fig, $name, $subsystem, $datahash );      $subsystem->set_variants( \%varhash );
167        $subsystem->incr_version();
168        $subsystem->db_sync();
169        $subsystem->write_subsystem();
170      }
171    
172      if ( defined( $comment ) && $comment ne '' ) {
173        my $info_component = $application->component( 'CommentInfo' );
174    
175        $info_component->content( $comment );
176        $info_component->default( 0 );
177        $content .= $info_component->output();
178      }
179    
180    
181      $content .= show_variants( $self, $cgi, $fig, $name, $subsystem, $can_alter, $datahash );
182    
183    ###############################    ###############################
184    # Display errors and comments #    # Display errors and comments #
# Line 91  Line 187 
187    if ( defined( $error ) && $error ne '' ) {    if ( defined( $error ) && $error ne '' ) {
188      $self->application->add_message( 'warning', $error );      $self->application->add_message( 'warning', $error );
189    }    }
   if ( defined( $comment ) && $comment ne '' ) {  
     $self->application->add_message( 'info', $comment );  
   }  
   
190    return $content;    return $content;
191  }  }
192    
# Line 102  Line 194 
194  # data method #  # data method #
195  ###############  ###############
196  sub get_data {  sub get_data {
197    my ( $fig, $name ) = @_;    my ( $fig, $cgi, $subsystem ) = @_;
198    
199    my $datahash = {};    my $datahash = {};
200    
   my $subsystem = $fig->get_subsystem( $name );  
201    my @genomes        = $subsystem->get_genomes;    my @genomes        = $subsystem->get_genomes;
202    
203      my %thesegenomes;
204    
205      if ( defined( $cgi->param( 'hundred_hundred' ) ) && $cgi->param( 'hundred_hundred' ) == 1 ) {
206        my %orgs = map { $_->[0] => 1 } grep { $_->[0] =~ /^\d+\.\d+$/ } $fig->get_attributes( undef, 'collection', 'hundred_hundred' );
207    
208        foreach my $g ( @genomes ) {
209          if ( defined( $orgs{ $g } ) ) {
210            $thesegenomes{ $g } = 1;
211          }
212        }
213        @genomes = keys %thesegenomes;
214      }
215    
216    my %variant_codes = map { $_ => $subsystem->get_variant_code( $subsystem->get_genome_index( $_ ) ) } @genomes;    my %variant_codes = map { $_ => $subsystem->get_variant_code( $subsystem->get_genome_index( $_ ) ) } @genomes;
217    my @roles          = $subsystem->get_roles;    my @roles          = $subsystem->get_roles;
218    
# Line 115  Line 220 
220    $datahash->{ 'varcodes' } = \%variant_codes;    $datahash->{ 'varcodes' } = \%variant_codes;
221    $datahash->{ 'roles' } = \@roles;    $datahash->{ 'roles' } = \@roles;
222    
223    return ( $datahash, $subsystem );    return $datahash;
224  }  }
225    
226  #########################################################  #########################################################
227  # show table with variants and button for changing them #  # show table with variants and button for changing them #
228  #########################################################  #########################################################
229  sub show_variants {  sub show_variants {
230    my ( $self, $cgi, $fig, $name, $sub, $datahash ) = @_;    my ( $self, $cgi, $fig, $name, $sub, $can_alter, $datahash ) = @_;
231    
232    my $application = $self->application();    my $application = $self->application();
233    
# Line 145  Line 250 
250      $has_filled{join(",",@has)}->{$variant_codes{$genome}}++;      $has_filled{join(",",@has)}->{$variant_codes{$genome}}++;
251    }    }
252    
253    my ( $col_hdrs, $tab, $pattern );    my ( $col_hdrs, $pattern_uq );
254      if ( $can_alter ) {
255    $col_hdrs = [ { name => "Pattern" }, { name => "# Genomes with Pattern" },    $col_hdrs = [ { name => "Pattern" }, { name => "# Genomes with Pattern" },
256                  { name => "Existing Variant Code" }, { name => "Set To" } ];                  { name => "Existing Variant Code" }, { name => "Set To" } ];
257    $tab = [];    }
258    foreach $pattern ( sort keys( %has_filled ) ) {    else {
259        $col_hdrs = [ { name => "Pattern" }, { name => "# Genomes with Pattern" },
260                      { name => "Existing Variant Code" } ];
261      }
262    
263      my @codes = keys( %{ $has_filled{ $pattern } } );    my $tab = [];
264      foreach $pattern_uq ( sort keys( %has_filled ) ) {
265    
266        my $pattern = quotemeta( $pattern_uq );
267    
268        my @codes = keys( %{ $has_filled{ $pattern_uq } } );
269      my $code;      my $code;
270      my $nrow = @codes;      my $nrow = @codes;
271      if ( @codes > 0 ) {      if ( @codes > 0 ) {
272        $code = shift @codes;        $code = shift @codes;
273        push( @$tab, [ $pattern,        if ( $can_alter ) {
274                       $has_filled{$pattern}->{$code},          push( @$tab, [ $pattern_uq,
275                           $has_filled{ $pattern_uq }->{ $code },
276                       $code,                       $code,
277                       $cgi->textfield(-name => "p:$pattern:$code", -size => 5, -value => $code, -override => 1)                         $cgi->textfield(-name => "p##:##$pattern##:##$code", -size => 5, -value => $code, -override => 1)
278                     ]);                     ]);
279      }      }
280          else {
281            push( @$tab, [ $pattern_uq,
282                           $has_filled{ $pattern_uq }->{ $code },
283                           $code
284                         ]);
285          }
286        }
287    
288      foreach $code ( @codes ) {      foreach $code ( @codes ) {
289          if ( $can_alter ) {
290        push( @$tab,[ $has_filled{ $pattern }->{ $code },          push( @$tab, [ $pattern_uq,
291                           $has_filled{ $pattern_uq }->{ $code },
292                      $code,                      $code,
293                      $cgi->textfield(-name => "p:$pattern:$code", -size => 5, -value => $code, -override => 1)                         $cgi->textfield(-name => "p##:##$pattern##:##$code", -size => 5, -value => $code, -override => 1)
294                    ]);                    ]);
295      }      }
296          else {
297            push( @$tab, [ $pattern_uq,
298                           $has_filled{ $pattern_uq }->{ $code },
299                           $code
300                         ]);
301          }
302        }
303    }    }
304    
305    $cont .= $frtable;    $cont .= $frtable;
   $cont .= $self->start_form();  
306    
307    # create table from parsed data    my $thistable = create_table( $self, $fig, \%has_filled, $col_hdrs, $tab );
308    my $table = $application->component( 'ShowVariantsTable' );  
309    $table->columns( $col_hdrs );  #  # create table from parsed data
310    $table->data( $tab );  #  my $table = $application->component( 'ShowVariantsTable' );
311    #  $table->columns( $col_hdrs );
312    #  $table->data( $tab );
313    
314      ############################################
315      # Variant Descriptions from the Notes file #
316      ############################################
317      $cont .= "<H2>Variant descriptions</H2>\n";
318      my $variants = $sub->get_variants();
319    
320      my $infotable = '';
321      if ( $can_alter ) {
322        $infotable .= "<TABLE class='table_table'><TR><TD class='table_first_row'>Variant</TD><TD class='table_first_row'>Description</TD></TR>";
323        foreach my $kv ( sort keys %$variants ) {
324          $infotable .= "<TR><TD class='table_odd_row'><INPUT TYPE=TEXT NAME='VARIANT' ID='VARIANT".$kv."' VALUE='$kv'></TD><TD class='table_odd_row'><INPUT TYPE=TEXT NAME='VARIANTDESC' ID='VARIANTDESC".$kv."' VALUE='".$variants->{ $kv }."' STYLE='width: 500px;'></TD></TR>";
325        }
326        $infotable .= "<TR><TD class='table_odd_row'><INPUT TYPE=TEXT NAME='NEWVARIANT' ID='NEWVARIANT'></TD><TD class='table_odd_row'><INPUT TYPE=TEXT NAME='NEWVARIANTDESC' ID='NEWVARIANTDESC' STYLE='width: 500px;'></TD></TR>";
327        $infotable .= "<TR><TD>";
328        $infotable .= $cgi->submit( -name => "addsave_variants", -value => "Add/Save Variants" );
329        $infotable .= "</TD></TR></TABLE>";
330    
331        $cont .= $infotable;
332      }
333      else {
334        my $infotable = $application->component( 'VarDescTable' );
335        $infotable->columns( [ { name => "Variant" }, { name => "Description" } ] );
336    
337        my $vardata;
338        foreach my $kv ( sort keys %$variants ) {
339          push @$vardata, [ $kv, $variants->{ $kv } ];
340        }
341        $infotable->data( $vardata );
342        $cont .= $infotable->output();
343      }
344    
345      my $esc_name = uri_escape($name);
346    
347    $cont .= "<H2>Variant groups</H2>\n";    $cont .= "<H2>Variant groups</H2>\n";
348    $cont .= $application->component( 'ShowVariantsTable' )->output();  #  $cont .= $application->component( 'ShowVariantsTable' )->output();
349      $cont .= $thistable;
350    
351    $cont .= $cgi->hidden(-name => 'request', -value => 'set_variants', -override => 1);    $cont .= $cgi->hidden(-name => 'request', -value => 'set_variants', -override => 1);
352    $cont .= $cgi->hidden(-name => 'subsystem', -value => $name, -override => 1);    $cont .= $cgi->hidden(-name => 'subsystem', -value => $name, -override => 1);
353    
354      if ( defined( $cgi->param( 'hundred_hundred' ) ) ) {
355        $cont .= $cgi->hidden(-name => 'hundred_hundred', -value => $cgi->param( 'hundred_hundred' ), -override => 1 );
356      }
357    
358      if ( $can_alter ) {
359    $cont .= $cgi->br;    $cont .= $cgi->br;
360      }
361    $cont .= $cgi->submit( -name => "set_variants", -value => "Set Variants" );    $cont .= $cgi->submit( -name => "set_variants", -value => "Set Variants" );
362    $cont .= $self->end_form();    $cont .= $self->end_form();
363    
# Line 255  Line 428 
428        foreach my $role ( @roles ) {        foreach my $role ( @roles ) {
429          push( @has, ( $sub->get_pegs_from_cell( $genome, $role ) > 0 ) ? $abbrev->{ $role } : () );          push( @has, ( $sub->get_pegs_from_cell( $genome, $role ) > 0 ) ? $abbrev->{ $role } : () );
430        }        }
431        my $pattern = join( ",", @has );        my $pattern = quotemeta( join( ",", @has ) );
432        push( @{ $genomes_with{ "$pattern, $vc" } }, $genome );        push( @{ $genomes_with{ "$pattern, $vc" } }, $genome );
433      }      }
434    
435      my $comment = '';      my $comment = '';
436        my @params = grep { $_ =~ /^p##:##/ } $cgi->param;
437    
     my @params = grep { $_ =~ /^p:/ } $cgi->param;  
438      foreach my $param (@params) {      foreach my $param (@params) {
439        if ( $param =~ /^p:(.*):(.*)$/ ) {  
440          if ( $param =~ /^p##:##(.*)##:##(.*)$/ ) {
441          my ( $pattern, $vc ) = ( $1, $2 );          my ( $pattern, $vc ) = ( $1, $2 );
442    
443          $pattern =~ s/ //g;          $pattern =~ s/ //g;
444          $vc      =~ s/ //g;          $vc      =~ s/ //g;
445          my $to = $cgi->param( $param );          my $to = $cgi->param( $param );
446    
447          if ( my $x = $genomes_with{ "$pattern, $vc" } ) {          if ( my $x = $genomes_with{ "$pattern, $vc" } ) {
   
448            foreach my $genome ( @$x ) {            foreach my $genome ( @$x ) {
449    
450              if ( $to ne $variant_codes{ $genome } ) {              if ( $to ne $variant_codes{ $genome } ) {
451    
452                my $old = $variant_codes{$genome};                my $old = $variant_codes{$genome};
453                my $gs = $fig->genus_species($genome);                my $gs = $fig->genus_species($genome);
454                $comment .= "resetting $genome $gs from $old to $to<BR>\n";                $comment .= "resetting $genome $gs from $old to $to<BR>\n";
# Line 283  Line 459 
459          }          }
460        }        }
461      }      }
462    
463        $sub->incr_version();
464        $sub->db_sync();
465      $sub->write_subsystem();      $sub->write_subsystem();
466    
467      return $comment;      return $comment;
468  }  }
469    
470    sub create_table {
471      my ($self, $fig, $has_filled, $col_hdrs, $tab ) = @_;
472    
473      my $in;
474      my $tabl = "<TABLE class='table_table'><TR>";
475    
476      foreach my $ch ( @$col_hdrs ) {
477        $tabl .= "<TD class='table_first_row'>";
478        $tabl .= $ch->{ name };
479        $tabl .= "</TD>";
480      }
481    
482      foreach my $r ( @$tab ) {
483        $tabl .= "<TR>";
484    
485        my $num = scalar( keys %{ $has_filled->{ $r->[0] } } );
486        my $pat = $r->[0];
487        if ( $num > 1 ) {
488          if ( !$in->{ $pat } ) {
489            $tabl .= "<TD rowspan=$num class='table_odd_row' STYLE='vertical-align: middle;'>".$r->[0]."</TD>";
490            $in->{ $pat } = 1;
491          }
492        }
493        else {
494          $tabl .= "<TD class='table_odd_row'>".$r->[0]."</TD>";
495        }
496        my $next = 0;
497        foreach my $cell ( @$r ) {
498          if ( $next == 0 ) {
499            $next = 1;
500            next;
501          }
502          else {
503            $tabl .= "<TD class='table_odd_row'>".$cell."</TD>";
504          }
505        }
506        $tabl .= "</TR>";
507      }
508    
509      $tabl .= "</TABLE>";
510    
511      return $tabl;
512    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3