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

Diff of /SubsystemEditor/WebPage/MetaSpreadsheet.pm

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

revision 1.7, Thu Sep 11 12:00:05 2008 UTC revision 1.8, Mon Sep 15 10:27:51 2008 UTC
# Line 27  Line 27 
27    
28    $self->application->register_component( 'Table', 'SubsystemSpreadsheet' );    $self->application->register_component( 'Table', 'SubsystemSpreadsheet' );
29    $self->application->register_component( 'TabView', 'functionTabView' );    $self->application->register_component( 'TabView', 'functionTabView' );
30      $self->application->register_component( 'Info', 'CommentInfo');
31      $self->application->register_component( 'OrganismSelect', 'OSelect');
32    $self->application->register_component( 'Table', 'LD_SUBSETS' );    $self->application->register_component( 'Table', 'LD_SUBSETS' );
33    $self->application->register_component( 'Table', 'LD_ROLES' );    $self->application->register_component( 'Table', 'LD_ROLES' );
34    $self->application->register_component( 'Table', 'FunctionalRolesTable'  );    $self->application->register_component( 'Table', 'FunctionalRolesTable'  );
# Line 123  Line 125 
125    # TASKS #    # TASKS #
126    #########    #########
127    
128      my ( $error, $comment ) = ( "", "" );
129    if ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'LimitSubsets' ) {    if ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'LimitSubsets' ) {
130    
131      my @showsets = $self->{ 'cgi' }->param( 'show_set' );      my @showsets = $self->{ 'cgi' }->param( 'show_set' );
# Line 154  Line 157 
157    elsif ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'NOTPLUSMINUS' ) {    elsif ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'NOTPLUSMINUS' ) {
158      $self->{ 'plusminus' } = 0;      $self->{ 'plusminus' } = 0;
159    }    }
160      elsif ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'DeleteGenomes' ) {
161        my @genomesIds = $self->{ 'cgi' }->param( 'genome_checkbox' );
162        my ( $putcomment ) = $self->remove_genomes( \@genomesIds );
163        $comment .= $putcomment;
164      }
165      elsif ( defined( $self->{ 'cgi' }->param( 'buttonpressed' ) ) && $self->{ 'cgi' }->param( 'buttonpressed' ) eq 'Add selected genome(s) to spreadsheet' ) {
166        my @newGenomes = $self->{ 'cgi' }->param( 'new_genome' );
167        my $specialsetlist = $self->{ 'cgi' }->param( 'add_special_set' );
168        my $usersetlist = $self->{ 'cgi' }->param( 'add_user_set' );
169        my $ghash = {};
170        unless( $specialsetlist eq 'None' ) {
171          my @subsetspecial = $self->moregenomes( $specialsetlist );
172          my %tmpspecialhash = map { $_ => 1 } @subsetspecial;
173          $ghash = \%tmpspecialhash;
174        }
175        unless( $usersetlist eq 'None' ) {
176          $ghash = get_userlist_hash( $usersetlist, $ghash );
177        }
178    
179        # take only the fig-tax id from the genome label #
180        foreach my $g ( @newGenomes ) {
181          $ghash->{ $g } = 1;
182        }
183    
184        my @garray = keys %$ghash;
185        my ( $puterror, $putcomment ) = $self->add_refill_genomes( \@garray );
186        $error .= $puterror;
187        $comment .= $putcomment;
188      }
189    if ( !defined( $self->{ 'activeSubsetHash' } ) ) {    if ( !defined( $self->{ 'activeSubsetHash' } ) ) {
190      $self->{ 'activeSubsetHash' } = $self->getActiveSubsetHash();      $self->{ 'activeSubsetHash' } = $self->getActiveSubsetHash();
191    }    }
# Line 191  Line 223 
223    # limitdisplaypanel #    # limitdisplaypanel #
224    my $limitdisplaypanel = $self->limit_display_panel();    my $limitdisplaypanel = $self->limit_display_panel();
225    my $limitsubsetspanel = $self->limit_subsets_panel();    my $limitsubsetspanel = $self->limit_subsets_panel();
226      # addgenomespanel #
227      my $addgenomepanel = $self->add_genomes_panel( $application );
228    
229    # spreadsheetbuttons #    # spreadsheetbuttons #
230    my $spreadsheetbuttons = $self->get_spreadsheet_buttons();    my $spreadsheetbuttons = $self->get_spreadsheet_buttons();
# Line 198  Line 232 
232    my $tab_view_component = $self->application->component( 'functionTabView' );    my $tab_view_component = $self->application->component( 'functionTabView' );
233    $tab_view_component->width( 900 );    $tab_view_component->width( 900 );
234    if ( $self->{ 'can_alter' } ) {    if ( $self->{ 'can_alter' } ) {
235  #    $tab_view_component->add_tab( '<H2>&nbsp; Add Genomes to Spreadsheet &nbsp;</H2>', "$addgenomepanel" );      $tab_view_component->add_tab( '<H2>&nbsp; Add Genomes to Spreadsheet &nbsp;</H2>', "$addgenomepanel" );
236    }    }
237    $tab_view_component->add_tab( '<H2>&nbsp; Color Spreadsheet &nbsp;</H2>', "$colorpanel" );    $tab_view_component->add_tab( '<H2>&nbsp; Color Spreadsheet &nbsp;</H2>', "$colorpanel" );
238    $tab_view_component->add_tab( '<H2>&nbsp; Limit Genomes &nbsp;</H2>', "$limitdisplaypanel" );    $tab_view_component->add_tab( '<H2>&nbsp; Limit Genomes &nbsp;</H2>', "$limitdisplaypanel" );
# Line 230  Line 264 
264    
265    my $content = "<H1>Subsystem Metaview for $ssname</H1>";    my $content = "<H1>Subsystem Metaview for $ssname</H1>";
266    
267      if ( defined( $comment ) && $comment ne '' ) {
268        my $info_component = $application->component( 'CommentInfo' );
269    
270        $info_component->content( $comment );
271        $info_component->default( 0 );
272        $content .= $info_component->output();
273      }
274    
275    # start form #    # start form #
276    $content .= $self->start_form( 'subsys_spreadsheet', $hiddenvalues );    $content .= $self->start_form( 'subsys_spreadsheet', $hiddenvalues );
277    $content .= "<TABLE><TR><TD>";    $content .= "<TABLE><TR><TD>";
# Line 1415  Line 1457 
1457  }  }
1458    
1459    
 sub moregenomes {  
   my ( $self, $more ) = @_;  
   
   if ($more eq "Cyanobacteria")              { return &selectgenomeattr( $self->{ 'fig' }, "phylogeny", "Cyanobacteria")}  
   if ($more eq "NMPDR")                      { return &selectgenomeattr( $self->{ 'fig' }, "filepresent", "NMPDR")}  
   if ($more eq "BRC")                        { return &selectgenomeattr( $self->{ 'fig' }, "filepresent", "BRC")}  
   if ($more eq "higher_plants")              { return &selectgenomeattr( $self->{ 'fig' }, "higher_plants")}  
   if ($more eq "eukaryotic_ps")              { return &selectgenomeattr( $self->{ 'fig' }, "eukaryotic_ps")}  
   if ($more eq "nonoxygenic_ps")             { return &selectgenomeattr( $self->{ 'fig' }, "nonoxygenic_ps")}  
   if ($more eq "Hundred by a hundred")       { return &selectgenomeattr( $self->{ 'fig' }, "hundred_hundred")}  
   if ($more eq "functional_coupling_paper")  { return &selectgenomeattr( $self->{ 'fig' }, "functional_coupling_paper")}  
 }  
1460    
1461  sub selectgenomeattr {  sub selectgenomeattr {
1462    my ( $fig, $tag, $value )=@_;    my ( $self, $tag, $value )=@_;
1463    my @orgs;    my @orgs;
1464    
1465    if ( $tag eq "phylogeny" ) {    if ( $tag eq "phylogeny" ) {
1466      my $taxonomic_groups = $fig->taxonomic_groups_of_complete(10);      my $taxonomic_groups = $self->{ 'fig' }->taxonomic_groups_of_complete(10);
1467      foreach my $pair (@$taxonomic_groups)      foreach my $pair (@$taxonomic_groups)
1468        {        {
1469          push @orgs, @{$pair->[1]} if ($pair->[0] eq "$value");          push @orgs, @{$pair->[1]} if ($pair->[0] eq "$value");
1470        }        }
1471    }    }
1472    elsif ( $tag eq "filepresent" ) {    elsif ( $tag eq "filepresent" ) {
1473      foreach my $genome ( $fig->genomes ) {      foreach my $genome ( $self->{ 'fig' }->genomes ) {
1474        push(@orgs, $genome) if (-e $FIG_Config::organisms."/$genome/$value");        push(@orgs, $genome) if (-e $FIG_Config::organisms."/$genome/$value");
1475      }      }
1476    }    }
1477    else {    else {
1478      if ( $value ) {      if ( $value ) {
1479        @orgs = map { $_->[0]} grep {$_->[0] =~ /^\d+\.\d+$/ } $fig->get_attributes( undef, $tag, $value );        @orgs = map { $_->[0]} grep {$_->[0] =~ /^\d+\.\d+$/ } $self->{ 'fig' }->get_attributes( undef, $tag, $value );
1480      }      }
1481      else {      else {
1482        @orgs = map { $_->[0]} grep {$_->[0] =~ /^\d+\.\d+$/ } $fig->get_attributes( undef, 'collection', $tag );        @orgs = map { $_->[0]} grep {$_->[0] =~ /^\d+\.\d+$/ } $self->{ 'fig' }->get_attributes( undef, 'collection', $tag );
1483      }      }
1484    }    }
1485    return @orgs;    return @orgs;
# Line 1464  Line 1494 
1494    my $plusminus = "<INPUT TYPE=BUTTON VALUE='PlusMinus View' ID='PLUSMINUS' NAME='PLUSMINUS' ONCLICK='SubmitSpreadsheet( \"PLUSMINUS\", 0 );'>";    my $plusminus = "<INPUT TYPE=BUTTON VALUE='PlusMinus View' ID='PLUSMINUS' NAME='PLUSMINUS' ONCLICK='SubmitSpreadsheet( \"PLUSMINUS\", 0 );'>";
1495    my $notplusminus = "<INPUT TYPE=BUTTON VALUE='Normal View' ID='NOTPLUSMINUS' NAME='NOTPLUSMINUS' ONCLICK='SubmitSpreadsheet( \"NOTPLUSMINUS\", 0 );'>";    my $notplusminus = "<INPUT TYPE=BUTTON VALUE='Normal View' ID='NOTPLUSMINUS' NAME='NOTPLUSMINUS' ONCLICK='SubmitSpreadsheet( \"NOTPLUSMINUS\", 0 );'>";
1496    
1497      my $delete_button = "<INPUT TYPE=HIDDEN VALUE=0 NAME='DeleteGenomesHidden' ID='DeleteGenomesHidden'>";
1498      $delete_button .= "<INPUT TYPE=BUTTON VALUE='Delete selected genomes' NAME='DeleteGenomes' ID='DeleteGenomes' ONCLICK='if ( confirm( \"Do you really want to delete the selected genomes from the spreadsheet?\" ) ) {
1499     document.getElementById( \"DeleteGenomesHidden\" ).value = 1;
1500    SubmitSpreadsheet( \"DeleteGenomes\", 0 ); }'>";
1501    
1502    my $spreadsheetbuttons = "<DIV id='controlpanel'><H2>Actions</H2>\n";    my $spreadsheetbuttons = "<DIV id='controlpanel'><H2>Actions</H2>\n";
1503    
1504    $spreadsheetbuttons .= "<TABLE><TR><TD><B>View:</B></TD><TD>$plusminus</TD></TR></TABLE><BR>";    $spreadsheetbuttons .= "<TABLE><TR><TD><B>View:</B></TD><TD>$plusminus</TD></TR></TABLE><BR>";
1505      $spreadsheetbuttons .= "<TABLE><TR><TD><B>Selection:</B></TD><TD>$delete_button</TD></TR></TABLE><BR>";
1506    
1507    return $spreadsheetbuttons;    return $spreadsheetbuttons;
1508  }  }
1509    
1510    
1511    ##################################
1512    # Add genomes to the spreadsheet #
1513    ##################################
1514    sub add_refill_genomes {
1515      my ( $self, $genomes ) = @_;
1516    
1517      my $comment = "";
1518    
1519      my %newgenomes = map { $_ => 1 } @$genomes;
1520      $self->{ 'metasubsystem' }->add_genomes( \%newgenomes );
1521      $self->{ 'metasubsystem' }->write_metasubsystem();
1522    
1523      $comment .= "Added ". scalar( keys( %newgenomes ) ). " genomes to the spreadsheet:<BR>";
1524    
1525      foreach my $g ( @$genomes ) {
1526        $comment .= " - $g <BR>";
1527      }
1528    
1529      return ( '', $comment );
1530    }
1531    
1532    #######################################
1533    # Remove genomes from the spreadsheet #
1534    #######################################
1535    sub remove_genomes {
1536      my( $self, $genomes ) = @_;
1537    
1538      my $comment = '';
1539    
1540      if ( scalar( @$genomes ) == 0 ) {
1541        return "No genomes selected to delete<BR>\n";
1542      }
1543    
1544      my %delgenomes;
1545      foreach my $genm ( @$genomes ) {
1546        $genm =~ /^genome_checkbox_(\d+\.\d+.*)/;
1547        my $genome = $1;
1548        my $rawgenome = $genome;
1549        $delgenomes{ $genome } = 1;
1550    
1551        if ( $genome =~ /(\d+\.\d+)\:(.*)/ ) {
1552          $rawgenome = $1;
1553          my $loc = $2;
1554          my $genomename = $self->{ 'fig' }->genus_species( $rawgenome );
1555          $comment .= "Deleted region $genomename".": $loc ( $genome ) from the spreadsheet<BR>\n";
1556        }
1557        else {
1558          my $genomename = $self->{ 'fig' }->genus_species( $rawgenome );
1559          $comment .= "Deleted genome $genomename ( $genome ) from the spreadsheet<BR>\n";
1560        }
1561      }
1562    
1563    
1564      $self->{ 'metasubsystem' }->remove_genomes( \%delgenomes );
1565      $self->{ 'metasubsystem' }->write_metasubsystem();
1566    
1567      return $comment;
1568    }
1569    
1570    ##################################
1571    # Upper panel for adding genomes #
1572    ##################################
1573    sub add_genomes_panel {
1574    
1575      my ( $self, $application ) = @_;
1576    
1577      ####################################
1578      # collect some data into variables #
1579      ####################################
1580      # get a hash of all genomes of that subsystem #
1581      my %genomes = %{ $self->{ 'metasubsystem' }->{ 'genomes' } };
1582    
1583      #################################
1584      # Put The New OrganismSelect in #
1585      #################################
1586      my $oselect = $application->component( 'OSelect' );
1587      $oselect->multiple( 1 );
1588      $oselect->width( 500 );
1589      $oselect->name( 'new_genome' );
1590      $oselect->blacklist( \%genomes );
1591    
1592      my @options = ( 'None',
1593                       'NMPDR',
1594                       'BRC',
1595                       'Hundred by a hundred' );
1596    
1597      my @genomeListsUser = GenomeLists::getListsForUser();
1598      unshift @genomeListsUser, 'None';
1599    
1600      ###################
1601      # Build HTML here #
1602      ###################
1603    
1604      my $addgenomespanel .= "<TABLE><TR><TD><TABLE><TR><TD COLSPAN=4>";
1605    
1606      $addgenomespanel .= $oselect->output();
1607    
1608      $addgenomespanel .= "</TD></TR><TR><TD>";
1609    
1610      $addgenomespanel .= "<B>Specific Sets</B></TD><TD><B>User Sets</B></TD></TR><TR><TD>";
1611    
1612      # now special sets #
1613      $addgenomespanel .= $self->{ 'cgi' }->scrolling_list( -id      => 'add_special_set',
1614                                                            -name    => 'add_special_set',
1615                                                            -values  => \@options,
1616                                                            -default => 'None',
1617                                                            -size => 4
1618                                                          );
1619      $addgenomespanel .= "</TD><TD><TABLE><TR><TD>\n";
1620    
1621      $addgenomespanel .= $self->{ 'cgi' }->scrolling_list( -id      => 'add_user_set',
1622                                                            -name    => 'add_user_set',
1623                                                            -values  => \@genomeListsUser,
1624                                                            -default => 'None',
1625                                                            -size => 4
1626                                                          );
1627      $addgenomespanel .= "</TD><TD>\n";
1628      $addgenomespanel .= "<INPUT TYPE=BUTTON VALUE=\"Show selected\ngenome list\" ID='ShowSelectionButton' ONCLICK='OpenGenomeList( \"".$application->url()."\" );'>";
1629      $addgenomespanel .= "</TD></TR></TABLE></TD></TR></TABLE>\n";
1630    
1631      $addgenomespanel .= "</TD></TR><TR><TD>";
1632    
1633      $addgenomespanel .= "<INPUT TYPE=BUTTON VALUE='Add selected genome(s) to spreadsheet' ONCLICK='SubmitSpreadsheet( \"Add selected genome(s) to spreadsheet\", 0 );'>";
1634    
1635      $addgenomespanel .= "</TD></TR></TABLE><BR>";
1636    
1637    
1638      return $addgenomespanel;
1639    }
1640    
1641    sub moregenomes {
1642      my ( $self, $more ) = @_;
1643    
1644      if ($more eq "Cyanobacteria")              { return $self->selectgenomeattr( $self->{ 'fig' }, "phylogeny", "Cyanobacteria")}
1645      if ($more eq "NMPDR")                      { return $self->selectgenomeattr( $self->{ 'fig' }, "filepresent", "NMPDR")}
1646      if ($more eq "BRC")                        { return $self->selectgenomeattr( $self->{ 'fig' }, "filepresent", "BRC")}
1647      if ($more eq "higher_plants")              { return $self->selectgenomeattr( $self->{ 'fig' }, "higher_plants")}
1648      if ($more eq "eukaryotic_ps")              { return $self->selectgenomeattr( $self->{ 'fig' }, "eukaryotic_ps")}
1649      if ($more eq "nonoxygenic_ps")             { return $self->selectgenomeattr( $self->{ 'fig' }, "nonoxygenic_ps")}
1650      if ($more eq "Hundred by a hundred")       { return $self->selectgenomeattr( $self->{ 'fig' }, "hundred_hundred")}
1651      if ($more eq "functional_coupling_paper")  { return $self->selectgenomeattr( $self->{ 'fig' }, "functional_coupling_paper")}
1652    }
1653    
1654    sub get_userlist_hash {
1655      my ( $usersetlist, $ghash ) = @_;
1656    
1657      my $gl = GenomeLists::load( $usersetlist );
1658      my $gs = $gl->{ 'genomes' };
1659      foreach my $ssu ( @$gs ) {
1660        $ghash->{ $ssu } = 1;
1661      }
1662      return $ghash;
1663    }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3