#!/usr/bin/perl ############################################## ############################################## # SCRIPT NAME: Page_Change_Format.cgi # FUNCTION: Different Formats for Database # Entries (to aid analysis) ############################################## # MINE: Molecular INformation Explorer # Copyright 2000 Dawn Field. All rights reserved. # The CGI-PERL scripts belonging to MINE # may be used and modified freely, but I do # request that this copyright notice remain attached # to this file/source code. If you make modifications # please do not distribute unless # you fully document the modifications. use CGI; require "CGI-MINE.pl"; # use the module Seq.pm from the bioperl package # you must install this yourself from http://bio.perl.org/ use lib "/users/www/htdocs/pseudomonas/cgi-bin/MINE/"; use Bio::Seq; # for revcom and translate, basic sequence object use Bio::SeqIO; # for switching formats... ################# # START EACH MINE CGI SCRIPT ################# # this redirects the error messages to the user's screen # and is useful for debugging CGI scripts! open (STDERR, ">&STDOUT"); # print errors to screen $| = 1; # flush the print buffer continuously # make a new query object using CGI.pm module $query = new CGI; # print the required header and start the web page print $query->header; print $query->start_html('MINE: File Conversion'); # Each time a script is invoked for the first time (or $action undef), # log the visit in the custom MINE server log (see CGI-MINE.pl) # (put this after the header incase an error message is printed) # check value of $action $action = ""; $action = $query->param('action'); if ($action eq undef) {&log();} ####### # START THE WEBPAGE ####### # print the MINE menu &menu; # start the basic gray table used for formatting MINE pages &table_top(); # put the main title of your page here print "Change Sequence Formats
";
############
# START FORM
############
&table_top();
# write a form to get a user input sequence
print $query->startform();
# TEXT must align LEFT
print $var = < Here is another MINE script that uses the bioperl module SeqIO.pm to inter-convert
1 or more sequences in a file between the most common file formats
(genbank, fasta, embl, gcg etc): Page_SeqIO_converter.cgi.
Hopefully more Perl-CGI scripts that use bioperl modules will appear
in MINE soon....
TEXT
print " ";
$demo_file = <*0001.db> || <*001.db>;
print "Enter a MINE file to convert (e.g. $demo_file): ",$query->textfield('savefile'),"\n";
print " ";
# name all the methods for changing format that are handled below in the script
@methods_to_call = ( 'fasta', 'html', 'revcom','translate', 'translate3', 'translate6');
# make nice labels corresponding to each of the values in @methods_to_call
%labels = (
"fasta" => "View in fasta format",
"html" => "View as HTML",
"revcom"=>"Reverse Complement",
"translate" => "Quick Translate (one frame only)",
"translate3" => "Quick Translate (all three 5'to 3' frames)",
"translate6" => "Quick Translate (six frames)",
);
# Start the radio check box (only one option can be selected by user)
print " Change Entry Format ";
print $query->submit('action', 'GO!');
# print a 'clear' button at end of form: script self-calls
print $query->defaults('Clear');
# put a hard break between the form and the output
print " ";
print $query->endform();
&table_bottom();
#################
# END FORM
#################
#################
# PROCESS FORM
################
# get the values
# get the values passed from the form by iterating over @my_methods
# get the values for "method_called" & "savefile"
@my_methods = ("method_called", "savefile"); # get all the form variables
foreach $my_methods (@my_methods) {
$$my_methods = $query ->param($my_methods) || undef;
}
# THIS WILL GO WITH NEW SEQ.pm just need seq for revcome and trans
# restore into $query everything in the database file and get these values too
$query = &restore_parameters($query) if $query->param('action') eq 'GO!';
@info = ("id", "def", "origin", "seq");
foreach $info (@info) {
$$info = $query ->param($info) || undef;
}
############ IF "html" ##################
if ($method_called eq html) {
&ToHtml($savefile); # read query to screen (html)
}
# check if an input sequence has been submitted (if not, undef $seq)
$seq = $query ->param(seq) || undef;
# once a sequence has been submitted, "analyze" it
if ($seq) {
&table_top();
$region = $seq;
# make a new object with the string in $region
if ($seq) {
$region_obj = Bio::Seq->new( -seq =>$region, -type => 'Dna');
}
############ IF "fasta" ##################
if ($method_called eq fasta) {
# try to get a def line to make the header
$header = $query ->param(def) || $query ->param(Definition) || undef;
if (!$header) {$header = "Sorry no header found";}
if ($header eq "-") {$header = "Header not entered (only a \"-\" found in header line of MINE file $file)";}
# get the length of the sequence and format it
$length_seq = length $region;
&wrap_output($region, $length_seq, $wrapped_seq);
print "The fasta formatted sequence of this file is: >$header $wrapped_seq ";
}
############ IF "revcom" ##################
if ($method_called eq revcom) {
# use the method revcom on the object and store results in $rev
$rev = $region_obj->revcom();
# get the actual string out of $rev (the reversed string)
$region = $rev->seq;
# get the length of the sequence and format it
$length_seq = length $region;
&wrap_output($region, $length_seq, $wrapped_seq);
print "The reverse complement of file $savefile: $wrapped_seq ";
}
############ IF "translate" ##################
if ($method_called eq translate) {
# use the method translate() on the object and store results in $seq
$seq = $region_obj->translate();
# get the actual sequence part of the object
$region = $seq ->seq;
# get the length of the sequence and format it
$length_seq = length $region;
&wrap_output($region, $length_seq, $wrapped_seq);
print "The translation of file $savefile: $wrapped_seq ";
}
############ IF "translate3" ##################
if ($method_called eq translate3) {
# use the method translate() on the object and store results in $seq
print "Three forward reading frames $wrapped_seq ";
}
}
############ IF "translate6" ##################
if ($method_called eq translate6) {
# use the method translate() on the object and store results in $seq
print "Three forward reading frames $wrapped_seq ";
}
print "Three reverse complemented reading frames $wrapped_seq ";
}
}
} # end if ($seq)
&table_bottom();
#################
# END PROCESS FORM
#################
# PRINT BOTTOM OF EACH WEB PAGE
# if $show_source is set to 1 show a link
# at the bottom of each script to the source
# code - pass the name of this script to the
# function in CGI-MINE.pl
if ($show_source) {
$script_name = $query->script_name();
&source ($script_name);
}
# ATTACH the MINE copywrite
&mine_cp;
print $query->end_html;
#################
# END WEBPAGE
#################
&table_bottom();
#############################
# FUNCTIONS
#############################
#############################
# FUNCTION: WRAP-OUTPUT
#############################
# takes a long sequence without
# line breaks and introduces
# a 70 character per line format
# Usage: &wrap_output($seq_no_format, $seq_no_format_length, $wrapped_seq);
# the new variable $wrapped_seq will hold the formatted sequence
#############################
sub wrap_output
{
my($string,$len) = @_;
my($offset) = 0;
$wrapped_seq = "";
$sub = "";
$LINE_WIDTH = 70;
while($offset < $len)
{
$sub = substr($string,$offset,$LINE_WIDTH);
$wrapped_seq .= "$sub\n";
$offset += $LINE_WIDTH;
}
}
sub save_parameters {
local($query) = @_;
local($filename) = &clean_name($query->param('savefile'));
if (open(FILE,">$filename")) {
$query->save(FILE);
close FILE;
print "Information has been saved to file $filename\n";
} else {
print "Error: couldn't write to file $filename: $!\n";
}
}
sub restore_parameters {
local($query) = @_;
local($filename) = &clean_name($query->param('savefile'));
if (open(FILE,$filename)) {
$query = new CGI(FILE); # Throw out the old query, replace it with a new one
close FILE;
# print "File $filename\n";
} else {
print "Error: couldn't restore file $filename: $!\n";
}
return $query;
}
# Very important subroutine -- get rid of all the naughty
# metacharacters from the file name. If there are, we
# complain bitterly and die.
sub clean_name {
local($name) = @_;
unless ($name=~/^[\w\._-]+$/) {
print "$name has naughty characters. Only ";
print "alphanumerics are allowed. You can't use absolute names.";
die "Attempt to use naughty characters";
}
return $name;
}
";
print $query->radio_group(-name=>'method_called',
-value=>[@methods_to_call],
-labels=>\%labels,
-linebreak=>'true');
# print some buttons
print "
";
for ($i=0; $i<3; $i++) {
# $seq is called $region...
$subseq = substr($region, $i);
$region_obj = Bio::Seq->new( -seq =>$subseq, -type => 'Dna');
$seq = $region_obj->translate();
# get the actual sequence part of the object
$trans = $seq ->seq;
# get the length of the sequence and format it
$length_seq = length $trans;
&wrap_output($trans, $length_seq, $wrapped_seq);
print "
";
for ($i=0; $i<3; $i++) {
# $seq is called $region...
$subseq = substr($region, $i);
$region_obj = Bio::Seq->new( -seq =>$subseq, -type => 'Dna');
$seq = $region_obj->translate();
# get the actual sequence part of the object
$trans = $seq ->seq;
# get the length of the sequence and format it
$length_seq = length $trans;
&wrap_output($trans, $length_seq, $wrapped_seq);
print "
";
# use the method revcom on the object and store results in $rev
$rev = $region_obj->revcom();
# get the actual string out of $rev (the reversed string)
$region = $rev->seq;
for ($i=0; $i<3; $i++) {
# $seq is called $region...
$subseq = substr($region, $i);
$region_obj = Bio::Seq->new( -seq =>$subseq, -type => 'Dna');
$seq = $region_obj->translate();
# get the actual sequence part of the object
$trans = $seq ->seq;
# get the length of the sequence and format it
$length_seq = length $trans;
&wrap_output($trans, $length_seq, $wrapped_seq);
print "