#!/usr/local/bin/perl ############################################################################### # Program : PASS_View # $Id: GetPeptide 6798 2011-07-05 21:35:27Z tfarrah $ # # Description : PeptideAtlas Submission System main dataset viewer page # # SBEAMS is Copyright (C) 2000-2021 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. # ############################################################################### ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use POSIX qw(ceil); 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 CGI::Carp qw(fatalsToBrowser croak); use SBEAMS::Connection qw($q $log); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Connection::TabMenu; use SBEAMS::Connection::Utilities; use SBEAMS::PeptideAtlas; use SBEAMS::PeptideAtlas::Settings; use SBEAMS::PeptideAtlas::Tables; use SBEAMS::PeptideAtlas::ConsensusSpectrum; use SBEAMS::PeptideAtlas::ModificationHelper; use SBEAMS::PeptideAtlas::Utilities; use SBEAMS::PeptideAtlas::PASS; use SBEAMS::Proteomics::Tables; $sbeams = new SBEAMS::Connection; $sbeamsMOD = new SBEAMS::PeptideAtlas; $sbeamsMOD->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); my $modification_helper = new SBEAMS::PeptideAtlas::ModificationHelper(); my $PASS = new SBEAMS::PeptideAtlas::PASS; my $current_page = { organism => '', atlas_build_id => '' }; #$q = new CGI; ############################################################################### # Set program name and usage banner for command like use ############################################################################### $PROG_NAME = $FindBin::Script; $USAGE = < 'MS/MS dataset', 'SRM' => 'SRM dataset', 'MS1' => 'MS1 dataset', 'SWATH' => 'SWATH MS dataset', 'XlinkMS' => 'Cross-linking MS dataset', 'QC' => 'Ongoing QC dataset', 'Other' => 'Other', ); ############################################################################### # Set Global Variables and execute main() ############################################################################### main(); exit(0); ############################################################################### # Main Program: # # Call $sbeams->Authenticate() and exit if it fails or continue if it works. ############################################################################### sub main { #### Do the SBEAMS authentication and exit if a username is not returned exit unless ($current_username = $sbeams->Authenticate( permitted_work_groups_ref=>['PeptideAtlas_user','PeptideAtlas_admin', 'PeptideAtlas_readonly', 'PeptideAtlas_exec'], #connect_read_only=>1, 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 ); #### Decide what action to take based on information so far if (defined($parameters{filename}) && $parameters{filename} ne '') { handle_request(ref_parameters=>\%parameters); } else { my $project_id = $sbeamsMOD->getProjectID( atlas_build_id => $parameters{atlas_build_id} ); $sbeamsMOD->display_page_header(project_id => $project_id, init_tooltip => 1); handle_request(ref_parameters=>\%parameters); $sbeamsMOD->display_page_footer(); } $sbeams->profile_sql( list => 0 ); } # end main ############################################################################### # Handle Request ############################################################################### sub handle_request { my %args = @_; $log->debug( "Start page " . time() ); #### Process the arguments list my $ref_parameters = $args{'ref_parameters'} || die "ref_parameters not passed"; my %parameters = %{$ref_parameters}; my $output_mode = $sbeams->output_mode(); if (defined($parameters{filename}) && $parameters{filename} ne '') { $output_mode = 'direct'; } #### Show current user context information #$sbeams->printUserContext(); #### Get the HTML to display the tabs my $tabMenu = $sbeamsMOD->getTabMenu( parameters_ref => \%parameters, program_name => $PROG_NAME, ) if ($output_mode eq 'html'); if ($sbeams->output_mode() eq 'html') { print ""; print $tabMenu->asHTML(); } #### Define some generic variables my ($i,$element,$key,$value,$line,$result,$sql); #### Define some variables for a query and resultset my %resultset = (); my $resultset_ref = \%resultset; my (%url_cols,%hidden_cols,%max_widths,$show_sql); #### Read in the standard form values my $action = $parameters{'action'} || $parameters{'apply_action'}; #print "action='$action'
\n"; my $TABLE_NAME = $parameters{'QUERY_NAME'}; #### Check the session cookie for a PASS_emailaddress my $cachedEmailAddress = $sbeams->getSessionAttribute( key => 'PASS_emailAddress' ); my $cachedPassword = $sbeams->getSessionAttribute( key => 'PASS_xx' ); my $emailAddress = $parameters{'emailAddress'}; $emailAddress = $cachedEmailAddress if (!$emailAddress && $cachedEmailAddress); my $password = $parameters{'password'}; $password = $cachedPassword if (!$password && $cachedPassword); my $firstName; my $lastName; #### Compile any error we encounter in an array my @errors; my $printForm = 1; #### If the request was to LOGOUT, then purge everything if ($action =~ /LOGOUT/i ) { $sbeams->setSessionAttribute( key => 'PASS_emailAddress', value => '' ); $sbeams->setSessionAttribute( key => 'PASS_xx', value => '' ); $emailAddress = ''; $password = ''; } #### See if we're already logged in my $authentication; if ($emailAddress && $password) { $authentication = authenticateUser(emailAddress=>$emailAddress,password=>$password); if ($authentication->{result} eq 'Success') { $firstName = $authentication->{firstName}; $lastName = $authentication->{lastName}; } } #print "--Session cache: =",$cachedEmailAddress,"= --
\n"; #print "--Authentication status: =",$authentication->{result},"= ($firstName $lastName) --
\n"; #### Check authentication parameters and warn of any problems if ($action =~ /SUBMIT/i || $action =~ /LOGIN/i ) { unless ($emailAddress) { push(@errors,"The submitter email address is not filled in"); } unless ($password) { push(@errors,"The submitter password is not filled in"); } } #### Check authentication parameters and warn of any problems if ($action =~ /LOGIN/i && ! @errors ) { if ($authentication->{result} eq 'Success') { $sbeams->setSessionAttribute( key => 'PASS_emailAddress', value => $emailAddress ); $sbeams->setSessionAttribute( key => 'PASS_xx', value => $password ); } else { push(@errors,@{$authentication->{errors}}); } } #### If a dataset identifier was supplied, get the metadata for this dataset #### and check to see if current user is the owner my $datasetIdentifier = $parameters{'identifier'}; $datasetIdentifier = uc($datasetIdentifier) if ($datasetIdentifier); $datasetIdentifier =~ s/\s//g; my $datasetMetadata; my $isOwner = 0; my $isAccessible = 0; my $isAdmin = 0; my ($date) = `date '+%F'`; chomp($date); if ($datasetIdentifier) { $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); if ($datasetMetadata->{result} eq 'Success' && uc($emailAddress) eq uc($datasetMetadata->{emailAddress})) { $isOwner = 1; $isAccessible = 1; } elsif ($parameters{datasetPassword} && $datasetMetadata->{datasetPassword} eq $parameters{datasetPassword}) { $isAccessible = 1; } else { #print "Is '$date' ge '$datasetMetadata->{publicReleaseDate}'?
\n"; if ($datasetMetadata->{publicReleaseDate} && substr($date,0,10) ge substr($datasetMetadata->{publicReleaseDate},0,10)) { #print "INFO: Current date '$date' is greater than release date '$datasetMetadata->{publicReleaseDate}'
\n"; $isAccessible = 1; } } #### If the current session is logged in via SBEAMS as a user with Admin rights, set flag if ($sbeams->isAdminUser(current_group=>0)) { $isAccessible = 1; $isAdmin = 1; } push(@errors,@{$datasetMetadata->{errors}}) if ($datasetMetadata->{errors}); } #print "--Status: =",$datasetIdentifier,"= --
\n"; #print "--Access status: isAccessible=$isAccessible, isOwner=$isOwner, isAdmin=$isAdmin
\n"; #### If the desired action was to finalize the dataset if ($action eq "FINALIZE" && ! @errors ) { if ( ( $authentication->{result} eq 'Success' && uc($emailAddress) eq uc($datasetMetadata->{emailAddress}) ) || $isAdmin) { finalizeDataset( authentication=>$authentication, identifier=>$parameters{'identifier'}, emailAddress=>$datasetMetadata->{emailAddress}, ); $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); } else { push(@errors,@{$authentication->{errors}}) if ($authentication->{errors}); } } #### If the desired action was to finalize the dataset if ($action eq "UNFINALIZE" && ! @errors ) { if ( ( $authentication->{result} eq 'Success' && uc($emailAddress) eq uc($datasetMetadata->{emailAddress}) ) || $isAdmin) { unFinalizeDataset( authentication=>$authentication, identifier=>$parameters{'identifier'}, emailAddress=>$datasetMetadata->{emailAddress}, ); $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); } else { push(@errors,@{$authentication->{errors}}) if ($authentication->{errors}); } } #### If the desired action was to reset the password if ($action eq 'SET' && ! @errors ) { if (($authentication->{result} eq 'Success' && $isOwner) || $isAdmin) { my $result = setNewDatasetPassword( authentication => $authentication, identifier => $parameters{'identifier'}, newDatasetPassword => $parameters{'newDatasetPassword'}, ); if ($result->{errors}) { push(@errors,@{$result->{errors}}); } $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); # update json file } else { push(@errors,@{$authentication->{errors}}) if ($authentication->{errors}); } } #### If the desired action was to reset the Public Release Date if ($action eq 'SETDATE' && ! @errors ) { if (($authentication->{result} eq 'Success' && $isOwner) || $isAdmin) { my $result = setNewPublicReleaseDate( authentication => $authentication, identifier => $parameters{'identifier'}, newPublicReleaseDate => $parameters{'newPublicReleaseDate'}, ); if ($result->{errors}) { push(@errors,@{$result->{errors}}); } $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); } else { push(@errors,@{$authentication->{errors}}) if ($authentication->{errors}); } } ######################################################################### #### If UPDATE, see if there's enough information to update the dataset if ($action =~ /UPDATE/i && ! @errors) { if (($authentication->{result} eq 'Success' && $isOwner) || $isAdmin) { #### Okay to proceed. Switch to EDIT mode to show the form if data was not right $action = 'EDIT'; } else { push(@errors,"Only dataset owners may update a dataset record. If you have additional information about this dataset, please contact the dataset owner or a PeptideAtlas admin"); } unless (@errors) { my $validation = $PASS->validateDatasetAnnotations(formParameters=>\%parameters); if ($validation->{result} eq 'Success') { my $updateResult = updateDataset( authentication=>$authentication, formParameters=>\%parameters, identifier => $parameters{'identifier'}, ); if ($updateResult->{result} eq 'Success') { $printForm = 0; ## check if the publicReleaseDate change from ge Current date to le Current date if (($datasetMetadata->{publicReleaseDate}&& substr($datasetMetadata->{publicReleaseDate},0,10) ge substr($date,0,10)) && ($parameters{publicReleaseDate} && substr($parameters{publicReleaseDate},0,10) le substr($date,0,10)) ){ } } else { push(@errors,"updateResult returned $updateResult->{result}"); push(@errors,@{$updateResult->{errors}}) if ($updateResult->{errors}); } } else { push(@errors,@{$validation->{errors}}); } } } #### Logging $log->debug( "end param handling " . time() ); if (defined($parameters{filename}) && $parameters{filename} ne '') { unless ($isAccessible) { print "Content-type: text/plain\n\n"; print "ERROR: This file is not accessible\n"; return; } showFile(identifier=>$datasetIdentifier, baseURL=>$base_url, browseArea=>$parameters{browseArea}, path=>$parameters{path}, filename=>$parameters{filename}, ); return; } #### If the desired action was to edit a dataset, show the edit form if ($action eq 'EDIT' ) { return unless ($printForm); if (($authentication->{result} eq 'Success' && $isOwner) || $isAdmin) { my $result = displayEditMetaDataForm( authentication => $authentication, identifier => $parameters{'identifier'}, parameters => \%parameters, isOwner => $isOwner, isAdmin => $isAdmin, errors => \@errors, ); if ($result->{errors}) { push(@errors,@{$result->{errors}}); } } else { push(@errors,@{$authentication->{errors}}) if ($authentication->{errors}); } if (@errors) { print "
\n"; print "
"; foreach my $error ( @errors ) { print "
  • $error\n"; } print "
  • \n"; } return; } ######################################################################### #### Print the form if ($sbeams->output_mode() eq 'html') { print "

    View Dataset

    "; if (@errors) { print "
    \n"; print "
    "; foreach my $error ( @errors ) { print "
  • $error\n"; } print "
  • \n"; } print "
    \n"; print ""; print $q->start_form(-method=>"POST", -action=>"$base_url", -name=>"MainForm", ); if ($isAdmin) { my $current_username = $sbeams->getCurrent_username; print "Your SBEAMS authentication is $current_username, which has Admin rights. Viewing in Admin mode
    \n"; } if ($authentication->{result} eq 'Success') { print "Welcome $firstName $lastName ($emailAddress)\n"; print "      "; print $q->submit(-name => "action", -value => 'LOGOUT', -label => 'LOGOUT'); } else { print "Email address\n"; print qq~~; print "    \n"; print "Password"; print qq~~; print $q->submit(-name => "action", -style => "margin-left:30px;", -value => 'LOGIN', -label => 'LOGIN'); } print "

    \n"; print "Dataset Identifier\n"; print $q->textfield( "identifier", $datasetIdentifier, 10, 10); if (! $isAccessible || $parameters{datasetPassword}) { print "      "; print "Dataset Password\n"; print qq~~; } print $q->submit(-name => "action", -style => "margin-left:30px;", -value => 'VIEW', -label => 'VIEW'); print "
    \n"; print "
    \n"; unless ($datasetIdentifier) { print "

    Please provide a dataset identifier above and click [View].

    "; return; } if (@errors) { print "

    Please provide a valid dataset identifier above and click [View].

    "; return; } unless ($isAccessible) { print "

    $datasetIdentifier is not accessible with current credentials.

    "; print "If you are the owner of this dataset and have not logged in, please provide credentials above.

    "; print "The dataset is scheduled to become public on $datasetMetadata->{publicReleaseDate}, at which point you can access it.

    "; print "To access the dataset in advance of this date, enter the dataset password if it has been given to you,
    or you may contact the dataset owner $datasetMetadata->{submitterStr} to request the dataset password.

    "; return; } if ($parameters{browseArea}) { print "
    \n"; print "Back to main dataset view\n"; print "
    \n"; print DisplayPASSDirListing(identifier=>$datasetIdentifier, baseURL=>$base_url, browseArea=>$parameters{browseArea}, path=>$parameters{path}, ); return(1); } if ( 0 == 1 ) { print "Result=",$datasetMetadata->{result},"
    \n"; print "emailaddress=",$emailAddress,"
    \n"; print "metadata emailaddress=",$datasetMetadata->{emailAddress},"
    \n"; print "finalizedDate=",$datasetMetadata->{finalizedDate},"
    \n"; } if ($datasetMetadata->{result} eq 'Success' && (uc($emailAddress) eq uc($datasetMetadata->{emailAddress})) || $isAdmin) { if ($datasetMetadata->{finalizedDate}) { } else { print "Notice: This dataset has not yet been marked as finalized!
    "; print "If the upload is now done and you are happy with the result: "; print $q->submit(-name => "action", -value => 'FINALIZE', -label => 'FINALIZE'); print "
    \n"; print "Since the dataset is not currently finalized, you may: "; print $q->submit(-name => "action", -value => 'EDIT', -label => 'EDIT'); print "
    \n"; print "


    \n"; } } else { } #### Display the password if the user is the owner or an admin if ($isOwner || $isAdmin) { print "datasetPassword: $datasetMetadata->{datasetPassword}"; print "      "; print "change to "; print qq~~; print $q->submit(-name => "action", -value => 'SET', -label => 'SET'); print "
    \n"; print "Reset publicReleaseDate "; my $publicReleaseDate = substr($datasetMetadata->{publicReleaseDate},0,10); print qq~~; print $q->submit(-name => "action", -value => 'SETDATE', -label => 'SETDATE'); print qq~ ~; print "      "; print qq~\n~; if ($datasetMetadata->{finalizedDate}) { print "
    This dataset has been finalized, which means the data cannot be changed now. However, as the owner, you may "; print $q->submit(-name => "action", -value => 'UNFINALIZE', -label => 'UNFINALIZE'); print " if you find you must now make changes.
    \n"; } print "
    \n"; } print DisplayPASSMetaData(identifier=>$datasetIdentifier); print "
    \n"; print "Official URL for this dataset: http://www.peptideatlas.org/PASS/$datasetIdentifier
    \n"; print "To access files via FTP, use credentials:
    \n";
         print "Servername: ftp.peptideatlas.org\nUsername: $datasetIdentifier\nPassword: $datasetMetadata->{datasetPassword}\n

    \n"; print "Or use your browser's FTP mode: {datasetPassword}\@ftp.peptideatlas.org/\">ftp://$datasetIdentifier:$datasetMetadata->{datasetPassword}\@ftp.peptideatlas.org/

    \n"; print "
    \n"; print "

    Listing of files:

    \n"; print DisplayPASSDirListing(identifier=>$datasetIdentifier, baseURL=>$base_url, ); #print "
    \n"; print "

    Browse FTP upload area

    \n"; #print "Browse AutoQCprocessing area
    \n"; $sbeamsMOD->display_page_footer(); } if ($action !~ /LOG(OUT|IN)/i && $action !~ /(VIEW|SET)$/i ) { my $str = do '/net/dblocal/www/html/sbeams/lib/scripts/PeptideAtlas/create_PASS_Json.pl'; } return; } # end handle_request ####################################################################### # authenticateUser ####################################################################### sub authenticateUser { my %args = @_; my $SUB_NAME = 'authenticateUser'; #### Decode the argument list my $emailAddress = $args{'emailAddress'} || die "[$SUB_NAME] ERROR:emailAddress not passed"; my $password = $args{'password'} || die "[$SUB_NAME] ERROR:password not passed"; my $response; my $sql = qq~ SELECT submitter_id,firstName,lastName,password FROM $TBAT_PASS_SUBMITTER WHERE emailAddress = '$emailAddress' ~; my @rows = $sbeams->selectSeveralColumns($sql); if ( @rows ) { if (scalar(@rows) == 1) { my $databasePassword = $rows[0]->[3]; if ($password eq $databasePassword) { $response->{result} = 'Success'; $response->{firstName} = $rows[0]->[1]; $response->{lastName} = $rows[0]->[2]; $response->{emailAddress} = $emailAddress; $response->{submitter_id} = $rows[0]->[0]; } else { $response->{result} = 'IncorrectPassword'; push(@{$response->{errors}},'Incorrect password for this email address'); } } else { die("ERROR: Too many rows returned for email address '$emailAddress'"); } } else { $response->{result} = 'NoSuchUser'; push(@{$response->{errors}},"There is not any user registered to '$emailAddress'"); } return $response; } ####################################################################### # registerUser ####################################################################### sub registerUser { my %args = @_; my $SUB_NAME = 'registerUser'; #### Decode the argument list my $emailAddress = $args{'emailAddress'} || die "[$SUB_NAME] ERROR: emailAddress not passed"; my $password = $args{'password'} || die "[$SUB_NAME] ERROR: password not passed"; my $firstName = $args{'firstName'} || die "[$SUB_NAME] ERROR: firstName not passed"; my $lastName = $args{'lastName'} || die "[$SUB_NAME] ERROR: lastName not passed"; my $response; my $readyToRegister = 0; my $authentication = authenticateUser(emailAddress=>$emailAddress,password=>$password); if ($authentication->{result} eq 'Success') { $response->{result} = 'UserAlreadyExists'; push(@{$response->{errors}},"This user '$emailAddress' already exists. Login instead."); } elsif ($authentication->{result} eq 'IncorrectPassword') { $response->{result} = 'UserAlreadyExists'; push(@{$response->{errors}},"This user '$emailAddress' already exists, although the password provided is incorrect."); } elsif ($authentication->{result} eq 'NoSuchUser') { $readyToRegister = 1; } else { $response->{result} = 'UnknownError'; push(@{$response->{errors}},"Unknown error 456. Please report."); } my $PK; if ($readyToRegister) { my %rowdata = ( emailAddress => $emailAddress, password => $password, firstName => $firstName, lastName => $lastName, emailReminders => 'YES', emailPasswords => 'YES', ); $PK = $sbeams->updateOrInsertRow( insert => 1, table_name => $TBAT_PASS_SUBMITTER, rowdata_ref => \%rowdata, PK => 'submitter_id', return_PK => 1, add_audit_parameters => 1 ); } if ($PK && $PK > 0) { $response->{result} = 'Success'; } else { $response->{result} = 'Failed'; } return $response; } ####################################################################### # validateDatasetAnnotations ####################################################################### sub validateDatasetAnnotations { my %args = @_; my $SUB_NAME = 'validateDatasetAnnotations'; #### Decode the argument list my $formParameters = $args{'formParameters'} || die "[$SUB_NAME] ERROR: formParameters not passed"; my $response; my $test; $response->{result} = 'Success'; $test = $formParameters->{datasetType}; my $result = 0; for (my $i=0; $i < scalar(@datasetTypes); $i+=2) { my ($key,$label) = @datasetTypes[$i..$i+1]; $result = 1 if ($test eq $key); } unless ($result) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Dataset type is not a legal option"); } $test = $formParameters->{datasetTag}; unless (defined($test) && $test =~ /^[A-Za-z0-9\_\-]+$/ && length($test) > 5 && length($test) <= 20) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Dataset Tag must be an alphanumeric string with length more than 5 up to 20"); } $test = $formParameters->{datasetTitle}; unless (defined($test) && length($test) > 20 && length($test) <= 200) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Dataset Title must be a string with length more than 20 up to 200"); } $test = $formParameters->{publicReleaseDate}; unless (defined($test) && $test =~ /^(\d\d\d\d)\-(\d\d)\-(\d\d)$/ && $1>=2000 && $2>0 && $2<12 && $3>0 && $3<32) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Public release data must be a valid date of the form YYYY-MM-DD like 2011-10-25"); } $test = $formParameters->{contributors}; unless (defined($test) && length($test) > 10 && length($test) <= 10000) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Contributors must be a string with length more than 10 up to 10000"); } $test = $formParameters->{publication}; unless (defined($test) && length($test) > 5 && length($test) <= 1000) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Publication must be a string with length more than 5 up to 1000"); } $test = $formParameters->{instruments}; unless (defined($test) && length($test) > 5 && length($test) <= 1000) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Instruments must be a string with length more than 5 up to 1000"); } $test = $formParameters->{species}; unless (defined($test) && length($test) > 3 && length($test) <= 1000) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Species must be a string with length more than 3 up to 1000"); } $test = $formParameters->{massModifications}; unless (defined($test) && length($test) > 3 && length($test) <= 1000) { $response->{result} = 'Failed'; push(@{$response->{errors}},"Mass modidications must be a string with length more than 3 up to 1000"); } return $response; } ####################################################################### # getPASSMetaData ####################################################################### sub getPASSMetaData { my %args = @_; my $SUB_NAME = 'getPASSMetaData'; #### Decode the argument list my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $response; my $sql = qq~ SELECT datasetIdentifier,submitter_id,datasetType,datasetPassword,datasetTag,datasetTitle,publicReleaseDate,finalizedDate ,submitter_organization,lab_head_full_name,lab_head_email, lab_head_organization,lab_head_country FROM $TBAT_PASS_DATASET WHERE datasetIdentifier = '$identifier' ~; my @rows = $sbeams->selectSeveralColumns($sql); if (@rows) { my ($datasetIdentifier,$submitter_id,$datasetType,$datasetPassword,$datasetTag,$datasetTitle,$publicReleaseDate,$finalizedDate ,$submitter_organization,$lab_head_full_name,$lab_head_email, $lab_head_organization,$lab_head_country ,) = @{$rows[0]}; my $sql2 = qq~ SELECT firstName,lastName,emailAddress FROM $TBAT_PASS_SUBMITTER WHERE submitter_id = '$submitter_id' ~; my @rows2 = $sbeams->selectSeveralColumns($sql2); my $submitterStr = ''; my ($firstName,$lastName,$emailAddress); if (@rows2) { ($firstName,$lastName,$emailAddress) = @{$rows2[0]}; $submitterStr = "$firstName $lastName <$emailAddress>"; $response->{emailAddress} = $emailAddress; $response->{submitterStr} = $submitterStr; } else { $response->{results} = 'Failed'; push(@{$response->{errors}},"ERROR: Query
    \n$sql2
    failed to return any rows.
    "); } $response->{datasetIdentifier} = $datasetIdentifier; $response->{datasetType} = $datasetType; $response->{submitter} = $submitterStr; $response->{firstName} = $firstName; $response->{lastName} = $lastName; $response->{emailAddress} = $emailAddress; $response->{datasetPassword} = $datasetPassword; $response->{datasetTag} = $datasetTag; $response->{datasetTitle} = $datasetTitle; $response->{publicReleaseDate} = $publicReleaseDate; $response->{finalizedDate} = $finalizedDate; $response->{submitter_organization} = $submitter_organization; $response->{lab_head_full_name} = $lab_head_full_name; $response->{lab_head_email} = $lab_head_email; $response->{lab_head_organization} = $lab_head_organization; $response->{lab_head_country} = $lab_head_country; } else { if ($identifier =~ /^PASS\d{5}$/) { push(@{$response->{errors}},"ERROR: Nonexistent PASS accession number $identifier. Please enter the correct accession number.
    "); return($response); } else { push(@{$response->{errors}},"ERROR: Malformed PASS accession number '$identifier'. It should be PASSnnnnn, where nnnnn is a 5-digit number. Please enter the correct accession number.
    "); return($response); } } my $PASS_ACCOUNTS_BASE = '/prometheus/u1/home'; unless ( -d "$PASS_ACCOUNTS_BASE/${identifier}" ) { $PASS_ACCOUNTS_BASE = '/proteomics/peptideatlas2/home'; } my $infile = "$PASS_ACCOUNTS_BASE/${identifier}/${identifier}_DESCRIPTION.txt"; unless (open(INFILE,$infile)) { #EWD: Maybe there's no point in blaring the error at the user. We really should be alerting admins # Would be good to sweeping all datasets for this problem and resolving it somehow so there isn't this problem #print "ERROR: Unable to read description file for this submission: '$infile'

    \n"; $response->{result} = 'Success'; return $response; } #### Define a set of keys allowed to be in a DESCRIPTION file. All other keys will be assumed to be parts of the previous entry my @supportedKeys = qw ( identifier type tag title summary contributors publication growth treatment extraction separation digestion acquisition informatics instruments species massModifications ); my %supportedKeys; foreach my $supportedKey ( @supportedKeys ) { $supportedKeys{$supportedKey} = 1; } #### Also define some keys to remove. These should not have been here, but due to a past bug, these were written both as #### database table fields as well as here in the DESCRIPTION file. Remove them from the description file when reading. #### WARNING: There is an assumption below that all obsolete keys have spaces, just because they currently do. my @obsoleteKeys = ( 'submitter organization','lab head','lab head email','lab head organization','lab head country' ); my %obsoleteKeys; foreach my $obsoleteKey ( @obsoleteKeys ) { $obsoleteKeys{$obsoleteKey} = 1; } my $prevKey = 'none'; while (my $line = ) { $line =~ s/[\r\n]//g; #### If the line begins with a non-space-containing key, process it if ( $line =~ /^\s*(\w+):\s*(.*)$/ ) { my $key = $1; my $value = $2; if ( $supportedKeys{$key} ) { $response->{$key} = $value; $prevKey = $key; } else { $response->{$prevKey} .= "
    \n$line"; } #### At the moment, all of the obsolete keys have spaces, so look for them here } elsif ( $line =~ /^\s*([\w\s]+):/ ) { my $key = $1; if ( $obsoleteKeys{$key} ) { #### do nothing } else { $response->{$prevKey} .= "
    \n$line"; } #### If not a parseable key or not an obsolete space-containing key, then append to previous } else { $response->{$prevKey} .= "
    \n$line"; } } close(INFILE); $response->{result} = 'Success'; return $response; } ####################################################################### # DisplayPASSMetaData ####################################################################### sub DisplayPASSMetaData { my %args = @_; my $SUB_NAME = 'DisplayPASSMetaData'; #### Decode the argument list my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $response; my $result = getPASSMetaData(identifier=>$identifier); if ($result->{result} eq 'Success') { my @result_fields = qw(datasetIdentifier datasetType submitter submitter_organization lab_head_full_name lab_head_email lab_head_organization lab_head_country datasetTag datasetTitle publicReleaseDate finalizedDate summary contributors publication growth treatment extraction separation digestion acquisition informatics instruments species massModifications); print ''; print "\n"; for my $r (@result_fields) { print ""; $r = 'submitterStr' if ($r eq 'submitter'); print "\n"; } print "
    Metadata
    $r$result->{$r}
    \n\n"; } else { print "

    Metadata:

    ERROR: Unable to get dataset metadata.
    \n"; } return $response; } ####################################################################### # displayEditMetaDataForm ####################################################################### sub displayEditMetaDataForm { my %args = @_; my $SUB_NAME = 'displayEditMetaDataForm'; #### Decode the argument list my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $parameters_ref = $args{'parameters'} || die "[$SUB_NAME] ERROR: parameters not passed"; my %parameters = %{$parameters_ref}; my $isOwner = $args{'isOwner'} || 0; my $isAdmin = $args{'isAdmin'} || 0; my $errors = $args{'errors'}; my $response; my $result = getPASSMetaData(identifier=>$identifier); unless ($result->{result} eq 'Success') { push(@{$response->{errors}},'Unable to get metadata for dataset $identifier'); return $response; } if ($sbeams->output_mode() eq 'html') { print "

    Update Dataset Metadata

    "; $PASS->displayErrors(errors=>$errors); if ($response->{errors}) { print "
    \n"; print "
    "; foreach my $error ( @{$response->{errors}} ) { print "
  • $error\n"; } print "
  • \n"; } print "
    \n"; print $q->start_form(-method=>"POST", -action=>"$base_url", -name=>"MainForm", ); if ($isAdmin) { my $current_username = $sbeams->getCurrent_username; print "Your SBEAMS authentication is $current_username, which has Admin rights. Editing in Admin mode
    \n"; } elsif ($authentication->{result} eq 'Success') { print "Editing $result->{datasetIdentifier} as its owner: $authentication->{firstName} $authentication->{lastName} <$authentication->{emailAddress}>
    \n"; } else { push(@{$response->{errors}},'Unable to authenticate to edit this dataset. You must be the dataset owner to edit this dataset.'); return $response; } print ''; print ""; print "\n"; print $q->hidden(-name=>'identifier',-default=>$result->{datasetIdentifier}); print "\n"; #### If the parameters are not filled in already, fill them in from the previous data my @attributes = qw( datasetType datasetTag datasetTitle publicReleaseDate summary contributors submitter_organization lab_head_full_name lab_head_email lab_head_organization lab_head_country publication growth treatment extraction separation digestion acquisition informatics instruments species massModifications submitter_organization lab_head_full_name lab_head_email lab_head_organization lab_head_country ); foreach my $attribute ( @attributes ) { if (defined($parameters{$attribute})) { #### We'll stay with this } else { if (defined($result->{$attribute})) { $parameters{$attribute} = $result->{$attribute}; } else { # 12/05/13 TMF: after adding new fields (e.g. lab head full name) # the code below was activated and ended up storing a question # mark for any new field for which user did not provide a value. # Empty string seems better; hope it doesn't break anything. #$parameters{$attribute} = '?'; $parameters{$attribute} = ''; } } } #### Print the entry form print "\n"; print "\n"; print ""; print ""; print ""; print ""; print qq~ ~; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; print ""; print "
    $result->{datasetIdentifier}
    Dataset Identifier $result->{datasetIdentifier}
    Submitter $result->{submitterStr}
    Dataset type"; # (Please select the broad category classifying the dataset. This will aid in determining how to process it.)
    \n"; # do not allow edits to this field - 202108 LM #print qq~\n"; print $q->hidden(-name=>"datasetType",-value=>$parameters{'datasetType'}); print " $parameters{'datasetType'}

    Dataset tag"; print $q->textfield( "datasetTag", $parameters{'datasetTag'}, 20, 20); print "Enter a short {up to 20 characters} \"tag\" for this dataset
    It should be globally unique. It will be used in lists of datasets where the title might be too long.
    Dataset title"; print $q->textarea( "datasetTitle", $parameters{'datasetTitle'}, 3, 62); print "Enter a nice descriptive title {up to 200 characters} for this dataset
    Dataset Release Date"; print $q->textfield( "publicReleaseDate", $parameters{'publicReleaseDate'}, 10, 10); print "      "; print qq~\n~; print "Enter the date on which the data may be released publicly
    Please use the format 2011-08-16
    Contributors"; print $q->textarea( "contributors", $parameters{'contributors'}, 5, 62); print "Enter the names of people who are contributing this dataset, including the submitter, if applicable
    Submitter organization"; print qq~~; print "Enter submitter's organization
    Lab head"; print qq~~; print "Enter full name of lab head
    Lab head email"; print qq~~; print "Enter email of lab head
    Lab head organization"; print qq~~; print "Enter organization of lab head
    Lab head country"; print qq~~; print "Enter country of lab head's organization
    Publication"; print $q->textarea( "publication", $parameters{'publication'}, 5, 62); print "Enter the associated publication with this dataset
    Please enter a PubMed ID if available.
    "; print "If no PubMed ID is available yet, please use format: Smith, DA, and Wesson, TB, Manuscript Title, Journal, submitted
    "; print "Or if no publication is on the horizon, please just enter \"unpublished\")
    Instrument(s) used"; print $q->textarea( "instruments", $parameters{'instruments'}, 2, 62); print "Enter the model name of the instrument(s) used for this dataset
    \n"; print "Please use the format: Thermo Scientific LTQ Orbitrap, AB Sciex QTRAP 5600, etc. You may enter more than one if applicable
    Species studied"; print $q->textarea( "species", $parameters{'species'}, 2, 62); print "Enter the name of the species studied
    \n"; print "Please use the format: Human, Mouse, Drosophila melanogaster, etc. You may enter more than one if applicable
    Mass modifications"; print $q->textarea( "massModifications", $parameters{'massModifications'}, 2, 62); print "Enter any mass modifications applied to the sample
    \n"; print "Please use the format: static: C+57.021464, variable: K+8.014199, R+10.008269, or \"none\" if none.
    Summary"; print $q->textarea( "summary", $parameters{'summary'}, 6, 62); print "Enter a free-text summary or description of the dataset, experiment, or project
    Growth Protocol"; print $q->textarea( "growth", $parameters{'growth'}, 6, 62); print "Enter a free-text description of the growth protocol or organism preparation
    Treatment Protocol"; print $q->textarea( "treatment", $parameters{'treatment'}, 6, 62); print "Enter a free-text description of the treatments applied to the organism prior to sample acquisition
    Extraction Protocol"; print $q->textarea( "extraction", $parameters{'extraction'}, 6, 62); print "Enter a free-text description of the extraction of proteins from the treated sample(s)
    Separation Protocol"; print $q->textarea( "separation", $parameters{'separation'}, 6, 62); print "Enter a free-text description of the separation of proteins and/or peptides
    Digestion Protocol"; print $q->textarea( "digestion", $parameters{'digestion'}, 6, 62); print "Enter a free-text description of the digestion of the proteins into peptides
    Acquisition Protocol"; print $q->textarea( "acquisition", $parameters{'acquisition'}, 6, 62); print "Enter a free-text description of the acquisition of mass spectra from the peptide sample
    Informatics Protocol"; print $q->textarea( "informatics", $parameters{'informatics'}, 6, 62); print "Enter a free-text description of the informatics processing of the raw data produced by the instrument(s)

    "; print $q->submit(-name => "action", -class => 'form_button', -value => 'UPDATE', -label => 'UPDATE'); print "



    "; print $q->end_form; } return $response; } ####################################################################### # DisplayPASSDirListing ####################################################################### sub DisplayPASSDirListing { my %args = @_; my $SUB_NAME = 'DisplayPASSDirListing'; #### Decode the argument list my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $baseURL = $args{'baseURL'}; my $browseArea = $args{'browseArea'}; my $path = $args{'path'}; my $response; my $PASS_ACCOUNTS_BASE = '/prometheus/u1/home'; unless ( -d "$PASS_ACCOUNTS_BASE/${identifier}" ) { $PASS_ACCOUNTS_BASE = '/proteomics/peptideatlas2/home'; } my $PASS_PROCESSING_BASE = '/regis/sbeams/PASS'; my $base = $PASS_ACCOUNTS_BASE; if ($browseArea eq 'processed') { $base = $PASS_PROCESSING_BASE; print "
    \n"; print "[View upload area]
    \n"; } else { $base = $PASS_ACCOUNTS_BASE; #print "
    \n"; #print "[View processing area]
    \n"; } #print "
    \n"; $path = '/' unless ($path); $path =~ s/\.\.//g; my $fullPath = "$base/$identifier$path"; if ( ! -d $fullPath ) { return $response; } my @listing = `ls -lh '$fullPath'`; print "
    \n";
    
      if ($path ne '/') {
        my $parentPath = '/';
        if ($path =~ /^(.+)\//) {
          $parentPath = $1;
        }
        print "-- Back to top --\n";
        print "-- Back up one level --\n";
        print "\n";
        print "$path\n\n";
      }
    
      foreach my $line ( @listing ) {
        chomp($line);
        my @fields = split(/\s+/,$line);
        my $offset = index($line," $fields[4] ") + length($fields[4]) - 4;
    
        my $hlink = '';
        my $aclose = '';
        if (length($line) > 32) {
          if ($line =~ /^d/) {
    	my $dirname = substr($line,$offset+19,999);
    	my $tmpPath = $path;
    	$tmpPath = '' if ($path eq '/');
    	$hlink = "";
    	print substr($line,$offset,19).$hlink.$dirname."\n";
          } else {
    	my $filename = substr($line,$offset+19,999);
    	if (isSupportedFile(filename=>$filename)) {
    	  $hlink = "";
    	  $aclose="";
    	} else {
    	  $hlink="";
    	}
    	print substr($line,$offset,19).$hlink.$filename.$aclose."\n";
          }
        }
      }
      print "
    \n"; return $response; } ####################################################################### # isSupportedFile ####################################################################### sub isSupportedFile { my %args = @_; my $SUB_NAME = 'isSupportedFile'; #### Decode the argument list my $filename = $args{'filename'}; my %supportedFiles = ( 'summary.txt' => 1, 'summary.peptides.txt' => 1, 'summary.proteins.txt' => 1, 'summary.tsv' => 1, 'summary.html' => 1, 'summary.QCruns' => 1, 'tandem.params' => 1, 'interact-ipro.pep.summary.txt' => 1, 'interact-ipro.peptides.out' => 1, 'interact-ipro.proteins.out' => 1, ); return($supportedFiles{$filename}); } ####################################################################### # showFile ####################################################################### sub showFile { my %args = @_; my $SUB_NAME = 'showFile'; #### Decode the argument list my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $browseArea = $args{'browseArea'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $path = $args{'path'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $filename = $args{'filename'}; my $response; my $PASS_ACCOUNTS_BASE = '/prometheus/u1/home'; unless ( -d "$PASS_ACCOUNTS_BASE/${identifier}" ) { $PASS_ACCOUNTS_BASE = '/proteomics/peptideatlas2/home'; } my $PASS_PROCESSING_BASE = '/regis/sbeams/PASS'; my $base = $PASS_ACCOUNTS_BASE; if ($browseArea eq 'processed') { $base = $PASS_PROCESSING_BASE; } else { $base = $PASS_ACCOUNTS_BASE; } $path = '/' unless ($path); $path =~ s/\.\.//g; my $fullPath = "$base/$identifier$path/$filename"; if ( ! -f $fullPath ) { return $response; } if ($fullPath =~ /html$/i) { print "Content-type: text/html\n\n"; } else { print "Content-type: text/plain\n\n"; } open(INFILE,$fullPath) || die("ERROR: Unable to open file $fullPath"); foreach my $line ( ) { print $line; } close(INFILE); return $response; } ####################################################################### # finalizeDataset ####################################################################### sub finalizeDataset { my %args = @_; my $SUB_NAME = 'finalizeDataset'; #### Decode the argument list my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $emailAddress = $args{'emailAddress'}; my $PK; if ($identifier =~ /^\s*PASS(\d+)\s*$/) { $PK = $1; my %rowdata = ( finalizedDate => 'CURRENT_TIMESTAMP' ); my $result = $sbeams->updateOrInsertRow( update => 1, table_name => $TBAT_PASS_DATASET, rowdata_ref => \%rowdata, PK => 'dataset_id', PK_value => $PK, ); my $PASS_FTP_AGENT_BASE = '/prometheus/u1/home/PASSftpAgent'; my $cmdfile = "$PASS_FTP_AGENT_BASE/commands.queue"; open(CMDFILE,">>$cmdfile") || die("ERROR: Unable to append to '$cmdfile'"); print CMDFILE "FinalizeDataset $identifier\n"; close(CMDFILE); } else { print "ERROR: Unable to parse identifier '$identifier'. Please report this. ERROR449
    \n"; } #### Email PeptideAtlas team about the finalization my @toRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', 'Terry Farrah','terry.farrah@systemsbiology.org', 'Zhi Sun','zhi.sun@systemsbiology.org', ); my @ccRecipients = (); my @bccRecipients = (); my $adminMessage = qq~PASS submission PASS$PK has been finalized.\n To view the dataset, go to https://db.systemsbiology.net/sbeams/cgi/PeptideAtlas/PASS_View?identifier=PASS$PK ~; SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset PASS$PK finalized", message=>"$adminMessage\n\n", ); #### Send a nice thank you note to the submitter my $confirmationMessage = qq~Your PeptideAtlas submission PASS$PK is now finalized on our ftp server, and you may use your username and password to conveniently provide access to anyone you wish. If the public release date is passed, then no password is necessary. Please refer to your dataset with the URL: http://www.peptideatlas.org/PASS/PASS$PK If for some reason you need to modify your data or add additional data, you can un-finalize your submission, edit the dataset, and re-finalize. The PeptideAtlas receives many data submissions, and only a portion of them are actually processed and incorporated into the PeptideAtlas database. You may see your dataset at www.PeptideAtlas.org sometime in the future. Unfortunately, we do not currently have a system for informing submitters whether and when their data will be incorporated. Feel free to email us using the form at http://www.peptideatlas.org/feedback.php . Again, many thanks for offering your data to our compendium of proteomics results and adding to the world's global proteomics knowledge store. Sincerely, The PeptideAtlas team at the Institute for Systems Biology ~; my (@toRecipients,@ccRecipients,@bccRecipients); @toRecipients = ( 'PeptideAtlas Dataset Submitter',$emailAddress, ); @ccRecipients = (); @bccRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', ); SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset submission PASS$PK", message=>$confirmationMessage, ); return; } ####################################################################### # unFinalizeDataset ####################################################################### sub unFinalizeDataset { my %args = @_; my $SUB_NAME = 'unFinalizeDataset'; #### Decode the argument list my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $emailAddress = $args{'emailAddress'}; my $PK; if ($identifier =~ /^\s*PASS(\d+)\s*$/) { $PK = $1; my %rowdata = ( finalizedDate => 'NULL' ); my $result = $sbeams->updateOrInsertRow( update => 1, table_name => $TBAT_PASS_DATASET, rowdata_ref => \%rowdata, PK => 'dataset_id', PK_value => $PK, ); my $PASS_FTP_AGENT_BASE = '/prometheus/u1/home/PASSftpAgent'; my $cmdfile = "$PASS_FTP_AGENT_BASE/commands.queue"; open(CMDFILE,">>$cmdfile") || die("ERROR: Unable to append to '$cmdfile'"); print CMDFILE "UnFinalizeDataset $identifier\n"; close(CMDFILE); } else { print "ERROR: Unable to parse identifier '$identifier'. Please report this. ERROR449
    \n"; } #### Email PeptideAtlas team about the finalization my @toRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', 'Terry Farrah','terry.farrah@systemsbiology.org', 'Zhi Sun','zhi.sun@systemsbiology.org', ); my @ccRecipients = (); my @bccRecipients = (); my $adminMessage = qq~PASS submission PASS$PK has been unfinalized.\n To view the dataset, go to https://db.systemsbiology.net/sbeams/cgi/PeptideAtlas/PASS_View?identifier=PASS$PK ~; SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset PASS$PK unfinalized", message=>"$adminMessage\n\n", ); #### Send a nice thank you note to the submitter my $confirmationMessage = qq~Your PeptideAtlas submission PASS$PK has been unfinalized. This means that you may now update the data files via FTP as necessary again. When you have finished making changes to the files via FTP, FINALIZE your data again by going to: http://www.peptideatlas.org/PASS/PASS$PK Again, many thanks for using the PeptideAtlas PASS data repository. Sincerely, The PeptideAtlas team at the Institute for Systems Biology ~; my (@toRecipients,@ccRecipients,@bccRecipients); @toRecipients = ( 'PeptideAtlas Dataset Submitter',$emailAddress, ); @ccRecipients = (); @bccRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', ); SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset submission PASS$PK", message=>$confirmationMessage, ); return; } ####################################################################### # setNewDatasetPassword ####################################################################### sub setNewDatasetPassword { my %args = @_; my $SUB_NAME = 'setNewDatasetPassword'; #### Decode the argument list my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $newDatasetPassword = $args{'newDatasetPassword'}; my $response; $response->{result} = 'Failure'; #### Check to make sure the password is not empty if (!defined($newDatasetPassword) || $newDatasetPassword eq '') { push(@{$response->{errors}},"ERROR: You may not set a blank password.
    "); return $response; } #### Check to make sure the password is not too long if (length($newDatasetPassword) > 10) { push(@{$response->{errors}},"ERROR: Password may only be up to 10 characters.
    "); return $response; } #### If the identifier is valid, set the new password if ($identifier =~ /^PASS(\d+)$/) { my $PK = $1; my %rowdata = ( datasetPassword => $newDatasetPassword ); my $result = $sbeams->updateOrInsertRow( update => 1, table_name => $TBAT_PASS_DATASET, rowdata_ref => \%rowdata, PK => 'dataset_id', PK_value => $PK, ); my $PASS_FTP_AGENT_BASE = '/prometheus/u1/home/PASSftpAgent'; my $cmdfile = "$PASS_FTP_AGENT_BASE/commands.queue"; open(CMDFILE,">>$cmdfile") || die("ERROR: Unable to append to '$cmdfile'"); print CMDFILE "UpdatePassword for user $identifier to password $newDatasetPassword\n"; close(CMDFILE); } else { push(@{$response->{errors}},"ERROR: Unable to parse identifier '$identifier'. Please report this. ERROR450"); return $response; } $response->{result} = 'Success'; return $response; } ####################################################################### # setNewPublicReleaseDate ####################################################################### sub setNewPublicReleaseDate { my %args = @_; my $SUB_NAME = 'setNewPublicReleaseDate'; #### Decode the argument list my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $newPublicReleaseDate = $args{'newPublicReleaseDate'}; my $response; $response->{result} = 'Failure'; #### Check to make sure the newPublicReleaseDate is not empty if (!defined($newPublicReleaseDate) || $newPublicReleaseDate eq '') { push(@{$response->{errors}},"ERROR: You may not set a blank public release date.
    "); return $response; } #### Check to make sure the newPublicReleaseDate is formed correctly unless ($newPublicReleaseDate =~ /^\d{4}\-\d{2}-\d{2}\S*$/) { push(@{$response->{errors}},"ERROR: Malformed date. Please use format like 2012-01-01.
    "); return $response; } #### If the identifier is valid, set the new password if ($identifier =~ /^PASS(\d+)$/) { my $PK = $1; my %rowdata = ( publicReleaseDate => $newPublicReleaseDate ); my $result = $sbeams->updateOrInsertRow( update => 1, table_name => $TBAT_PASS_DATASET, rowdata_ref => \%rowdata, PK => 'dataset_id', PK_value => $PK, ); } else { push(@{$response->{errors}},"ERROR: Unable to parse identifier '$identifier'. Please report this. ERROR451"); return $response; } $response->{result} = 'Success'; return $response; } ####################################################################### # updateDataset ####################################################################### sub updateDataset { my %args = @_; my $SUB_NAME = 'updateDataset'; #### Decode the argument list my $authentication = $args{'authentication'} || die "[$SUB_NAME] ERROR: authentication not passed"; my $formParameters = $args{'formParameters'} || die "[$SUB_NAME] ERROR: formParameters not passed"; my $identifier = $args{'identifier'} || die "[$SUB_NAME] ERROR: identifier not passed"; my $datasetIdentifier = $identifier; my $response; $response->{result} = 'Failure'; my $verbose = 0; #We never really get here unless authentication was valid, so skip check. This check fails if $isAdmin anyway #return $response unless ($authentication->{result} eq 'Success'); $formParameters->{datasetTitle} =~ s/[\n\r]//g; my $PK = $datasetIdentifier; $PK =~ s/PASS(0*)//; my %rowdata = ( datasetType => $formParameters->{datasetType}, datasetTag => $formParameters->{datasetTag}, datasetTitle => $formParameters->{datasetTitle}, publicReleaseDate => $formParameters->{publicReleaseDate}, submitter_organization => $formParameters->{submitter_organization}, lab_head_full_name => $formParameters->{lab_head_full_name}, lab_head_email => $formParameters->{lab_head_email}, lab_head_organization => $formParameters->{lab_head_organization}, lab_head_country => $formParameters->{lab_head_country}, ); print "
    INFO: Updating database record for primary key $PK...
    \n" if ($verbose); print "
    \n";
      $PK = $sbeams->updateOrInsertRow(
    				   update => 1,
    				   table_name => $TBAT_PASS_DATASET,
    				   rowdata_ref => \%rowdata,
    				   PK => 'dataset_id',
    				   PK_value => $PK,
    				   add_audit_parameters => 1,
    				   #testonly => 1,
    				   #verbose => 1,
    				  );
    
      if ($PK && $PK > 0) {
        $response->{result} = 'Success';
        print "
    INFO: Success.
    \n" if ($verbose); } else { $response->{result} = 'Failed'; print "
    INFO: Failed.
    \n" if ($verbose); return $response; } print "
    \n"; my $PASS_FTP_AGENT_BASE = '/prometheus/u1/home/PASSftpAgent'; print "
    INFO: Writing out DESCRIPTION file.
    \n" if ($verbose); my $outfile = "$PASS_FTP_AGENT_BASE/Incoming/${datasetIdentifier}_DESCRIPTION.txt"; open(OUTFILE,">$outfile") || die("ERROR: Unable to write to '$outfile'"); my $metadata = ''; $metadata .= "identifier:\t$datasetIdentifier\r\n"; $metadata .= "type:\t$formParameters->{datasetType}\r\n"; $metadata .= "tag:\t$formParameters->{datasetTag}\r\n"; $metadata .= "title:\t$formParameters->{datasetTitle}\r\n"; $metadata .= "summary:\t$formParameters->{summary}\r\n"; $metadata .= "contributors:\t$formParameters->{contributors}\r\n"; $metadata .= "publication:\t$formParameters->{publication}\r\n"; foreach my $tag ( 'growth','treatment','extraction','separation','digestion','acquisition','informatics' ) { my $tmp = $formParameters->{$tag}; $tmp =~ s/^\s+//; $tmp =~ s/\s+$//; $metadata .= "$tag:\t$tmp\r\n"; } foreach my $tag ( 'instruments','species','massModifications' ) { my $tmp = $formParameters->{$tag}; $tmp =~ s/^\s+//; $tmp =~ s/\s+$//; $metadata .= "$tag:\t$tmp\r\n"; } print OUTFILE $metadata; close(OUTFILE); #### Tell the FTP agent to create the account print "
    INFO: Telling FTP agent to update to the new DESCRIPTION file.
    \n" if ($verbose); my $cmdfile = "$PASS_FTP_AGENT_BASE/commands.queue"; open(CMDFILE,">>$cmdfile") || die("ERROR: Unable to append to '$cmdfile'"); print CMDFILE "UpdateDataset $datasetIdentifier\n"; close(CMDFILE); #### Print the information for the user print "
    INFO: Preparing the confirmation information.
    \n" if ($verbose); my $confirmationMessage = qq~

    Thank you for updating the metadata for your dataset

    Your updated information has been saved for dataset $datasetIdentifier.
    Identifier: $datasetIdentifier
    Dataset type: $formParameters->{datasetType}
    Dataset tag: $formParameters->{datasetTag}
    Datset title: $formParameters->{datasetTitle}
    Thank you again for your contribution. If you have comments about this submission process, please leave us your comments at http://www.peptideatlas.org/feedback.php

    To return to the record, use the dataset's official URL:
    http://www.peptideatlas.org/PASS/$datasetIdentifier
    ~; print $confirmationMessage; #### Reformat the message for email $confirmationMessage =~ s/\//g; $confirmationMessage =~ s/\<\/H3\>/\n/g; $confirmationMessage =~ s/\//g; $confirmationMessage =~ s/\<\/PRE\>/\n/g; $confirmationMessage =~ s/\/\n/g; $confirmationMessage =~ s/\/\n/g; $confirmationMessage =~ s/\//g; $confirmationMessage =~ s/\<\/a\>//g; #### Get all current metadata from the submission, mostly to get the original submitter my $datasetMetadata = getPASSMetaData(identifier=>$datasetIdentifier); #### Send the submitter the information by email my (@toRecipients,@ccRecipients,@bccRecipients); @toRecipients = ( "$datasetMetadata->{firstName} $datasetMetadata->{lastName}",$datasetMetadata->{emailAddress}, ); @ccRecipients = (); @bccRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', ); SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset $datasetIdentifier update", message=>"Dear $datasetMetadata->{firstName},\n\n$confirmationMessage\n\n", ); #### Email PeptideAtlas team about the submission @toRecipients = ( 'Eric Deutsch','eric.deutsch@systemsbiology.org', # 'Terry Farrah','terry.farrah@systemsbiology.org', # 'Zhi Sun','zhi.sun@systemsbiology.org', ); @ccRecipients = (); @bccRecipients = (); my $adminMessage = qq~PASS dataset has been updated:\n Submitter: $datasetMetadata->{submitter} Dataset URL: http://www.peptideatlas.org/PASS/$datasetIdentifier $metadata ~; SBEAMS::Connection::Utilities::sendEmail( toRecipients=>\@toRecipients, ccRecipients=>\@ccRecipients, bccRecipients=>\@bccRecipients, subject=>"PeptideAtlas dataset $datasetIdentifier metadata was updated", message=>"$adminMessage\n\n", ); $response->{result} = 'Success'; return $response; }