#!/usr/local/bin/perl -w
###############################################################################
# Program treatment.cgi
# $Id: $
#
# Description : Form and processing logic for applying laboratory
# manipulation or treatment to a set of samples.
#
# SBEAMS is Copyright (C) 2000-2005 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.
#
###############################################################################
use strict;
use lib qw (../../lib/perl);
use File::Basename;
use SBEAMS::Connection qw($q $log);
use SBEAMS::Connection::Settings;
use SBEAMS::Biomarker;
use SBEAMS::Biomarker::Biosample;
use SBEAMS::Biomarker::Settings;
use SBEAMS::Biomarker::Tables;
## Globals ##
my $sbeams = new SBEAMS::Connection;
my $biomarker = new SBEAMS::Biomarker;
my $biosample = new SBEAMS::Biomarker::Biosample;
my $program = basename( $0 );
$biomarker->setSBEAMS($sbeams);
$biosample->set_sbeams($sbeams);
use constant DEFAULT_VOLUME => 10;
{ # Main
# Authenticate user.
my $current_username = $sbeams->Authenticate() || die "Authentication failed";
# Process cgi parameters
my $params = process_params();
my $content = 'placeholder';
$params->{apply_action} ||= 'new_run';
# Decision block, what type of page are we going to display?
if ( $params->{apply_action} eq 'Create run' ) {
my $status = create_run( $params );
# Where to go from here? redirect?
# print $q->redirect( 'lcms_run_list.cgi' );
if ( $status !~ /Error/ ) {
$sbeams->set_page_message( msg => $status, type => 'Info' );
$content = $biomarker->lcms_run_list($params);
} else {
# Give them back the page
$sbeams->set_page_message( msg => $status, type => 'Error' );
$q->delete( 'apply_action' );
print $q->redirect( $q->self_url() );
exit;
}
} elsif ( $params->{apply_action} eq 'list_runs' ) {
$content = $biomarker->lcms_run_list($params);
} elsif ( $params->{apply_action} eq 'download' ) {
download_run($params);
} elsif ( $params->{apply_action} eq 'run_details' ) {
$content = run_details($params);
} else {
$content = get_lcms_form($params);
}
# Print cgi headers
$biomarker->printPageHeader();
# Don't think I really need this, but...
$sbeams->printUserContext();
print $content;
# $sbeams->printCGIParams( $q );
$biomarker->printPageFooter();
} # end Main
#+
# Read/process CGI parameters
#-
sub process_params {
my $params = {};
# Standard SBEAMS processing
$sbeams->parse_input_parameters( parameters_ref => $params, q => $q );
#for ( keys( %$params ) ){ print "$_ = $params->{$_}
" }
# Process "state" parameters
$sbeams->processStandardParameters( parameters_ref => $params );
return $params;
}
#+
# Print lc/ms form
#-
sub get_lcms_form {
my $params = shift;
# hash of select lists for the form
my %input = get_input_fields_hash( $params );
# hash of labels for form
my %labels = get_labels_hash( $params );
my $ftable = SBEAMS::Connection::DataTable->new( BORDER => 0,
CELLSPACING => 2,
CELLPADDING => 2
);
my @b = $biomarker->get_form_buttons( name => 'apply_action',
value => 'Create run',
types => [ qw(submit reset) ] );
my $buttons = join " ", @b;
$log->info( $buttons );
# LC subform
$ftable->addRow( [$labels{ms_run_name}, $input{ms_run_name},
$labels{treatment_id}, $input{treatment_id} ] );
$ftable->addRow( [ $labels{lc_gradient_program}, $input{lc_gradient_program},
$labels{injection_volume}, $input{injection_volume}, ] );
$ftable->addRow( [$labels{lc_run_description}, $input{lc_run_description} ] );
# MS subform
$ftable->addRow( [$labels{ms_instrument}, $input{ms_instrument},
$labels{ms_protocol}, $input{ms_protocol} ] );
$ftable->addRow( [$labels{nstring}, $input{nstring}, undef, undef ] );
$ftable->addRow( [$labels{ms_run_parameters}, $input{ms_run_parameters} ] );
$ftable->addRow( [$labels{ms_run_description}, $input{ms_run_description} ] );
$ftable->addRow( [$labels{biosample_id}, $input{biosample_id} ] );
$ftable->addRow( [$buttons] );
# General caption/field rows
$ftable->setColAttr( ROWS=>[1..8], COLS=>[1,3], ALIGN => 'RIGHT' );
$ftable->setColAttr( ROWS=>[1..8], COLS=>[2,4], ALIGN => 'LEFT' );
# description rows
$ftable->setColAttr( ROWS=>[3,6,7,8], COLS=>[2], COLSPAN => 3 );
# Sample row
$ftable->setColAttr( ROWS=>[$ftable->getRowNum()], COLS=>[1], COLSPAN => 4,
ALIGN => 'CENTER');
# Captions
$ftable->setColAttr( ROWS=>[1..$ftable->getRowNum()], COLS=>[1], VALIGN => 'TOP' );
# Get javascript for experiment/samples interaction
my $expt_js = $biomarker->get_treatment_change_js('lcms_run');
# Return form
return <<" END";