#!/usr/bin/env perl
package Bio::AssemblyImprovement::Bin::OrderContigsWithAbacas;
# ABSTRACT: Given an assembly and a reference, order the contigs
# PODNAME: order_contigs_with_abacas

BEGIN { unshift( @INC, '../lib' ) }
use lib "/software/pathogen/internal/prod/lib";
use Moose;
use Getopt::Long;
use Cwd;
use Cwd 'abs_path';
use File::Path qw(make_path);
use Bio::AssemblyImprovement::Abacas::Iterative;
use Bio::AssemblyImprovement::Scaffold::SSpace::PreprocessInputFiles;

my ( $assembly_file,  $abacas_exec,$debug,$reference,$output_directory, $help );

GetOptions(
    'a|assembly=s'        => \$assembly_file,
    'c|reference=s'       => \$reference,
    'b|abacas_exec=s'     => \$abacas_exec,
    'd|debug'             => \$debug,
    'o|output_directory=s' => \$output_directory,
    'h|help'              => \$help,
);

( defined($assembly_file) && defined($reference) && ( -e $assembly_file ) && ( -e $reference ) && !$help ) or die <<USAGE;
Usage: order_contigs_with_abacas [options]
Take in an assembly in FASTA format and a reference, and order the contigs.

order_contigs_with_abacas -a contigs.fa -c my_reference.fa

# This help message
order_contigs_with_abacas -h

USAGE

$debug           ||= 0;
$abacas_exec     ||= 'abacas.pl';
$output_directory ||= getcwd();
$output_directory  = abs_path($output_directory);
make_path($output_directory);

my $preprocess_input_files = Bio::AssemblyImprovement::Scaffold::SSpace::PreprocessInputFiles->new(
    input_assembly => $assembly_file,
    reference      => $reference,
);
my $process_input_files_tmp_dir_obj = $preprocess_input_files->_temp_directory_obj();

my $scaffolding_obj = Bio::AssemblyImprovement::Abacas::Iterative->new(
  reference      => $preprocess_input_files->processed_reference,
  input_assembly => $preprocess_input_files->processed_input_assembly,
  abacas_exec    => $abacas_exec,
  debug          => $debug,
  output_base_directory => $output_directory
);
$scaffolding_obj->run();

__END__

=pod

=encoding UTF-8

=head1 NAME

order_contigs_with_abacas - Given an assembly and a reference, order the contigs

=head1 VERSION

version 1.140300

=head1 SYNOPSIS

Given an assembly and a reference, order the contigs.

   order_contigs_with_abacas -a contigs.fa -c my_reference.fa

   # This help message
   order_contigs_with_abacas -h

=head1 AUTHOR

Andrew J. Page <ap13@sanger.ac.uk>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007

=cut
