From 8df97a656543017b5485276bdfef3961fa463486 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 21 Oct 2012 11:04:18 -0500 Subject: another solution --- GRPH.pl | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 GRPH.pl 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); +} -- cgit v1.2.3