#!/usr/local/bin/perl
###############################################################################
# Program : GetTransitions
#
# Description : page retrieve peptides and MS/MS fragment ions from PABST
# and PATR tables
###############################################################################
$|++;
## Setup objects and globals
use strict;
use Getopt::Long;
use FindBin;
use lib "$FindBin::Bin/../../lib/perl";
use vars qw ( $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;
use SBEAMS::PeptideAtlas;
use SBEAMS::PeptideAtlas::Settings;
use SBEAMS::PeptideAtlas::Tables;
use SBEAMS::PeptideAtlas::BestPeptideSelector;
# Set up Atlas objects
my $sbeams = new SBEAMS::Connection;
my $atlas = new SBEAMS::PeptideAtlas;
$atlas->setSBEAMS($sbeams);
$sbeams->setSBEAMS_SUBDIR( 'PeptideAtlas' );
my $best_peptide = new SBEAMS::PeptideAtlas::BestPeptideSelector;
$best_peptide->setAtlas( $atlas );
$best_peptide->setSBEAMS( $sbeams );
my $pabst_build_id;
my $is_html = 0;
main();
exit(0);
# Main Program
sub main
{
# Authenticate and exit if a username is not returned
my $current_username = $sbeams->Authenticate( allow_anonymous_access => 0 );
exit unless $current_username;
$is_html = ( $sbeams->output_mode() eq 'html' ) ? 1 : 0;
#### Read in the default input parameters
my %parameters;
$parameters{uploaded_file_not_saved} = 1;
my $n_params_found = $sbeams->parse_input_parameters(
q=>$q,parameters_ref=>\%parameters);
# $sbeams->printCGIParams($q);
# 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);
# Fetch pabst_build_id based on params.
# 1 - passed pabst_build_id param
# 2 - passed organism
# 3 - cached pabst_build_id cookie
# 4 - global default
$pabst_build_id = $best_peptide->get_pabst_build( %parameters );
# This might have gotten overridden due to permissions.
$parameters{pabst_build_id} = $pabst_build_id;
if ( !$parameters{action} && !$is_html ) {
$log->debug( "in the auto-setting mode, command-line only!" );
$parameters{n_highest_intensity_fragment_ions} = 3;
$parameters{n_peptides_per_protein} = 3;
$parameters{protein_name_constraint} = 'YAL003W%';
$parameters{QUERY_NAME} = 'AT_GetPABSTList';
$parameters{action} = 'QUERY';
$parameters{pabst_build_id} = 12;
}
for my $p ( keys ( %parameters ) ) {
$log->debug( "$p => $parameters{$p}" );
}
# Decide what action to take based on information so far
if ( !$parameters{download_only} ) {
print_form ( %parameters );
}
if ( $parameters{action} eq 'QUERY' ) {
fetch_peptides( %parameters );
}
$atlas->display_page_footer();
} # end main
sub print_form {
my %args = @_;
# Historical, don't ask.
my %parameters = %args;
my $project_id = $atlas->getProjectID(
atlas_build_id => $parameters{atlas_build_id}
);
$atlas->display_page_header(project_id => $project_id);
#### Show current user context information
#$sbeams->printUserContext();
#### Get the HTML to display the tabs
my $tabMenu = $atlas->getTabMenu(
parameters_ref => \%parameters,
program_name => $PROG_NAME,
);
unless ( $atlas->is_srm_mode() ) {
print $tabMenu->asHTML() if ($sbeams->output_mode() eq 'html');
}
#### Define some generic variables
my ($i,$element,$key,$value,$line,$result,$sql);
#### 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'};
# Historical, don't ask.
#### Set some specific settings for this program
my $CATEGORY="Query Transitions";
$TABLE_NAME="AT_GetPABSTList" unless ($TABLE_NAME);
($PROGRAM_FILE_NAME) =
$atlas->returnTableInfo($TABLE_NAME,"PROGRAM_FILE_NAME");
my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$PROGRAM_FILE_NAME";
#### Get the columns and input types for this table/query
my @columns = $atlas->returnTableInfo($TABLE_NAME,"ordered_columns");
my %input_types =
$atlas->returnTableInfo($TABLE_NAME,"input_types");
#### Read the input parameters for each column
my $n_params_found = $sbeams->parse_input_parameters(
q=>$q,parameters_ref=>\%parameters,
columns_ref=>\@columns,input_types_ref=>\%input_types);
#$sbeams->printDebuggingInfo($q);
#### If the apply action was to recall a previous resultset, do it
my %rs_params = $sbeams->parseResultSetParams(q=>$q);
#### Set some reasonable defaults if no parameters supplied
unless ($n_params_found)
{
$parameters{input_form_format} = "minimum_detail";
}
$parameters{n_peptides_per_protein} ||= 3;
$parameters{n_highest_intensity_fragment_ions} ||= 3;
$parameters{pabst_build_id} = $pabst_build_id;
# pabst_build_id=7
# protein_name_constraint=Foo
# upload_file=
# peptide_sequence_constraint=
# peptide_length=
# empirical_proteotypic_constraint=
# n_protein_mappings_constraint=
# n_genome_locations_constraint=
# n_highest_intensity_fragment_ions=3
##Input form: action is set by PROGRAM_FILE_NAME, so sub it w/ display page:
$sbeams->collectSTDOUT();
my ( $tr, $link ) = $sbeams->make_table_toggle( name => 'pabst_penalty_form',
visible => 0,
tooltip => 'Show/Hide penalty form',
sticky => 0,
imglink => 0,
textlink => 1,
plaintext => 0,
hidetext => 'Hide form',
showtext => 'Show form' );
# my ( $thtml, $tlink ) = $sbeams->make_toggle_section( name => 'pabst_penalty_form',
# visible => 1,
# tooltip => 'Show/Hide penalty form',
# sticky => 1,
# imglink => 0,
# content => ' ',
# textlink => 1,
# hidetext => 'Hide form',
# showtext => 'Show form',
# );
my @link = split "\n", $link;
my $script_css = join( "\n", @link[0..$#link-1] );
# $log->debug( $script_css );
$sbeams->display_input_form(
TABLE_NAME=>$TABLE_NAME,
CATEGORY=>$CATEGORY,
apply_action=>$apply_action,
parameters_ref=>\%parameters,
input_types_ref=>\%input_types,
mask_user_context=> '1',
mask_query_constraints => 1,
);
my $form = $sbeams->fetchSTDOUT();
# $log->debug( $script_css );
my $subform = '';
my @form = split( "\n", $form, -1 );
my $accum = 0;
my $ending = 0;
for my $fline ( @form ) {
# $log->debug( "Next line" );
if ( $fline =~ /Protein Accession/ ) {
$accum++;
# $log->debug( "Acc line" );
}
next unless $accum;
$subform .= "$fline\n";
if ( $fline =~ /upload_file/ ) {
$ending++;
# $log->debug( "the end is near" );
# $log->debug( $fline );
}
if ( $ending && $fline =~ /\<\/TR\>/ ) {
# $log->debug( "the end is here" );
last;
}
}
my @buttons = $sbeams->getFormButtons( types => [ 'Submit','Back', 'Reset' ] );
my $buttons = join( " ", @buttons );
print qq~