commit e61652e4b8820e795df8d92ccf24baecd5b37e66 parent 6f05e2607b226a9cdae9ee76e2f4a5fa8c38c40d Author: Samir Parikh <noreply@samirparikh.com> Date: Sat, 27 Nov 2021 16:38:56 +0000 update NucleotideCount.pm Diffstat:
M | nucleotide-count/NucleotideCount.pm | | | 16 | +++++++++++++++- |
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/nucleotide-count/NucleotideCount.pm b/nucleotide-count/NucleotideCount.pm @@ -6,7 +6,21 @@ our @EXPORT_OK = qw<count_nucleotides>; sub count_nucleotides { my ($strand) = @_; - return undef; + my %count = ( + 'A' => 0, + 'C' => 0, + 'G' => 0, + 'T' => 0 + ); + #print "\$strand is $strand\n"; + if ($strand =~ /[^ACGT]/) { + return "Invalid nucleotide in strand"; + } else { + foreach (split //, $strand) { + $count{$_}++; + } + } + return \%count; } 1;