Hi all,
I have a problem that I have a dna sequence and i want to count the number of times a particular pattern appears in the entire sequence(for ex. how many times the triplet ATT or ATG appears in the dna sequence ). I wrote a programme it finds only the pattern and i also want to get count of the pattern. Can anyone there help me i am giving the programme below.
Thanx
#!/usr/bin/perl
#searching for motifs
#Ask the user for the file name
print "Please enter the file name of the dna sequence data \n";
$dna_filename= <STDIN>;
print "For this program to run, the sequence file to be processed must be in the\n";
print "current working directory. Ie. in:\n";
system pwd;
print "\n";
#remive filename from dna file
chomp $dna_filename;
#open the file or exit
unless (open(DNAFILE,"$dna_filename")){
print "cannot open file \"$dna_filename\"\n\n";
exit;
}
#read the protein sequence data from the file and store it into
#an array variable @dna
@dna = <DNAFILE>;
#close the file we've read dna into @dna
close DNAFILE;
$dna = join('',@dna);
$dna =~ s/\s//g;
do {
print "Enter a motif to search for:";
$motif = <STDIN>;
chomp $motif;
if ( $dna =~ /$motif/i ){
print "I found it:\n\n";
}
else{
print "I couldn\'t find it\n\n";
}
}until ( $motif =~/^\s*$/ );
exit;