next up previous
Next: 0.4 GNUPlot Basics Up: 0.3 Data Processing Previous: 0.3.1 Naive way (almost

0.3.2 Using Multipart (almost specifically Sequence data)

In this subsection we will check out how we can pass data a bit more elegantly (as data size goes up) from one HTML/CGI script to another. We'll be using a sequence file instead of copying n pasting stuff into a text field. Just create a sequence file with a few sequences and save it as (say) ``mysequence''. We will try to do clustalw again but this time we will upload the file directly using our browser.

Create a CGI file called ``/var/www/cgi-bin/L529guest/agopu/clustalw_file_upload.pl'' (as usual replace `agopu' ....) with the following content. A brief discussion follows the source code.

#!/usr/bin/perl
                                                                                                                             
use CGI qw(:standard);
                                                                                                                             
$query = new CGI;
$method="post";
$action="/cgi-bin/L529guest/agopu/clustalw_file_result.pl";
                                                                                                                             
print header, start_html;
print "\n";
print $query->start_multipart_form($method,$action,$encoding);
print "\n";
print filefield(-name=>'upload',-size=>60),br,submit(-label=>'Upload this file');
print "\n";
print $query->endform;
print "\n";
print end_html;

Create another CGI script called ``/var/www/cgi-bin/L529guest/agopu/clustalw_file_result.pl'' (as usual replace `agopu' ....) with the following content.

#!/usr/bin/perl
                                                                                                                             
use CGI qw(:standard);
                                                                                                                             
$file = param('upload');
                                                                                                                             
print header, start_html;
print "<pre>";
                                                                                                                             
my      $CLUSTALW="/usr/local/bio/bin/clustalw";
my      $DIR="/tmp/";
my      $TMPSEQS=$DIR."myseqs".$$;
                                                                                                                             
$|=1;
print " Temp FILENAME = $TMPSEQS<br>";
print " FILENAME Received = $file<br> Contents: <br>";
open(THISF, ">$TMPSEQS") or die "open $TMPSEQS failed";
while(<$file>) {
        print THISF  $_;
        print $_;
}
close THISF;
                                                                                                                             
system ("$CLUSTALW $TMPSEQS > $TMPSEQS.out 2>&1");
print " <p> Alignment: <br>";
open(THISF, "$TMPSEQS.aln") or die "open $TMPSEQS.aln failed";
while(<THISF>) {
        print $_;
}
close THISF;
print end_html;

Do not forget to change permissions for these files as shown in the previous section:

[L529guest@biokdd agopu]\$ chmod 755 /var/www/cgi-bin/L529guest/agopu/*.pl
This is the stuff you can expect to see on your browser if you visit:

http://biokdd.informatics.indiana.edu/cgi-bin/L529guest/agopu/clustalw_file_upload.pl

(Replace `agopu' with your user name or whatever you named your directory to be. Remove `L529guest' if you are using your own account.)

Figure 3: Screen shot of Clustalw.html using Multipart
\begin{figure}\epsfig{file=images/clustalw_file_upload.ps, width=16cm}
\end{figure}

Upload a sequence file using the Browse button and the Upload button. This is what you can expect to see as results of your script.



Figure 4: Screen shot of Clustalw.pl script output using Multipart
\begin{figure}\epsfig{file=images/clustalw_file_result.ps, width=16cm}
\end{figure}


next up previous
Next: 0.4 GNUPlot Basics Up: 0.3 Data Processing Previous: 0.3.1 Naive way (almost
Arvind Gopu 2006-03-24