#! /usr/bin/perl

use IO::File;
use strict;

my $out=undef;
my $exp;
my $oldexp="";
my $header;
my %FILES;

my $io = new IO::File($ARGV[0], "r") || die "$!";
$header = $io->getline(); #shift header
while(<$io>) {
  chomp;
  ($exp) = (/^([^\t]+)\t/);
  if ($oldexp ne $exp) {
     $out = new IO::File($exp.".qtl", "w") || die "$!";
     $FILES{$exp}=$out;
     print $out $header;
  }
  print $out $_,"\n";
  $oldexp=$exp;
}
$io->close();
foreach my $of (keys(%FILES)) {
   close($FILES{$of});
}
