#!/usr/local/bin/perl
# File: runBander
# Author: Terry Furey
# Date: 1/1/01
# Project: Human
# Description: Runs the bander program to predict the locations of the cytogenetic bands

# Usage message
if ($#ARGV != 3) {
  print stderr "USAGE: runBander <FISH> <ISCN> <set bands> <ctg dir>\n";
  exit(1);
}

# Read parameters
$markerfile = shift(@ARGV);
$bandfile = shift(@ARGV);
$setbandfile = shift(@ARGV);
$ctgdir = shift(@ARGV);
@chroms = (1..22,X,Y);

# Find lengths of each of the chromosomes
foreach $thischr (@chroms) {
  open(CTG, "<$ctgdir/$thischr/lift/ordered.lft") || die("Could not open $ctgdir/$thischr/lift/ordered.lft");
  $line = <CTG>;
  chomp($line);
  ($start, $name, $ctglen, $chr, $chrlen) = split(' ',$line);
  $length{$thischr} = $chrlen;
  close(CTG);
}

# Run bander on each of the chromosomes
foreach $chr (@chroms) {
  $command =  "bander chr$chr $bandfile $markerfile $setbandfile $chr $length{$chr} 100 2.0 2";
  print stderr "$command\n";
  system($command);
}

# Compile the results into a single file
`cat chr[1,2,3,4,5,6,7,8,9].bed chr1[0,1,2,3,4,5,6,7,8,9].bed chr2[0,1,2].bed chr[X,Y].bed > cytobands.bed`;
`rm chr*.bed`;

