#!/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~
SWATHs definition file (optional):
$title2help->{swaths_file}
Proteome mapping file (optional):
$title2help->{pep_file}      
Analyze Library
     
Assess mass diffs(optional):
$title2help->{assess_massdiff} Yes No
Print definitions for each test(optional):
$title2help->{col_defs} Yes No        
Correct Library
     
Filter problem assays:
$title2help->{assess_massdiff}  
Re-compute m/z values:
$title2help->{assess_massdiff}          

~; return $form; my $extra = qq~ Skip DECOYs(optional): $title2help->{skip_decoys} Yes No Alternate DECOY string (optional): $title2help->{alt_decoy} Yes ~; } sub process_params { my $params = {}; # for my $p ( qw( skip_decoy swaths_file massdiff ion_library coldefs ) ) { # $params->{$p} = $q->param( $p ); # } # $log->info( $params ); $q = new CGI; $sbeams->parse_input_parameters( q => $q, parameters_ref => $params ); $sbeams->processStandardParameters( parameters_ref => $params ); return( $params ); } sub js_redirect { my $url = shift || return; print qq~~; } sub print_js_status { my $msg = shift or return; $log->info( $msg ); my $replace = shift || 0; if ( $replace ) { print "" ; } else { print "" ; } } sub get_build_path { my %args = @_; return unless $args{build_id}; my $path = $atlas->getAtlasBuildDirectory( atlas_build_id => $args{build_id} ); $path =~ s/DATA_FILES//; return $path; } sub get_draw_chart_function { my $sample_arrayref = shift || return ''; my @samples; for my $s ( @{$sample_arrayref} ) { push @samples, [ $s->[1], $s->[4], $s->[7] ]; } my $GV = SBEAMS::Connection::GoogleVisualization->new(); my ( $chart ) = $GV->setDrawBarChart( samples => \@samples, data_types => [ 'string', 'number', 'number' ], headings => [ 'Sample', 'Distinct peptides (n_obs > 1)', 'Cumulative peptides (n_obs > 1)' ], show_table => 0, truncate_labels => 24 ); my $header = $GV->getHeaderInfo(); return ( $chart, $header ); } sub get_public_libsets { my $sql = qq~ SELECT set_tag, instrument_type_name, organism_name, px_identifier, contributors, coverage_statement, COUNT(*) AS cnt FROM $TBAT_DIA_LIBRARY DIL JOIN $TBAT_DIA_LIBRARY_SET DILS ON DILS.dia_library_set_id = DIL.dia_library_set_id JOIN $TBAT_INSTRUMENT_TYPE IT ON IT.instrument_type_id = DIL.instrument_type_id JOIN $TB_ORGANISM O ON O.organism_id = DIL.organism_id WHERE project_id IN ( $project_ids ) AND DIL.record_status = 'N' GROUP BY set_tag, instrument_type_name, organism_name, px_identifier, contributors, coverage_statement ORDER BY set_tag, instrument_type_name ~; # 0 set_tag # 1 instrument_type_name # 2 organism_name # 3 px_identifier # 4 contributors # 5 coverage_statement # 6 cnt my $sth = $sbeams->get_statement_handle( $sql ); my %sets; while ( my @row = $sth->fetchrow_array() ) { if ( $sets{$row[0]} ) { $sets{$row[0]}->{inst} = $row[1] if $row[1] =~ /TripleTOF/; $sets{$row[0]}->{lib_cnt} += $row[6]; } else { my $px = ( $row[3] ) ? ( $row[3] =~ /^PXD/ ) ? "$row[3]" : "$row[3]" : $sbeams->makeInactiveText( 'na' ); $sbeams->makeInactiveText( 'na' ); $row[5] =~ s/Proteome Coverage//gi; $sets{$row[0]} = { inst => $row[1], lib_cnt => $row[6], px => $px, org => $row[2], cov => $row[5], cont => $row[4] }; } } use JSON; my $json = new JSON; my $jstr = $json->encode( \%sets ); # my @lib_data = ( [ qw( Library Organism Instrument Contributors Coverage ProteomeExchange NumFiles ) ] ); # my @lib_data = ( [ qw( Library Instrument Contributors Coverage ) ] ); my @lib_data = ( [ 'Library', 'Proteome Coverage', 'Contributors' ] ); for my $lib ( sort( keys( %sets ) ) ) { # push @lib_data, [ $lib, $sets{$lib}->{org}, $sets{$lib}->{inst}, $sets{$lib}->{cont}, $sets{$lib}->{cov}, $sets{$lib}->{px}, $sets{$lib}->{lib_cnt} ]; # push @lib_data, [ $lib, $sets{$lib}->{inst}, $sets{$lib}->{cont}, $sets{$lib}->{cov} ]; push @lib_data, [ $lib, $sets{$lib}->{cov}, $sets{$lib}->{cont} ]; } my $lib_table = $atlas->encodeSectionTable( header => 1, width => '800', align => [ qw(left left left left ) ], rows => \@lib_data, chg_bkg_idx => 0, bg_color => '#EAEAEA', sortable => 0, nowrap => [1,2,3], table_id => 'libraries', table_only => 1, close_table => 1, ); print qq~ $lib_table ~; } __DATA__