#!/usr/bin/perl -w

my $usage = "Usage: $0 feat [execdir [datadir]]\n" .
  "  feat\t\tOne or two letter identifier of conditioning feature\n" .
  "  execdir\tDirectory in which executables reside (default curdir/exec)\n" .
  "  datadir\tDirectory in which data resides (default curdir/data)\n\n";

my $feature = shift or die $usage;
die $usage if $feature eq '-h';
chomp(my $pwd = `pwd`);
my $execpath = shift || "$pwd/exec/";
my $datapath = shift || "$pwd/data/";
#$datapath = $pwd . "/" . $datapath if '/' ne substr $datapath, 0, 1;
#$datapath .= "/" if '/' ne substr $datapath, -1;
#$execpath = $pwd . "/" . $execpath if '/' ne substr $execpath, 0, 1;
#$execpath .= "/" if '/' ne substr $execpath, -1;

print STDERR $execpath, "\n", $datapath, "\n";

foreach my $exe (qw(rCounts selFeats iScale trainRs)) {
  die "Can't find executable $exe in $execpath, aborting" 
	if !-e "$execpath/$exe";
}

unlink $datapath . $feature . ".ff";
system ("$execpath/rCounts", '-P', $feature, $datapath);
unlink $datapath . $feature . ".f";
system ("$execpath/selFeats", $feature, 98, $datapath);
unlink $datapath . $feature . ".g";
system ("$execpath/iScale", $feature, $datapath);
system ("$execpath/trainRs", $feature, $datapath);
