#!/usr/bin/env perl

use strict;
use warnings;
use rlib '../lib';
use Bio::BPWrapper::SeqManipulations;
use 5.010;
use Getopt::Long qw(:config gnu_getopt);
use Pod::Usage;

####################### Option parsing ######################
my %opts;
GetOptions(
    \%opts,
    "help|h",
    "man",
    "composition|c",
    "delete|d=s",
    "fetch|f=s", # Retrieve sequence by accession number
    "nogaps|g",
    "input|i=s",
    "length|l",
    "numseq|n",
    "output|o=s",
    "pick|p=s",
    "revcom|r",
    "subseq|s=s",
    "translate|t=i", #Needs error checking
    "restrict|x=s",
    "anonymize|A:10",    # default 10 char (for phylip) (prefix + num_digits)
    "break|B",
    "count-codons|C",
    "feat2fas|F",
    "leadgaps|G",
    "hydroB|H",
    "linearize|L",
    "reloop|R=i", # recircularize a genome at "loop_at"
    "version|V",
    "removestop|X", # for PAML/codeml
    "split-cdhit=s",
 #   "longest-orf|C",
 #   "extract|e",
 #   "dotplot|D=s",
 #   "rename|N=s",
 #   "slidingwindow|S=i",
 #   "prefix=s",
 #   "split|S=i",
) or pod2usage(2);

pod2usage(1) if $opts{"help"};
pod2usage(-exitstatus => 0, -verbose => 2) if $opts{"man"};
&print_version() if $opts{"version"};


######################## Main #####################

# This sets all internal variables, and loads Bio::Seq objects
initialize(\%opts);

for my $option (keys %opts) {
    # Don't process these options: they are for SeqIO
    next if $option eq 'input' || $option eq 'output';

    # If there is a function to handle the current option, execute it
    if (can_handle($option)) { handle_opt($option); exit }
    else { warn "Missing handler for: $option\n" }
}

# Let seq-manipulations act as a converter when no other options are given.
write_out();
