[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.10, Mon Jul 7 18:50:53 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 );    ############################################
310    $table->data( $tab );    # Variant Descriptions from the Notes file #
311      ############################################
312      $cont .= "<H2>Variant descriptions</H2>\n";
313      my $variants = $sub->get_variants();
314    
315      my $infotable = '';
316      if ( $can_alter ) {
317        $infotable .= "<TABLE class='table_table'><TR><TD class='table_first_row'>Variant</TD><TD class='table_first_row'>Description</TD></TR>";
318        foreach my $kv ( sort keys %$variants ) {
319          $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>";
320        }
321        $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>";
322        $infotable .= "<TR><TD>";
323        $infotable .= $cgi->submit( -name => "addsave_variants", -value => "Add/Save Variants" );
324        $infotable .= "</TD></TR></TABLE>";
325    
326        $cont .= $infotable;
327      }
328      else {
329        my $infotable = $application->component( 'VarDescTable' );
330        $infotable->columns( [ { name => "Variant" }, { name => "Description" } ] );
331    
332        my $vardata;
333        foreach my $kv ( sort keys %$variants ) {
334          push @$vardata, [ $kv, $variants->{ $kv } ];
335        }
336        $infotable->data( $vardata );
337        $cont .= $infotable->output();
338      }
339    
340      my $esc_name = uri_escape($name);
341    
342    $cont .= "<H2>Variant groups</H2>\n";    $cont .= "<H2>Variant groups</H2>\n";
343    $cont .= $application->component( 'ShowVariantsTable' )->output();  #  $cont .= $application->component( 'ShowVariantsTable' )->output();
344      $cont .= $thistable;
345    
346    $cont .= $cgi->hidden(-name => 'request', -value => 'set_variants', -override => 1);    $cont .= $cgi->hidden(-name => 'request', -value => 'set_variants', -override => 1);
347    $cont .= $cgi->hidden(-name => 'subsystem', -value => $name, -override => 1);    $cont .= $cgi->hidden(-name => 'subsystem', -value => $name, -override => 1);
348    
349      if ( defined( $cgi->param( 'hundred_hundred' ) ) ) {
350        $cont .= $cgi->hidden(-name => 'hundred_hundred', -value => $cgi->param( 'hundred_hundred' ), -override => 1 );
351      }
352    
353      if ( $can_alter ) {
354    $cont .= $cgi->br;    $cont .= $cgi->br;
355      }
356    $cont .= $cgi->submit( -name => "set_variants", -value => "Set Variants" );    $cont .= $cgi->submit( -name => "set_variants", -value => "Set Variants" );
357    $cont .= $self->end_form();    $cont .= $self->end_form();
358    
# Line 201  Line 369 
369    
370      my $col_hdrs = [ "Column", "Abbrev", "Functional Role" ];      my $col_hdrs = [ "Column", "Abbrev", "Functional Role" ];
371    
372      my $n = 1;      my ( $tab, $abbrevP ) = format_existing_roles( $fig, $subsystem );
     my ( $tab, $abbrevP ) = format_existing_roles( $fig, $subsystem, \$n );  
373    
374      # create table from parsed data      # create table from parsed data
375      my $table = $application->component( 'FRTable' );      my $table = $application->component( 'FRTable' );
# Line 220  Line 387 
387  # get rows of the functional role table #  # get rows of the functional role table #
388  #########################################  #########################################
389  sub format_existing_roles {  sub format_existing_roles {
390      my ( $fig, $subsystem, $nP ) = @_;      my ( $fig, $subsystem ) = @_;
391      my $tab = [];      my $tab = [];
392      my $abbrevP = {};      my $abbrevP = {};
393    
# Line 228  Line 395 
395        my $i = $subsystem->get_role_index( $role );        my $i = $subsystem->get_role_index( $role );
396        my $abbrev = $role ? $subsystem->get_role_abbr( $i ) : "";        my $abbrev = $role ? $subsystem->get_role_abbr( $i ) : "";
397        $abbrevP->{ $role } = $abbrev;        $abbrevP->{ $role } = $abbrev;
398        push( @$tab, [ $$nP, $abbrev, $role ] );        push( @$tab, [ $i + 1, $abbrev, $role ] );
399      }      }
400    
401      return ( $tab, $abbrevP );      return ( $tab, $abbrevP );
# Line 255  Line 422 
422        foreach my $role ( @roles ) {        foreach my $role ( @roles ) {
423          push( @has, ( $sub->get_pegs_from_cell( $genome, $role ) > 0 ) ? $abbrev->{ $role } : () );          push( @has, ( $sub->get_pegs_from_cell( $genome, $role ) > 0 ) ? $abbrev->{ $role } : () );
424        }        }
425        my $pattern = join( ",", @has );        my $pattern = quotemeta( join( ",", @has ) );
426        push( @{ $genomes_with{ "$pattern, $vc" } }, $genome );        push( @{ $genomes_with{ "$pattern, $vc" } }, $genome );
427      }      }
428    
429      my $comment = '';      my $comment = '';
430        my @params = grep { $_ =~ /^p##:##/ } $cgi->param;
431    
     my @params = grep { $_ =~ /^p:/ } $cgi->param;  
432      foreach my $param (@params) {      foreach my $param (@params) {
433        if ( $param =~ /^p:(.*):(.*)$/ ) {  
434          if ( $param =~ /^p##:##(.*)##:##(.*)$/ ) {
435          my ( $pattern, $vc ) = ( $1, $2 );          my ( $pattern, $vc ) = ( $1, $2 );
436    
437          $pattern =~ s/ //g;          $pattern =~ s/ //g;
438          $vc      =~ s/ //g;          $vc      =~ s/ //g;
439          my $to = $cgi->param( $param );          my $to = $cgi->param( $param );
440    
441          if ( my $x = $genomes_with{ "$pattern, $vc" } ) {          if ( my $x = $genomes_with{ "$pattern, $vc" } ) {
   
442            foreach my $genome ( @$x ) {            foreach my $genome ( @$x ) {
443    
444              if ( $to ne $variant_codes{ $genome } ) {              if ( $to ne $variant_codes{ $genome } ) {
445    
446                my $old = $variant_codes{$genome};                my $old = $variant_codes{$genome};
447                my $gs = $fig->genus_species($genome);                my $gs = $fig->genus_species($genome);
448                $comment .= "resetting $genome $gs from $old to $to<BR>\n";                $comment .= "resetting $genome $gs from $old to $to<BR>\n";
449                $sub->set_variant_code( $sub->get_genome_index( $genome ), $to );                $sub->set_variant_code( $sub->get_genome_index( $genome ), $to );
450              }              }
451            }            }
   
452          }          }
453        }        }
454      }      }
455    
456        $sub->incr_version();
457        $sub->db_sync();
458      $sub->write_subsystem();      $sub->write_subsystem();
459    
460      return $comment;      return $comment;
461  }  }
462    
463    sub create_table {
464      my ($self, $fig, $has_filled, $col_hdrs, $tab ) = @_;
465    
466      my $in;
467      my $tabl = "<TABLE class='table_table'><TR>";
468    
469      foreach my $ch ( @$col_hdrs ) {
470        $tabl .= "<TD class='table_first_row'>";
471        $tabl .= $ch->{ name };
472        $tabl .= "</TD>";
473      }
474    
475      foreach my $r ( @$tab ) {
476        $tabl .= "<TR>";
477    
478        my $num = scalar( keys %{ $has_filled->{ $r->[0] } } );
479        my $pat = $r->[0];
480        if ( $num > 1 ) {
481          if ( !$in->{ $pat } ) {
482            $tabl .= "<TD rowspan=$num class='table_odd_row' STYLE='vertical-align: middle;'>".$r->[0]."</TD>";
483            $in->{ $pat } = 1;
484          }
485        }
486        else {
487          $tabl .= "<TD class='table_odd_row'>".$r->[0]."</TD>";
488        }
489        my $next = 0;
490        foreach my $cell ( @$r ) {
491          if ( $next == 0 ) {
492            $next = 1;
493            next;
494          }
495          else {
496            $tabl .= "<TD class='table_odd_row'>".$cell."</TD>";
497          }
498        }
499        $tabl .= "</TR>";
500      }
501    
502      $tabl .= "</TABLE>";
503    
504      return $tabl;
505    }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3