diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-11-19 02:49:04 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-11-19 02:49:04 -0600 |
commit | 705deaf4444a5200e1646b0fb58b5794c7296b81 (patch) | |
tree | 206b47fa209292e06e6e644bf32ff98c24731a7e | |
parent | 33fb8bbafbdb663fac565053a62d8bec24d04975 (diff) | |
download | rosalind-705deaf4444a5200e1646b0fb58b5794c7296b81.tar.gz rosalind-705deaf4444a5200e1646b0fb58b5794c7296b81.zip |
another solution
-rw-r--r-- | PDST.pl | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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); +} |