Solved

Related to previous question- initialisation problem transferring variables from one script to another

Posted on 2009-05-18
2
199 Views
Last Modified: 2012-05-07
I'm trying to transfer some variables from one script (ORFfinder.pl) to another (mass.pl)
The variables are $orfprotein1 to 6, @fragments, @mis_cleave, $enzyme, $dna_header.

They are initialised in ORFfinder.pl as various variables, the script is shown below.

I'm trying to transfer these over to mass.pl, but do not know how to set the variables in ORFfinder so that i do not need to re-initilise them again.

Thanks.
#!/usr/bin/perl -w
use CGI::Carp 'fatalsToBrowser';
# ORFfinder.pl
# Perl programme to read in FastA format to find all possible open
# reading frames (ORFS) beginning with ATG and ending with a stop codon,
# TGA, TAA, TAG)
 
# Analyse all six open reading frames and predict ORFS in all six. Only
# longest ORF will be used.
 
use CGI;
use strict;
use warnings;
use DNALib;
use ReadingFrameModules;
my $query = new CGI;
 
# Initialise variables
my ($dna, $dna1, $dna2, $dna3, $dna5, $dna6, $revcom, $revcom1, $revcom2, $longorf1, $longorf2, $longorf3, $longorf4, $longorf5, $longorf6, 
$dna_filename);
$dna=$dna1=$dna2=$dna3=$dna5=$dna6=$revcom=$revcom1=$revcom2=$longorf1=$longorf2=$longorf3=$longorf4=$longorf5=$longorf6=$dna_filename='';
my $dna_file;
my @file_data;
my $dna_header;
 
   # If a text box provided, take from that
if ($query->param('dna-textbox')) {
   $dna1 = $query->param('dna-textbox');
   # take header and save it as a string $dna_header
   ($dna_header, $dna1) = split(/\n/, $dna1, 2);
 
   $dna = extract_string_sequence_from_fasta_data($dna1);
 }
   # Else see if file upload
elsif($query->param('fileupload'))  {
 
   #  Retrieve the file from the web post instead of the filesystem
  @file_data = get_file_data();
   # take the first line as the header line title
   $dna_header = shift(@file_data);
   #Extract the sequence from the contents of the file
   $dna = extract_sequence_from_fasta_data(@file_data);
}
 
 
# Add ACGT Validation, changing all non ACGT code to A
$dna =~ s/[^acgt]/a/g;
 
 
# feed the DNA data into open_reading_frame to return the longest ORF
 
$longorf1 = open_reading_frame($dna);
 
# remove first base from sequence
$dna2 = substr $dna, 1;
$longorf2 = open_reading_frame($dna2);
 
# remove first base from $dna2
$dna3 = substr $dna2, 1;
$longorf3 = open_reading_frame($dna3);
 
#Reverse compliment the DNA sequence
$revcom = revcom($dna);
$longorf4 = open_reading_frame($revcom);
 
 
#remove first base from sequence
$dna5 = substr $revcom, 1;
$longorf5 = open_reading_frame($dna5);
 
#remove a further base from the sequence
$dna6 = substr $dna5, 1;
$longorf6 = open_reading_frame($dna6);
 
# SECOND HALF OF THE PROGRAM - THIS WAS ORIGINALLY TO BE SENT TO A SECOND SCRIPT
# FOR TASK 2 BUT HAD PROBLEMS WITH THE CGI IMPLEMENTING TWO SCRIPTS ON ONE HTML FORM
 
# my($longorf1,$longorf2,$longorf3,$longorf4,$longorf5,$longorf6)=@ARGV;
 
#Transfer Open Reading Frames over to ProteinDigest
# system './proteindigest.pl', $longorf1,$longorf2,$longorf3,$longorf4,$longorf5,$longorf6;
 
# Initialise second program variables
my $orfprotein1 = '';
my $orfprotein2 = '';
my $orfprotein3 = '';
my $orfprotein4 = '';
my $orfprotein5 = '';
my $orfprotein6 = '';
my $codon;
 
# Convert DNA sequence to Protein sequence - Translate each three base
# codon into an amino acid, and append to the protein
 
for(my $i=0; $i < (length($longorf1) -2) ; $i += 3) {
$codon = substr($longorf1,$i,3);
$orfprotein1 .= codon2aa($codon);
}
 
for(my $i=0; $i < (length($longorf2) -2) ; $i += 3) {
$codon = substr($longorf2,$i,3);
$orfprotein2 .= codon2aa($codon);
}
 
for(my $i=0; $i < (length($longorf3) -2) ; $i += 3) {
$codon = substr($longorf3,$i,3);
$orfprotein3 .= codon2aa($codon);
}
 
for(my $i=0; $i < (length($longorf4) -2) ; $i += 3) {
$codon = substr($longorf4,$i,3);
$orfprotein4 .= codon2aa($codon);
}
 
for(my $i=0; $i < (length($longorf5) -2) ; $i += 3) {
$codon = substr($longorf5,$i,3);
$orfprotein5 .= codon2aa($codon);
}
 
for(my $i=0; $i < (length($longorf6) -2) ; $i += 3) {
$codon = substr($longorf6,$i,3);
$orfprotein6 .= codon2aa($codon);
}
 
#Remove Stop Codon Overhang
$orfprotein1 =~ s/_//g;
$orfprotein2 =~ s/_//g;
$orfprotein3 =~ s/_//g;
$orfprotein4 =~ s/_//g;
$orfprotein5 =~ s/_//g;
$orfprotein6 =~ s/_//g;
 
 
 
my $enzyme = $query->param('enzyme');
 
# Select an enzyme from the radio buttons on form
my $re;
if   ($enzyme eq   'TRYPSIN') { $re=qr/(?<=[KR])(?!P)/; }
elsif($enzyme eq 'ENDOPROTL') { $re=qr/(?<=K)(?!P)/; }
elsif($enzyme eq 'ENDOPROTA') { $re=qr/(?<=R)(?!P)/; }
elsif($enzyme eq    'V8PROT') { $re=qr/(?<=E)(?!P)/; }
else {die "Unknown enzyme selection '$enzyme'\n";}
 
 
# To cleave all proteins, and put then in the same array
my @parts;
foreach my $seq ($orfprotein1,$orfprotein2,$orfprotein3,$orfprotein4,$orfprotein5,$orfprotein6) {
    push @parts, split($re, $seq);
}
 
# Now, @parts contains everything
# Generate an array of all digested protein fragments
my @fragments = join("<br>\n", @parts); 
 
print "Content-type:  text/html
 
<html>
<head>
<link href='thrColElsHdr.css' rel='stylesheet' type='text/css' />
</head>
<div class='thrColElsHdr'>
 
<div id='container'>
  <div id='header'>
     
     <img src='dna.png' alt='DNA double helix' />
 
         <h2>Peptide mass/charge analyser</h2>
 
    
  <!-- end #header --></div>
  <div id='sidebar1'>
  
  <!-- end #sidebar1 --></div>
  <div id='sidebar2'>
  
  <!-- end #sidebar2 --></div>
  <div id='mainContent'>
  
<label>
<h2>Protein Digestion Results for $dna_header</h2>
 
 
</label>
<form id='form3' name='form3' method='post' action='mass.pl'>
<label>Please select a Mass to be analysed before continuing to the mass 
analyser:<br />    <br />
    <label>
      <input type='radio' name='mass' value='average' 
id='average' />
      Average</label>
    <label>
      <input type='radio' name='mass' value='mono-isotopic' 
id='mono-isotopic'
/>
      Mono-Isotopic</label>
    <br />
<br />
 
Please click here:
 
 
 
  <input type=\"hidden\" name=\"orfprotein1\" value=\"$orfprotein1\" />
  <input type=\"hidden\" name=\"orfprotein2\" value=\"$orfprotein2\" />
  <input type=\"hidden\" name=\"orfprotein3\" value=\"$orfprotein3\" />
  <input type=\"hidden\" name=\"orfprotein4\" value=\"$orfprotein4\" />
  <input type=\"hidden\" name=\"orfprotein5\" value=\"$orfprotein5\" />
  <input type=\"hidden\" name=\"orfprotein6\" value=\"$orfprotein6\" />
  <input type=\"hidden\" name=\"fragments\" value=\"@fragments\" />
  <input type=\"hidden\" name=\"fragments\" value=\"$enzyme\" />
  <input type=\"hidden\" name=\"fragments\" value=\"$dna_header\" />
<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>
 
</form>
 
<hr />
 
<p>List of protein cleavage fragments, cleaved with enzyme $enzyme;</p>
<p>@fragments</p>  
 
  
  
  
  
 
 
 
 
 
	<!-- end #mainContent --></div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class='clearfloat' />
   <div id='footer'>
<p><a href='Help.pl#references'>REFERENCES</a> | <a href='Help.pl#about'>ABOUT</a></p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</div>
</html>
 
";

Open in new window

0
Comment
Question by:StephenMcGowan
  • 2
2 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24417910
Since you are using web forms to pass the variables from ORFfinder.pl to mass.pl, you need to access those variables in mass.pl via the CGI API. For every parameter in the HTML being generated from ORFfinder.pl, the browser will re-post it to mass.pl as a web form.

For each form var in ORFfinder.pl:

  <input type=\"hidden\" name=\"foo\" value=\"$foo\" />

You'll need in mass.pl:

  my $foo = $query->param('foo');


Also, in mass.pl you'll need the CGI module the same as you have it in ORFfinder.pl, though you may already have it.

use CGI;

my $query = new CGI;


my $orfprotein1 = $query->param('orfprotein1');
my $orfprotein2 = $query->param('orfprotein2');
my $orfprotein3 = $query->param('orfprotein3');
my @fragments = $query->param('fragments');

0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24417921
And it is important to understand, the Perl scripts are not calling each other directly.

browser calls ORRfinder.pl -> ORFfinder.pl runs -> generates HTML output to browser -> browser posts to mass.pl

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 98
PERL get the value for query 4 157
Strange perl issue 6 131
Awk Question 2 131
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question