#!/usr/bin/perl

use strict;

my $comp = { "A"=>"T", "C"=>"G", "G"=>"C", "T"=>"A"};

my $submitted = "~/public_html/MOUSE/HS/final-9-2-5.csv";
my $submit;
open(SUBMITTED, "dos2unix < $submitted|");
while(<SUBMITTED>) {
	chomp;
	my ( $rs,$seq ) = split /,/;
	my ( $left, $a1, $a2, $right ) = $seq =~ /^(.+)\[(.).(.)\](.+)$/;
	$submit->{$rs} = [$left, $a1, $a2, $right];
}	

my $returned = "/scratch/jf/Oxford_Allele_Report_04012005.csv";
my $bad = 0;
my $good = 0;
my $reversed = 0;
my $missed = 0;
open(RETURNED, "dos2unix <$returned|");
while(<RETURNED>) {
	chomp;
	my ( $rs,$a1, $a2,$seq ) = split /,/;
	if ( exists( $submit->{$rs} ) ) {
		if ( ( $a1 eq $submit->{$rs}[1] && $a2 eq $submit->{$rs}[2] ) || ($a1 eq $submit->{$rs}[2] && $a2 eq $submit->{$rs}[1] )) {
			$good ++;
			print "$good $rs $a1 $a2 ok\n";
		}
		else {
			my $r1 = $comp->{$a1};
			my $r2 = $comp->{$a2};
		if ( ( $r1 eq $submit->{$rs}[1] && $r2 eq $submit->{$rs}[2] ) || ($r1 eq $submit->{$rs}[2] && $r2 eq $submit->{$rs}[1] )) {
			$reversed ++;
			print "$reversed $rs $r1 $r2 reversed\n";

		}
else {
			$bad++;
			print "$bad $rs $a1 $a2 $submit->{$rs}[1] $submit->{$rs}[2]\n"; }
}
	
}	
	else {
		$missed++;
		print "$missed $rs missed\n";
	}

}
