#!/usr/bin/perl -wT # Copyright 2010 Emma Rath. All rights reserved. # Soon this program will be released under an open source software license such as GNU General Public License or # Creative Commons license for Free Software Foundation's GNU General Public License at creativecommons.org # perl -T renumbermodellerenergy.pl -infile Spneumo_MsmRaf_all.profile -from 201 -to 300 -add -200 # This perl program runs as a as a cgi script on a web server that displays web pages. # This perl program also runs as a batch program on the command line. # This program reads in a Modeller profile file containing one line per residue. # This program extracts only residues specific in the "from" and "to" parameters, # add the specified number to them (which will usually be a negative number), # and writes them out, with the file heading lines. # The point of this program is to allow Modeller to run its energy calculations on all subunits/chains of a PDB file, # such that residues in the interface between 2 subunits or 2 chains will have atoms from other subunits impacting on it. # This program extracts just one chain, with the numbering it would have had if only the one chain had been processed, # but with atoms from other chains having been taken into account in the energy calculations of residues of this chain being processed. # An example input file : # # Energy of each residue is written to: Spneumo_MsmRaf_all.profile # # The profile IS normalized by the number of restraints. # # The profiles are smoothed over a window of residues: 13 # # The sum of all numbers in the file: -54.8802 # #COLUMNS S S N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N # # RESID RES 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 TOTAL # # 1 MET 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 # 2 VAL 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.36E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.36E-01 # 3 GLU 0.0 0.0 0.0 0.0 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0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 # 27 ASN 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 # 28 ILE 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.35E-01 # 29 LYS 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.36E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.36E-01 # 30 ASP 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.37E-01 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -0.37E-01 use warnings; use strict; use diagnostics; use Getopt::Long; use Math::Complex; use Math::Trig; use CGI; use Data::Dumper; # $Data::Dumper::Purity = 1; # print "var x = " . Dumper( $x ) . "\n"; # debug # my $wait_for_key_press = ; # debug my $q = new CGI; my $global; my $input; my $output; my $debug = ''; #=================================================================================================== #================================= MAIN ================================== #=================================================================================================== init(); get_program_mode(); if ($global->{'program_mode'} eq 'cgi-display-form') { display_html_form(); } elsif ($global->{'program_mode'} eq 'cgi-output') { get_html_input(); if ($global->{'got_error'} == 0) { build_and_output_results_for_html_output(); } else { display_html_form(); } } else { # $global->{'program_mode'} eq 'command-line' get_command_line_input(); if ($global->{'got_error'} == 0) { my $untainted_infile = untaint( $input->{'infile'} ); if ($untainted_infile eq '') { $untainted_infile = "renumbermodellerenergy"; } my $output_file = $untainted_infile . ".txt"; open( OUTFILE, ">$output_file") or die "Cannot open $output_file for writing\n"; build_and_output_results_for_command_line(); close OUTFILE; } else { output_command_line_help(); } } #=================================================================================================== # this is the main logic subroutine of this program for command-line mode. # given an input file, process the input and produce the output. #=================================================================================================== sub build_and_output_results_for_command_line { build_the_output(); my @output_lines = @{$output->{'output_lines'}}; foreach my $line (@output_lines) { print OUTFILE "$line\n"; } } #=================================================================================================== # this is the main logic subroutine of this program for cgi-output mode. # given an input file, process the input and produce the output. #=================================================================================================== sub build_and_output_results_for_html_output { build_the_output(); if ($input->{'whereto'} eq 'S') { # write output to the screen print $q->header(); print #$q->start_html(-title=>$text_title), "\n", '' . "\n", "\n"; print "\n"; my @output_lines = @{$output->{'output_lines'}}; foreach my $line (@output_lines) { $line =~ s/ / /g; $line = "$line
\n"; print $line; } print "
\n"; } else { # $input->{'whereto'} eq 'F' # write output to a file to be downloaded print $q->header("Content-type: text/plain"); my @output_lines = @{$output->{'output_lines'}}; foreach my $line (@output_lines) { print "$line\n"; } } if ($debug ne '') { print "$debug\n"; } } #=================================================================================================== # move the input Modeller file contents to output, changing the residue numbering #=================================================================================================== sub build_the_output { my @input_lines = @{$input->{'input_lines'}}; my @output_lines; $output->{'output_lines'} = \@output_lines; my $from = $input->{'from'}; my $to = $input->{'to'}; my $add = $input->{'add'}; for ( my $i = 0; $i < @input_lines; $i++ ) { my $line = $input_lines[$i]; my $trimmed_line = trim($line); if ($trimmed_line eq '') { push( @output_lines, $line ); } else { my $char1 = substr( $line, 0, 1 ); if ($char1 eq '#') { push( @output_lines, $line ); } else { my @bits = split( /\s+/, $trimmed_line ); my $word1 = trim($bits[0]); if (($word1 >= $from) && ($word1 <= $to)) { my $rest_of_line = substr( $line, 6 ); $word1 = $word1 + $add; $word1 = sprintf("%6s",$word1); my $output_line = $word1 . $rest_of_line; push( @output_lines, $output_line ); } } } } } #=================================================================================================== # this program is being called to display the HTML input form #=================================================================================================== sub display_html_form { html_header(); my $request_uri = $ENV{'REQUEST_URI'}; my @bits = split(/\//, $request_uri); my $pgm_name = $bits[$#bits]; print "

\n"; print "
\n", " \n"; if ($global->{'got_error'} == 1) { print " \n", " \n", " \n"; } print " \n", " \n", " \n"; print " \n", " \n", " \n"; print "
\n", "

" . $global->{'err_msg'} . "
Didn't process because of input error(s).

\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "Please provide a Modeller profile file. See format here.
\n", "
\n", "Upload the Modeller file from your computer.
Please note that this Modeller file is not validated, so make sure that it is a valid Modeller file.
\n", "
\n", "
\n", "\n", "\n", "
or
\n", "
\n", "\n", "\n", "\n", "\n", "
Enter the Modeller file contents here.
Please note that these Modeller file contents are not validated, so make sure that they are valid Modeller file contents.
(Provide either a file or enter the contents here, not both.
If both provided, then contents here will be processed instead of uploaded file.)

\n", "
\n", "From residue number : ", "", " (optional field)

\n", "
\n", "To residue number : ", "", " (optional field)

\n", "
\n", "Add this number to each residue number : ", "", " (mandatory field, can be negative)

\n", "
\n", "Display results on screen
\n", "Write results to output file

\n", "
\n", "\n", "
\n", "
\n", "


", "", "Here is an example of the input file, a Modeller profile energy file :
\n", "
\n", "\n", "# Energy of each residue is written to: Spneumo_MsmRaf_all.profile
\n", "# The profile IS normalized by the number of restraints.
\n", "# The profiles are smoothed over a window of residues:   13
\n", "# The sum of all numbers in the file:     -54.8802
\n", "#COLUMNS S S  N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N 
\n", "# RESID  RES            1           2           3           4           5           6           7           8           9          10          11          12          13          14          15          16          17          18          19          20          21          22          23          24          25          26          27          28          29          30          31          32          33          34          35          36          37          38          39     TOTAL
\n", "
\n", "     1  MET       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01
\n", "     2  VAL       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01
\n", "     3  GLU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01
\n", "     4  LEU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01
\n", "     5  ASN       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01
\n", "     6  LEU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01
\n", "     7  LYS       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01
\n", "     8  ASN       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.33E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.33E-01
\n", "     9  ILE       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.31E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.31E-01
\n", "    10  TYR       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.29E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.29E-01
\n", "    11  LYS       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.26E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.26E-01
\n", "    12  LYS       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01
\n", "    13  TYR       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01
\n", "    14  PRO       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01
\n", "    15  ASN       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.24E-01
\n", "    16  SER       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.25E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.25E-01
\n", "    17  GLU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.25E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.25E-01
\n", "    18  HIS       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.26E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.26E-01
\n", "    19  TYR       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.28E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.28E-01
\n", "    20  SER       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.28E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.28E-01
\n", "    21  VAL       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.30E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.30E-01
\n", "    22  GLU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.30E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.30E-01
\n", "    23  ASP       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.32E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.32E-01
\n", "    24  PHE       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.34E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.34E-01
\n", "    25  ASN       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.34E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.34E-01
\n", "    26  LEU       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01
\n", "    27  ASN       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01
\n", "    28  ILE       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.35E-01
\n", "    29  LYS       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.36E-01
\n", "    30  ASP       0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01     0.0         0.0         0.0         0.0         0.0         0.0         0.0         0.0       -0.37E-01
\n", "
\n", "
\n", "
\n", "
\n"; html_footer(); } #=================================================================================================== # in command line mode - get the command line options, read the input file. #=================================================================================================== sub get_command_line_input { my $input_file; my $input_from; my $input_to; my $input_add; my $input_h; my $input_help; GetOptions( "infile=s" => \$input_file, "from=s" => \$input_from, "to=s" => \$input_to, "add=s" => \$input_add, "h" => \$input_h, "help" => \$input_help ); if (!defined $input_file) { die "Usage $0 -infile INPUTFILE -from FROM -to TO -add ADD\n"; } if (defined $input_file) { $input->{'infile'} = $input_file; } if (defined $input_from) { $input->{'from'} = $input_from; } if (defined $input_to) { $input->{'to'} = $input_to; } if (defined $input_add) { $input->{'add'} = $input_add; } if (defined $input_h) { $input->{'h'} = $input_h; } if (defined $input_help) { $input->{'help'} = $input_help; } if ((defined $input_h) || (defined $input_help)) { $global->{'got_error'} = 1; } open INFILE, $input->{'infile'} or die $!; my @input_lines = ; my @new_input_lines; foreach my $line (@input_lines) { chomp($line); push(@new_input_lines, $line); } $input->{'input_lines'} = \@new_input_lines; } #=================================================================================================== # get the input from the html form, so can process the input #=================================================================================================== sub get_html_input { my $params = $q->Vars; if (defined($params->{'from'})) { my $input_from = trim( $params->{'from'} ); if ($input_from eq '') { $input_from = 1; } else { if (is_valid_integer($input_from) == 1) { $input->{'from'} = $input_from; } else { $global->{'got_error'} = 1; $global->{'err_msg'} .= $global->{'err_msg'} . "The 'From residue number' that you entered is invalid. It must be a positive integer.
\n"; } } } if (defined($params->{'to'})) { my $input_to = trim( $params->{'to'} ); if ($input_to eq '') { $input_to = 9999999; } else { if (is_valid_integer($input_to) == 1) { $input->{'to'} = $input_to; } else { $global->{'got_error'} = 1; $global->{'err_msg'} .= $global->{'err_msg'} . "The 'To residue number' that you entered is invalid. It must be a positive integer.
\n"; } } } if (defined($params->{'add'})) { if ($params->{'add'} ne '') { my $input_add = trim( $params->{'add'} ); if (is_valid_add_number($input_add) == 1) { $input->{'add'} = $input_add; } else { $global->{'got_error'} = 1; $global->{'err_msg'} .= $global->{'err_msg'} . "The number to add that you entered is not a valid integer.
\n"; } } } if (defined($params->{'whereto'})) { if ($params->{'whereto'} ne '') { my $input_whereto = trim( $params->{'whereto'} ); $input->{'whereto'} = uc($input_whereto); if (($input->{'whereto'} ne 'S') and ($input->{'whereto'} ne 'F')) { $input->{'whereto'} = 'S'; } } } my @input_lines; $input->{'input_lines'} = \@input_lines; my $user_provided_file_contents = 0; if (defined($params->{'file_contents'})) { my $file_contents = trim( $params->{'file_contents'} ); if ($file_contents ne '') { $user_provided_file_contents = 1; my @file_lines = split(/\n|\r/, $file_contents); foreach my $file_line (@file_lines) { $file_line = trim($file_line); if ($file_line ne '') { push( @input_lines, $file_line ); } } } } if ( (defined($params->{'upload_file'})) && ($user_provided_file_contents == 0)) { my $upload_file = $q->param('upload_file'); my $upload_filehandle = $q->upload('upload_file'); if ($upload_file ne '') { if ($upload_filehandle eq '') { $global->{'got_error'} = 1; $global->{'err_msg'} .= "The upload didn't work. Probably your file is too big - bigger than 5MB.
"; } else { # read the uploaded file my @uploaded_lines; my $user_data = ''; while ( <$upload_filehandle> ) { my $input_line = $_; chomp($input_line); push( @input_lines, $input_line ); } } } } if ($global->{'got_error'} == 0) { my $num_input_lines = $#{$input->{'input_lines'}}; if ($num_input_lines < 1) { $global->{'got_error'} = 1; $global->{'err_msg'} .= "No input lines were given. Please enter your Modeller file contents or upload a Modeller file.
"; } } } #=================================================================================================== # figure out whether this program is being called to display the HTML input form, # or whether the form has been filled and now the results need to be displayed, # or whether this program is being run in batch mode from the command line. #=================================================================================================== sub get_program_mode { $global->{'program_mode'} = 'command-line'; if (defined($ENV{'REQUEST_METHOD'})) { if ($ENV{'REQUEST_METHOD'} eq 'POST') { $global->{'program_mode'} = 'cgi-output'; } else { $global->{'program_mode'} = 'cgi-display-form'; } } else { $global->{'program_mode'} = 'command-line'; } } #=================================================================================================== # html code for the graphics part of the header of the html page #=================================================================================================== sub html_code_for_graphics_header { my $title = shift; my $html_code = ''; $html_code .= "
\n" . "\n" . #" style='background-image: url(\"bluegold.gif\");\n" . #" background-attachment: fixed;\n" . #" background-position: top right;\n" . #" background-repeat: no-repeat;'>\n" . " \n" . " \n" . " \n" . "
\n" . " \n" . " \n" . " \n" . " \n" . #" \n" . #" \n" . " \n" . " \n" . "
\n" . " $title\n" . " \n" . #" $title\n" . #" \n" . #" \n" . #" \n" . " \n" . "
\n" . "
\n" . "
\n" . "
\n
"; return $html_code; } #=================================================================================================== # html code for the header of the html page #=================================================================================================== sub html_header { my $title = 'RENUMBER RESIDUE NUMBERS IN MODELLER PROFILE FILE'; print $q->header(); print #$q->start_html(-title=>$text_title), "$title\n", '' . "\n", "\n"; my $output_line = html_code_for_graphics_header($title); print $output_line; } #=================================================================================================== # html code for the footer of the html page #=================================================================================================== sub html_footer { print $debug . "
\n"; print "

\n"; print "SOURCE CODE : renumbermodellerenergy_pl.txt
\n"; print "

\n"; print "COPYRIGHT :
\n"; print "Copyright © 2010 Emma Rath. All rights reserved.
\n"; print "Soon this program will be released under an open source software license such as GNU General Public License or
\n"; print "Creative Commons license for Free Software Foundation's GNU General Public License at creativecommons.org
\n"; print "

\n"; print "
\n"; print $q->end_html(); } #=================================================================================================== # initialise global and program variables before starting processing. #=================================================================================================== sub init { my %global_hash; $global = \%global_hash; $global->{'got_error'} = 0; $global->{'err_msg'} = ''; my %input_hash; $input = \%input_hash; $input->{'infile'} = ''; $input->{'from'} = ''; $input->{'to'} = ''; $input->{'add'} = ''; $input->{'whereto'} = ''; $input->{'h'} = ''; $input->{'help'} = ''; my @input_lines; $input->{'input_lines'} = \@input_lines; } #=================================================================================================== sub is_valid_chain { my $chain = shift; my $is_ok = 0; if (length($chain) <= 1) { $is_ok = 1; } return $is_ok; } #=================================================================================================== sub is_valid_decimal { my $input_integer = shift; my $return = 1; if ($input_integer !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { $return = 0; } else { if ($input_integer < 1) { $return = 0; } } return $return; } #=================================================================================================== sub is_valid_integer { my $input_integer = shift; my $return = 1; if ($input_integer !~ /^\d+$/) { $return = 0; } else { if ($input_integer < 1) { $return = 0; } } return $return; } #=================================================================================================== sub is_valid_add_number { my $input_integer = shift; my $return = 1; if ($input_integer !~ /^-?\d+$/) { $return = 0; } return $return; } #=================================================================================================== # in command line mode, output some text help #=================================================================================================== sub output_command_line_help { my $command_line_help_text = ''; # perl -T renumbermodellerenergy.pl -infile Spneumo_MsmRaf_all.profile -from 201 -to 300 -add -200 # This perl program runs as a as a cgi script on a web server that displays web pages. # This perl program also runs as a batch program on the command line. # This program reads in a Modeller profile file containing one line per residue. # This program extracts only residues specific in the "from" and "to" parameters, # add the specified number to them (which will usually be a negative number), # and writes them out, with the file heading lines. $command_line_help_text .= "Here is an example of calling this program in command line mode :\n"; $command_line_help_text .= "\n"; $command_line_help_text .= " perl -T renumbermodellerenergy.pl -infile Spneumo_MsmRaf_all.profile -from 201 -to 300 -add -200\n"; $command_line_help_text .= "\n"; $command_line_help_text .= "This program reads in a Modeller profile file containing one line per residue.\n"; $command_line_help_text .= "This program extracts only residues specific in the \"from\" and \"to\" parameters,\n"; $command_line_help_text .= "add the specified number to them (which will usually be a negative number),\n"; $command_line_help_text .= "and writes them out, with the file heading lines.\n"; $command_line_help_text .= "\n"; print $command_line_help_text; } #=================================================================================================== # a perl utility subroutine - remove leading and trailing blanks from a string #=================================================================================================== sub trim { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } #=================================================================================================== # untaint file name #=================================================================================================== sub untaint { my $path = shift; # user_error("path cannot contain metacharacters") if $path=~/[\n|<>&!;\'\"]/; # extract only legal alphanumerics from the filename # $path =~ m!(/[a-zA-Z/0-9._~\-]+)!; # $path =~ /([\w"-"".""_"]+)/; $path =~ /([a-zA-Z0-9._~\-]+)/; if (defined($1)) { $path = $1; } else { $path = ''; } # user_error("path cannot contain relative directories") # if $path=~m!\.\.!; return $path; }