#!/usr/local/bin/perl
###############################################################################
# Program : buildInfo
# Author : Terry Farrah and Zhi Sun (tfarrah@systemsbiology.org)
# $Id: main.cgi 5994 2009-03-06 08:01:38Z dcampbel $
#
# Description : This script displays details about all default Atlas builds
#
# 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.
#
###############################################################################
###############################################################################
# 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);
use lib qw (../../lib/perl);
use CGI::Carp qw(fatalsToBrowser croak);
use Data::Dumper;
use SBEAMS::Connection qw($q $log);
use SBEAMS::Connection::DataTable;
use SBEAMS::Connection::Settings;
use SBEAMS::Connection::Tables;
use SBEAMS::Connection::TabMenu;
use SBEAMS::PeptideAtlas;
use SBEAMS::PeptideAtlas::Settings;
use SBEAMS::PeptideAtlas::Tables;
$sbeams = new SBEAMS::Connection;
$sbeamsMOD = new SBEAMS::PeptideAtlas;
$sbeamsMOD->setSBEAMS($sbeams);
###############################################################################
# Global Variables
###############################################################################
$PROG_NAME = 'buildInfo';
main();
###############################################################################
# Main Program:
#
# Call $sbeams->Authentication and stop immediately if authentication
# fails else continue.
###############################################################################
sub main
{
#### Do the SBEAMS authentication and exit if a username is not returned
exit unless ($current_username = $sbeams->Authenticate(
permitted_work_groups_ref=>['PeptideAtlas_user','PeptideAtlas_admin',
'PeptideAtlas_readonly', 'PeptideAtlas_exec'],
#connect_read_only=>1,
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
);
## get project_id to send to HTMLPrinter display
my $project_id = $sbeamsMOD->getProjectID(
atlas_build_name => $parameters{atlas_build_name},
atlas_build_id => $parameters{atlas_build_id}
);
#### Process generic "state" parameters before we start
$sbeams->processStandardParameters(parameters_ref=>\%parameters);
# $sbeams->printCGIParams($q);
#### Decide what action to take based on information so far
if ($parameters{action} eq "???") {
# Some action
} else {
# zhi says maybe make a new version of this subroutine to put in new style sheet
if ($sbeams->output_mode() =~ /tsv/i ) {
my $header = $sbeams->get_http_header( mode => 'tsv', filename => 'build_information_table.tsv' );
print $header;
handle_request(ref_parameters=>\%parameters);
} else {
$sbeamsMOD->display_page_header(project_id => $project_id);
handle_request(ref_parameters=>\%parameters);
$sbeamsMOD->display_page_footer();
}
}
} # end main
###############################################################################
# Show the page
###############################################################################
sub handle_request {
my %args = @_;
#### Process the arguments list
my $ref_parameters = $args{'ref_parameters'}
|| die "ref_parameters not passed";
my %parameters = %{$ref_parameters};
#### Get the current atlas_build_id based on parameters or session
my $atlas_build_id = $sbeamsMOD->getCurrentAtlasBuildID(
parameters_ref => \%parameters,
);
if (defined($atlas_build_id) && $atlas_build_id < 0) {
#### Don't return. Let the user pick from a valid one.
#return;
}
#### Get the HTML to display the tabs
my $tabMenu = $sbeamsMOD->getTabMenu(
parameters_ref => \%parameters,
program_name => $PROG_NAME,
);
if ($sbeams->output_mode() eq 'html') {
print $tabMenu->asHTML() if ($sbeams->output_mode() eq 'html');
print "
\n";
}
#### 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 $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";
my $ppt = $parameters{'ppt'} || 0;
my $table_width = $parameters{'width'} || 800;
#### Get a list of accessible project_ids
my @accessible_project_ids = $sbeams->getAccessibleProjects();
my $accessible_project_ids = join( ",", @accessible_project_ids ) || '0';
#### Get a list of accessible atlas builds
my $sql = qq~
SELECT AB.atlas_build_id, atlas_build_name, default_atlas_build_id
FROM $TBAT_ATLAS_BUILD AB
LEFT JOIN $TBAT_DEFAULT_ATLAS_BUILD DAB
ON DAB.atlas_build_id = AB.atlas_build_id
WHERE AB.project_id IN ( $accessible_project_ids )
--AND AB.atlas_build_id IN ( SELECT DISTINCT atlas_build_id FROM $TBAT_PEPTIDE_INSTANCE )
AND ( DAB.record_status IS NULL OR DAB.record_status != 'D' )
AND AB.record_status != 'D'
AND NOT ( DAB.organism_id IS NULL AND default_atlas_build_id IS NOT NULL ) -- keep global default from showing up 2x
~;
my @atlas_builds = $sbeams->selectSeveralColumns($sql);
my $atlas_atlas_build_id_output_idx = 0;
my $atlas_build_name_idx = 1;
my $def_atlas_build_id_output_idx = 2;
# Get name of current (default) atlas build
my $default_build_name = '';
foreach my $atlas_build ( @atlas_builds ) {
if ($atlas_build->[$atlas_atlas_build_id_output_idx] == $atlas_build_id) {
$default_build_name = $atlas_build->[$atlas_build_name_idx];
}
}
# Make hash out of accessible atlas builds
my %atlas_build_hash;
foreach my $atlas_build ( @atlas_builds ) {
my $id = $atlas_build->[$atlas_atlas_build_id_output_idx];
$atlas_build_hash{$id} = $atlas_build;
}
my %accessible_default_builds;
my $adb_sql = qq~
SELECT AB.atlas_build_id, atlas_build_name
FROM $TBAT_DEFAULT_ATLAS_BUILD DAB
JOIN $TBAT_ATLAS_BUILD AB ON AB.atlas_build_id = DAB.atlas_build_id
WHERE organism_specialized_build IS NULL
AND DAB.organism_id IS NOT NULL
~;
my $sth = $sbeams->get_statement_handle( $adb_sql );
while ( my @row = $sth->fetchrow_array() ) {
$accessible_default_builds{$row[0]} = $row[1];
}
my $table = SBEAMS::Connection::DataTable->new();
# print $table->asTSV();
my $is_html = ( $sbeams->output_mode =~ /html/i ) ? 1 : 0;
#### If the output_mode is HTML, then display the form
if ( 1 ) {
print qq~
~ if $is_html;
print $q->start_form(-method=>"POST",
-action=>"$base_url",
-name=>"AtlasBuildList",
) if $is_html;
unless ($default_build_name) {
$default_build_name = qq~ - NONE - ~;
}
my ( $tr, $link ) = $sbeams->make_table_toggle( name => 'atlas_build_select',
visible => 0,
tooltip => 'Show/Hide Section',
imglink => 1,
textlink => 1,
tr_asref => 1,
hidetext => 'View default builds',
showtext => 'View all builds',
sticky => 1 );
my $earl = $q->self_url();
$earl .= '?output_mode=tsv';
my $download_link = "Download table as a TSV file \n";
if ( !$ppt ) {
print qq~
To hide any row, click its Build Name. To reset, reload page.
\n" if $is_html; } ### Construct headers for info table my $this_row = $table->getRowNum(); ### IF YOU CHANGE THE INDICES BELOW, CHANGE IN EXACTLY THE SAME WAY ### IN BuildInfo.pm my $build_name_idx = 0; my $org_idx = 1; my $peptide_inclusion_idx = 2; my $smpl_count_idx = 3; my $spectra_searched_idx = 4; my $psm_count_idx = 5; my $distinct_peps_idx = 6; my $n_canonicals_idx = 7; my $n_canon_dist_idx = 8; my $n_disting_prots_idx = 9; my $n_seq_unique_prots_idx = 10; my $n_swiss_idx = 11; my $n_covering_idx = 12; my $descr_idx = 13; my $atlas_build_id_output_idx = 14; my $ncols = 15; my @ppt_cols; my $build_name_ppt_idx; my $peptide_inclusion_ppt_idx; my $smpl_count_ppt_idx; my $spectra_searched_ppt_idx; my $psm_count_ppt_idx; my $distinct_peps_ppt_idx; my $n_canonicals_ppt_idx; my $n_swiss_ppt_idx; my $descr_ppt_idx; my $ppt_ncols; if ($ppt) { @ppt_cols = (0,2,3,4,5,6,7,11); $build_name_ppt_idx = 0; $peptide_inclusion_ppt_idx = 1; $smpl_count_ppt_idx = 2; $spectra_searched_ppt_idx = 3; $psm_count_ppt_idx = 4; $distinct_peps_ppt_idx = 5; $n_canonicals_ppt_idx = 6; $n_swiss_ppt_idx = 7; $ppt_ncols = 8; #-------------------------------------------------- # # for testing # @ppt_cols = (0,2,3,6,7,11); # $build_name_ppt_idx = 0; # $peptide_inclusion_ppt_idx = 1; # $smpl_count_ppt_idx = 2; # $distinct_peps_ppt_idx = 3; # $n_canonicals_ppt_idx = 4; # $n_swiss_ppt_idx = 5; # $ppt_ncols = 6; #-------------------------------------------------- } #Open and read the cached .tsv file. my $tsv_file = "$PHYSICAL_BASE_DIR/tmp/buildInfo.tsv"; open (TSV, $tsv_file) || die "$PROG_NAME: cannot open $tsv_file for reading."; my $header =