#!/usr/bin/env perl
#
# cat aaindex | aaindex.pl
#

use strict;
use warnings;

my $entry = "";
my $head = "";
while (my $l = <STDIN>) {
  if ($l =~ /^(\S+)/) {
    $head = $1;
  }
  if ($l =~ /^H +(\S+)/) {
    $entry = $1;
  }
  if ($head eq "R") {
    if ($l =~ /PMID: ?(\d+)/) {
      print "aaindex:$entry\tpubmed:$1\n";
    }
  }
  elsif ($head eq "C") {
    aaindex($l);
  }
  if ($l =~ /^\/\//) {
    $entry = "";
    $head = "";
  }
}

sub aaindex {
  my $s = shift;
  my @r = ($s =~ /([A-Z]{4}\d{6})/g);
  foreach my $e (@r) {
    print "aaindex:$entry\taaindex:$e\n";
  }
}

