#!/usr/bin/perl -w # DNA.pm # First package to manipulate DNA sequences # (c) 2008/2/25 Natasha Khuri package DNA; # give this package a name sub count_base($$) { # expect two scalar my ($base, $dna) = @_; my %hash = (); while ( $char = chop($dna)) { $hash{$char}++; } return $hash{$base}; } # a complement is a string in which # A is replaced with T, C is replaced with G # T is replaced with A, G is replaced with C sub complement($) { # expect a string my ($dna) = @_; my $complement = ''; foreach ( split(//, $dna) ) { $complement .= 'A' if $_ eq 'T'; $complement .= 'T' if $_ eq 'A'; $complement .= 'C' if $_ eq 'G'; $complement .= 'G' if $_ eq 'C'; } return $complement; } return 1; # satisfy require statement