package SBEAMS::Biomarker::HTMLPrinter; ############################################################################### # Program : SBEAMS::Biomarker::HTMLPrinter # Author : Eric Deutsch # $Id$ # # 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_work_group_id $current_work_group_name # $current_project_id $current_project_name $current_user_context_id); #use SBEAMS::Connection::DBConnector; #use SBEAMS::Connection::TableInfo; use SBEAMS::Connection qw($log); use SBEAMS::Connection::Settings; use SBEAMS::Biomarker::Settings; use SBEAMS::Biomarker::Tables; ############################################################################### # printPageHeader ############################################################################### sub printPageHeader { my $this = shift; $this->display_page_header(@_); } sub getMenu { my $self = shift; my $sbeams = $self->getSBEAMS(); my $pad = "   "; my $optional =<<" END";
$pad Analysis_file
$pad Attribute
$pad Attribute_type
$pad Biosample
$pad Biosource
$pad Disease
$pad Disease_type
$pad Experiment
$pad Storage_location
$pad Treatment
$pad Treatment_type
END my ( $content, $link ) = $sbeams->make_toggle_section( content => $optional, name => 'biomarker', sticky => 1, visible => 1 ); my $menu = qq~
$DBTITLE Home
$SBEAMS_PART Home
Logout
 
Lab Workflow:
$pad View experiments
$pad Upload samples
$pad View treatments
$pad $pad Add treatment
$pad View LC/MS runs
$pad $pad Add LC/MS run
 
$link Manage Tables:
$content
 
Browse Data:
   Browse BioSeqs
~; print STDERR "In getMenu\n"; return $menu; } ############################################################################### # display_page_header ############################################################################### sub display_page_header { my $this = shift; my %args = @_; my $navigation_bar = $args{'navigation_bar'} || "YES"; #### If the output mode is interactive text, display text header my $sbeams = $this->get_sbeams(); if ($sbeams->output_mode() eq 'interactive') { $sbeams->printTextHeader(); return; } #### If the output mode is not html, then we don't want a header here if ($sbeams->output_mode() ne 'html') { return; } #### Obtain main SBEAMS object and use its http_header $sbeams = $this->get_sbeams(); my $http_header = $sbeams->get_http_header(); print qq~$http_header $DBTITLE - $SBEAMS_PART ~; $this->printJavascriptFunctions(); $this->printStyleSheet(); #### Determine the Title bar background decoration my $header_bkg = "bgcolor=\"$BGCOLOR\""; $header_bkg = "background=\"/images/plaintop.jpg\"" if ($DBVERSION =~ /Primary/); print qq~ ~; my $message = $sbeams->get_page_message(); print STDERR "Message is $message\n"; #print ">>>http_header=$http_header
\n"; if ($navigation_bar eq "YES") { my $pad = "   "; my $management_table =<<" END";
ISB DBSBEAMS

$DBTITLE - $SBEAMS_PART
$DBVERSION

$pad Analysis_file
$pad Attribute
$pad Attribute_type
$pad Biosample
$pad Biosource
$pad Disease
$pad Disease_type
$pad Experiment
$pad Storage_location
$pad Treatment
$pad Treatment_type
END my ( $content, $link ) = $sbeams->make_toggle_section( content => $management_table, name => 'biomarker', sticky => 1, visible => 1 ); print qq~
$DBTITLE Home
$SBEAMS_PART Home
Logout
 
Lab Workflow:
$pad View experiments
$pad Upload samples
$pad View treatments
$pad $pad Add treatment
$pad View LC/MS runs
$pad $pad Add LC/MS run
 
$link Manage Tables:
$content
 
Browse Data:
   Browse BioSeqs
$message ~; } else { print qq~
$message ~; } } # ############################################################################### # 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 $this = shift; #### Obtain main SBEAMS object and use its style sheet my $sbeams = $this->get_sbeams(); $sbeams->printStyleSheet(); } ############################################################################### # 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 $this = shift; my $javascript_includes = shift; print qq~ ~; } ############################################################################### # printPageFooter ############################################################################### sub printPageFooter { my $this = shift; $this->display_page_footer(@_); } ############################################################################### # display_page_footer ############################################################################### sub display_page_footer { my $this = shift; my %args = @_; # Surely this is a cut and paste residue... #### If the output mode is interactive text, display text header my $sbeams = $this->get_sbeams(); 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'); } } ## Interface routines ## sub get_treatment_sample_select { my $this = shift; my %args = @_; my $params = $args{params} || die "missing required 'params' hashref"; my $type = $args{types} || die "missing required parameter types"; $params->{experiment_id} ||= $this->get_first_experiment_id(@_); return undef unless $params->{experiment_id}; die "Must pass type as an arrayref" unless (ref($type) eq 'ARRAY'); my $sbeams = $this->get_sbeams(); my $pid = $sbeams->getCurrent_project_id || die("Can't determine project_id"); my @acc = $sbeams->getAccessibleProjects(); my $table = SBEAMS::Connection::DataTable->new( BORDER => 1 ); my $sql =<<" END"; SELECT biosample_id, biosample_name || ' - ' || bio_group_name AS sample FROM $TBBM_BIOSAMPLE BS JOIN $TBBM_BIO_GROUP BG ON BS.biosample_group_id = BG.bio_group_id WHERE BS.experiment_id = $params->{experiment_id} AND BS.record_status <> 'D' AND BG.record_status <> 'D' ORDER BY biosample_group_id ASC, biosample_id ASC END my @current = split /,/, $params->{biosample_id}; my $options = $sbeams->buildOptionList($sql, $params->{biosample_id}, 'MULTIOPTIONLIST' ); my $select = ""; return $select; ## Deprecated in favor of a multi-select list for my $row ( $sbeams->selectSeveralColumns( $sql ) ) { $row->[0] = get_ts_checkbox( $row->[0] ); $table->addRow( $row ); } $table->alternateColors( PERIOD => 3, BGCOLOR => '#FFFFFF', DEF_BGCOLOR => '#E0E0E0', FIRSTROW => 0 ); $table->setColAttr( ROWS => [ 2..$table->getRowNum() ], COLS => [ 1,2 ], ALIGN => 'RIGHT' ); $table->setColAttr( ROWS => [ 1 ], COLS => [ 1..2], ALIGN => 'CENTER' ); my $list = $table->asHTML(); return $list; } sub get_lcms_sample_select { my $this = shift; my %args = @_; my $params = $args{params} || die "missing required 'params' hashref"; my $type = $args{types} || die "missing required parameter types"; $params->{treatment_id} ||= $this->get_first_treatment_id(@_); return 'n/a' if !defined $params->{treatment_id}; die "Must pass type as an arrayref" unless (ref($type) eq 'ARRAY'); my $sbeams = $this->get_sbeams(); my $pid = $sbeams->getCurrent_project_id || die("Can't determine project_id"); my @acc = $sbeams->getAccessibleProjects(); my $table = SBEAMS::Connection::DataTable->new( BORDER => 1 ); my $sql =<<" END"; SELECT biosample_id, biosample_name || ' - ' || bio_group_name AS sample FROM $TBBM_BIOSAMPLE BS JOIN $TBBM_BIO_GROUP BG ON BS.biosample_group_id = BG.bio_group_id WHERE BS.treatment_id = $params->{treatment_id} AND BS.record_status <> 'D' AND BG.record_status <> 'D' ORDER BY biosample_group_id ASC, biosample_id ASC END my @current = split /,/, $params->{biosample_id}; my $options = $sbeams->buildOptionList($sql, $params->{biosample_id}, 'MULTIOPTIONLIST' ); my $select = ""; return $select; ## Deprecated in favor of a multi-select list for my $row ( $sbeams->selectSeveralColumns( $sql ) ) { $row->[0] = get_ts_checkbox( $row->[0] ); $table->addRow( $row ); } $table->alternateColors( PERIOD => 3, BGCOLOR => '#FFFFFF', DEF_BGCOLOR => '#E0E0E0', FIRSTROW => 0 ); $table->setColAttr( ROWS => [ 2..$table->getRowNum() ], COLS => [ 1,2 ], ALIGN => 'RIGHT' ); $table->setColAttr( ROWS => [ 1 ], COLS => [ 1..2], ALIGN => 'CENTER' ); my $list = $table->asHTML(); return $list; } sub get_ts_checkbox { my $val = shift; return ""; } #+ # Routine builds a list of experiments/samples within. #- sub get_experiment_overview { my $this = shift; my $sbeams = $this->get_sbeams(); my $pid = $sbeams->getCurrent_project_id || die("Can't determine project_id"); my %msruns = $sbeams->selectTwoColumnHash( <<" END" ); SELECT e.experiment_id, COUNT(msrs.biosample_id) FROM $TBBM_EXPERIMENT e LEFT OUTER JOIN $TBBM_BIOSAMPLE b ON e.experiment_id = b.experiment_id LEFT OUTER JOIN $TBBM_MS_RUN_SAMPLE msrs ON b.biosample_id = msrs.biosample_id -- JOIN $TBBM_MS_RUN msr -- ON e. = msrs.ms_run_id = msr.ms_run_id WHERE project_id = $pid -- Just grab the 'primary' samples GROUP BY e.experiment_id END my $sql =<<" END"; SELECT e.experiment_id, experiment_name, experiment_tag, experiment_type, experiment_description, COUNT(biosample_id) FROM $TBBM_EXPERIMENT e LEFT OUTER JOIN $TBBM_BIOSAMPLE b ON e.experiment_id = b.experiment_id -- JOIN $TBBM_MS_RUN_SAMPLE msrs -- ON e. = b.biosample_id = msrs.biosample_id -- JOIN $TBBM_MS_RUN msr -- ON e. = msrs.ms_run_id = msr.ms_run_id WHERE project_id = $pid -- Just grab the 'primary' samples AND parent_biosample_id IS NULL GROUP by experiment_name, experiment_description, experiment_type, e.experiment_id, experiment_tag ORDER BY experiment_name ASC END $log->error( $sql ); my $table = SBEAMS::Connection::DataTable->new( WIDTH => '100%' ); $table->addResultsetHeader( ['Experiment Name', 'Tag', 'Type', 'Description', '# samples', '# ms runs' ] ); for my $row ( $sbeams->selectSeveralColumns($sql) ) { my @row = @$row; my $id = shift @row; $row[3] = ( length $row[3] <= 50 ) ? $row[3] : shortlink($row[3], 50); $row[0] =<<" END"; $row[0] END push @row, $msruns{$id}; $table->addRow( \@row ) } $table->alternateColors( PERIOD => 1, BGCOLOR => '#FFFFFF', DEF_BGCOLOR => '#E0E0E0', FIRSTROW => 0 ); $table->setColAttr( ROWS => [ 2..$table->getRowNum() ], COLS => [ 4..6 ], ALIGN => 'RIGHT' ); $table->setColAttr( ROWS => [ 1 ], COLS => [ 1..6 ], ALIGN => 'CENTER' ); return $table; } #+ # Routine builds a list of experiments/samples within. #- sub treatment_list { my $this = shift; my $sbeams = $this->get_sbeams(); my $pid = $sbeams->getCurrent_project_id || die("Can't determine project_id"); my $sql =<<" END"; SELECT t.treatment_id, treatment_name, treatment_description, treatment_type_name, COUNT(b.biosample_id) num_samples FROM $TBBM_TREATMENT t JOIN $TBBM_TREATMENT_TYPE tt ON tt.treatment_type_id = t.treatment_type_id JOIN $TBBM_BIOSAMPLE b ON b.treatment_id = t.treatment_id JOIN $TBBM_EXPERIMENT e ON e.experiment_id = b.experiment_id WHERE project_id = $pid GROUP BY treatment_name, treatment_description, treatment_type_name, t.treatment_id ORDER BY t.treatment_id DESC END $log->error( $sql ); my $table = SBEAMS::Connection::DataTable->new( WIDTH => '100%' ); $table->addResultsetHeader( ['Name', 'Description', 'Type', '# samples'] ); for my $row ( $sbeams->selectSeveralColumns($sql) ) { my @row = @$row; my $id = shift @row; $row[1] = ( length $row[1] <= 40 ) ? $row[1] : shortlink($row[1], 40); $row[0] =<<" END"; $row[0] END $table->addRow( \@row ) } $table->alternateColors( PERIOD => 1, BGCOLOR => '#FFFFFF', DEF_BGCOLOR => '#E0E0E0', FIRSTROW => 0 ); $table->setColAttr( ROWS => [ 2..$table->getRowNum() ], COLS => [ 4], ALIGN => 'RIGHT' ); $table->setColAttr( ROWS => [ 1 ], COLS => [ 1..4 ], ALIGN => 'CENTER' ); return $table; } #+ # #- ### #+ # Routine builds a list of experiments/samples within. #- sub lcms_run_list { my $this = shift; my $sbeams = $this->get_sbeams(); my $pid = $sbeams->getCurrent_project_id || die("Can't determine project_id"); my $sql =<<" END"; SELECT msr.ms_run_id, ms_run_name, ms_run_description, instrument_name, ms_run_date, COUNT( b.biosample_id ) num_samples FROM $TBBM_MS_RUN msr JOIN $TBBM_MS_RUN_SAMPLE msrs ON msrs.ms_run_id = msr.ms_run_id JOIN $TBBM_BIOSAMPLE b ON b.biosample_id = msrs.biosample_id JOIN $TBBM_EXPERIMENT e ON e.experiment_id = b.experiment_id LEFT OUTER JOIN $TBBM_INSTRUMENT i ON i.instrument_id = msr.ms_instrument WHERE project_id = $pid GROUP BY msr.ms_run_id, ms_run_name, ms_run_description, instrument_name, ms_run_date ORDER BY ms_run_date DESC, ms_run_name ASC END $log->error( $sql ); my $foo =<<' EMD'; SELECT msr.ms_run_id, ms_run_name, ms_run_description, ms_instrument, ms_run_date, COUNT( b.biosample_id ) num_samples FROM biomarker.dbo.BMRK_ms_run msr JOIN biomarker.dbo.BMRK_ms_run_sample msrs ON msrs.ms_run_id = msr.ms_run_id JOIN biomarker.dbo.BMRK_biosample b ON b.biosample_id = msrs.biosample_id JOIN biomarker.dbo.BMRK_experiment e ON b.experiment_id = e.experiment_id WHERE project_id = 542 GROUP BY msr.ms_run_id, ms_run_name, ms_run_description, ms_instrument, ms_run_date ORDER BY ms_run_date DESC, ms_run_name ASC EMD my $table = SBEAMS::Connection::DataTable->new( WIDTH => '100%' ); $table->addResultsetHeader( ['Run Name', 'Description', 'Instrument', 'Run Date', '# samples', undef] ); for my $row ( $sbeams->selectSeveralColumns($sql) ) { my @row = @$row; my $id = shift @row; $row[2] = ( length $row[2] <= 40 ) ? $row[2] : shortlink($row[2], 40); $row[0] =<<" END"; $row[0] END push @row, download_link( $id ); $table->addRow( \@row ) } $table->setColAttr( ROWS => [ 1 ], COLS => [ 7 ], BGCOLOR => '#FFFFFF' ); $table->alternateColors( PERIOD => 1, BGCOLOR => '#FFFFFF', DEF_BGCOLOR => '#E0E0E0', FIRSTROW => 0 ); $table->setColAttr( ROWS => [ 2..$table->getRowNum() ], COLS => [ 4..6 ], ALIGN => 'RIGHT' ); $table->setColAttr( ROWS => [ 1 ], COLS => [ 1..6 ], ALIGN => 'CENTER' ); return $table; } #+ # #- sub get_ms_instrument_select { my $this = shift; my %args = @_; # Select currval? if ( $args{current} && ref($args{current} eq 'ARRAY') ) { # stringify args if we were passed an arrayref $args{current} = join ",", @{$args{current}}; } my $sbeams = $this->get_sbeams(); my $sql =<<" END"; SELECT instrument_id, instrument_name FROM $TBBM_INSTRUMENT WHERE record_status <> 'D' ORDER BY instrument_name ASC END my $options = $sbeams->buildOptionList( $sql, $args{current} ); my $select_name = $args{name} || 'ms_instrument'; my $select = ""; return $select; } #+ # #- sub get_storage_loc_select { my $this = shift; my %args = @_; # Select currval? if ( $args{current} && ref($args{current} eq 'ARRAY') ) { # stringify args if we were passed an arrayref $args{current} = join ",", @{$args{current}}; } my $sbeams = $this->get_sbeams(); my $sql =<<" END"; SELECT storage_location_id, location_name FROM $TBBM_STORAGE_LOCATION WHERE record_status <> 'D' ORDER BY location_name ASC END my $options = $sbeams->buildOptionList( $sql, $args{current} ); my $select_name = $args{name} || 'storage_location_id'; my $select = ""; return $select; } #+ # #- sub get_treatment_type_select { my $this = shift; my %args = @_; # Select currval? if ( $args{current} && ref($args{current} eq 'ARRAY') ) { # stringify args if we were passed an arrayref $args{current} = join ",", @{$args{current}}; } my $sbeams = $this->get_sbeams(); my $sql =<<" END"; SELECT treatment_type_id, treatment_type_name FROM $TBBM_TREATMENT_TYPE WHERE record_status <> 'D' ORDER BY treatment_type_name ASC END my $options = $sbeams->buildOptionList( $sql, $args{current} ); my $select_name = $args{name} || 'treatment_type_id'; my $select = ""; return $select; # deprecated my @rows = $sbeams->selectSeveralColumns( $sql ); for my $row ( @rows ) { $select .= "