summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);
+}