{{{
#!/usr/bin/perl
#
# Andy 20100920 reverse the string
#
# Sample:
# echo "ell" | test.pl
# DNASequence.pl DNAFile
#
# out:
# four different sequence
# Original, rever dna,
# Origianl complement, reversa complement
use strict;
# Reverse the contnet
my $DNA = <>;
chomp($DNA);
print ("Original sequence: $DNA\n");
my $reverseDNA = DNAReverse($DNA);
print ("Reverse sequence: $reverseDNA\n");
my $complementDNA = DNAComplement($DNA);
print ("postive complement sequence: $complementDNA\n");
my $reverseComplementDNA = DNAComplement($reverseDNA);
print ("Nagative complement sequence: $reverseComplementDNA");
#=======================================================================
# Need a DNA sequence
# Paramenter:
# DNA sequence as the parameter zero and to reverit
#=========================================================================
sub DNAReverse () {
chomp($_[0]);
my $reverse = reverse($_[0]);
#print "reverse: $reverse\n";
return $reverse;
}
# change the content for
#my $string = "hello Andy";
#print substr($string, 6, 1);
#=====================================================
# Action the DNA complement
# Parameter:
# [0] is the DNA and change to the complement
#
# MEthod:
# A->T,
# T->A,
# G->C,
# C->G
#
# Return
# complement array
#
#================================================================
sub DNAComplement () {
# Declare the hash of chage complemt content
my %complementHash = ("A"=> "T", "T" => "A", "G" => "C", "C" => "G");
#print "hash array $complementHash{'A'}"; # Test OK
# Declare the complement DNA sequence
my $complementDNA;
# Preprocess the parameter
chomp($_[0]);
my $DNA = $_[0];
#print "hash DNA: $DNA\n"; # for deub
# Run the change method
for (my $i = 0; $i < length($DNA); $i++)
{
my $unit = $complementHash{ substr($DNA, $i, 1) };
#print ($unit);
$complementDNA = $complementDNA.$unit;
#print ("complement $complementDNA");
} # end process the complement for string
return $complementDNA;
}
}}}
2010年9月22日 星期三
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言