#!/usr/bin/perl

use strict;

my $build37 = "build37.map";
my $mm10 = "hglft_genome_751b_dcc510.bed";

open(BUILD37,$build37) || die "Could not open $build37\n";

my @b37;
my $snp37;
while(<BUILD37>) {
    chomp;
    my @a = split;
    push @b37, \@a;
    $snp37->{$a[3]} = \@a;
}
close(BUILD37);

open(MM10,$mm10) || die "Could not open $mm10\n";

my @m10;
my $snp10;
while(<MM10>) {
    chomp;
    my @a = split;
    push @m10, \@a;
    $snp10->{$a[3]} = \@a;
}
close(MM10);

foreach my $snp ( keys %$snp37 ) {
    if ( exists( $snp10->{$snp} )) {
	print "$snp:  $snp10->{$snp}[0]  $snp37->{$snp}[0]\n" if ( $snp10->{$snp}[0] ne $snp37->{$snp}[0] ) ;
    }
    else {
	print "$snp: null  $snp37->{$snp}[0]\n";
    }
}

my $n=0;
for( my $k=1;$k<$#b37;$k++) {
    if ( $b37[$k-1][0] eq $b37[$k][0] && $b37[$k+1][0] eq $b37[$k][0] ) {
	my $s1 = $b37[$k-1][3];
	my $s2 = $b37[$k][3];
	my $s3 = $b37[$k+1][3];
	my $r1 = $snp10->{$s1};
	my $r2 = $snp10->{$s2};
	my $r3 = $snp10->{$s3};
	if ( !( $r1->[0] eq $r1->[0] && $r2->[0] eq $r3->[0] && $r1->[1] < $r2->[1] && $r2->[1] < $r3->[1] )) {
	    $n++;
	    print "$n " . join( " " , @{$b37[$k]}, @{$r2}) . "\n";
	}
    }
}

    
