summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-11-19 02:49:04 -0600
committerJesse Luehrs <doy@tozt.net>2012-11-19 02:49:04 -0600
commit705deaf4444a5200e1646b0fb58b5794c7296b81 (patch)
tree206b47fa209292e06e6e644bf32ff98c24731a7e
parent33fb8bbafbdb663fac565053a62d8bec24d04975 (diff)
downloadrosalind-705deaf4444a5200e1646b0fb58b5794c7296b81.tar.gz
rosalind-705deaf4444a5200e1646b0fb58b5794c7296b81.zip
another solution
-rw-r--r--PDST.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/PDST.pl b/PDST.pl
new file mode 100644
index 0000000..811ca04
--- /dev/null
+++ b/PDST.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.016;
+
+my @dna;
+
+{
+ my $dna;
+ while (<>) {
+ chomp;
+ if (/^>(.*)/) {
+ push @dna, $dna if $dna;
+ $dna = '';
+ }
+ else {
+ $dna .= $_;
+ }
+ }
+ push @dna, $dna;
+}
+
+for my $dna1 (@dna) {
+ my @row;
+ for my $dna2 (@dna) {
+ push @row, sprintf "%0.2f", hamming($dna1, $dna2) / length($dna1);
+ }
+ say join(' ', @row);
+}
+
+sub hamming {
+ my ($str1, $str2) = @_;
+ return length(($str1 ^ $str2) =~ s/\x00//gr);
+}