package SBEAMS::Glycopeptide::HTMLPrinter; ############################################################################### # Program : SBEAMS::Glycopeptide::HTMLPrinter # $Id: HTMLPrinter.pm 3976 2005-09-26 17:25:12Z dcampbel $ # # Description : This is part of the SBEAMS::WebInterface module which handles # standardized parts of generating HTML. # # This really begs to get a lot more object oriented such that # there are several different contexts under which the a user # can be in, and the header, button bar, etc. vary by context ############################################################################### use strict; use vars qw($sbeams $current_contact_id $current_username $current_work_group_id $current_work_group_name $current_project_id $current_project_name $current_user_context_id); use CGI::Carp qw( croak); use SBEAMS::Connection::DBConnector; use SBEAMS::Connection::Settings; use SBEAMS::Connection::TableInfo; use SBEAMS::Connection::Log; my $log = SBEAMS::Connection::Log->new(); use SBEAMS::Glycopeptide::Settings; use SBEAMS::Glycopeptide::TableInfo; ############################################################################### # printPageHeader ############################################################################### sub printPageHeader { my $self = shift; $self->display_page_header(@_); } # displayPhosphopepHeader ############################################################################### sub displayPhosphopepHeader { my $self = shift; my %args = @_; my $loadscript = "$args{onload};" || ''; #### Obtain main SBEAMS object and use its http_header my $sbeams = $self->getSBEAMS(); my $http_header = $sbeams->get_http_header(); my $navigation_bar = $args{'navigation_bar'} || "YES"; my $LOGIN_URI = "$SERVER_BASE_DIR$ENV{REQUEST_URI}"; if ($LOGIN_URI =~ /\?/) { $LOGIN_URI .= "&force_login=yes"; } else { $LOGIN_URI .= "?force_login=yes"; } my $LOGIN_LINK = qq~LOGIN~; use LWP::UserAgent; use HTTP::Request; my $ua = LWP::UserAgent->new(); my $organism_param = $sbeams->getSessionAttribute( key => 'phosphopep_organism' ) || ''; if ( $organism_param ) { $log->debug( "org param is $organism_param" ); $organism_param = '?ppep_organism=' . $organism_param; } elsif ( $self->{_build_id} ) { $log->debug( "Halla" ); } $log->debug( "ppep org is $organism_param" ); # my $skinLink = 'http://www.phosphopep.org/newlook/'; my $skinLink = 'http://www.phosphopep.org'; my $response = $ua->request( HTTP::Request->new( GET => "$skinLink/.index.dbbrowse.php${organism_param}" ) ); my @page = split( "\r", $response->content() ); my $skin = ''; my $cnt = 0; my $cutoff_widget = $self->get_prophet_control(); # print STDERR "Original content is " . $response->content() . "\n"; for my $line ( @page ) { $cnt++; if ( $line =~ /LOGIN_LINK/ ) { $line =~ s/\<\!-- LOGIN_LINK --\>/$LOGIN_LINK/; } elsif ( $line =~ /PSCORE_CUTOFF/ ) { $line =~ s/\<\!-- PSCORE_CUTOFF --\>/$cutoff_widget/; } elsif ( $line =~ /\ $line =~ s/(ONLOAD=')/${1}$loadscript;self.focus();/; } else { $line =~ s/(\ $skin END_PAGE # print ''; print $sbeams->get_page_message(); $self->printJavascriptFunctions(); } sub decorate_phospho_sequence { my $self = shift; my $seq = shift || return ''; $seq =~ s/([A-Z]\*)/$1<\/SPAN>/g; $seq =~ s/([A-Z])\&/$1\*<\/SPAN>/g; return $seq; } sub get_phospho_css { my $self = shift; $log->printStack("debug"); my %colors = ( 'Signal Sequence' => 'lavender', 'Signal Sequence web' => '#CCCCFF', Anchor => 'lavender', Anchor => 'lavender', Anchor_web => '#CCCCFF', Transmembrane => 'lightgreen', Transmembrane_web => '#CCFFCC', Intracellular => 'coral', id_track_type => 'firebrick', Extracellular => 'mediumseagreen', Coverage => 'beige', glyco_site_track => '#EE9999', predicted_track_type => 'goldenrod', ambi_site_track => 'lightyellow' ); return( <<" END_STYLE" ); END_STYLE } # displayUnipepHeader ############################################################################### sub displayUnipepHeader { my $self = shift; my %args = @_; #### Obtain main SBEAMS object and use its http_header my $sbeams = $self->getSBEAMS(); my $http_header = $sbeams->get_http_header(); my $navigation_bar = $args{'navigation_bar'} || "YES"; my $LOGIN_URI = "$SERVER_BASE_DIR$ENV{REQUEST_URI}"; if ($LOGIN_URI =~ /\?/) { $LOGIN_URI .= "&force_login=yes"; } else { $LOGIN_URI .= "?force_login=yes"; } my $LOGIN_LINK = qq~LOGIN~; use LWP::UserAgent; use HTTP::Request; my $ua = LWP::UserAgent->new(); # my $skinLink = 'http://www.unipep.org/newlook/'; my $skinLink = 'http://www.unipep.org'; my $response = $ua->request( HTTP::Request->new( GET => "$skinLink/.index.dbbrowse.php" ) ); my @page = split( "\r", $response->content() ); my $skin = ''; my $cnt = 0; # print STDERR "Original content is " . $response->content() . "\n"; for my $line ( @page ) { $cnt++; if ( $line =~ /LOGIN/ ) { $line =~ s/\<\!-- LOGIN_LINK --\>/$LOGIN_LINK/; } elsif ( $line =~ /td\s+\{font/ ) { # next; } elsif ( $line =~ /body\s+\{font/ ) { # next; } $skin .= $line; last if $line =~ /--- Main Page Content ---/; } $skin =~ s/\/images\//\/sbeams\/images\//gm; print "$http_header\n\n"; print <<" END_PAGE"; $skin END_PAGE # print ''; # $self->printStyleSheet(); $self->printJavascriptFunctions(); } sub getGlycoStyleSheet { use Env qw (HTTP_USER_AGENT); my $FONT_SIZE=9; my $FONT_SIZE_SM=8; my $FONT_SIZE_LG=12; my $FONT_SIZE_HG=14; if ( $HTTP_USER_AGENT =~ /Mozilla\/4.+X11/ ) { $FONT_SIZE=12; $FONT_SIZE_SM=11; $FONT_SIZE_LG=14; $FONT_SIZE_HG=19; } my $css =<displayUnipepHeader( %args ); # return; # } ############################################################################### # display_page_header ############################################################################### sub display_page_header { my $self = shift; my %args = @_; my $navigation_bar = $args{'navigation_bar'} || "YES"; #### If the output mode is interactive text, display text header my $sbeams = $self->getSBEAMS(); if ($sbeams->output_mode() eq 'interactive') { $sbeams->printTextHeader(); return; } my $loadscript = "$args{onload};" || ''; #### If the output mode is not html, then we don't want a header here if ($sbeams->output_mode() ne 'html') { return; } # if ( $self->get_current_motif_type() =~ /phospho/ ) { # $self->displayPhosphopepHeader(%args); # return(); # } elsif( $sbeams->isGuestUser() ) { if ( $sbeams->isGuestUser() ) { $self->displayPhosphopepHeader(%args); # $self->displayUnipepHeader(%args); return(); } #### Obtain main SBEAMS object and use its http_header $sbeams = $self->getSBEAMS(); my $http_header = $sbeams->get_http_header(); print qq~$http_header $DBTITLE - $SBEAMS_PART ~; $self->printJavascriptFunctions(); $self->printStyleSheet(); #### Determine the Title bar background decoration my $header_bkg = "bgcolor=\"$BGCOLOR\""; $header_bkg = "background=\"/images/plaintop.jpg\"" if ($DBVERSION =~ /Primary/); print qq~ ~; my $prophet_control = $self->get_prophet_control(); my $message = $sbeams->get_page_message(); my $sp = ' ' x 2; # # if ($navigation_bar eq "YES") { print qq~
ISB DBSBEAMS

$DBTITLE - $DBVERSION

   Mass Search
   Fetch Annotations
$DBTITLE Home
$SBEAMS_PART Home
Logout
 
Browse Data:
   Search Observed Peptides
   Observed Proteins
   Pathway Search
   Bulk Search
   Get MRM Transitions
   Spectral Search
   Phosphopep Home
 
Manage Tables:
   BioSequenceSets
   Samples
${sp} Build Settings
 
$prophet_control
$message ~; } else { print qq~
$message ~; } } sub getStatsHTML { my $self = shift; my $sbeams = $self->getSBEAMS(); my $current = $self->get_current_prophet_cutoff(); return $sbeams->getGifSpacer(800); } sub get_prophet_control { my $self = shift; my %args = @_; my $current = $self->get_current_prophet_cutoff(); my $show_form = $args{show_form} || 1; my @stock = qw( 0.5 0.6 0.7 0.8 0.9 0.95 0.99 1.0 ); if ( defined $current && !grep /^$current$/, @stock ) { push @stock, $current; @stock = sort{ $a <=> $b }(@stock); } my $update_script = 'ONCHANGE="update_prophet_score()"'; $sbeams ||= $self->getSBEAMS(); my $self_url = $sbeams->get_self_url(); $self_url =~ s/\?.*$//g; my $url_params = $sbeams->get_url_params( escape => 0, omit => [qw( glyco_prophet_cutoff )] ); my $select = $sbeams->new_option_list( names => \@stock, 'values' => \@stock, selected => $current, list_name => 'glyco_prophet_cutoff', attrs => $update_script ); my $label = 'Prophet cutoff'; $label = "$label" if $args{white_label}; my $form =<<" END";
$url_params
$label: $select
END return ( $show_form ) ? $form : $select; } ############################################################################### # printStyleSheet # # Print the standard style sheet for pages. Use a font size of 10pt if # remote client is on Windows, else use 12pt. This ends up making fonts # appear the same size on Windows+IE and Linux+Netscape. Other tweaks for # different browsers might be appropriate. ############################################################################### sub printStyleSheet { my $self = shift; #### Obtain main SBEAMS object and use its style sheet $sbeams = $self->getSBEAMS(); $sbeams->printStyleSheet(); # print ''; } ############################################################################### # printJavascriptFunctions # # Print the standard Javascript functions that should appear at the top of # most pages. There probably should be some customization allowance here. # Not sure how to design that yet. ############################################################################### sub printJavascriptFunctions { my $self = shift; my $javascript_includes = shift; print qq~ ~; } ############################################################################### # printPageFooter ############################################################################### sub printPageFooter { my $self = shift; $self->display_page_footer(@_); } ############################################################################### # display_page_footer ############################################################################### sub display_page_footer { my $self = shift; my %args = @_; if ( $self->get_current_motif_type() =~ /phospho/ ) { # No-op print $self->{'_external_footer'} if $self->{'_external_footer'}; return; } #### If the output mode is interactive text, display text header my $sbeams = $self->getSBEAMS(); if ($sbeams->output_mode() eq 'interactive') { $sbeams->printTextHeader(%args); return; } #### If the output mode is not html, then we don't want a header here if ($sbeams->output_mode() ne 'html') { return; } #### Process the arguments list my $close_tables = $args{'close_tables'} || 'YES'; my $display_footer = $args{'display_footer'} || 'YES'; my $separator_bar = $args{'separator_bar'} || 'NO'; #### If closing the content tables is desired if ($close_tables eq 'YES') { print qq~
~; } #### If displaying a fat bar separtor is desired if ($separator_bar eq 'YES') { print "


\n"; } #### If finishing up the page completely is desired if ($display_footer eq 'YES') { #### Default to the Core footer $sbeams->display_page_footer(display_footer=>'YES'); } } sub getSpectrastViewer { my $self = shift; my %args = @_; return '' unless $args{offset}; my $libname = "$PHYSICAL_BASE_DIR/usr/Glycopeptide/" . $self->getSpectraSTLib() . '.splib'; unless ( -e $libname ) { $log->error( "Missing SpectraST library: $libname" ); return ''; } my $url = "http://www.peptideatlas.org/cgi/spectrast/plotspectrast.cgi?LibFile=$libname&LibFileOffset=FILE_OFFSET&QueryFile=$PHYSICAL_BASE_DIR/tmp/images/spectrum.none"; $log->debug( $url ); # my $url = "http://www.peptideatlas.org/cgi/spectrast/plotspectrast.cgi?LibFile=/net/dblocal/wwwspecial/sbeams/devDC/sbeams/usr/Glycopeptide/raw_consensus.splib&LibFileOffset=FILE_OFFSET&QueryFile=/net/dblocal/wwwspecial/sbeams/devDC/sbeams/tmp/images/spectrum.none"; # $url = "http://regis-web/tpp-hlam/cgi-bin/plotspectrast.cgi?LibFile=/data2/search/hlam/ForDaveC/raw_consensus.splib&LibFileOffset=FILE_OFFSET&QueryFile=/data2/search/hlam/ForDaveC/spectrum.none"; $url =~ s/FILE_OFFSET/$args{offset}/; my $cipher = $self->getSBEAMS()->getAuthCipher(); # my @auth = split "::", $cipher->decrypt_hex( '645c9938dc49eccc193553a57950ac78e5b0d69106f72331'); my @auth = ( 'none', 'required' ); # Subclass LWP::UserAgent for Auth { package SpectrastViewerAgent; our @ISA = qw(LWP::UserAgent); sub new { my $self = LWP::UserAgent::new(@_); $self->agent("SpectraSTViewer"); return $self; } sub get_basic_credentials { return( @auth ); } } # End UserAgent subclass my $ua = SpectrastViewerAgent->new(); my $req = HTTP::Request->new(GET=>$url); my $response = $ua->request( $req ); my $content = $response->content(); # Remove submit button # Pull out png link # get png, save to /tmp/ # Rewrite png link to local #
#
my $file_name = $args{pep_seq} || $self->getSBEAMS()->getRandomString(num_chars => 24); $file_name .= '.png'; $file_name =~ s/S\*/S\[167\]/g; $file_name =~ s/Y\*/Y\[243\]/g; $file_name =~ s/T\*/T\[180\]/g; my $original_img = $PHYSICAL_BASE_DIR . "/tmp/images/spectrum.png"; my $named_img = $original_img; $named_img =~ s/spectrum.png/$file_name/g; # Is there an existing version of this image? my $existed = 0; if ( -e $named_img ) { $log->info( "replacing spectrum file $named_img" ); } my $result = system( "cp $original_img $named_img" ); $log->error( "Error on cp $original_img to $named_img" ) if $result; my $web_img = $HTML_BASE_DIR . "/tmp/images/" . $file_name; $content =~ s/\//gm; $content =~ s/sbeams.*spectrum\.png/$web_img/gm; $content =~ s/ACTION\=\"\//ACTION\=\"http:\/\/www\.peptideatlas\.org\//gm; return $content; my $local_img = $HTML_BASE_DIR . "/tmp/images/" . $file_name; $content =~ s/\//gm; $content =~ s/\/sbeams.*spectrum\.png/$local_img/gm; $content =~ s/ACTION\=\"\//ACTION\=\"http:\/\/www\.peptideatlas\.org\//gm; #
return $content; # my $img_url = "http://regis-web/data2/search/hlam/ForDaveC/spectrum.png"; # my $tmpdir = $PHYSICAL_BASE_DIR . '/tmp/images/'; # my $req = HTTP::Request->new(GET=>$img_url); # my $response = $ua->request( $req ); # open ( PNG, ">$tmpdir/$file_name" ) || return ''; # print PNG $response->content(); return $content; } ############################################################################### 1; __END__ ############################################################################### ############################################################################### ############################################################################### =head1 NAME SBEAMS::WebInterface::HTMLPrinter - Perl extension for common HTML printing methods =head1 SYNOPSIS Used as part of this system use SBEAMS::WebInterface; $adb = new SBEAMS::WebInterface; $adb->printPageHeader(); $adb->printPageFooter(); $adb->getGoBackButton(); =head1 DESCRIPTION This module is inherited by the SBEAMS::WebInterface module, although it can be used on its own. Its main function is to encapsulate common HTML printing routines used by this application. =head1 METHODS =item B Prints the common HTML header used by all HTML pages generated by theis application =item B Prints the common HTML footer used by all HTML pages generated by this application =item B Returns a form button, coded with javascript, so that when it is clicked the user is returned to the previous page in the browser history. =head1 AUTHOR Eric Deutsch =head1 SEE ALSO perl(1). =cut