#!/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~
Number of proteins returned on click may differ from tallies shown here:
  • Protein tallies exclude decoy, unmapped, and some contaminant proteins.
  • Swiss-Prot click returns only 6-char core identifiers, not splice variants.
  • See Protein ID terms in sidebar menu for nomenclature. $download_link
    ~ if $is_html; } else { print "

    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 = ; chomp $header; my @headers = split("\t", $header); # Remove unwanted headers for ppt if ($ppt) { my @ppt_headers=(); for my $col (@ppt_cols) { my $header = $headers[$col]; if (($header =~ /spectra searched/i) || ($header =~ /observations/i) || ($header =~ /psms/i) || ($header =~ /peptide spectrum matches/i)) { $header .= " (1000's)"; } push (@ppt_headers, $header); } @headers = @ppt_headers; } else { if ( $parameters{protease_info} ) { push @headers, 'Build Enzyme Usage'; } } # Define header row $table ->addRow( \@headers ); # setRowAttr does not take a COLS arg. $table->setRowAttr( ROWS => [1], BGCOLOR => '#002664', ALIGN=>'CENTER', NOWRAP => 0, HEIGHT => 35 ); $table->setHeaderAttr(WHITE_TEXT=>1,BOLD=>1); # this actually has effect via sub formatHeader # Read in the rows my $selected = ''; my @rows; my @build_ids; my $col_n = 0; while (my $line = ) { chomp $line; my @row = split("\t", $line); my $build_name = $row[$build_name_idx]; $build_name =~ s/.*">//; $build_name =~ s/<.*//; push @row, $build_name; push (@rows, \@row); $col_n = scalar @row; push @build_ids, $row[$#row]; # Assumes build id is last column } # my %accessible_default_builds; # my %atlas_build_hash; my $accessible_string = join( ',', keys( %atlas_build_hash ) ); my $enzyme_info = get_enzyme_info( $accessible_string ); # Sort the rows based on organism. my %organisms = ( 'Human'=>0, 'Chimpanzee'=>1, 'Mouse'=>2, 'Cow'=>5, 'Pig'=>6, 'Horse'=>7, 'Canine'=>8, 'Dog'=>8, 'Drosophila'=>10, 'Honeybee'=>11, 'C Elegans'=>20, 'Yeast'=>25, 'Fission Yeast'=>26, 'Leptospira interrogans'=>31, 'Candida albicans'=>33, 'Ecoli'=>39, 'Streptococcus'=>40, 'Halobacterium'=>41, 'Mtuberculosis'=>42, 'Dengue virus'=>50, ); # Put any additional organisms at the end for my $row (@rows) { if (! defined $organisms{$row->[$org_idx]} ) { $organisms{$row->[$org_idx]} = 100; } } @rows = sort { $a->[$col_n -1] cmp $b->[$col_n -1]} @rows; # This is supposed to do an alphabetical sub-sort, but it's not working #|| $a->[$build_name_idx] cmp $b->[$build_name_idx] # Process and output the rows for my $row_aref (@rows) { my @row = @{$row_aref}; pop @row; my @trinfo; my $selected = ''; my $bgcolor = '#f3f1e4'; # Check atlas build ID my $id = $row[$atlas_build_id_output_idx]; my $atlas_build = $atlas_build_hash{$id}; next if (! defined $atlas_build); $row[$spectra_searched_idx] = $sbeams->commifyNumber($row[$spectra_searched_idx]); $row[$psm_count_idx] = $sbeams->commifyNumber($row[$psm_count_idx]); $row[$distinct_peps_idx] = $sbeams->commifyNumber($row[$distinct_peps_idx]); $row[$n_canonicals_idx] = $sbeams->commifyNumber($row[$n_canonicals_idx]); $row[$n_canon_dist_idx] = $sbeams->commifyNumber($row[$n_canon_dist_idx]); $row[$n_disting_prots_idx] = $sbeams->commifyNumber($row[$n_disting_prots_idx]); $row[$n_seq_unique_prots_idx] = $sbeams->commifyNumber($row[$n_seq_unique_prots_idx]); $row[$n_swiss_idx] = $sbeams->commifyNumber($row[$n_swiss_idx]); $row[$n_covering_idx] = $sbeams->commifyNumber($row[$n_covering_idx]); if ( $parameters{organism_default_builds} ) { next if !$accessible_default_builds{$id}; } if ( $parameters{protease_info} ) { push @row, $enzyme_info->{$id}->{enz_info}; } # Post-processing for ppt format my $row_id; if ($ppt) { # Remove unwanted columns for ppt my @ppt_row=(); for my $col (@ppt_cols) { my $content = $row[$col]; # Remove any hyperlink if ($content =~ /(.*)<\/a>/i ) { $content = $1; } # Tidy build names if ($col == $build_name_idx) { $content =~ s/ PeptideAtlas//; # remove PeptideAtlas $content =~ s/ Ens..//; # remove Ensembl version number $content =~ s/ Milk//; # "Cow Milk" atlas has much more than milk $content =~ s/Prob 0.99 //; # prob is shown in its own column $content =~ s/Prob 0.9 //; # tidy species names $content =~ s/HoneyBee/Honeybee/; $content =~ s/Pyogenes/pyogenes/; $content =~ s/Tuberculosis/tuberculosis/; $content =~ s/CelegansPhospho/C\. elegans Phospho/; $content =~ s/Celegans/C\. elegans/; $content =~ s/Leptospira/L\./; # general tidy $content =~ s/Yeast_MRM_Atlas_2008-03_P0.9/Yeast SRMAtlas 2008-03/; # Add padding whitespace $content .= "      "; # Add an element for hiding the row. $row_id = "row_$id"; $content = qq~$content~; } # Show spectra, obs in 1000's if (($col == $spectra_searched_idx ) || ($col == $psm_count_idx)) { $content = sprintf("%0.0f", $content/1000); } push (@ppt_row, $content); } @row = @ppt_row; } # Add the row to the table. $table->addRow( \@row ); $this_row = $table->getRowNum(); # This manages which builds are shown for "View default builds" if ($id == $atlas_build_id) { $selected = 'CHECKED '; } if ( !$atlas_build->[$def_atlas_build_id_output_idx] ) { if ( $selected ne 'CHECKED ' ) { # We will show the current build regardless $log->debug( "checking is $atlas_build->[$atlas_atlas_build_id_output_idx]" ); @trinfo = ( $tr =~ /(NAME)=('[^']+')\s+(ID)=('[^']+')\s+(CLASS)=('[^']+')/ ); } $bgcolor = '#d3d1c4' unless ($ppt); } if (! $ppt) { $table->setRowAttr( ROWS => [$this_row], BGCOLOR => $bgcolor, @trinfo ); } else { # overwrites special ID for current atlas build, but should be OK. $table->setRowAttr( ROWS => [$this_row], BGCOLOR => $bgcolor, @trinfo , NOWRAP => 0, HEIGHT => 25, ID=>qq~"$row_id"~,); } } close TSV; # Set display attributes for the various columns. # 05/02/12: value below is always zero! my $nrows = $this_row; if (!$ppt) { $table->setColAttr( COLS => [$build_name_idx+1], ROWS => [2..$nrows], NOWRAP => 1 ); $table->setColAttr( COLS => [$descr_idx+1], ROWS => [2..$nrows], NOWRAP => 1 ); $table->setColAttr( COLS => [$build_name_idx+1], ROWS => [1..$nrows], ALIGN => 'LEFT' ); $table->setColAttr( COLS => [$build_name_idx+2..$descr_idx], ROWS => [1..$nrows], ALIGN => 'CENTER' ); $table->setColAttr( COLS => [$descr_idx+1], ROWS => [1..$nrows], ALIGN => 'LEFT' ); $table->setColAttr( COLS => [$atlas_build_id_output_idx+1], ROWS => [1..$nrows], HIDDEN => 1 ); # ppt } else { $table->setColAttr(COLS=>[$build_name_ppt_idx+1],ROWS=>[2..$nrows],NOWRAP=>1); $table->setColAttr(COLS=>[$peptide_inclusion_ppt_idx+1],ROWS=>[2..$nrows],NOWRAP=>1); $table->setColAttr(COLS=>[$build_name_ppt_idx+1..$peptide_inclusion_ppt_idx+1],ROWS=>[1..$nrows],ALIGN=>'LEFT'); $table->setColAttr( COLS => [$peptide_inclusion_ppt_idx+2..$n_swiss_ppt_idx+1], ROWS => [1..$nrows], ALIGN => 'RIGHT' ); $table->setColAttr( COLS => [$atlas_build_id_output_idx+1], ROWS => [1..$nrows], HIDDEN => 1 ); } if ( $is_html ) { print $link unless $ppt; #table toggle } } # Display the table! if ( $is_html ) { my $style = qq~ ~; # This stringify is implicitly calling the asHTML method... $table = $style . "$table"; $table =~ s/hidden( "apply_action", ''); print $q->end_form; } elsif ( $sbeams->output_mode =~ /tsv/i ) { print $table->asTSV( strip_markup => 1 ); } } # end showMainPage sub get_enzyme_info { my $build_str = shift || return {}; my $enz_sql = qq~ SELECT atlas_build_id, name, COUNT(*) FROM $TBAT_ATLAS_BUILD_SEARCH_BATCH ABSB JOIN $TBAT_ATLAS_SEARCH_BATCH ASB ON ASB.atlas_search_batch_id = ABSB.atlas_search_batch_id JOIN $TBAT_SAMPLE S on S.sample_id = ASB.sample_id JOIN $TBAT_PROTEASES P on P.id = S.protease_id WHERE atlas_build_id IN ( $build_str ) GROUP BY P.name, atlas_build_id ORDER BY atlas_build_id, name ~; my %builds; my $sth = $sbeams->get_statement_handle( $enz_sql ); my %enz; while ( my @row = $sth->fetchrow_array() ) { $builds{$row[0]} ||= {}; $builds{$row[0]}->{$row[1]} = $row[2]; $builds{$row[0]}->{total} += $row[2]; $enz{$row[1]}++; } for my $id ( keys( %builds ) ) { for my $enz ( sort( keys( %{$builds{$id}} ) ) ) { next if $enz eq 'total'; $builds{$id}->{$enz} = sprintf( "%0.1f", 100*($builds{$id}->{$enz}/$builds{$id}->{total}) ); my $sep = ( $builds{$id}->{enz_info} ) ? ', ' : ''; $builds{$id}->{enz_info} .= $sep . "$enz: $builds{$id}->{$enz}" . '%'; } } return \%builds; }