Difference between revisions of "Exercise 5.4D"

From Earlham CS Department
Jump to navigation Jump to search
 
Line 1: Line 1:
 
Return to [[Week 2]]
 
Return to [[Week 2]]
 
<br>
 
<br>
Exercise 5.4 in <i>Beginning Perl for Bioinformatics</i></b>
+
Exercise 5.4 in <i>Beginning Perl for Bioinformatics</i>
  
 
<pre>
 
<pre>

Latest revision as of 11:49, 18 December 2009

Return to Week 2
Exercise 5.4 in Beginning Perl for Bioinformatics

#Ex 5-4 

#Pseudocode:

#Write program to calculate the reverse complement of a string of DNA.

#First, get DNA sequence from user input.

#Second, calculate reverse complement using substr

#Print result 

#my variables 

my $DNA = 0;

my $reversecomplement = 0;

my $base = 0;

my $position = 0; 

#Ask the user for a string of DNA (change it to upper)

print "Please input a string of DNA to get  its reverse complement:\n\n"; 

$DNA = <STDIN>;

chomp $DNA; 

#Calculate reverse complement (refer to pg. 80 and what if it is not uppercase) 

for ($position = 0 ; $position < length $DNA ; ++$position){ 

    $base = substr($dna, $position, 1); 

    if ( $base eq 'T' ) { 

       $reversecomplement = $reverse_dna.'A';

   

    } elsif ( $base eq 'A' ) { 

        $reversecomplement = $reverse_dna.'T'; 

    } elsif ( $base eq 'G' ) { 

        $reversecomplement = $reverse_dna.'C'; 

    } elsif ( $base eq 'C' ) { 

        $reverse_dna = $reverse_dna.'G';

    }

} 

#Strip $reverse_dna of it's first character (why??????) 

$reverse_dna =~ s/^0*//; 

#Print result 
 

print "The corresponding reverse complement sequence is: $reverse_dna.\n\n"; 

#The End         

exit;