Our Sponsors



Download BioinformaticsOnline(BOL) Apps in your chrome browser.




  • BioScripts
  • Anjana
  • Perl script to count the number of Adenine, Thymine, Guanine and Cytosine in your DNA Sequence

Perl script to count the number of Adenine, Thymine, Guanine and Cytosine in your DNA Sequence

  • Public
By Anjana 2879 days ago
#!/usr/local/bin/perl -w # While executing this script it asks for the file name of the DNA sequence. If the sequence file is not available in the same directory of this script, enter the name of the file along with the path. In windows: c:\dnafile.txt, In Linux: /home/user/sequence/dnafile.txt print "ENTER THE FILENAME OF THE DNA SEQUENCE:= "; $dna_filename = <STDIN>; chomp $dna_filename; unless ( open(DNAFILE, $dna_filename) ) { print "Sorry the file does not exist!!! \n"; print "Cannot open file \"$dna_filename\"\n"; die; } @DNA = <DNAFILE>; close DNAFILE; $DNA = join( '', @DNA); print " \n The original DNA file is:\n $DNA \n"; $DNA =~ s/\s//g; @DNA = split( '', $DNA ); $count_of_A = 0; $count_of_C = 0; $count_of_G = 0; $count_of_T = 0; $errors = 0; foreach $base (@DNA) { if ( $base eq 'a' ) { ++$count_of_A; } elsif ( $base eq 'c' ) { ++$count_of_C; } elsif ( $base eq 'g' ) { ++$count_of_G; } elsif ( $base eq 't' ) { ++$count_of_T; } elsif ( $base eq 'T' ) { ++$count_of_T; } elsif ( $base eq 'C' ) { ++$count_of_C; } elsif ( $base eq 'A' ) { ++$count_of_A; } elsif ( $base eq 'G' ) { ++$count_of_G; } else { print "Error - Unknown base: $base\n"; ++$errors; } } print "Adenine = $count_of_A\n"; print "Cytosine = $count_of_C\n"; print "Guanine = $count_of_G\n"; print "Thymine = $count_of_T\n"; if ($errors) { print "There were $errors unrecognized bases.\n"; }