#!/usr/local/bin/perl
###############################################################################
# $Id: peptideSearch.cgi 4670 2006-04-22 01:54:05Z dcampbel $
#
# SBEAMS is Copyright (C) 2000-2005 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 $sbeamsMOD $PROG_NAME
$current_contact_id $current_username $glyco_query_o);
use lib qw (../../lib/perl);
use CGI::Carp qw(fatalsToBrowser croak);
use Data::Dumper;
use SBEAMS::Connection qw($q $log);
use SBEAMS::Connection::Settings;
use SBEAMS::Connection::Tables;
use SBEAMS::Connection::DataTable;
use SBEAMS::Glycopeptide;
use SBEAMS::Glycopeptide::Settings;
use SBEAMS::Glycopeptide::Tables;
use SBEAMS::Glycopeptide::Get_glyco_seqs;
use SBEAMS::Glycopeptide::Glyco_query;
###############################################################################
# Global Variables
###############################################################################
#
$sbeams = new SBEAMS::Connection;
$sbeamsMOD = new SBEAMS::Glycopeptide;
$sbeamsMOD->setSBEAMS($sbeams);
$glyco_query_o = new SBEAMS::Glycopeptide::Glyco_query;
$glyco_query_o->setSBEAMS($sbeams);
$sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR);
my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/massSearch";
{ # Main
# Authenticate or exit
exit unless ($current_username = $sbeams->Authenticate(
# permitted_work_groups_ref=>['Glycopeptide_user','Glycopeptide_admin', 'Glycopeptide_readonly'],
# connect_read_only=>1,
allow_anonymous_access=>1,
));
#### Read in the default input parameters
my %params;
$sbeams->parse_input_parameters( q=>$q, parameters_ref=>\%params );
$sbeams->processStandardParameters(parameters_ref=>\%params);
if ( $params{unipep_build_id} ) {
my $build_id = $sbeamsMOD->get_current_build( build_id => $params{unipep_build_id} );
if ( $build_id != $params{unipep_build_id} ) {
$sbeams->set_page_message( type => 'Error', msg => 'You must log in to access specified build' );
}
}
## get project_id to send to HTMLPrinter display
my $project_id = $sbeams->getCurrent_project_id();
my $page = $sbeams->getGifSpacer( 800 ) . "
\n";
if ( $params{ipi_data_id} ) {
$page .= get_ortholog_display( \%params );
} else {
$page .= $sbeams->getErrorText( "Missing required parameter ipi_data_id" );
}
# Display page
$sbeamsMOD->display_page_header(project_id => $project_id);
$sbeams->printStyleSheet();
print $page;
$sbeamsMOD->display_page_footer();
} # end main
sub get_ortholog_display {
my $params = shift;
my $content;
for my $arg ( qw( id_list id_type ) ) {
unless ( $params->{$arg} ) {
$content .= "Missing required parameter: $arg
\n";
return $content;
}
}
# for my $p ( keys( %$params ) ) { $content .= "$p => " . $params->{$p} . "
\n"; }
my $id_list = $params->{id_list};
$id_list =~ s/\s+/ /gm;
my @ids = split( " ", $id_list );
my $pep_o = new SBEAMS::Glycopeptide::Get_peptide_seqs(glyco_obj => $sbeamsMOD);
my $results = $sbeamsMOD->runBulkSearch( ids => \@ids, %{$params} );
$content .= get_submit_js();
my $table = SBEAMS::Connection::DataTable->new( BORDER => 0 );
$table->addRow( ['Accession', 'SwissProt', 'Symbol','Protein Name', 'Synonyms', 'Sequence', 'Prophet', 'Mass', 'dCn' ] );
$table->setRowAttr( ROWS => [1], BGCOLOR => '#C0D0C0' );
my $current;
my $prot_cnt = 1;
my $grp_row = 2;
my $bgcolor = '#F1F1F1';
for my $peptide ( @$results ) {
my ( $ipi,
$swiss_id,
$ipi_data_id,
$seq,
$symbol,
$protein_name,
$peptide_id,
$prophet_score,
$peptide_mass,
$dcn,
$synonyms
) = @$peptide;
my $ipi_base = $ipi . $synonyms;
# $current = $ipi_base unless $current;
# $current = $ipi_base unless $current;
# my $tissues = $pep_o->observed_tissues( $peptide_id ) || '';
my $ipi_link = $ipi;
my $motif = $sbeamsMOD->get_current_motif_type();
if ( $params->{action} ne 'download' ) {
# $tissues = $sbeams->truncateStringWithMouseover( string => $tissues, len => 20 );
$protein_name= $sbeams->truncateStringWithMouseover( string => $protein_name, len => 25 );
$ipi_link = get_search_link( name => $ipi, motif => $motif );
$log->debug( $motif );
$synonyms = get_kegg_link( name => $synonyms ) if $motif =~ /phospho/;
$seq = $sbeamsMOD->decorate_phospho_sequence( $seq );
}
my $chk_box = "$ipi_link";
$prophet_score = sprintf( "%0.2f", $prophet_score);
$peptide_mass = sprintf( "%0.4f", $peptide_mass);
$log->debug( "ipi_base is $ipi_base, current is $current" );
if ( !$current || $ipi_base ne $current ) {
$table->addRow( [ $chk_box, $swiss_id, $symbol, $protein_name, $synonyms, $seq, $prophet_score, $peptide_mass, $dcn ] );
$prot_cnt++;
$log->debug( "In da not current loop" );
my $current_row = $table->getRowNum();
# $log->info( "group row is $grp_row, current row is $current_row, bgcolor is $bgcolor" );
$table->setRowAttr( ROWS => [$grp_row..$current_row - 1], BGCOLOR => $bgcolor );
$grp_row = $current_row;
$bgcolor = ( $bgcolor eq '#E0E0E0' ) ? '#F1F1F1' : '#E0E0E0';
$current = $ipi_base;
} else {
$table->addRow( [ ' ',' ',' ',' ', ' ',
$seq, $prophet_score, $peptide_mass, $dcn ] );
}
my $current_row = $table->getRowNum();
$table->setRowAttr( ROWS => [$grp_row..$current_row], BGCOLOR => $bgcolor );
}
my $current_row = $table->getRowNum();
$table->setColAttr( COLS => [ 1 ], ROWS => [1..$current_row], NOWRAP => 1 );
return "Query returned no results" unless @$results;
if ( $params->{action} eq 'download' ) {
$content = $table->asTSV();
$log->debug( "Content is " . length($content) . " characters long" );
} else {
my $prot = ( $prot_cnt > 1 ) ? 'proteins' : 'protein';
my $num = ( @ids > 1 ) ? 'numbers' : 'number';
my $pep = ( $table->getRowNum() > 2 ) ? 'peptides' : 'peptide';
$content .= "Search with " . scalar( @ids ) . " accession $num yeilded ";
$content .= $table->getRowNum() - 1 . " $pep from $prot_cnt $prot
\n";
$content .= get_download_form($params);
$content .=<<" END";