Solved

Sending data over to another Script at the click of a button!

Posted on 2009-05-17
5
178 Views
Last Modified: 2013-12-25
I have a perl script which generates a HTML output page.

Contained on this page is a button to send the user to a next page (mass.pl) where they can generate a second set of results.

Please click here:
<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>

this sends them to mass.pl.

What i'd like to do is, when they click the button and go to mass.pl, i'd like some variables to be sent over to mass.pl aswell so that this second set of results can be generated.

so... If user hits button --> User gets sent to mass.pl
                                     --> Data gets sent over, results generated in mass.pl

The script is below, i am trying to send over $orfprotein1, $orfprotein2, $orfprotein3, $orfprotein4, $orfprotein5, $orfprotein6 and @fragments
when the button is hit.

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.
 

require 'module.pm';

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();

   #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);

}
 

# Add N-terminal to each reading frame
 

$orfprotein1 = $orfprotein1 = "_$orfprotein1";

$orfprotein2 = $orfprotein2 = "_$orfprotein2";

$orfprotein3 = $orfprotein3 = "_$orfprotein3";

$orfprotein4 = $orfprotein4 = "_$orfprotein4";

$orfprotein5 = $orfprotein5 = "_$orfprotein5";

$orfprotein6 = $orfprotein6 = "_$orfprotein6";
 
 
 
 
 
 
 
 
 

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'>

  

  <form id='form2' name='form2' method='post' action='save.pl'>
 

<h2>Protein Digestion Results for $dna_header</h2>

<form method= 'link' action='save.pl'>

<label>To Save this data to a text file, Click Here:  <input class='form-button' type='submit' value='Save Results'>
 

</label>

</form>

<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:

<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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
Comment Utility

<form id=\"form2\" name=\"form2\" method=\"post\" action=\"save.pl\">

  <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=\"submit\" value=\"save\" />

</form>
 

    

Open in new window

0
 

Author Comment

by:StephenMcGowan
Comment Utility
Hi Adam.

The button is shown in the image below. Once the user has selected a mass, the button should take them to mass.pl and at the same time transfer over $orfprotein1, $orfprotein2, $orfprotein3, $orfprotein4, $orfprotein5, $orfprotein 6 and @fragments all to mass.pl.

The button to transfer the user over to mass.pl is:

<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>

so would i incorporate your advice, to say....

<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\" />
<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>

</form>

Thanks.

<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:

<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>
 

</form>

Open in new window

output101.jpg
0
 
LVL 39

Expert Comment

by:Adam314
Comment Utility
The second <form> tag isn't needed - you only need 1 form tag.
0
 

Author Comment

by:StephenMcGowan
Comment Utility
Yeah i've removed it, my only real query was tying in teh hidden buttons with the button which sends the user over to mass.pl: i.e.

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\" />
<form method= 'link' action='mass.pl'> <input class='form-button' type='submit' value='M/Z Analyser'>

because i noticed with your save button, you used:

<input type=\"submit\" value=\"save\" /> which is different, so i was wondering if there would be a problem? i've tried it, but i'm receiving a weird error message... something i'll probably have to set up in a related question. But as long as the code above is fine, then it's a huge weight of my mind, and it's not the code causing the error message.
0
 
LVL 39

Expert Comment

by:Adam314
Comment Utility
The second <form> tag in your HTML will cause a problem.  Other than that, your code looks correct.

If you don't want to have to put a \ in front of all the ", you should use some other character to quote your string.

Here is an example, these two line produce the exact same output.  It demonstrates how you can use some other character, in this case, curly braces.
print "this string \" has double \" quotes in it\n";

print qq{this string " has double " quotes in it\n};

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now