#!/usr/local/bin/perl ############################################################################### # Program : ViewPeptideExpression # $Id: GetProtein 7773 2015-02-03 00:06:08Z zsun $ # # Description : Prints summary of ... # # # SBEAMS is Copyright (C) 2000-2015 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. # ############################################################################### ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use Data::Dumper; $|++; use lib "$FindBin::Bin/../../lib/perl"; use vars qw ($sbeams $sbeamsMOD $q $current_contact_id $current_username $PROG_NAME $USAGE %OPTIONS $QUIET $VERBOSE $DEBUG $DATABASE $TABLE_NAME $PROGRAM_FILE_NAME $CATEGORY $DB_TABLE_NAME @MENU_OPTIONS); use SBEAMS::Connection qw($q $log); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Connection::TabMenu; $sbeams = new SBEAMS::Connection; my $htmlmode; use SBEAMS::BioLink; my $biolink = SBEAMS::BioLink->new(); $biolink->setSBEAMS($sbeams); use SBEAMS::BioLink; my $biolink = new SBEAMS::BioLink; use SBEAMS::PeptideAtlas; use SBEAMS::PeptideAtlas::Settings; use SBEAMS::PeptideAtlas::Tables; use SBEAMS::PeptideAtlas::ProtInfo; use SBEAMS::PeptideAtlas::GetOrigeneCov; $sbeamsMOD = new SBEAMS::PeptideAtlas; $sbeamsMOD->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); my $origenecov = new SBEAMS::PeptideAtlas::GetOrigeneCov; use SBEAMS::PeptideAtlas::KeySearch; my $keySearch = new SBEAMS::PeptideAtlas::KeySearch; $keySearch->setSBEAMS($sbeams); use SBEAMS::PeptideAtlas::BestPeptideSelector; my $bestPeptideSelector = new SBEAMS::PeptideAtlas::BestPeptideSelector; $bestPeptideSelector->setSBEAMS($sbeams); $bestPeptideSelector->setAtlas($sbeamsMOD); # Global sequence coverage array, will be populated post-graphic my @coverage; my $max_intensity = 1; my %coverage=(); my @methods = qw(ITCID FTCID ITETD FTETD HCD); # Swiss Prot annotations my @sp_rows; my $sp_rationale; my $current_page = { organism => '', atlas_build_id => '' }; my $parameters; use constant MIN_OBS_LENGTH => 6; use constant MAX_OBS_LENGTH => 40; ############################################################################### # Set program name and usage banner for command like use ############################################################################### $PROG_NAME = $FindBin::Script; $USAGE = <Authenticate() and exit if it fails or continue if it works. ############################################################################### 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, )); #### Read in the default input parameters my %parameters; $parameters = \%parameters; my $n_params_found = $sbeams->parse_input_parameters( q=>$q, parameters_ref=>\%parameters); #$sbeams->printDebuggingInfo($q); #### Process generic "state" parameters before we start $sbeams->processStandardParameters(parameters_ref=>\%parameters); # Cache current output mode $htmlmode = ( $sbeams->output_mode() eq 'html' ) ? 1 : 0; #### Decide what action to take based on information so far if ($parameters{action} eq "???") { # Some action } else { my $project_id = $sbeamsMOD->getProjectID( atlas_build_id => $parameters{atlas_build_id} ); # TMF $sbeamsMOD->display_page_header(project_id => $project_id, init_tooltip => 1); handle_request(ref_parameters=>\%parameters); $sbeamsMOD->display_page_footer(); } } # end main ############################################################################### # Handle Request ############################################################################### sub handle_request { my %args = @_; my $spacer = $sbeams->getGifSpacer( 900 ); #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ref_parameters not passed"; my %parameters = %{$ref_parameters}; # put a spacer so that showing hidden content doesn't mangle the layout print "
$spacer\n" if $htmlmode; #### Get the HTML to display the tabs my $tabMenu = $sbeamsMOD->getTabMenu( parameters_ref => \%parameters, program_name => $PROG_NAME, ); print $tabMenu->asHTML() if ($sbeams->output_mode() eq 'html'); my $contact_id = $sbeams->getCurrent_contact_id(); my $samples = getSamples(); my $sample_list = getSampleList( sample_list => $samples ); my $htmlmode = 1; ############################################################# ## Display the samples list ## # Widget to allow show/hide of sample map section my ( $tr, $link ) = $sbeams->make_table_toggle( name => 'getprotein_samplemap', visible => 1, tooltip => 'Show/Hide Section', imglink => 1, sticky => 1 ); print "

"; print " Protein Accession: $parameters->{acc}
"; print " SNP position: $parameters->{pos}
"; print " SNP description: $parameters->{desc}

"; print " SNP supporting peptides

"; print "\n"; print " Original sequence supporting peptides
"; print "\n"; my @speps; my @opeps; my $pep_seq = "'" . join( "','", keys( %speps ), keys( %opeps ) ) . "'"; my $sql = qq~ SELECT DISTINCT peptide_instance_id, peptide_sequence, n_observations FROM $TBAT_PEPTIDE P JOIN $TBAT_PEPTIDE_INSTANCE PI ON P.peptide_id = PI.peptide_id WHERE peptide_sequence IN ( $pep_seq ) AND atlas_build_id = $parameters->{atlas_build_id} ORDER BY n_observations DESC, peptide_sequence ASC ~; my $sth = $sbeams->get_statement_handle($sql); while ( my @db_row = $sth->fetchrow_array() ) { if ( $speps{$db_row[1]} ) { push @speps, $db_row[0]; } elsif ( $opeps{$db_row[1]} ) { push @opeps, $db_row[0]; } else { die "Stray peptide $db_row[1]"; } } my $sampleMap = $sbeamsMOD->getSampleMapDisplayMod( snp_support => \@speps, snp_original => \@opeps, atlas_build_id => $parameters->{atlas_build_id}, link => $link, tr_info => $tr, header_text => "Shows per-experiment expression observed peptides" ); print "$sampleMap
" if $htmlmode; # die $contact_id; } sub getSamples { my %args = @_; my $SUB_NAME = 'getSamples'; my $sql = qq~ SELECT sample_id,sample_title FROM $TBAT_SAMPLE WHERE record_status != 'D' ORDER BY sample_id ~; my @samples = $sbeams->selectSeveralColumns($sql); return \@samples; } # end getSamples sub getSampleList { my %args = @_; #### Decode the argument list return [] unless $args{sample_list}; # each row has an accession, sample_string pair. my %observed_samples; foreach my $row (@{$args{sample_list}}) { my $observed_sample_list = $row->[1]; my @all = split(/[,;]/,$observed_sample_list); foreach my $element ( @all ) { $observed_samples{$element}++; } } my @keys = keys( %observed_samples ); return \@keys; }