#!/usr/bin/perl 

# This script will convert the genomic coordinates to different versions
# I have generated conversion algorithms based on differences generated by 
# the EMBOSS 'diffseq' program between several different versions.
# 

use strict;
use File::Copy;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use tim_file_helper qw(
	open_tim_data_file
	write_tim_data_file
	open_to_write_fh
);

print "\n This script will convert yeast genomic coordinates\n";

# useage
unless (@ARGV) {
	print " Usage: convert_genome_version.pl filename [conversion number]\n";
	&print_version_choices;
	exit;
}

# run parameters
my $filename = $ARGV[0];
my $version = $ARGV[1];



# Ask for which conversion
unless ($version) {
	&print_version_choices;
	print " enter the number of the conversion you want   ";
	$version = <STDIN>;
	chomp $version;
}
my $goconvert; # this will be a reference to the appropriate version subroutine
my $old_version_number; # the date of the originating version
my $new_version_number; # the date of the new version
if ($version == 1) {
	$goconvert = \&version_20050806_20070113;
	$old_version_number = '20050806';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 2) {
	$goconvert = \&version_20051106_20070113;
	$old_version_number = '20051106';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 3) {
	$goconvert = \&version_20060204_20070113;
	$old_version_number = '20060204';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 4) {
	$goconvert = \&version_20031001_20070113;
	$old_version_number = '20031001';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 5) {
	$goconvert = \&version_200601xx_20070113;
	$old_version_number = '200601xx';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 6) {
	$goconvert = \&version_20060916_20070113;
	$old_version_number = '20060916';
	$new_version_number = '20070113';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 7) {
	$goconvert = \&version_20070113_20100109;
	$old_version_number = '20070113';
	$new_version_number = '20100109';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 8) {
	$goconvert = \&version_20050806_20100109;
	$old_version_number = '20050806';
	$new_version_number = '20100109';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
elsif ($version == 9) {
	$goconvert = \&version_20070113_20100109;
	# the 20070113 and 20070901 versions are identical so reuse the sub
	$old_version_number = '20070901';
	$new_version_number = '20100109';
	print " converting file '$filename' from version $old_version_number to " . 
		"$new_version_number...\n";
} 
else {
	die " unknown version conversion!\n";
}




# Open the input file
my ($fh, $metadata_ref) = open_tim_data_file($filename);

# Identify the columns
my $chromo_index;
my $pos_index; # first position, or start
my $pos2_index; # a second position, or end
if ($metadata_ref->{extension} =~ /sgr/i) { 
	# file is a *.sgr
	$chromo_index = 0;
	$pos_index = 1;
} 
elsif ($metadata_ref->{extension} =~ /gff/i) { 
	# file is a gff file
	$chromo_index = 0;
	$pos_index = 3;
	$pos2_index = 4;
} 
elsif ($metadata_ref->{extension} =~ /bed/i) { 
	# file is a bed file
	$chromo_index = 0;
	$pos_index = 1;
	$pos2_index = 2;
} 
else { 
	# a non-standard file
	# identify the indices to the genomic coordinates
	for (my $i = 0; $i < $metadata_ref->{'number_columns'}; $i++) {
		# check the names of each column
		# looking for chromo, start, stop
		if ($metadata_ref->{$i}{'name'} =~ /^chr|refseq/i) {
			$chromo_index = $i;
		}
		elsif ($metadata_ref->{$i}{'name'} =~ /start/i) {
			$pos_index = $i;
		}
		elsif ($metadata_ref->{$i}{'name'} =~ /stop|end/i) {
			$pos2_index = $i;
		}
	}
	unless ( 
		# check that we have these basic genomic coordinates
		defined $chromo_index and
		defined $pos_index
	) {
		die " unable to identify chromosome, start, and/or stop datasets!";
	}
	print " Using column $chromo_index for chromosome, $pos_index for start";
	if (defined $pos2_index) {
		print ", $pos2_index for stop\n";
	}
	else {
		print "\n";
	}
}




# Open the output file
my $gz;
if ($metadata_ref->{extension} =~ /gz/) {
	$gz = 1;
}
else {
	$gz = 0;
}
push @{ $metadata_ref->{other} }, 
	# record a miscelleneous header line to explain the conversion
	"# Converted genome coordinates from $old_version_number to $new_version_number";
$metadata_ref->{data_table} = []; # create an empty data table
push @{ $metadata_ref->{data_table} }, $metadata_ref->{'column_names'};
my $new_filename = $metadata_ref->{path} . $metadata_ref->{basename} . '.' . 
	$new_version_number . $metadata_ref->{extension};
unless ( write_tim_data_file( {
		'data'       => $metadata_ref,
		'filename'   => $new_filename,
		'gz'         => $gz,
	} )
) {
	die " unable to open file for writing!\n";
}
my $out_fh = open_to_write_fh($new_filename, $gz, 1) or 
	die " unable to re-open file for writing!\n";



# Do the conversion
my $totalcount = 0; # a running tally
my $changecount = 0; # a running tally
while (my $line = $fh->getline) {
	my $changed = 0;
	
	# process each line
	chomp $line;
	my @data = split /\t/, $line;
	my $chromo = $data[$chromo_index];
	my $position = $data[$pos_index];
	
	# convert the first position
	my $newposition = &{$goconvert}($chromo, $position); # do the conversion
	if ($newposition != $position) {
		$data[$pos_index] = $newposition;
		$changed = 1;
	}
	
	# convert the second position if necessary
	if (defined $pos2_index) {
		my $position2 = $data[$pos2_index];
		if ($position == $position2) {
			# they're the same position, often the case in my gff files
			# then match the new position if necessary
			if ($newposition != $position) {
				$data[$pos2_index] = $newposition;
			}
		} 
		else {
			# using different start and end positions
			my $newposition2 = &{$goconvert}($chromo, $position2); 
			if ($newposition2 != $position2) {
				$data[$pos2_index] = $newposition2;
				$changed = 1;
			}
		}
	}
		
	# put back
	$changecount++ if $changed;
	$totalcount++;
	print {$out_fh} join("\t", @data) . "\n";	
}
close INFILE;
print " converted $changecount out of $totalcount features to new coordinates\n";


# Finish
$fh->close;
$out_fh->close;
print " wrote converted file '$new_filename'\n";


# the conversion subroutines
	# the adjustment numbers below were obtained by running the EMBOSS program 
	# 'diffseq' on the two sequences. I used -wordsize of 10 and -globaldifferences Y
	# I wrote a shell script find_diffs.sh to expediate the search
	# The diffseq program will report the location and sequence changes between the two 
	# sequence versions. I am using the highest position of the 2003 sequence as 
	# my trigger below, and using the difference in length between the two mismatched 
	# regions. If 2007 is longer, then +; if 2003 is longer, then -.
	
	# new version subroutines may be added by duplicating the subroutine,
	# renaming it, and making the necessary changes. Don't forget to add it to the
	# choice menu below

sub print_version_choices {
print " Available conversions:
   1) 20050806 to 20070113
   2) 20051106 to 20070113
   3) 20060204 to 20070113
   4) 20031001 (UCSC SacCer1) to 20070113
   5) 200601xx to 20070113
   6) 20060916 (Pugh's GeneTrack) to 20070113
   7) 20070113 (my old standard) to 20100109
   8) 20050806 (perocchi..steinmetz version) to 20100109
   9) 20070901 (xu..steinmetz version) to 20100109
";
}


sub version_20050806_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		if ($position >= 76147) {$new += 1}
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 478026) {$new += 1}
		if ($position >= 613205) {$new += 1}
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		if ($position >= 946899) {$new += 1}
		if ($position >= 962548) {$new -= 1}
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		if ($position >= 54132) {$new += 1}
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 101726) {$new += 1}
		if ($position >= 120804) {$new += 6}
		if ($position >= 120890) {$new += 72}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		if ($position >= 185987) {$new -= 2}
		if ($position >= 255409) {$new += 1}
		if ($position >= 363801) {$new += 1}
		if ($position >= 552426) {$new += 1}
		if ($position >= 552516) {$new -= 1}
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		if ($position >= 922648) {$new += 1}
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		if ($position >= 60402) {$new += 1}
		if ($position >= 68346) {$new += 1} # this one is not present in 20051106
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		if ($position >= 42534) {$new += 1}
		if ($position >= 803745) {$new += 1}
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}



sub version_20051106_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		if ($position >= 76147) {$new += 1}
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 478026) {$new += 1}
		if ($position >= 613205) {$new += 1}
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		if ($position >= 946899) {$new += 1}
		if ($position >= 962548) {$new -= 1}
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		if ($position >= 54132) {$new += 1}
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 101726) {$new += 1}
		if ($position >= 120804) {$new += 6}
		if ($position >= 120890) {$new += 72}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		if ($position >= 185987) {$new -= 2}
		if ($position >= 255409) {$new += 1}
		if ($position >= 363801) {$new += 1}
		if ($position >= 552426) {$new += 1}
		if ($position >= 552516) {$new -= 1}
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		if ($position >= 922648) {$new += 1}
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		if ($position >= 60402) {$new += 1}
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		if ($position >= 42534) {$new += 1}
		if ($position >= 803745) {$new += 1}
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}



sub version_20060204_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		# no changes
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		#if ($position >= 478023) {$new += 1}
		# comment this out for Segal's 2006 version only
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		# no changes
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		# no changes
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 120805) {$new += 6}
		if ($position >= 120891) {$new += 72}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		# no changes
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		# no changes
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		# no changes
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		# no changes
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}


sub version_200601xx_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		# no changes
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 478023) {$new += 1}
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		# no changes
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		# no changes
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 120805) {$new += 6}
		if ($position >= 120891) {$new += 72}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		# no changes
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		# no changes
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		# no changes
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		# no changes
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}

sub version_20060916_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		# no changes
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		# no changes
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		# no changes
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		# no changes
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 120805) {$new += 6}
		if ($position >= 120891) {$new += 72}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		# no changes
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		# no changes
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		# no changes
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		# no changes
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}


sub version_20031001_20070113 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		if ($position >= 41778) {$new += 1}
		if ($position >= 51691) {$new -= 2}
		if ($position >= 130247) {$new += 1}
		if ($position >= 143846) {$new += 1}
		if ($position >= 166768) {$new -= 1}
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		if ($position >= 18364) {$new += 1}
		if ($position >= 21346) {$new += 4}
		if ($position >= 40893) {$new -= 2}
		if ($position >= 93896) {$new += 1}
		if ($position >= 96957) {$new += 37}
		if ($position >= 203175) {$new += 1}
		if ($position >= 216779) {$new -= 1}
		if ($position >= 320082) {$new -= 2}
		if ($position >= 366381) {$new -= 1}
		if ($position >= 457296) {$new += 1}
		if ($position >= 553996) {$new += 1}
		if ($position >= 742173) {$new += 2}
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		if ($position >= 76147) {$new += 1}
		if ($position >= 101692) {$new += 4}
		if ($position >= 105969) {$new -= 1}
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 235713) {$new += 1}
		if ($position >= 478022) {$new += 1}
		if ($position >= 503839) {$new += 1}
		if ($position >= 613203) {$new += 1}
		if ($position >= 819477) {$new += 1}
		if ($position >= 1192051) {$new -= 1}
	# no changes for Chromosome 5
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		if ($position >= 231670) {$new -= 1}
		if ($position >= 242179) {$new += 1}
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		if ($position >= 53811) {$new += 1}
		if ($position >= 93036) {$new += 1}
		if ($position >= 93253) {$new += 1}
		if ($position >= 93423) {$new -= 1}
		if ($position >= 124278) {$new += 1}
		if ($position >= 124330) {$new -= 1}
		if ($position >= 130105) {$new += 1}
		if ($position >= 130297) {$new -= 1}
		if ($position >= 130414) {$new -= 1}
		if ($position >= 131043) {$new += 1}
		if ($position >= 506671) {$new += 1}
		if ($position >= 946896) {$new += 1}
		if ($position >= 952554) {$new -= 1}
		if ($position >= 962546) {$new -= 1}
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		if ($position >= 54135) {$new += 1}
		if ($position >= 98460) {$new += 1}
		if ($position >= 217748) {$new -= 1}
		if ($position >= 367891) {$new += 1}
		if ($position >= 455307) {$new += 1}
		if ($position >= 455502) {$new += 1}
	# no changes for Chromosome 9
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 89893) {$new += 1}
		if ($position >= 101724) {$new += 1}
		if ($position >= 118302) {$new -= 1}
		if ($position >= 120804) {$new += 6}
		if ($position >= 120890) {$new += 72}
		if ($position >= 121257) {$new += 220}
		if ($position >= 411267) {$new += 1}
		if ($position >= 460191) {$new -= 1}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		if ($position >= 48828) {$new += 1}
		if ($position >= 58939) {$new += 3}
		if ($position >= 185983) {$new -= 2}
		if ($position >= 255405) {$new += 1}
		if ($position >= 363798) {$new += 1}
		if ($position >= 374307) {$new += 1}
		if ($position >= 550828) {$new += 1}
		if ($position >= 552420) {$new += 1}
		if ($position >= 552510) {$new -= 1}
		if ($position >= 603770) {$new += 1}
		if ($position >= 611272) {$new += 1}
		if ($position >= 638899) {$new += 1}
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		if ($position >= 553548) {$new += 1}
		if ($position >= 553629) {$new += 1}
		if ($position >= 760764) {$new -= 2}
		if ($position >= 899751) {$new += 1}
		if ($position >= 922644) {$new += 1}
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		if ($position >= 804684) {$new -= 1}
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		if ($position >= 60402) {$new += 1}
		if ($position >= 68346) {$new += 1}
		if ($position >= 254767) {$new += 1}
		if ($position >= 254925) {$new += 1}
		if ($position >= 271648) {$new += 1}
		if ($position >= 472581) {$new -= 1}
		if ($position >= 505511) {$new += 1}
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		if ($position >= 42534) {$new += 1}
		if ($position >= 803745) {$new += 1}
		if ($position >= 877622) {$new += 2}
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		if ($position >= 347285) {$new += 1}
		if ($position >= 347373) {$new += 1}
	}
	# no changes for Chromosome MT
	return $new;
}



sub version_20070113_20100109 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		# no changes
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 382379) {$new += 1}
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		if ($position >= 1038054) {$new += 1}
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		# no changes
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 126896) {$new -= 1}
		if ($position >= 599597) {$new -= 1}
		if ($position >= 599640) {$new -= 1}
		if ($position >= 599715) {$new -= 1}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		# no changes
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		# no changes
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		if ($position >= 472585) {$new += 1}
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		# no changes
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}



sub version_20050806_20100109 {
	my ($chromo, $position) = @_;
	my $new = $position;
	if ($chromo =~ /^chr0?1$/i) { # Chromosome 1
		# no changes
	} elsif ($chromo =~ /^chr0?2$/i) { # Chromosome 2
		# no changes
	} elsif ($chromo =~ /^chr0?3$/i) { # Chromosome 3
		if ($position >= 76147) {$new += 1}
	} elsif ($chromo =~ /^chr0?4$/i) { # Chromosome 4
		if ($position >= 382381) {$new += 1}
		if ($position >= 478023) {$new += 1}
		if ($position >= 613205) {$new += 1}
	} elsif ($chromo =~ /^chr0?5$/i) { # Chromosome 5
		# no changes
	} elsif ($chromo =~ /^chr0?6$/i) { # Chromosome 6
		# no changes
	} elsif ($chromo =~ /^chr0?7$/i) { # Chromosome 7
		if ($position >= 946899) {$new += 1}
		if ($position >= 962548) {$new -= 1}
		if ($position >= 1038054) {$new += 1}
	} elsif ($chromo =~ /^chr0?8$/i) { # Chromosome 8
		if ($position >= 54132) {$new += 1}
	} elsif ($chromo =~ /^chr0?9$/i) { # Chromosome 9
		# no changes
	} elsif ($chromo =~ /^chr10$/i) { # Chromosome 10
		if ($position >= 101726) {$new += 1}
		if ($position >= 120804) {$new += 6}
		if ($position >= 120890) {$new += 72}
		if ($position >= 126817) {$new -= 1}
		if ($position >= 599518) {$new -= 1}
		if ($position >= 599561) {$new -= 1}
		if ($position >= 599636) {$new -= 1}
	} elsif ($chromo =~ /^chr11$/i) { # Chromosome 11
		if ($position >= 185979) {$new -= 1}
		if ($position >= 185987) {$new -= 1}
		if ($position >= 255409) {$new += 1}
		if ($position >= 363801) {$new += 1}
		if ($position >= 552426) {$new += 1}
		if ($position >= 552516) {$new -= 1}
	} elsif ($chromo =~ /^chr12$/i) { # Chromosome 12
		if ($position >= 922648) {$new += 1}
	} elsif ($chromo =~ /^chr13$/i) { # Chromosome 13
		# no changes
	} elsif ($chromo =~ /^chr14$/i) { # Chromosome 14
		if ($position >= 60402) {$new += 1}
		if ($position >= 68346) {$new += 1}
		if ($position >= 472579) {$new += 1}
	} elsif ($chromo =~ /^chr15$/i) { # Chromosome 15
		if ($position >= 42534) {$new += 1}
		if ($position >= 803745) {$new += 1}
	} elsif ($chromo =~ /^chr16$/i) { # Chromosome 16
		# no changes
	}
	# no changes for Chromosome MT
	return $new;
}






