Counting Nucleotides


#!/usr/bin/perl -w print "Please type filename of DNA sequence data: "; $dna_filename = <STDIN>; chomp $dna_filename; unless ( -e dna_filename ) { print "FILE NOT FOUND\n"; exit; } unless( open(DNAFILE, $dna_filename) ){ print "CANNOT OPEN FILE\n"; exit; } @DNA = <DNAFILE>; close DNAFILE; $DNA = join('',@DNA); $DNA =~ s/\s//g; #remove whitespace $a=0; $c=0; $g=0; $t=0; $e=0; while($DNA =~ /a/ig) {$a++} while($DNA =~ /c/ig) {$c++} while($DNA =~ /g/ig) {$g++} while($DNA =~ /t/ig) {$t++} while($DNA =~ /[^acgt]/ig) {$e++} print "A=$a, C=$c, G=$g, T=$t, errors=$e\n"; $outputfile = "countbase"; unless ( open(COUNTBASE, ">$outputfile") ) { print "CANNOT OPEN FILE\n"; exit; } print COUNTBASE "A=$a, C=$c, G=$g, T=$t, errors=$e\n"; close(COUNTBASE); exit;
ASSIGNMENT: