#!/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 STRIDEtoPDBsecondarystruct.pl -infile STRIDE_output.txt # 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 STRIDE output file # and converts the secondary structure in it to PDB format. # For SHEET, some of the secondary structure is missing. # For SHEET, each strand is recorded as being its own beta sheet, without matching it to other strands, and has sheetID = A. # This is enough SHEET information for use by the VALPRED program. # An example of STRIDE output that is input to this program : # REM -------------------- Secondary structure summary ------------------- ~~~~ # REM ~~~~ # CHN SDH_HUMAN.pdb A ~~~~ # REM ~~~~ # REM . . . . . ~~~~ # SEQ 1 SAQYPVVDHEFDAVVVGAGGAGLRAAFGLSEAGFNTACVTKLFPTRSHTV 50 ~~~~ # STR TTTTTEEEEEEEEEEE HHHHHHHHHHHHH EEEETTTTGGG GGG ~~~~ # REM ~~~~ # LOC AlphaHelix GLY 71 A ALA 83 A ~~~~ # LOC AlphaHelix TRP 119 A SER 130 A ~~~~ # LOC AlphaHelix GLN 136 A TYR 156 A ~~~~ # LOC AlphaHelix ARG 195 A ARG 210 A ~~~~ # LOC 310Helix VAL 395 A LYS 397 A ~~~~ # LOC 310Helix ASP 545 A LYS 547 A ~~~~ # LOC 310Helix PHE 618 A GLU 620 A ~~~~ # LOC 310Helix LEU 65 B LYS 67 B ~~~~ # LOC Strand VAL 57 A VAL 67 A ~~~~ # LOC Strand THR 87 A VAL 90 A ~~~~ # LOC Strand ILE 107 A ASN 108 A ~~~~ # LOC Strand GLN 170 A ARG 171 A ~~~~ # LOC TurnIV SER 52 A TYR 55 A ~~~~ # LOC TurnVIII ALA 53 A PRO 56 A ~~~~ # LOC TurnVIII PHE 62 A VAL 65 A ~~~~ # LOC TurnIV THR 91 A PHE 94 A ~~~~ # LOC TurnIV GLY 112 A GLU 115 A ~~~~ # LOC TurnI' SER 130 A LEU 133 A ~~~~ # LOC TurnI THR 163 A GLY 166 A ~~~~ # LOC GammaInv GLU 154 B TYR 156 B ~~~~ # LOC GammaInv LEU 234 B ASP 236 B ~~~~ # An example PDB file : # HELIX 1 1 GLY A 28 ALA A 41 1 14 # HELIX 2 2 PHE A 52 ALA A 61 5 10 # HELIX 3 3 ASN A 76 SER A 88 1 13 # HELIX 4 4 ASP A 93 GLY A 115 1 23 # HELIX 34 34 CYS D 65 VAL D 92 1 28 # HELIX 35 35 GLY D 94 HIS D 122 1 29 # HELIX 36 36 GLY D 125 LYS D 135 1 11 # SHEET 1 A 4 VAL A 15 GLU A 19 0 # SHEET 2 A 4 ILE A 202 ARG A 206 1 O ILE A 202 N VAL A 16 # SHEET 3 A 4 GLU A 188 CYS A 196 -1 N ALA A 194 O HIS A 203 # SHEET 4 A 4 TYR A 177 GLU A 185 -1 N LEU A 183 O GLY A 191 # SHEET 1 B 6 SER A 172 VAL A 175 0 # SHEET 2 B 6 THR A 45 THR A 49 1 N THR A 45 O SER A 172 # SHEET 3 B 6 ALA A 22 VAL A 25 1 N VAL A 24 O VAL A 48 # SHEET 4 B 6 ASN A 209 VAL A 212 1 O VAL A 211 N VAL A 25 # SHEET 5 B 6 GLN A 386 ALA A 395 1 O TYR A 394 N THR A 210 # SHEET 6 B 6 GLN A 378 VAL A 383 -1 N VAL A 383 O GLN A 386 # An example of output from this program that is in PDB format : # HELIX 1 1 GLY A 28 ALA A 41 1 14 # HELIX 2 2 PHE A 52 ALA A 61 5 10 # HELIX 3 3 ASN A 76 SER A 88 1 13 # HELIX 4 4 ASP A 93 GLY A 115 1 23 # HELIX 34 34 CYS D 65 VAL D 92 1 28 # HELIX 35 35 GLY D 94 HIS D 122 1 29 # HELIX 36 36 GLY D 125 LYS D 135 1 11 # SHEET 1 A 1 VAL A 15 GLU A 19 0 # SHEET 1 A 1 ILE A 202 ARG A 206 0 # SHEET 1 A 1 GLU A 188 CYS A 196 0 # SHEET 1 A 1 TYR A 177 GLU A 185 0 # SHEET 1 A 1 SER A 172 VAL A 175 0 # SHEET 1 A 1 THR A 45 THR A 49 0 # SHEET 1 A 1 ALA A 22 VAL A 25 0 # SHEET 1 A 1 ASN A 209 VAL A 212 0 # SHEET 1 A 1 GLN A 386 ALA A 395 0 # SHEET 1 A 1 GLN A 378 VAL A 383 0 # PDB FORMAT Version 2.3 # http://www.wwpdb.org/documentation/format23/sect5.html # # HELIX # # COLUMNS DATA TYPE FIELD DEFINITION # -------------------------------------------------------------------- # 1 - 6 Record name "HELIX " # 8 - 10 Integer serNum Serial number of the helix. # This starts at 1 and increases # incrementally. # 12 - 14 LString(3) helixID Helix identifier. In addition # to a serial number, each helix is # given an alphanumeric character # helix identifier. # 16 - 18 Residue name initResName Name of the initial residue. # 20 Character initChainID Chain identifier for the chain # containing this helix. # 22 - 25 Integer initSeqNum Sequence number of the initial # residue. # 26 AChar initICode Insertion code of the initial # residue. # 28 - 30 Residue name endResName Name of the terminal residue of # the helix. # 32 Character endChainID Chain identifier for the chain # containing this helix. # 34 - 37 Integer endSeqNum Sequence number of the terminal # residue. # 38 AChar endICode Insertion code of the terminal # residue. # 39 - 40 Integer helixClass Helix class (see below). # 41 - 70 String comment Comment about this helix. # 72 - 76 Integer length Length of this helix. # # SHEET # # COLUMNS DATA TYPE FIELD DEFINITION # -------------------------------------------------------------- # 1 - 6 Record name "SHEET " # 8 - 10 Integer strand Strand number which starts at 1 # for each strand within a sheet # and increases by one. # 12 - 14 LString(3) sheetID Sheet identifier. # 15 - 16 Integer numStrands Number of strands in sheet. # 18 - 20 Residue name initResName Residue name of initial residue. # 22 Character initChainID Chain identifier of initial # residue in strand. # 23 - 26 Integer initSeqNum Sequence number of initial # residue in strand. # 27 AChar initICode Insertion code of initial residue # in strand. # 29 - 31 Residue name endResName Residue name of terminal residue. # 33 Character endChainID Chain identifier of terminal # residue. # 34 - 37 Integer endSeqNum Sequence number of terminal # residue. # 38 AChar endICode Insertion code of terminal # residue. # 39 - 40 Integer sense Sense of strand with respect to # previous strand in the sheet. 0 # if first strand, 1 if parallel, # -1 if anti-parallel. # 42 - 45 Atom curAtom Registration. Atom name in # current strand. # 46 - 48 Residue name curResName Registration. Residue name in # current strand. # 50 Character curChainId Registration. Chain identifier in # current strand. # 51 - 54 Integer curResSeq Registration. Residue sequence # number in current strand. # 55 AChar curICode Registration. Insertion code in # current strand. # 57 - 60 Atom prevAtom Registration. Atom name in # previous strand. # 61 - 63 Residue name prevResName Registration. Residue name in # previous strand. # 65 Character prevChainId Registration. Chain identifier in # previous strand. # 66 - 69 Integer prevResSeq Registration. Residue sequence # number in previous strand. # 70 AChar prevICode Registration. Insertion code in # previous strand. 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 = "STRIDEtoPDBsecondarystruct"; } 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 STRIDE file contents to output, reformatting it to PDB format #=================================================================================================== sub build_the_output { my @input_lines = @{$input->{'input_lines'}}; my @output_lines; $output->{'output_lines'} = \@output_lines; my $helix_upto = 0; 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 $is_helix = 0; my $is_sheet = 0; if (length($line) >= 3) { my $bit1 = substr( $line, 0, 3 ); if ($bit1 eq 'LOC') { my $bit2 = uc(substr( $line, 5, 10 )); my $idx1 = index($bit2, 'HELIX'); my $idx2 = index($bit2, 'STRAND'); if ($idx1 >= 0) { $is_helix = 1; } elsif ($idx2 >= 0) { $is_sheet = 1; } } if ($is_helix == 1) { my $resn1 = substr($line,18,3); my $resi1 = trim(substr($line,22,5)); my $chain1 = substr($line,28,1); my $resn2 = substr($line,35,3); my $resi2 = trim(substr($line,40,5)); my $chain2 = substr($line,46,1); $helix_upto++; my $print_helix_upto = sprintf("%3s",$helix_upto); my $print_resi1 = sprintf("%4s",$resi1); my $print_resi2 = sprintf("%4s",$resi2); my $length = $resi2 - $resi1 + 1; my $print_length = sprintf("%5s",$length); my $output_line = 'HELIX ' . $print_helix_upto . ' ' . $print_helix_upto . ' ' . $resn1 . ' ' . $chain1 . ' ' . $print_resi1 . ' ' . $resn2 . ' ' . $chain2 . ' ' . $print_resi2 . ' 1 ' . $print_length; push( @output_lines, $output_line ); } elsif ($is_sheet == 1) { my $resn1 = substr($line,18,3); my $resi1 = trim(substr($line,22,5)); my $chain1 = substr($line,28,1); my $resn2 = substr($line,35,3); my $resi2 = trim(substr($line,40,5)); my $chain2 = substr($line,46,1); my $print_resi1 = sprintf("%4s",$resi1); my $print_resi2 = sprintf("%4s",$resi2); my $output_line = 'SHEET 1 A 1 ' . $resn1 . ' ' . $chain1 . $print_resi1 . ' ' . $resn2 . ' ' . $chain2 . $print_resi2 . ' 0'; 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", "This program reads in a STRIDE output file and converts the secondary structure in it to PDB format.
\n", "For SHEET, some of the secondary structure is missing.
\n", "For SHEET, each strand is recorded as being its own beta sheet, without matching it to other strands, and has sheetID = A.
\n", "This is enough SHEET information for use by the VALPRED program.\n", "
\n", "Please provide a STRIDE file. See format here.
\n", "
\n", "Upload the STRIDE file from your computer.
Please note that this STRIDE file is not validated, so make sure that it is a valid STRIDE file.
\n", "
\n", "
\n", "\n", "\n", "
or
\n", "
\n", "\n", "\n", "\n", "\n", "
Enter the STRIDE file contents here.
Please note that these STRIDE file contents are not validated, so make sure that they are valid STRIDE 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", "Display results on screen
\n", "Write results to output file

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


", ""; print "Here is an example of STRIDE output that is input to this program :
\n", "
\n", "\n", "REM  -------------------- Secondary structure summary -------------------  ~~~~
\n", "REM                                                                        ~~~~
\n", "CHN  SDH_HUMAN.pdb A                                                       ~~~~
\n", "REM                                                                        ~~~~
\n", "REM                .         .         .         .         .               ~~~~
\n", "SEQ  1    SAQYPVVDHEFDAVVVGAGGAGLRAAFGLSEAGFNTACVTKLFPTRSHTV   50          ~~~~
\n", "STR       TTTTTEEEEEEEEEEE   HHHHHHHHHHHHH   EEEETTTTGGG GGG               ~~~~
\n", "REM                                                                        ~~~~
\n", "LOC  AlphaHelix   GLY    71 A      ALA     83 A                            ~~~~
\n", "LOC  AlphaHelix   TRP   119 A      SER    130 A                            ~~~~
\n", "LOC  AlphaHelix   GLN   136 A      TYR    156 A                            ~~~~
\n", "LOC  AlphaHelix   ARG   195 A      ARG    210 A                            ~~~~
\n", "LOC  310Helix     VAL   395 A      LYS    397 A                            ~~~~
\n", "LOC  310Helix     ASP   545 A      LYS    547 A                            ~~~~
\n", "LOC  310Helix     PHE   618 A      GLU    620 A                            ~~~~
\n", "LOC  310Helix     LEU    65 B      LYS     67 B                            ~~~~
\n", "LOC  Strand       VAL    57 A      VAL     67 A                            ~~~~
\n", "LOC  Strand       THR    87 A      VAL     90 A                            ~~~~
\n", "LOC  Strand       ILE   107 A      ASN    108 A                            ~~~~
\n", "LOC  Strand       GLN   170 A      ARG    171 A                            ~~~~
\n", "LOC  TurnIV       SER    52 A      TYR     55 A                            ~~~~
\n", "LOC  TurnVIII     ALA    53 A      PRO     56 A                            ~~~~
\n", "LOC  TurnVIII     PHE    62 A      VAL     65 A                            ~~~~
\n", "LOC  TurnIV       THR    91 A      PHE     94 A                            ~~~~
\n", "LOC  TurnIV       GLY   112 A      GLU    115 A                            ~~~~
\n", "LOC  TurnI'       SER   130 A      LEU    133 A                            ~~~~
\n", "LOC  TurnI        THR   163 A      GLY    166 A                            ~~~~
\n", "LOC  GammaInv     GLU   154 B      TYR    156 B                            ~~~~
\n", "LOC  GammaInv     LEU   234 B      ASP    236 B                            ~~~~
\n","
\n", "
\n"; print "Here is an example of output from this program that is in PDB format :
\n", "
\n", "\n", "HELIX    1   1 GLY A   28  ALA A   41  1                                  14
\n", "HELIX    2   2 PHE A   52  ALA A   61  5                                  10
\n", "HELIX    3   3 ASN A   76  SER A   88  1                                  13
\n", "HELIX    4   4 ASP A   93  GLY A  115  1                                  23
\n", "HELIX   34  34 CYS D   65  VAL D   92  1                                  28
\n", "HELIX   35  35 GLY D   94  HIS D  122  1                                  29
\n", "HELIX   36  36 GLY D  125  LYS D  135  1                                  11
\n", "SHEET    1   A 1 VAL A  15  GLU A  19  0
\n", "SHEET    1   A 1 ILE A 202  ARG A 206  0
\n", "SHEET    1   A 1 GLU A 188  CYS A 196  0
\n", "SHEET    1   A 1 TYR A 177  GLU A 185  0
\n", "SHEET    1   A 1 SER A 172  VAL A 175  0
\n", "SHEET    1   A 1 THR A  45  THR A  49  0
\n", "SHEET    1   A 1 ALA A  22  VAL A  25  0
\n", "SHEET    1   A 1 ASN A 209  VAL A 212  0
\n", "SHEET    1   A 1 GLN A 386  ALA A 395  0
\n", "SHEET    1   A 1 GLN A 378  VAL A 383  0
\n", "
\n", "
\n"; print "
\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_h; my $input_help; GetOptions( "infile=s" => \$input_file, "h" => \$input_h, "help" => \$input_help ); if (!defined $input_file) { die "Usage $0 -infile INPUTFILE\n"; } if (defined $input_file) { $input->{'infile'} = $input_file; } 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->{'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 STRIDE file contents or upload a STRIDE 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 = 'CONVERT STRIDE SECONDARY STRUCTURE TO PDB FORMAT'; 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 "

\n"; print "SOURCE CODE : STRIDEtoPDBsecondarystruct_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->{'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 STRIDEtoPDBsecondarystruct.pl -infile STRIDE_output.txt # 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 STRIDE output file # and converts the secondary structure in it to PDB format. # For SHEET, some of the secondary structure is missing. # For SHEET, each strand is recorded as being its own beta sheet, without matching it to other strands, and has sheetID = A. # This is enough SHEET information for use by the VALPRED program. $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 STRIDEtoPDBsecondarystruct.pl -infile STRIDE_output.txt\n"; $command_line_help_text .= "\n"; $command_line_help_text .= "This program reads in a STRIDE output file and converts the secondary structure in it to PDB format.\n"; $command_line_help_text .= "For SHEET, some of the secondary structure is missing.\n"; $command_line_help_text .= "For SHEET, each strand is recorded as being its own beta sheet, without matching it to other strands, and has sheetID = A.\n"; $command_line_help_text .= "This is enough SHEET information for use by the VALPRED program.\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; }