diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-10-21 11:04:18 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-10-21 11:04:18 -0500 |
commit | 8df97a656543017b5485276bdfef3961fa463486 (patch) | |
tree | 7a18de2e283f7cc2dee1efbb5dffe423767ac371 | |
parent | ff3a114540a01c0a8a3eafe50068006ac1ce1075 (diff) | |
download | rosalind-8df97a656543017b5485276bdfef3961fa463486.tar.gz rosalind-8df97a656543017b5485276bdfef3961fa463486.zip |
another solution
-rw-r--r-- | GRPH.pl | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -0,0 +1,40 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.016; + +my %dna; + +sub check_pair { + my ($name, $other) = @_; + return if $name eq $other; + if (substr($dna{$name}, 0, 3) eq substr($dna{$other}, -3)) { + say "$other $name"; + } + if (substr($dna{$other}, 0, 3) eq substr($dna{$name}, -3)) { + say "$name $other"; + } +} + +my ($name, $dna); +while (<>) { + chomp; + if (/^>(.*)/) { + my $new_name = $1; + if ($name) { + $dna{$name} = $dna; + for my $other (keys %dna) { + check_pair($name, $other); + } + } + $name = $new_name; + $dna = ''; + } + else { + $dna .= $_; + } +} +$dna{$name} = $dna; +for my $other (keys %dna) { + check_pair($name, $other); +} |