#!/usr/local/bin/perl ############################################################################### # Program : UploadProteinList # Author : Nichole King # # Description : Upload a protein list, format it, and pass to # GetPeptides # ############################################################################### ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use lib "$FindBin::Bin/../../lib/perl"; use vars qw ($sbeams $sbeamsMOD $q $current_contact_id $current_username $PROG_NAME $USAGE %OPTIONS $QUIET $VERBOSE $DEBUG $DATABASE $TABLE_NAME $PROGRAM_FILE_NAME $CATEGORY $DB_TABLE_NAME @MENU_OPTIONS); use SBEAMS::Connection qw($q $log); 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); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); #$CGI::DISABLE_UPLOADS = 0; ##enable uploads ## USAGE: $PROG_NAME = $FindBin::Script; $USAGE = <Authenticate() and exit if it fails or continue if it works. ############################################################################### sub main { ##authenticate and exit if unsuccessful exit unless ($current_username = $sbeams->Authenticate( permitted_work_groups_ref=>['PeptideAtlas_user','PeptideAtlas_admin', 'PeptideAtlas_readonly', 'PeptideAtlas_exec'], 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); #### 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 "???") { # Some action } else { my $project_id = $sbeamsMOD->getProjectID( atlas_build_id => $parameters{atlas_build_id} ); $sbeamsMOD->display_page_header(project_id => $project_id); 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}; print "
\n"; my $CATEGORY="UploadProteinList"; my $PROGRAM_FILE_NAME = $PROG_NAME; my $base_url = "$CGI_BASE_DIR/$SBEAMS_SUBDIR/$PROGRAM_FILE_NAME"; if ($sbeams->output_mode() eq 'html') { print ""; print $q->start_multipart_form( -method=>"POST", -action=>"$base_url", -enctype =>"multipart/form-data" ); print ""; print""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print $q->end_multipart_form; print "
File of Proteins To Upload:   
Mass (m/z in Da):   
Best Probability Constraint:   
Number of Observations:   
Number of Protein Id's w/ a Peptide:   
 
"; print $q->submit(-name => "query", -value => 'QUERY', -label => 'QUERY'); print "
"; } ## upload the file to a file handler my $fh = $q->upload('upload_file'); if (!$fh && $q->cgi_error) { print $q->header(-status=>$q->cgi_error); } ## size constraint of 10 MB ## restrict $count < 30000 if ( (-T $fh) && (-s $fh < 1000000)) { my $count = 0; my $read_file=0; ## protein list my %protein_hash; while (<$fh>) { my $str=$_; chomp($str); $protein_hash{$str} = $str; $count = $count + 1; last if ($count > 30000); } my $n_proteins = keys %protein_hash; print "
uploaded $count entries (= $n_proteins proteins).
"; ## join with a semi-colon: my $protein_list = join("%3B", %protein_hash); # ## construct redirect url root using $ENV{HTTP_REFERER} # my $http_referer = $ENV{HTTP_REFERER}; # my $redirect_url; # # my $queryString = "biosequence_name_constraint=$protein_list"; # # ## assume it's an sbeams # if ($http_referer =~ /$HOSTNAME/) # { # ## remove end of URL: # $http_referer =~ s/(.*)\/(.*)$/$1/; # $redirect_url = "$http_referer/GetPeptides?$queryString"; # } else # { # ## this will kick user out of secure connection # $redirect_url = "http://$HOSTNAME/$CGI_BASE_DIR/$SBEAMS_SUBDIR/GetPeptides?" . # "$queryString"; # } # # ## redirect to GetPeptides # print ""; # # exit; } else { # print "looks like binary or file is too big
"; } }