#!/usr/local/bin/perl

# purpose: take a splice predictor output file and a
# direct/reverse indication as parameters, and split 
# the input files into files for each sequences

sub usage
{
    die "usage: sp_reformat input_file direct/reverse";
}

if ($#ARGV != 1) {&usage;}

if (!-r $ARGV[0]) {die "can't have access to file $ARGV[0]";}

if ($ARGV[1] eq "direct") {$side=1;}
elsif ($ARGV[1] eq "reverse") {$side=2;}
else {&usage;}

open (INPUT_FILE, "<$ARGV[0]") || die "can't open file $ARGV[0]";

$copy=0;
while (<INPUT_FILE>)
{
    if ($_ =~ /^_+/ && $copy == 1) {close OUTPUT_FILE; $copy=0;next;}
    if (($seq) = ($_ =~ /^Sequence\s+\d+:\s+(\d+)/)) 
    {
	$copy=1;
	open (OUTPUT_FILE, ">seq${seq}splicep${side}.txt") || die "can't open output file seq${seq}splicep${side}.txt";
    }

    if ($copy == 1)
    {
	print OUTPUT_FILE;
    }
}

if ($copy) {close OUTPUT_FILE;}
close INPUT_FILE;


