#!/usr/local/bin/perl
#FILE: createBanderMarkers
#Author: Terry Furey
#Date: 6/10/2004
#Description: Convert fishClones.bed file to input file for
# bander software

if ($#ARGV != 0) {
    print stderr "USAGE: createBanderMarkers <fishClones.bed>\n";
    exit(1);
}
$file = shift(@ARGV);
open(FILE, "$file") || die("Could not open $file\n");

# Read in and convert
while ($line = <FILE>) {
    ($chr, $start, $end, $clone, $score, $mapcount, $mapstart, $mapend, $center, @rest) = split("\t",$line);
    @mstart = split(",", $mapstart);
    @mend = split(",", $mapend);
    @mcenters = split(",", $center);
    for ($i = 0; $i < $mapcount; $i++) {
	if ((substr($mstart[$i], 1, 1) eq "p") 
	    || (substr($mstart[$i], 1, 1) eq "q")
	    || (substr($mstart[$i], 1, 1) eq "c")) {
	    $fishchr = substr($mstart[$i], 0, 1);
	    $mstart = substr($mstart[$i], 1);
	    $mend = substr($mend[$i], 1);
	} elsif ((substr($mstart[$i], 2, 1) eq "p")
	    || (substr($mstart[$i], 2, 1) eq "q")
	    || (substr($mstart[$i], 2, 1) eq "c")) {
	    $fishchr = substr($mstart[$i], 0, 2);
	    $mstart = substr($mstart[$i], 2);
	    $mend = substr($mend[$i], 2);
	} else {
	    print stderr "Could not parse $mstart[$i]\n";
	}
	print "$chr\t$start\t$end\t$clone\t$mstart\t$mend\t$mcenters[$i]\tfalse\t$fishchr\n";
    }
}

