#!/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'], allow_anonymous_access=>1, )); $sbeamsMOD->display_page_header(); handle_request(); $sbeamsMOD->display_page_footer(); } # end main ############################################################################### # Handle Request ############################################################################### sub handle_request { my %args = @_; 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 "  File of Proteins:   "; print""; print "

"; # $q->filefield( # -name => 'upload_file', # -size => 30, # -max_length => 120, # ); print $q->submit(-name => "query", -value => 'QUERY', -label => 'POST to GetPeptides'); print $q->end_multipart_form; # print $q->endform; } ## 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... add more contraints if needed... ## could restrict $count < 6000 too... if ( (-T $fh) && (-s $fh < 1000000)) { # print "looks like text and small enough. uploading...
"; my $count = 0; my $read_file=0; ## protein list my %protein_hash; ## could add a num proteins constraint here while (<$fh>) { my $str=$_; chomp($str); $protein_hash{$str} = $str; $count = $count + 1; } 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/) { # print "looks like valid referer
"; ## 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
"; } }