#!/usr/local/bin/perl ############################################################################### # Program : Summarize_Peptide # # Description : Prints global summary of a given peptide # # 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. # ############################################################################### ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use Data::Dumper; use POSIX qw(ceil); use lib "$FindBin::Bin/../../lib/perl"; use vars qw ($sbeams $atlas $q $current_contact_id $current_username $script_name $USAGE %OPTIONS $QUIET $VERBOSE $DEBUG $DATABASE $TABLE_NAME $CATEGORY $DB_TABLE_NAME @MENU_OPTIONS); ##use CGI::Carp qw(fatalsToBrowser croak); use SBEAMS::Connection qw($q $log); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Connection::TabMenu; use SBEAMS::Connection::GoogleVisualization; use SBEAMS::PeptideAtlas; use SBEAMS::PeptideAtlas::Settings; use SBEAMS::PeptideAtlas::Tables; #use SBEAMS::PeptideAtlas::ConsensusSpectrum; use SBEAMS::PeptideAtlas::ModificationHelper; use SBEAMS::BioLink::Tables; use SBEAMS::Proteomics::Tables; # Global vars $sbeams = new SBEAMS::Connection; $atlas = new SBEAMS::PeptideAtlas; $atlas->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); my $modification_helper = new SBEAMS::PeptideAtlas::ModificationHelper(); my $peptide_clause; #$q = new CGI; ############################################################################### # Set program name and usage banner for command like use ############################################################################### $script_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( allow_anonymous_access=>1 ) ); #### Read in the default input parameters my %parameters; my $n_params_found = $sbeams->parse_input_parameters( q=>$q, parameters_ref=>\%parameters ); %global_rs_params = $sbeams->parseResultSetParams( q => $q ); $is_html++ if $sbeams->output_mode() =~ /HTML/i; $is_xml++ if $sbeams->output_mode() =~ /XML/i; $atlas->display_page_header(); handle_request(ref_parameters=>\%parameters); $atlas->display_page_footer(); } # end main ############################################################################### # Handle Request ############################################################################### sub handle_request { my %args = @_; #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ref_parameters not passed"; my %parameters = %{$ref_parameters}; #### Show current user context information #### Get the HTML to display the tabs my $tabMenu = $atlas->getTabMenu( parameters_ref => \%parameters, program_name => $script_name, ); if ( $is_html ) { print $tabMenu->asHTML() } #### Define some generic variables my ($i,$element,$key,$value,$line,$result,$sql, $peptide, $peptide_acc); # Get the search keyword $peptide = $parameters{'searchForThis'}; if ( $peptide =~ /^PAp\d+$/ ) { my $sql = "SELECT DISTINCT peptide_sequence FROM $TBAT_PEPTIDE WHERE peptide_accession = '$peptide'"; my $sth = $sbeams->get_statement_handle( $sql ); while( my @row = $sth->fetchrow_array() ) { $peptide = $row[0]; last; } } # Getting the last session information for a user, if it exists or setting up a new one # If a new protein_name was supplied, store it if ($peptide) { $sbeams->setSessionAttribute( key => 'PeptideAtlas_peptide_name', value => $peptide, ); #### Else see if we had one stored } else { $peptide = $sbeams->getSessionAttribute( key => 'PeptideAtlas_peptide_name', ); if ($peptide) { $parameters{'apply_action'} = 'GO'; } else { ## Setting the value to some given peptide for those users who visits the page first time $peptide='VSFLSALEEYTK'; $parameters{'apply_action'} = 'GO'; } } ## End else # At this point we have a peptide sequence to query, one way or the other. $parameters{peptide} ||= $peptide; # Get list of accessible projects my @accessible_project_ids = $sbeams->getAccessibleProjects(); $parameters{project_string} = join( ",", @accessible_project_ids ); $log->debug( "Projects are $parameters{project_string}" ); my $form = get_form( \%parameters ); print $form if $is_html; if ( $is_xml ) { print $sbeams->getXMLEncodingStatement(); print "\n"; } if ( $is_xml ) { print "\t\n"; } my $physData = get_pa_list( \%parameters ); print $physData; print "
" if $is_html; if ( $is_html ) { print $atlas->encodeSectionHeader( text => "PeptideAtlas Summary", LMTABS=>1, no_toggle => 1 ); } if ( $parameters{show_all_builds} ) { $parameters{default_build_clause} = ''; } else { $parameters{default_build_clause} = qq~ AND AB.atlas_build_id IN ( SELECT atlas_build_id FROM $TBAT_DEFAULT_ATLAS_BUILD WHERE record_status = 'N' ) ~; } my $pa_results = get_pa_resultset( \%parameters ); print $pa_results; if ( $is_html ) { my $plot_html = get_abundance_plot( \%parameters ); print $plot_html; print "
" } else { print "\t
\n" if $is_xml; } if ( $is_xml ) { print "\t\n"; } else { print '' . $atlas->encodeSectionHeader( text => "SRM Atlas Summary", LMTABS=>1, no_toggle=>1 ) . '
'; } my $srm_results = get_srm_resultset( \%parameters ); print $srm_results; print "\t
\n" if ( $is_xml ); print "
" if $is_html; if ( $is_xml ) { print "\t\n" if ( $is_xml ); } else { print '' . $atlas->encodeSectionHeader( text => "PASSEL Summary" , LMTABS=>1, no_toggle=>1) . '
'; } my $passel_results = get_passel_resultset( \%parameters ); print $passel_results; print "\t
\n" if ( $is_xml ); print "
" if $is_html; print "
\n" if ( $is_xml ); } sub get_form { my $params = shift; my @buttons = $sbeams->getFormButtons( types => [ 'Submit', 'Reset' ] ); my $buttons = join( " ", @buttons ); $params->{output_mode} ||= 'html'; my %selected = ( html => '', xml => '' ); if ( $params->{output_mode} =~ /html/i ) { $selected{html} = 'selected'; } else { $selected{xml} = 'selected'; } my $form = qq~

Summary for :    as: $buttons
~; return $form; } sub get_pa_list { my $params = shift; my $sql = qq~ SELECT DISTINCT P.peptide_accession, P.peptide_sequence, STR(P.SSRCalc_relative_hydrophobicity,4,1) AS SSRCalc, STR(P.molecular_weight,8,4) AS molecular_weight, STR(P.peptide_isoelectric_point,3,1) AS pI FROM $TBAT_PEPTIDE P WHERE peptide_sequence = '$params->{peptide}' ~; my $sth = $sbeams->get_statement_handle( $sql ); my @items; my $acc; my $seq; while ( my @row = $sth->fetchrow_array() ) { push @items, { key => 'Peptide Accession', value => $row[0] }; push @items, { key => 'Peptide Sequence', value => $row[1] }; push @items, { key => 'Avg Molecular Weight', value => $row[3] }; push @items, { key => 'pI', value => $row[4] }; push @items, { key => 'SSRCalc', value => $row[2] }; $acc = $row[0]; $seq = $row[1]; } my $list = $atlas->encodeFullSectionList ( header_text => "$acc ($seq) Physical Data", header_element => "PhysicalPeptideData", list_items => \@items, LMTABS=>1, no_toggle=>1 ); return $list; } sub get_pa_resultset { my $params = shift; my $sql = qq~ SELECT DISTINCT OZ.organism_name, AB.atlas_build_name, PI.atlas_build_id, PI.n_observations, AB.project_id, peptide_sequence FROM $TBAT_PEPTIDE_INSTANCE PI INNER JOIN $TBAT_PEPTIDE P ON ( PI.peptide_id = P.peptide_id ) INNER JOIN $TBAT_ATLAS_BUILD AB ON (PI.atlas_build_id = AB.atlas_build_id) INNER JOIN $TBAT_BIOSEQUENCE_SET BS ON (AB.biosequence_set_id = BS.biosequence_set_id) INNER JOIN $TB_ORGANISM OZ ON (BS.organism_id= OZ.organism_id) WHERE 1 = 1 AND peptide_sequence = '$params->{peptide}' AND AB.project_id IN ( $params->{project_string} ) $params->{default_build_clause} ORDER BY OZ.organism_name, PI.n_observations DESC,AB.atlas_build_name ~; $sbeams->collectSTDOUT(); my $pa_resultset = {}; #### Fetch the results from the database server $sbeams->fetchResultSet( sql_query=>$sql, resultset_ref=>$pa_resultset, ); my $name_base = 'PeptideAtlasSummary'; my %rs_params = ( set_name => $name_base . '_' . 'SETME' ); if ( $global_rs_params{set_name} =~ /$name_base/ ) { %rs_params = %global_rs_params; } #### Store the resultset and parameters to disk resultset cache $sbeams->writeResultSet( resultset_file_ref=>\$rs_params{set_name}, resultset_ref=>$pa_resultset, query_parameters_ref=>$params, resultset_params_ref=>\%rs_params, query_name=>"$SBEAMS_SUBDIR/$script_name", ); my %url_cols = ( atlas_build_name => 'buildDetails?atlas_build_id=%2V', n_observations => 'GetPeptide?atlas_build_id=%2V;searchWithinThis=Peptide+Sequence&searchForThis=%5V;action=QUERY' ); my %max_widths; my %hidden_cols = ( atlas_build_id => 1, project_id => 1, peptide_sequence => 1 ); my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$script_name"; #### Display the resultset $sbeams->displayResultSet( resultset_ref=>$pa_resultset, query_parameters_ref=>$params, rs_params_ref=>\%rs_params, url_cols_ref=>\%url_cols, hidden_cols_ref=>\%hidden_cols, max_widths=>\%max_widths, column_titles_ref=> $pa_resultset->{column_list_ref}, base_url=>$base_url, suppress_header => 1 ); my $resultset = $sbeams->fetchSTDOUT(); return $resultset; } # End get_pa_resultset sub get_passel_resultset { my $params = shift; my $sql = qq~ SELECT COUNT(*) AS total, I.instrument_name AS "instrument", SELPI.peptide_charge, SELTG.fragment_ions, S.sample_tag AS "sample", O.organism_name AS "organism", S.sample_id, stripped_peptide_sequence, SELE.SEL_experiment_id FROM $TBAT_SEL_TRANSITION_GROUP SELTG LEFT JOIN $TBAT_SEL_CHROMATOGRAM SELC ON ( SELC.SEL_transition_group_id = SELTG.SEL_transition_group_id ) LEFT JOIN $TBAT_SEL_PEAK_GROUP SELPG ON ( SELPG.SEL_chromatogram_id = SELC.SEL_chromatogram_id ) LEFT JOIN $TBAT_SEL_PEPTIDE_ION SELPI ON ( SELPI.SEL_peptide_ion_id = SELTG.SEL_peptide_ion_id ) LEFT JOIN $TBAT_SEL_PEPTIDE_ION_PROTEIN SELPIP ON ( SELPIP.SEL_peptide_ion_id = SELPI.SEL_peptide_ion_id ) LEFT JOIN $TBAT_SEL_RUN SELR ON ( SELR.SEL_run_id = SELTG.SEL_run_id ) LEFT JOIN $TBAT_SEL_EXPERIMENT SELE ON ( SELE.SEL_experiment_id = SELR.SEL_experiment_id ) LEFT JOIN $TBAT_SAMPLE S ON ( S.sample_id = SELE.sample_id ) LEFT JOIN $TB_ORGANISM O ON ( S.organism_id = O.organism_id ) LEFT JOIN $TBPR_INSTRUMENT I ON ( I.instrument_id = S.instrument_model_id ) WHERE 1 = 1 AND ( stripped_peptide_sequence LIKE '$params->{peptide}' ) AND SELE.project_id in ( $params->{project_string} ) AND SELPI.is_decoy = 'N' AND SELE.record_status != 'D' AND SELR.record_status != 'D' GROUP BY -- SELPIP.protein_accession, I.instrument_name, SELPI.peptide_charge, SELTG.fragment_ions, S.sample_tag, O.organism_name, S.sample_id, stripped_peptide_sequence, SELE.SEL_experiment_id ~; $sbeams->collectSTDOUT(); my $passel_resultset = {}; #### Fetch the results from the database server $sbeams->fetchResultSet( sql_query=>$sql, resultset_ref=>$passel_resultset, ); my $name_base = 'PasselResultset'; my %rs_params = ( set_name => $name_base . '_' . 'SETME' ); if ( $global_rs_params{set_name} =~ /$name_base/ ) { %rs_params = %global_rs_params; } $passel_resultset = post_process_passel_resultset( $passel_resultset ); #### Store the resultset and parameters to disk resultset cache $sbeams->writeResultSet( resultset_file_ref=>\$rs_params{set_name}, resultset_ref=>$passel_resultset, query_parameters_ref=>$params, resultset_params_ref=>\%rs_params, query_name=>"$SBEAMS_SUBDIR/$script_name", ); # AFU my %url_cols = ( experiment => 'GetSELTransitions?stripped_peptide_sequence_constraint=%6V;SEL_experiments=%7V;QUERY_NAME=AT_GetSELTransitions;action=QUERY;apply_action=QUERY' ); my %max_widths; my %hidden_cols = ( sequence => 1, sample_id => 1, SEL_experiment_id => 1); my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$script_name"; #### Display the resultset $sbeams->displayResultSet( resultset_ref=>$passel_resultset, query_parameters_ref=>$params, rs_params_ref=>\%rs_params, url_cols_ref=>\%url_cols, hidden_cols_ref=>\%hidden_cols, max_widths=>\%max_widths, column_titles_ref=> $passel_resultset->{column_list_ref}, base_url=>$base_url, suppress_header => 1 ); my $resultset = $sbeams->fetchSTDOUT(); return $resultset; } # End get_passel_resultset sub get_srm_resultset { my $params = shift; my $peptide_sql = qq~ SELECT DISTINCT build_name, PP.pabst_peptide_id, peptide_sequence, PP.pabst_build_id, instrument_type_name, TPII.n_observations FROM $TBAT_PABST_BUILD PB JOIN $TBAT_PABST_PEPTIDE PP ON PB.pabst_build_id = PP.pabst_build_id JOIN $TBAT_PABST_PEPTIDE_ION TPI ON TPI.pabst_peptide_id = PP.pabst_peptide_id JOIN $TBAT_PABST_PEPTIDE_ION_INSTANCE TPII ON TPII.pabst_peptide_ion_id = TPI.pabst_peptide_ion_id JOIN $TBAT_INSTRUMENT_TYPE IT ON TPII.source_instrument_type_id = IT.instrument_type_id WHERE peptide_sequence = '$params->{peptide}' AND PB.project_id IN ( $params->{project_string} ) ~; my %peptides; my $sth = $sbeams->get_statement_handle( $peptide_sql ); while ( my @row = $sth->fetchrow_array() ) { $peptides{$row[1]}++; } $params->{pabst_peptide_ids} = join( ',', keys( %peptides ) ); $sbeams->collectSTDOUT(); my $srm_resultset = {}; #### Fetch the results from the database server $sbeams->fetchResultSet( sql_query=>$peptide_sql, resultset_ref=>$srm_resultset, ); $srm_resultset = post_process_srm_resultset( $srm_resultset ); my $name_base = 'SRMAtlasSummary'; my %rs_params = ( set_name => $name_base . '_' . 'SETME' ); if ( $global_rs_params{set_name} =~ /$name_base/ ) { %rs_params = %global_rs_params; } #### Store the resultset and parameters to disk resultset cache $sbeams->writeResultSet( resultset_file_ref=>\$rs_params{set_name}, resultset_ref=>$srm_resultset, query_parameters_ref=>$params, resultset_params_ref=>\%rs_params, query_name=>"$SBEAMS_SUBDIR/$script_name", ); # die Dumper( $srm_resultset ); my %url_cols = ( build_name => 'GetTransitions?pabst_build_id=%2V;default_search=1;peptide_sequence_constraint=%1V;apply_action=QUERY;n_highest_intensity_fragment_ions=8'); my %max_widths; my %hidden_cols = ( peptide_sequence => 1, pabst_build_id => 1 ); my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$script_name"; #### Display the resultset $sbeams->displayResultSet( resultset_ref=>$srm_resultset, query_parameters_ref=>$params, rs_params_ref=>\%rs_params, url_cols_ref=>\%url_cols, hidden_cols_ref=>\%hidden_cols, max_widths=>\%max_widths, column_titles_ref=> $srm_resultset->{column_list_ref}, base_url=>$base_url, suppress_header => 1 ); my $resultset = $sbeams->fetchSTDOUT(); return $resultset; } # End get_srm_resultset #################### sub post_process_passel_resultset { my $resultset = shift || die; # 958, # 'QTRAP 5500', # 3, # 'y6,y7', # 'VerifBruTreatDiag', # 'Human', # 5608 # 'YYYYYYYYK' # # 0 'total', # 1 'instrument', # 2 'peptide_charge', # 3 'fragment_ions', # 4 'sample', # 5 'organism', # 6 'sample_id' # 7 'sequence' # 8 'SEL_experiment_id' my $data = $resultset->{data_ref}; my %instr; my %builds; for my $row ( @{$data} ) { $instr{$row->[1]}++; $builds{$row->[4]} ||= {}; $builds{$row->[4]}->{organism} ||= $row->[5]; $builds{$row->[4]}->{seq} ||= $row->[7]; $builds{$row->[4]}->{id} ||= $row->[6]; $builds{$row->[4]}->{instrument} ||= $row->[1]; $builds{$row->[4]}->{SEL_experiment_id} ||= $row->[8]; $builds{$row->[4]}->{count} += $row->[0]; $builds{$row->[4]}->{fragments} ||= {}; my @frg = split( /,/, $row->[3] ); for my $frg ( @frg ) { $builds{$row->[4]}->{fragments}->{$frg}++; } $builds{$row->[4]}->{charges} ||= {}; $builds{$row->[4]}->{charges}->{$row->[2]}++; } my $prec = [ 255, 255, 4, 255, 255, 4, 255, 4 ]; my $types = [ qw( varchar varchar int, varchar, varchar, int, varchar, int ) ]; my $col_list = [ 'experiment', 'organism', 'experiment_id', 'charges', 'fragments', 'N_Obs', 'sequence', 'SEL_experiment_id', ]; my $col_num = {}; for ( my $i = 0; $i < scalar( @{$col_list}); $i++ ) { $col_num->{$col_list->[$i]} = $i; } my $na = $sbeams->makeInactiveText( 'n/a' ); my @data; for my $build ( sort( keys( %builds ) ) ) { my $expt = $builds{$build}->{SEL_experiment_id}; my $seq = $builds{$build}->{sequence}; # my $build_link = "$build"; my @row = ( $build, $builds{$build}->{organism}, $builds{$build}->{id} ); my $chgs = join( ',', keys( %{$builds{$build}->{charges}} ) ); push @row, $chgs; my $frgs = join( ',', keys( %{$builds{$build}->{fragments}} ) ); push @row, $frgs; push @row, $builds{$build}->{count}; push @row, $builds{$build}->{seq}; push @row, $expt; push @data, \@row; } my $new_rs = { 'page_size' => 100, 'precisions_list_ref' => $prec, 'types_list_ref' => $types, 'row_counter' => 0, 'data_ref' => \@data, 'column_list_ref' => $col_list, 'column_hash_ref' => $col_num }; return $new_rs; } #################### sub post_process_srm_resultset { my $resultset = shift || die; my $data = $resultset->{data_ref}; my %instr; my %builds; for my $row ( @{$data} ) { $instr{$row->[4]}++; $builds{$row->[0]} ||= {}; $builds{$row->[0]}->{$row->[4]} += $row->[5]; $builds{$row->[0]}->{seq} ||= $row->[2]; $builds{$row->[0]}->{id} ||= $row->[3]; } my $prec = [ 255, 255, 4 ]; my $types = [ qw( varchar varchar int ) ]; my $col_list = [ 'build_name', 'peptide_sequence', 'pabst_build_id' ]; my @inst; for my $inst ( sort( keys( %instr ) ) ) { push @inst, $inst; push @{$col_list}, $inst . '_N_obs'; push @{$prec}, 4; push @{$types}, 'int'; } my $col_num = {}; for ( my $i = 0; $i < scalar( @{$col_list}); $i++ ) { $col_num->{$col_list->[$i]} = $i; } my $na = $sbeams->makeInactiveText( 'n/a' ); my @data; for my $build ( sort( keys( %builds ) ) ) { my @row = ( $build, $builds{$build}->{seq}, $builds{$build}->{id} ); for my $inst ( @inst ) { my $cnt = ( defined $builds{$build}->{$inst} ) ? $builds{$build}->{$inst} : $na; push @row, $cnt; } push @data, \@row; } my $new_rs = { 'page_size' => 100, 'precisions_list_ref' => $prec, 'types_list_ref' => $types, 'row_counter' => 0, 'data_ref' => \@data, 'column_list_ref' => $col_list, 'column_hash_ref' => $col_num }; return $new_rs; my $foo = qq~ 'page_size' => 100, 'precisions_list_ref' => [ 255, 4, 255, 4, 255, 4 ], 'types_list_ref' => [ 'varchar', 'int', 'varchar', 'int', 'varchar', 'int' ], 'row_counter' => 0, 'data_ref' => [ [ 'Anderson_2012-01-22', 632546, 'WFYIASAFR', 115, 'IonTrap', 47 ], 'column_list_ref' => [ 'build_name', 'pabst_peptide_id', 'peptide_sequence', 'pabst_build_id', 'instrument_type_name', 'n_observations' ], 'row_pointer' => 0, 'column_hash_ref' => { 'peptide_sequence' => 2, 'pabst_build_id' => 3, 'instrument_type_name' => 4, 'build_name' => 0, 'pabst_peptide_id' => 1, 'n_observations' => 5 } ~; return $resultset; } sub get_abundance_plot { my $params = shift; return '' unless $params->{peptide}; return '' unless $params->{project_string}; my $sql = qq~ SELECT distinct PI.n_observations, AB.atlas_build_name, ( SELECT SUM (cast(n_searched_spectra as bigint)) FROM $TBAT_ATLAS_BUILD_SEARCH_BATCH ABSB JOIN $TBAT_ATLAS_SEARCH_BATCH ASB ON ASB.atlas_search_batch_id = ABSB.atlas_search_batch_id WHERE ABSB.atlas_build_id = AB.atlas_build_id ) AS total_searched FROM $TBAT_PEPTIDE_INSTANCE PI INNER JOIN $TBAT_PEPTIDE P ON P.peptide_id = PI.peptide_id INNER JOIN $TBAT_ATLAS_BUILD AB ON (PI.atlas_build_id = AB.atlas_build_id) WHERE peptide_sequence = '$params->{peptide}' AND AB.project_id IN ( $params->{project_string} ) $params->{default_build_clause} ORDER BY AB.atlas_build_name ~; my @build_plot; my @obs_per_million_build_plot; while ( my $row = $sbeams->selectSeveralColumnsRow( sql => $sql ) ) { my $hits_per_M = '1'; if ( $row->[2] ) { $hits_per_M = sprintf( "%0.1f", $row->[0]/$row->[2] * 1000000); } $row->[1] =~ s/PeptideAtlas/PA/g; push @build_plot, [ $row->[1], $row->[0] ]; push @obs_per_million_build_plot, [ $row->[1], $hits_per_M ]; } my ($sheader, $sHTML) = $atlas->getSamplePlotDisplay( n_obs => \@build_plot, obs_per_million => \@obs_per_million_build_plot, ); ; return ( "$sheader
\n $sHTML

\n " ); my $header = ''; my $build_results = ''; if ( @build_plot ) { my $GV = SBEAMS::Connection::GoogleVisualization->new(); my $chart = $GV->setDrawBarChart( samples => \@build_plot, data_types => [ 'string', 'number', 'number' ], headings => [ 'Build Name', 'Number of Observations', "Obs per Million Spectra" ], truncate_labels => 30 ); $header = $GV->getHeaderInfo(); $build_results = "$chart\n"; } return ( "$header
\n $build_results
\n " ); } __DATA__ my $lib_sql = qq~ SELECT DISTINCT preceding_residue, PI.modified_peptide_sequence, following_residue, synthesis_adjusted_score, instrument_type_name, precursor_ion_mz, precursor_ion_charge, fragment_ion_mz, fragment_ion_charge, fragment_ion_label, ion_rank, relative_intensity, SSRCalc_relative_hydrophobicity, $ssr_field, biosequence_id, merged_score, PII.n_observations, source_build, PSP.priority, PTI.is_predicted, $weight_clause, PII.max_precursor_intensity FROM $TBAT_PABST_PEPTIDE PP JOIN $TBAT_PABST_PEPTIDE_ION PI ON PP.pabst_peptide_id = PI.pabst_peptide_id JOIN $TBAT_PABST_PEPTIDE_ION_INSTANCE PII ON PI.pabst_peptide_ion_id = PII.pabst_peptide_ion_id JOIN $TBAT_PABST_TRANSITION PT ON PT.pabst_peptide_ion_id = PI.pabst_peptide_ion_id JOIN $TBAT_PABST_TRANSITION_INSTANCE PTI ON PT.pabst_transition_id = PTI.pabst_transition_id JOIN $TBAT_INSTRUMENT_TYPE IT ON ( IT.instrument_type_id = PTI.source_instrument_type_id AND IT.instrument_type_id = PII.source_instrument_type_id ) JOIN $TBAT_PABST_SOURCE_PRIORITY PSP ON ( PSP.source_instrument_type_id = PTI.source_instrument_type_id ) JOIN $TBAT_PABST_PEPTIDE_MAPPING PM ON PM.pabst_peptide_id = PP.pabst_peptide_id $ssr_join WHERE PP.pabst_peptide_id IN ( $pep_id_string ) AND PM.biosequence_id IN ( $bioseq_id_string ) $pabst_build_clause $atlas_build_clause $transition_source_clause $target_instrument_clause $ssr_clause $modifications_constraint ORDER BY biosequence_id, PTI.is_predicted ASC, SRC_WEIGHT DESC, synthesis_adjusted_score DESC, PI.modified_peptide_sequence, PSP.priority ASC, PII.max_precursor_intensity DESC, PII.n_observations DESC, relative_intensity DESC, ion_rank ASC ~; #### Define some variables for a query and resultset my %resultset = (); my $resultset_ref = \%resultset; my (%url_cols,%hidden_cols,%max_widths,$show_sql); #### Read in the standard form values my $apply_action = $parameters{'action'} || $parameters{'apply_action'}; my $TABLE_NAME = $parameters{'QUERY_NAME'}; #### Set some specific settings for this program my $CATEGORY="Summarize_Peptide"; my $PROGRAM_FILE_NAME = $PROG_NAME; my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$PROGRAM_FILE_NAME"; my $help_url = "$CGI_BASE_DIR/help_popup.cgi"; ###### Definfing the constants URL to build dynamic links my $url= "$CGI_BASE_DIR/$SBEAMS_SUBDIR"; my $build_link= "/buildDetails?atlas_build_id="; my $pep_link1="/GetPeptide?atlas_build_id="; my $pep_link2="&searchWithinThis=Peptide+Sequence&searchForThis="; my $pep_link3="&action=QUERY"; return unless $project_string; # Sanity check #### Build search options for textbox: my $peptide_search_constraint = ( "peptide_sequence_constraint" ); my $textbox_option_tags = ("Peptide Sequence" ); #### Apply any parameter adjustment logic $parameters{display_options} = 'ShowSQL'; my ($selected_atlas_build_name, $selected_key, $selected_key_search); ## Display HTML FORM to select Atlas and Search constraints: my $searchValue = $parameters{searchForThis}; unless ( $apply_action eq "QUERY" || $apply_action eq "GO") { ## if receive from link, don't assign null $apply_action = $parameters{"query"}; } if ($sbeams->output_mode() eq 'html') { # print $atlas->init_pa_tooltip(); } ### Implicit Assignment of PEPTIDE SEQ to $parameters with the search constraint 'peptide_sequence_constraint' $parameters{$peptide_search_constraint} = $peptide; ######################################################################### #### Process all the constraints #### Build Search constraint if ($peptide=~/PAp\d+/) { $peptide_clause = $sbeams->parseConstraint2SQL( constraint_column=>"P.peptide_accession", constraint_type=>"plain_text", constraint_name=>"Peptide Accession", constraint_value=>$peptide ); return if ($peptide_clause eq '-1'); } else { $peptide_clause = $sbeams->parseConstraint2SQL( constraint_column=>"P.peptide_sequence", constraint_type=>"plain_text", constraint_name=>"Peptide Sequence", constraint_value=>$peptide ); $peptide_clause =~s/LIKE/=/gi; return if ($peptide_clause eq '-1'); } # Will do project checking after grabbing the peptide info # my $atlas_project_clause = "AND AB.project_id IN ( $project_string )"; #### Define the SQL statement $sql = qq~ SELECT distinct P.peptide_accession,P.peptide_sequence, P.SSRCalc_relative_hydrophobicity, P.molecular_weight, P.peptide_isoelectric_point, PI.n_observations, PI.atlas_build_id, AB.atlas_build_name, OZ.organism_name, ( SELECT SUM (n_searched_spectra) FROM $TBAT_ATLAS_BUILD_SEARCH_BATCH ABSB JOIN $TBAT_ATLAS_SEARCH_BATCH ASB ON ASB.atlas_search_batch_id = ABSB.atlas_search_batch_id WHERE ABSB.atlas_build_id = AB.atlas_build_id ) AS total_searched , AB.project_id FROM $TBAT_PEPTIDE_INSTANCE PI INNER JOIN $TBAT_PEPTIDE P ON ( PI.peptide_id = P.peptide_id ) INNER JOIN $TBAT_ATLAS_BUILD AB ON (PI.atlas_build_id = AB.atlas_build_id) INNER JOIN $TBAT_BIOSEQUENCE_SET BS ON (AB.biosequence_set_id = BS.biosequence_set_id) INNER JOIN $TB_ORGANISM OZ ON (BS.organism_id= OZ.organism_id) WHERE 1 = 1 $peptide_clause ORDER BY P.peptide_sequence, OZ.organism_name, PI.n_observations DESC,AB.atlas_build_name ~; if ($apply_action =~ /QUERY|GO/i ) { my (@peptide_info,@builds, $dynamic_content, $vocab, @build_plot); while (my $row = $sbeams->selectSeveralColumnsRow(sql=>$sql)) { my ($pep_acc,$peptide_seq,$ssr_calc,$mol_wt,$pi,$n_obs,$build_id,$build_name,$org_name,$n_searched,$project_id)= @{$row}; ##Copying the value of Peptide Accession to global variable $peptide_acc $peptide_acc=$pep_acc; @peptide_info = ($pep_acc,$peptide_seq,$mol_wt,$pi,$ssr_calc); next unless ( grep /^$project_id$/, @accessible_project_ids ); ####### Building the link for No of observations my $peptide_url=qq~$url$pep_link1$build_id$pep_link2$peptide_seq$pep_link3~; my $peptide_html_link=qq~$n_obs~; ##### Building the link for the Atlas Builds my $build_url=qq~ $url$build_link$build_id ~; my $build_html_link=qq~$build_name~; my @temp_array=($org_name,$peptide_html_link,$build_html_link); ##### Passing by reference to the @builds array as per the requirement of the EncodesectionTable Method push (@builds, \@temp_array); my $hits_per_10K = '1'; $log->debug( "n searched is $n_searched" ); if ( $n_searched ) { $hits_per_10K = sprintf( "%0.1f", $n_obs/$n_searched * 1000000); } $build_name =~ s/PeptideAtlas/PA/g; push @build_plot, [ $build_name, $n_obs, $hits_per_10K ]; } ## END WHILE LOOP ##### Display on the Page if and only if user entered a peptide which was present in the Peptideatals if( defined $peptide_acc) { $dynamic_content=DisplayPeptide(view1=>\@peptide_info, view2=>\@builds); $vocab=$atlas->vocabHTML(); my $header = ''; my $build_results = ''; if ( @build_plot ) { my $GV = SBEAMS::Connection::GoogleVisualization->new(); my $chart = $GV->setDrawBarChart( samples => \@build_plot, data_types => [ 'string', 'number', 'number' ], headings => [ 'Build Name', 'Number of Observations', "Obs per Million Spectra" ], truncate_labels => 30 ); $header = $GV->getHeaderInfo(); $build_results = "$chart\n$vocab\n"; } else { $build_results = "Although the peptide $peptide_info[1] was given a Peptide Atlas accession ($peptide_info[0]), it was not found in any builds to which you currently have access, which can happen for a couple of reasons. First of all, some older builds have been deprecated, the peptide might have appeared in one of these (which typically had a somewhat higher false discovery rate [FDR] than more recent builds). Secondly, the Peptide Atlas contains many 'private' builds which often contain pre-publication data. These builds are generally made public once the results are published."; } print <<" END"; $header $dynamic_content

$build_results END } else { ### if the peptide was not found in the peptide atlas. print "The peptide was not found. Please enter again"; } } # END if loop } ### END Handle Request sub DisplayPeptide { my %args =@_; ## unless( $args{view1} && $args{view2} ) { $log->error( "No information passed to display" ); return; } ### Defining global symbols and values here my ($table1, $table2 ); my $view1 = $args{view1}; my $view2 = $args{view2}; #### $view2 now contains a reference to an array... derefrencing it. my @view2= @{$view2}; my ($pa,$seq,$mw,$pi,$ssr_calc) = @{$view1}; ###### Basic Peptide info table being created using the subroutine encodesection my $peptide_accession = $pa; my $peptide_sequence= $seq; my $SSR_Calc = sprintf("%0.2f",$ssr_calc); my $mol_wt= sprintf( "%0.2f", $mw); my $Pi = sprintf( "%0.1f", $pi ); $table1 = "
\n"; $table1.=$atlas->encodeSectionHeader( text => "$peptide_accession", bold => 1, width => 900 ); $table1 .= $atlas->encodeSectionItem( key => 'Peptide Accession', value => $peptide_accession, key_width => '20%' ); $table1.= $atlas->encodeSectionItem( key => 'Peptide Sequence', value => $peptide_sequence ); $table1 .= $atlas->encodeSectionItem( key => 'Avg Molecular Weight', value => "$mol_wt" ) if $mol_wt; $table1 .= $atlas->encodeSectionItem( key => 'pI (approx)', value => "$Pi" ) if $Pi; $table1.= $atlas->encodeSectionItem( key => 'SSRCalc Relative Hydrophobicity', value => "$SSR_Calc" ); $table1 .= '
'; ##### Printing the second table with build and no of observation information for each peptide $table2 = "
"; my @headings = ( 'Organism Name', 'No. of Observations', 'Build Names in which Peptide is found', ); $table2 .= $atlas->encodeSectionHeader( text => 'Peptide Found in these builds', width => 900 ); ########### In the row argument of encodeSectionTable we need to pass referenced arrays $table2 .= $atlas->encodeSectionTable(rows => [ \@headings, @view2 ], header => 1, nowrap => [1..scalar(@headings)], align => [ qw(left left left) ], bg_color => '#EAEAEA', set_download=>0); $table2 .= '
'; ###### Generating a single scalar for each peptide information to be displayed my $peptide_info_html = $table1.$table2; return($peptide_info_html); } #### End of Display Peptide