Newer browsers recognize a <INPUT TYPE="FILE"> field. You can
generate this from CGI.pm with the filefield() function.
Annoying complication: You have to start the form with
start_multipart_form() rather than start_form().
#!/usr/bin/perl
# file: sequpload.pl
use CGI ':standard';
print header;
print start_html('Reverse Complementation'),
h1('Reverse Complementator'),
start_multipart_form,
"Enter your sequence here:",br,
textarea(-name=>'sequence',-rows=>5,-cols=>60),br,
'Or upload a sequence here: ',filefield(-name=>'uploaded_sequence'),
submit('Reverse Complement'),
end_form,
hr;
if ( param ) {
my $sequence;
# look for the uploaded sequence first...
if ( my $upload = param('uploaded_sequence') ) {
print h2("Reverse complement of $upload");
while (my $line = <$upload>) {
chomp $line;
next unless $line =~ /^[gatcnGATCN]/;
$sequence .= $line;
}
} else { # ... not found, so read it from the text field
print h2('Reverse complement');
$sequence = param('sequence');
}
$reversec = do_reverse($sequence);
$reversec =~ s/(.{60})/$1\n/g; # do word wrap
print pre($reversec);
}
print end_html;
sub do_reverse {
my $seq = shift;
$seq =~ s/\s//g; # strip whitespace
$seq =~ tr/gatcGATC/ctagCTAG/; # complement
$seq = reverse $seq; # and reverse
return $seq;
} |
|
| Contents | Next |