#!/usr/bin/perl

use strict;
my @map;
my $sep = "\t";
my $mastermap = "/projects/HS_Sequencing/ILLUMINA/BUILD34_GENOTYPES/MarkerMap.Build34";
my $data;
my $build = "34";

open(MAP, $mastermap) || die "Could not open $mastermap\n";
while(<MAP>) {
  chomp;
  my ( $marker, $chr, $strand, $bp, $snp ) = split;
  $data->{$snp} = [ $chr, $strand, $bp, $snp ];
}

foreach my $file ( glob( "*.basepairs")) {
  open(FILE, $file) || die "Could not open $file\n";
  while(<FILE>) {
    chomp;
    my ( $chr, $snp, $bp, $cm ) = split;
    warn "map error $snp $data->{$snp}[2] $bp\n" if ( $data->{$snp}[2] != $bp );
#    push @map, [ $snp, $build,$chr, $bp,$data->{$snp}[1], $cm];
    push @map, [ $snp, $chr, $bp];
  }
}

@map = sort { my $x = $a->[0] <=> $b->[0]; $x = $a->[1] <=> $b->[1] if ( ! $x ); $x} @map;

#print join( $sep, "marker","genome_build","chromosome","bp_position","strand","cm\n");
print join( $sep, "marker","chromosome","bp\n");

foreach my $ref ( @map ) {
  print join( $sep, @$ref ) . "\n";
}

