summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-21 11:04:18 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-21 11:04:18 -0500
commit8df97a656543017b5485276bdfef3961fa463486 (patch)
tree7a18de2e283f7cc2dee1efbb5dffe423767ac371
parentff3a114540a01c0a8a3eafe50068006ac1ce1075 (diff)
downloadrosalind-8df97a656543017b5485276bdfef3961fa463486.tar.gz
rosalind-8df97a656543017b5485276bdfef3961fa463486.zip
another solution
-rw-r--r--GRPH.pl40
1 files changed, 40 insertions, 0 deletions
diff --git a/GRPH.pl b/GRPH.pl
new file mode 100644
index 0000000..65c351e
--- /dev/null
+++ b/GRPH.pl
@@ -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);
+}