#!/usr/local/bin/perl
###############################################################################
# $Id: AssessDIALibrary 5692 2008-07-08 17:17:27Z dcampbel $
#
# SBEAMS is Copyright (C) 2000-2016 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 lib qw (../../lib/perl);
use Data::Dumper;
use File::Basename;
use File::Copy qw( move copy );
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use CGI;
use SBEAMS::Connection qw($q $log);
use SBEAMS::Connection::Settings;
use SBEAMS::Connection::Tables;
#use SBEAMS::Connection::SBPage;
use SBEAMS::Connection::DataTable;
use SBEAMS::Connection::TabMenu;
use SBEAMS::PeptideAtlas;
use SBEAMS::PeptideAtlas::Settings;
use SBEAMS::PeptideAtlas::Tables;
###############################################################################
# Global Variables
###############################################################################
my $sbeams = new SBEAMS::Connection;
$sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR);
my $atlas = new SBEAMS::PeptideAtlas;
$atlas->setSBEAMS($sbeams);
my $max_size = 200000;
$CGI::POST_MAX = 1024 * $max_size;
my $json = new JSON;
# Read input parameters
my $params = process_params();
$log->info( "params processed" );
my $username = $sbeams->Authenticate( allow_anonymous_access => 1) || exit;
$sbeams->setSessionAttribute( key => 'PA_resource', value => 'DIAAtlas' );
# Get a list of accessible project_ids
my @project_ids = $sbeams->getAccessibleProjects();
my $project_ids = join( ",", @project_ids ) || '0';
my $show_image = 0;
my $tabMenu;
my %basespace = ( basespace_params => '' );
my $page = '';
{ # Main
# Authenticate or exit
## get current settings
my $project_id = $sbeams->getCurrent_project_id();
# print $sbeams->get_http_header();
$atlas->display_page_header( tracker_type => 'swath' );
# Get the HTML to display the tabs
$tabMenu = $atlas->getTabMenu(
parameters_ref => $params,
program_name => $0,
);
my $css = $sbeams->printStyleSheet( module_only => 1 );
$page .=<<" END";
$css
END
if ( 1 ) {
my $title = qq~
........| DIA Library Assessment.
~;
# $page .= $title;
$page .= $tabMenu;
$page .= qq~
~;
if ( $params->{ion_library} ) {
$page .= get_status_box("Analyzing library, may take several minutes") unless $params->{action} eq 'trigger';
print $page;
$page = analyze_library();
$page .= get_status_box("");
} else {
$page .= qq~
~;
$page .= get_subset_form();
}
}
$page .= " ";
# Print what we already have, speed up apparent page loading time.
print $page;
$atlas->display_page_footer();
$sbeams->setSessionAttribute( key => 'PA_resource', value => '' );
} # end main
sub get_status_box {
my $msg = shift || '';
my $wait = "\\";
if ( $msg ) {
return qq~
$wait $msg
~;
} else {
return ""
}
}
sub get_help_links {
my %title2text = (
'ion_library' => "Ion library to be analyzed (required) ",
'pep_file' => "Mapping file of reference proteome, protein/peptide TSV, one peptide per line. ",
'swaths_file' => "File of SWATH bins, format is lower mz bound, upper bound mz, one per line TAB delimited",
'col_defs' => "Print out definitions for all tests",
'skip_decoys' => "Skip DECOY assess in compiling library statistics",
'alt_decoy' => "Alternate prefix to denote DECOY assays, default is DECOY",
'assess_massdiff' => "Compute difference between assay m/z and theoretical values, report on outliers",
);
my %title2link;
for my $title ( keys( %title2text ) ) {
my $text = $title2text{$title};
$title2link{$title} = qq~
~;
}
return \%title2link;
}
sub get_protein_list_selector {
my $sql =<<" END";
SELECT title, protein_list_id
FROM $TBAT_DOMAIN_PROTEIN_LIST DPL
JOIN $TB_CONTACT C ON DPL.owner_contact_id = C.contact_id
WHERE project_id IN ( $project_ids )
ORDER BY title
END
my $sth = $sbeams->get_statement_handle( $sql );
my $select;
while( my @row = $sth->fetchrow_array() ) {
my $selected = ( $row[1] == $params->{domain_protein_list_id} ) ? 'selected' : '';
my $title = $row[0];
$title =~ s/known to be associated with human/associated with/g;
my $option = "\n";
$select .= $option;
}
$select .= "\n";
my $blank = ( $select =~ /selected/ ) ? '' : '';
$select = qq~