#!/usr/local/bin/perl
###############################################################################
# Program : GetAnnotations
# Author : Eric Deutsch
# $Id: GetHaloAnnotations 4767 2006-06-13 23:39:49Z dcampbel $
#
# SBEAMS is Copyright (C) 2000-2008 by Eric Deutsch
# 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.
#
###############################################################################
###############################################################################
# Set up all needed modules and objects
###############################################################################
use strict;
use FindBin;
use lib "$FindBin::Bin/../lib/perl";
use vars qw ($sbeams $q $current_contact_id $current_username);
use SBEAMS::Connection qw( $q $log );
use SBEAMS::Connection::Settings;
use SBEAMS::Connection::Tables;
$sbeams = new SBEAMS::Connection;
{ # Main program
# Do the SBEAMS authentication and exit if a username is not returned
$current_username = $sbeams->Authenticate( connect_read_only => 1 ) || die;
#### Read in the default input parameters
my %parameters;
$sbeams->parse_input_parameters( q=>$q, parameters_ref => \%parameters);
my $page = qq~
Modules with testing package activated:
~;
for my $dir ( qw( SNP Cytometry Glycopeptide PeptideAtlas TOES BioLink Biosap
Proteomics Inkjet MODULETEMPLATE Ontology PhenoArray
Biomarker Oligo Immunostain BEDB Genotyping Tools
SIGID Microarray Interactions ProteinStructure ) ) {
if ( -f "$dir/testSBEAMS.cgi" ) {
$page .= "
\n";
$sbeams->display_page_header( );
print $page;
$sbeams->display_page_footer();
}
__DATA__
###############################################################################
# Set program name and usage banner for command like use
###############################################################################
$PROG_NAME = $FindBin::Script;
$USAGE = <Authenticate() and exit if it fails or continue if it works.
###############################################################################
sub main {
#### Do the SBEAMS authentication and exit if a username is not returned
exit unless ($current_username = $sbeams->Authenticate(
permitted_work_groups_ref=>['ProteinStructure_user',
'ProteinStructure_admin','ProteinStructure_readonly','Admin'],
#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);
#$sbeams->printDebuggingInfo($q);
$q->delete('page_only');
#### Process generic "state" parameters before we start
$sbeams->processStandardParameters(parameters_ref=>\%parameters);
#### Decide what action to take based on information so far
if ($parameters{action} eq "xxxx") {
} elsif ( $current_username eq 'ext_halo' ) {
if ( $parameters{page_only} ) {
print $sbeamsMOD->get_page_only_header();
print "\n";
handle_request(ref_parameters=>\%parameters);
print $sbeamsMOD->get_page_only_footer();
} else {
my $url = $q->self_url();
$url .= ( $url =~ /\?/ ) ? ';page_only=yes' : '?page_only=yes';
$sbeamsMOD->display_page_header( navigation_bar=>$parameters{navigation_bar}, centered=>1 );
print "";
$sbeamsMOD->display_page_footer();
}
}else {
$sbeamsMOD->display_page_header(
navigation_bar=>$parameters{navigation_bar});
handle_request(ref_parameters=>\%parameters);
$sbeamsMOD->display_page_footer();
}
} # end main
###############################################################################
# Handle Request
###############################################################################
sub handle_request {
my %args = @_;
#### Process the arguments list
my $ref_parameters = $args{'ref_parameters'}
|| die "ref_parameters not passed";
my %parameters = %{$ref_parameters};
#### Define some generic varibles
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'};
#### Set some specific settings for this program
my $PROGRAM_FILE_NAME="GetHaloAnnotations";
my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$PROGRAM_FILE_NAME";
#### Get the columns and input types for this table/query
my @columns = ( 'search_scope','search_key' );
my %input_types = ( 'optionlist','text' );
#### 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);
#### If the apply action was to recall a previous resultset, do it
my %rs_params = $sbeams->parseResultSetParams(q=>$q);
if ($apply_action eq "VIEWRESULTSET") {
$sbeams->readResultSet(resultset_file=>$rs_params{set_name},
resultset_ref=>$resultset_ref,query_parameters_ref=>\%parameters);
$n_params_found = 99;
}
#### Set some reasonable defaults if no parameters supplied
unless ($n_params_found) {
}
#### Apply any parameter adjustment logic
#$parameters{display_options} = 'ShowSQL';
#### Display the user-interaction input form
if ($sbeams->output_mode() eq 'html') {
my @options = ( 'All','GeneSymbol','ORFName',
'FullGeneName','ECNumbers','Aliases',
'RedundantORFs' );
my %options = ( 'GeneSymbol' => 'Gene Symbol',
'ORFName' => 'ORF Name',
'FullGeneName' => 'Full Gene Name',
'ECNumbers' => 'EC Number',
'Aliases' => 'Aliases',
'RedundantORFs' => 'Redundant ORFs',
'All' => 'All Attributes',
);
#### Build the option list
my $optionlist = '';
foreach my $key ( @options ) {
my $flag = '';
$flag = 'SELECTED' if ($parameters{search_scope} eq $key);
$optionlist .= "\n";
};
print qq~
~;
## PREPEND summary links
print " $counter Results Returned ";
$table_html = qq~
-Download Tab-delimited Summary
~ . $table_html;
if (@p_ids) {
my $p_list = join ",", @p_ids;
$table_html = qq~
-View all Protein Entries
~ . $table_html;
}
if (@d_ids) {
my $d_list = join ",", @d_ids;
$table_html = qq~
-View all DNA Entries
~ . $table_html;
}
if (@array_expression_genes) {
my $array_expression_ids = join "%3B", @array_expression_genes;
$table_html = qq~
-View Microarray data -Download Microarray data
~ . $table_html;
}
#### Print HTML
print $table_html;
}elsif ($sbeams->output_mode() =~ /tsv|csv|excel/) {
#### If the invocation_mode is http, provide a header
my $delimiter = "\t";
my $header = "Content-type: text/tab-separated-values\n\n";
if ($sbeams->invocation_mode() eq 'http') {
if ($sbeams->output_mode() =~ /tsv/) {
$header = "Content-type: text/tab-separated-values\n\n";
$delimiter = "\t";
} elsif ($sbeams->output_mode() =~ /csv/) {
$header = "Content-type: text/comma-separated-values\n\n";
$delimiter = ",";
} elsif ($sbeams->output_mode() =~ /excel/) {
$header = "Content-type: application/excel\n\n";
$delimiter = "\t";
}
}
print $header if ($sbeams->invocation_mode() eq 'http');
print "ORF Name\tChromosome\tCoordinates\tGene Symbol\tFunction\tAliases\tRedundant ORFs";
print "\tComments" if ($sbeams->getCurrent_username() ne 'ext_halo');
print "\n";
foreach my $row (@rows) {
my $protein_biosequence_id = $row->[0];
my $biosequence_annotation_id = $row->[1];
my $biosequence_name = $row->[2];
my $gene_symbol = $row->[3];
my $functional_description = $row->[4];
my $chromosome = $row->[5];
my $start = $row->[6];
my $stop = $row->[7];
my $aliases = $row->[8];
my $duplicate_biosequences = $row->[9];
my $comments = $row->[10];
$comments =~ s/\s+/ /g;
my $biosequence_accession = $row->[11];
my $dna_biosequence_id = $row->[12] if ($row->[12]);
my @line = ($biosequence_name,
$chromosome,
"$start..$stop",
$gene_symbol,
$functional_description,
$aliases,
$duplicate_biosequences,
$comments);
# remove 'comments' if user eq ext_halo
pop @line if ($sbeams->getCurrent_username() eq 'ext_halo');
print join ($delimiter, @line);
print "\n";
}
}
if ($sbeams->invocation_mode() ne 'http') {
print "You need to supply some parameters to contrain the query\n";
}
} # end handle_request
###############################################################################
# getColorizedTD- returns a
tagset
###############################################################################
sub getColorizedTD {
my %args = @_;
my $tag = $args{'tag'};
my $data = $args{'data'};
my $text = $args{'text'};
my $link = $args{'link'};
my $target = $args{'target'};
my $tooltip = $args{'tooltip'};
$tooltip = "NO $tag" unless ($tooltip) ;
my $go_color = "#66FF33";
my $stop_color = "#FF0033";
my $html = "