[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.5, Thu Mar 20 19:28: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  }  }
26    
27  sub require_javascript {  sub require_javascript {
# Line 35  Line 36 
36  sub output {  sub output {
37    my ( $self ) = @_;    my ( $self ) = @_;
38    
39    my $can_alter = 1;    my $can_alter = 0;
40      my $user = $self->application->session->user;
41    
42    my $fig = new FIG;    my $fig = new FIG;
43    my $cgi = $self->application->cgi;    my $cgi = $self->application->cgi;
# Line 44  Line 46 
46    my $ssname = $name;    my $ssname = $name;
47    $ssname =~ s/\_/ /g;    $ssname =~ s/\_/ /g;
48    
49      my $dbmaster = DBMaster->new( -database => 'WebAppBackend' );
50      my $ppoapplication = $dbmaster->Backend->init( { name => 'SubsystemEditor' } );
51    
52      # get a seeduser #
53      my $seeduser = '';
54      if ( defined( $user ) && ref( $user ) ) {
55        my $preferences = $dbmaster->Preferences->get_objects( { user => $user,
56                                                                 name => 'SeedUser',
57                                                                 application => $ppoapplication } );
58        if ( defined( $preferences->[0] ) ) {
59          $seeduser = $preferences->[0]->value();
60        }
61      }
62    
63      if ( $user && $user->has_right( $self->application, 'edit', 'subsystem', $name ) ) {
64        $can_alter = 1;
65        $fig->set_user( $seeduser );
66      }
67    
68    ######################    ######################
69    # Construct the menu #    # Construct the menu #
70    ######################    ######################
# Line 53  Line 74 
74    # Build nice tab menu here    # Build nice tab menu here
75    $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$name" );    $menu->add_category( 'Subsystem Info', "SubsysEditor.cgi?page=ShowSubsystem&subsystem=$name" );
76    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );
77    $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );    $menu->add_category( 'Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );
78    $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );    $menu->add_category( 'Illustrations', "SubsysEditor.cgi?page=ShowIllustrations&subsystem=$name" );
79    $menu->add_category( 'Subsystem Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );    $menu->add_category( 'Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );
80    $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );    $menu->add_category( 'Show Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );
81      $menu->add_category( 'Show Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );
82    
83    
84    ##############################    ##############################
# Line 72  Line 94 
94      return $content;      return $content;
95    }    }
96    
97    my ( $datahash, $subsystem ) = get_data( $fig, $name );    my $subsystem = $fig->get_subsystem( $name );
98      my ( $datahash ) = get_data( $fig, $subsystem );
99    
100    my $application = $self->application;    my $application = $self->application;
101    
# Line 81  Line 104 
104      $comment .= set_variants( $cgi, $fig, $name, $subsystem, $application, $datahash );      $comment .= set_variants( $cgi, $fig, $name, $subsystem, $application, $datahash );
105      ( $datahash, $subsystem ) = get_data( $fig, $name );      ( $datahash, $subsystem ) = get_data( $fig, $name );
106    }    }
107      elsif ( $cgi->param( 'addsave_variants' ) ) {
108        my @varcodes = $cgi->param( 'VARIANT' );
109        my @vardescs = $cgi->param( 'VARIANTDESC' );
110        my %varhash;
111    
112        for ( my $i = 0; $i < scalar( @varcodes ); $i++ ) {
113    
114    $content .= show_variants( $self, $cgi, $fig, $name, $subsystem, $datahash );        if ( $varcodes[$i] eq '' ) {
115            if ( $vardescs[$i] ne '' ) {
116              $comment .= "No Variant Code given for description ".$vardescs[$i].", so this variant could not be saved.<BR>\n";
117            }
118            next;
119          }
120          if ( defined( $varhash{ $varcodes[$i] } ) ) {
121            $comment .= "Variant ".$varcodes[$i]." already has the description ".$varhash{ $varcodes[$i] }.", so description ".$vardescs[$i]." was ignored.<BR>\n";
122            next;
123          }
124    
125          $varhash{ $varcodes[$i] } = $vardescs[$i];
126        }
127        my $newvarcode = $cgi->param( 'NEWVARIANT' );
128        my $newvardesc = $cgi->param( 'NEWVARIANTDESC' );
129        if ( defined( $newvarcode ) && $newvarcode ne '' && defined( $newvardesc ) && $newvardesc ne '' ) {
130          if ( $newvarcode eq '' ) {
131            if ( $newvarcode ne '' ) {
132              $comment .= "No Variant Code given for description $newvardesc, so this variant could not be saved.<BR>\n";
133            }
134          }
135          elsif ( defined( $varhash{ $newvarcode } ) ) {
136            $comment .= "Variant $newvarcode already has the description $newvardesc, so description $newvardesc was ignored.<BR>\n";
137          }
138          else {
139            $varhash{ $newvarcode } = $newvardesc;
140          }
141        }
142    
143        $subsystem->set_variants( \%varhash );
144        $subsystem->incr_version();
145        $subsystem->db_sync();
146        $subsystem->write_subsystem();
147      }
148    
149      $content .= show_variants( $self, $cgi, $fig, $name, $subsystem, $can_alter, $datahash );
150    
151    ###############################    ###############################
152    # Display errors and comments #    # Display errors and comments #
# Line 94  Line 158 
158    if ( defined( $comment ) && $comment ne '' ) {    if ( defined( $comment ) && $comment ne '' ) {
159      $self->application->add_message( 'info', $comment );      $self->application->add_message( 'info', $comment );
160    }    }
   
161    return $content;    return $content;
162  }  }
163    
# Line 102  Line 165 
165  # data method #  # data method #
166  ###############  ###############
167  sub get_data {  sub get_data {
168    my ( $fig, $name ) = @_;    my ( $fig, $subsystem ) = @_;
169    
170    my $datahash = {};    my $datahash = {};
171    
   my $subsystem = $fig->get_subsystem( $name );  
172    my @genomes        = $subsystem->get_genomes;    my @genomes        = $subsystem->get_genomes;
173    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;
174    my @roles          = $subsystem->get_roles;    my @roles          = $subsystem->get_roles;
# Line 122  Line 184 
184  # show table with variants and button for changing them #  # show table with variants and button for changing them #
185  #########################################################  #########################################################
186  sub show_variants {  sub show_variants {
187    my ( $self, $cgi, $fig, $name, $sub, $datahash ) = @_;    my ( $self, $cgi, $fig, $name, $sub, $can_alter, $datahash ) = @_;
188    
189    my $application = $self->application();    my $application = $self->application();
190    
# Line 165  Line 227 
227    
228      foreach $code ( @codes ) {      foreach $code ( @codes ) {
229    
230        push( @$tab,[ $has_filled{ $pattern }->{ $code },        push( @$tab, [ $pattern,
231                         $has_filled{ $pattern }->{ $code },
232                      $code,                      $code,
233                      $cgi->textfield(-name => "p:$pattern:$code", -size => 5, -value => $code, -override => 1)                      $cgi->textfield(-name => "p:$pattern:$code", -size => 5, -value => $code, -override => 1)
234                    ]);                    ]);
# Line 179  Line 242 
242    my $table = $application->component( 'ShowVariantsTable' );    my $table = $application->component( 'ShowVariantsTable' );
243    $table->columns( $col_hdrs );    $table->columns( $col_hdrs );
244    $table->data( $tab );    $table->data( $tab );
245    
246      ############################################
247      # Variant Descriptions from the Notes file #
248      ############################################
249      $cont .= "<H2>Variant descriptions</H2>\n";
250      my $variants = $sub->get_variants();
251    
252      my $infotable = '';
253      if ( $can_alter ) {
254        $infotable .= "<TABLE><TR><TH>Variant</TH><TH>Description</TH></TR>";
255        foreach my $kv ( sort keys %$variants ) {
256          $infotable .= "<TR><TD><INPUT TYPE=TEXT NAME='VARIANT' ID='VARIANT".$kv."' VALUE='$kv'></TD><TD><INPUT TYPE=TEXT NAME='VARIANTDESC' ID='VARIANTDESC".$kv."' VALUE='".$variants->{ $kv }."' STYLE='width: 500px;'></TD></TR>";
257        }
258        $infotable .= "<TR><TD><INPUT TYPE=TEXT NAME='NEWVARIANT' ID='NEWVARIANT'></TD><TD><INPUT TYPE=TEXT NAME='NEWVARIANTDESC' ID='NEWVARIANTDESC' STYLE='width: 500px;'></TD></TR>";
259        $infotable .= "<TR><TD>";
260        $infotable .= $cgi->submit( -name => "addsave_variants", -value => "Add/Save Variants" );
261        $infotable .= "</TD></TR></TABLE>";
262    
263        $cont .= $infotable;
264      }
265      else {
266        my $infotable = $application->component( 'VarDescTable' );
267        $infotable->columns( [ { name => "Variant" }, { name => "Description" } ] );
268    
269        my $vardata;
270        foreach my $kv ( sort keys %$variants ) {
271          push @$vardata, [ $kv, $variants->{ $kv } ];
272        }
273        $infotable->data( $vardata );
274        $cont .= $infotable->output();
275      }
276    
277    
278    $cont .= "<H2>Variant groups</H2>\n";    $cont .= "<H2>Variant groups</H2>\n";
279    $cont .= $application->component( 'ShowVariantsTable' )->output();    $cont .= $application->component( 'ShowVariantsTable' )->output();
280    
# Line 283  Line 379 
379          }          }
380        }        }
381      }      }
382    
383        $sub->incr_version();
384        $sub->db_sync();
385      $sub->write_subsystem();      $sub->write_subsystem();
386    
387      return $comment;      return $comment;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3