
package Shape;

use Exporter;
@ISA = (Exporter);
@EXPORT = qw(RunShapeMode);

sub new{

    my $this = shift;
    my (
	$infile,
	$outfile, 
	$alpha,
	$maxgap, 
	$CovThreshold,
	$LenThreshold,
	$bothendzero,
	$cut 
	) = @_ ;
    
    my $Shape = {
	"in" => $infile,
	"out" => $outfile,
	"alpha" => $alpha,
        "maxgap" => $maxgap,
        "CovThreshold" => $CovThreshold,
	"LenThreshold" => $LenThreshold,
	"bothendzero" => $bothendzero,
	"cut" => $cut
    };

    bless $Shape, $this;
    return $Shape;
}

sub RunShapeMode
{
    $this = shift;
    my $options = &makeCommandOptions($this);
    my $bindir = $FindBin::Bin."/bin";
    #print "$bindir/ShapeAlign $options\n";
    system("$bindir/ShapeAlign $options");
}

sub makeCommandOptions
{
    my $this = shift;
    my $options="";
    $options.="-c $this->{in} -o $this->{out} -t $this->{CovThreshold} ";
    if($this->{LenThreshold} > 0){$options.="-l $this->{LenThreshold} ";}

    if($this->{maxgap} < 0){ $options.="-g flow -a $this->{alpha} "; }
    else{ $options.="-g fix -n $this->{maxgap} "; }

    if(!$this->{bothendzero}){$options.="-z ";}

    return $options;
}

1;
