#!/usr/local/bin/perl
###############################################################################
# $Id$
#
# Description : This script authenticates the user, and then
# displays the opening access page.
#
# SBEAMS is Copyright (C) 2000-2021 Institute for Systems Biology
# This program is governed by the terms of the GNU General Public License (GPL)
# version 2 as published by the Free Software Foundation. It is provided
# WITHOUT ANY WARRANTY. See the full description of GPL terms in the
# LICENSE file distributed with this software.
#
###############################################################################
###############################################################################
# Get the script set up with everything it will need
###############################################################################
use strict;
use vars qw ($q $sbeams $atlas $PROG_NAME
$current_contact_id $current_username);
use lib qw (../../lib/perl);
use CGI::Carp qw(fatalsToBrowser croak);
use SBEAMS::Connection qw($q $log);
use SBEAMS::Connection::DataTable;
use SBEAMS::Connection::Settings;
use SBEAMS::Connection::Tables;
use SBEAMS::Connection::TabMenu;
use SBEAMS::PeptideAtlas::Tables;
use SBEAMS::PeptideAtlas::BestPeptideSelector;
use SBEAMS::PeptideAtlas::Settings;
use SBEAMS::PeptideAtlas;
###############################################################################
# Global Variables
###############################################################################
$PROG_NAME = 'ViewSRMBuild';
$SBEAMS_SUBDIR = 'PeptideAtlas';
$sbeams = new SBEAMS::Connection;
$atlas = new SBEAMS::PeptideAtlas;
$atlas->setSBEAMS($sbeams);
my $peptide_selector = new SBEAMS::PeptideAtlas::BestPeptideSelector;
$peptide_selector->setAtlas( $atlas );
$peptide_selector->setSBEAMS( $sbeams );
my $GV = SBEAMS::Connection::GoogleVisualization->new();
my $instrument_map = $peptide_selector->getInstrumentMap();
$instrument_map->{Any} = 0;
my %code2instrument = reverse( %{$instrument_map} );
# Coverage hash keyed by build_id
my %builds;
my %current_build;
my %parameters;
main();
###############################################################################
# Main Program:
#
# Call $sbeams->Authentication and stop immediately if authentication
# fails else continue.
###############################################################################
sub main
{
# Do the SBEAMS authentication and exit if a username is not returned
exit unless ($current_username = $sbeams->Authenticate(
permitted_work_groups_ref=>['PeptideAtlas_user','PeptideAtlas_admin',
'PeptideAtlas_readonly', 'PeptideAtlas_exec'],
#connect_read_only=>1,
allow_anonymous_access=>1,
));
$sbeams->setSessionAttribute( key => 'PA_resource', value => 'SRMAtlas' );
# Read in the default input parameters
my $n_params_found = $sbeams->parse_input_parameters(
q=>$q,
parameters_ref=>\%parameters
);
# Process generic "state" parameters before we start
$sbeams->processStandardParameters(parameters_ref=>\%parameters);
# This will look for mod-specific params and do the right thing
$atlas->processModuleParameters(parameters_ref=>\%parameters);
$parameters{cov_level} ||= 'cov_3';
# get project_id
my $project_id = $atlas->getProjectID(
atlas_build_name => $parameters{atlas_build_name},
atlas_build_id => $parameters{atlas_build_id}
);
$atlas->display_page_header(project_id => $project_id);
my $atlas_build_id = $atlas->getCurrentAtlasBuildID(
parameters_ref => \%parameters,
);
$parameters{atlas_build_id} = $atlas_build_id;
# Will use passed build_id if any, then cached (cookie) id, then default
# If user passed bogus value it should get sorted out here.
my $pabst_build_id = $peptide_selector->get_pabst_build( %parameters );
$parameters{pabst_build_id} = $pabst_build_id;
#### Get the HTML to display the tabs
my $tabMenu = $atlas->getTabMenu(
parameters_ref => \%parameters,
program_name => $PROG_NAME,
);
if ($sbeams->output_mode() eq 'html') {
print "";
print $tabMenu->asHTML();
print "
\n";
}
my $content = '';
$content .= get_build_list(%parameters);
$content .= "
\n";
$content .= $sbeams->makeInfoText( "Charts shows detailed coverage plots for selected build, use radio buttons in table (above) to switch
" );
$content .= get_build_details(%parameters);
print "$content";
$atlas->display_page_footer();
$sbeams->setSessionAttribute( key => 'PA_resource', value => '' );
} # end main
###############################################################################
# Show the main welcome page
###############################################################################
sub get_build_details {
my %parameters = @_;
my $section_header = $atlas->encodeSectionHeader(
LMTABS => 1,
no_toggle => 1,
text => "SRMAtlas Build: $builds{$parameters{pabst_build_id}}->{name} ($parameters{pabst_build_id})"
);
my @instruments = sort {$a <=> $b} keys( %{$builds{$parameters{pabst_build_id}}->{instruments}} );
push @instruments, shift( @instruments );
print "
"; # print Dumper( @instruments ); print ""; my @samples; my @csamples; if ( $current_build{instruments}->{0}->{cov_any} < 500 ) { $current_build{bioseq_cnt} = $current_build{instruments}->{0}->{cov_any}; } for my $instrument ( @instruments ) { my @inst_row = ( $code2instrument{$instrument} ); my @cumulative_row = ( $code2instrument{$instrument} ); my $cov_0 = $current_build{instruments}->{$instrument}->{cov_0}; if ( $current_build{bioseq_cnt} < 1000 ) { $cov_0 = $current_build{instruments}->{$instrument}->{cov_any} - $current_build{bioseq_cnt}; $cov_0 = 0 if $cov_0 < 1; } # Format $cov_0 = sprintf( "%0.1f", 100*($cov_0/$current_build{bioseq_cnt})) if $cov_0; push @inst_row, $cov_0; push @cumulative_row, $cov_0; my $cumulative; my @individual; my @cumulative; for my $cov ( reverse( qw( cov_1 cov_2 cov_3 cov_4 cov_5 ) ) ) { $cumulative += $current_build{instruments}->{$instrument}->{$cov}; my $currcum = ( $cumulative ) ? sprintf( "%0.1f", 100*($cumulative/$current_build{bioseq_cnt}) ) : 0; push @cumulative, $currcum; my $currval = $current_build{instruments}->{$instrument}->{$cov}; $currval = sprintf( "%0.1f", 100*($currval/$current_build{bioseq_cnt}) ) if $currval; push @individual, $currval; } push @inst_row, reverse( @individual ); push @cumulative_row, reverse( @cumulative ); push @samples, \@inst_row; push @csamples, \@cumulative_row; } my $ichart = make_individual_chart_function( \@samples ); my $cchart = make_cumulative_chart_function( \@csamples ); my $header = $GV->getHeaderInfo(); my $content = qq~
"; for my $id ( @instruments ) { my $cnt = ' - '; if ( $builds{$build->[0]}->{instruments}->{$id} ) { # print "we have $id for $build->[0]\n"; if ( $builds{$build->[0]}->{instruments}->{$id}->{$parameters{cov_level}} ) { # print "we have $parameters{cov_level}!!\n"; # $cnt = sprintf( "%0.1f", 100*$builds{$build->[0]}->{instruments}->{$id}->{$parameters{cov_level}}/$ref_db_cnt ) . '%'; $cnt = sprintf( "%0.1f", 100*$builds{$build->[0]}->{instruments}->{$id}->{$parameters{cov_level}}/$ref_db_cnt ) . '%'; } } push @build_row, $cnt; } # print "build is $build->[0], cov is $parameters{cov_level}"; # print Dumper( $builds{$build->[0]} ); print ""; push @build_row, $build->[2]; push @builds, \@build_row; } my ( $html, $rs_name ) = $atlas->encodeSectionTable( header => 1, width => '600', rows => \@builds, rows_to_show => 5000, max_rows => 5000, help_text => '', align => [ qw( center left right right right right right right right left ) ], bg_color => '#EAEAEA', sortable => 0, table_id => 'SRMAtlas', ); # $table->setColAttr( COLS => [2..8], ROWS => [1..$table->getRowNum()], ALIGN => 'RIGHT' ); # $html =~ s/TABLE NOOP/TABLE style="display:none" NOOP/gm; $content .= "