#!/usr/bin/perl

my $input = shift;
my $base = $input;
$base =~ s/\..+//;
my $output = "$base.primers";

my $id;
#my (@id,@fwd,@rev);
my ($id,$fwd,$rev,$size);

open (IN, "<$input") or die "cannot open $input: $!\n";
open (OUT, ">$output") or die "cannot open $output: $!\n";

print OUT "OLIGO            start  len      tm     gc%   any    3' seq\n\n";

while (<IN>) {
    if (/^PRIMER PICKING RESULTS FOR (.+)$/) {
	$id = $1;
	next;
    }
    if (/^LEFT PRIMER/) {
	chomp ($fwd = $_);
	chomp ($rev = <IN>);
	die unless ($rev =~ /^RIGHT PRIMER/);
	next;
    }
    if (/^(PRODUCT SIZE: \d+),/) {
	$size = $1;
	print OUT "$id\n";	
	print OUT "$fwd\n";
	print OUT "$rev\n";
 	print OUT "$size\n\n";
	next;
    }
}
