#!/usr/bin/env perl
use strict;
use warnings;
use Pod::Usage;
use FindBin;                      # Find the location of seq-manipulations
use v5.10;
use rlib '../lib';
use Getopt::Long qw( :config bundling permute no_getopt_compat );
use Bio::BPWrapper;
use Bio::BPWrapper::PopManipulations;

################# Option parsing #################
my %opts;
my %flags;
GetOptions(
    \%opts,
    "help|h",
    "man",
#    "distance|d",
#    "dist-method|D=s" => \$flags{"dist-method"},
    "bihaps",
    "bisites",
    "bisites-for-r",
    "heterozygosity|H",
    "input|i=s" => \$flags{"input"},
    "mismatch|m",
    "mut-info",
#    "numseq|n=i"    => \$flags{"numseq"},
    "pi|p",
    "stats|s=s@",    # Comma-separated, or multiply specified, list
    "snp",
    "snp-coding",
    "snp-coding-long",
    "snp-noncoding",
    "version|V",
    "segsites|S",
    "bipart",
#    "mutrec|b",
#    "exclude|group3|seq3|r=s@",
#    "ingroup|group1|seq1|p=s@",
#    "simmk|k",
#    "outgroup|group2|seq2|q=s@",
#    "kaks=s",
) or pod2usage(2);

use constant PROGRAM => File::Basename::basename(__FILE__);
Bio::BPWrapper::print_version(PROGRAM) if $opts{"version"};

# This sets all internal variables, and loads AlignIO objects
initialize(\%opts, \%flags);
write_out(\%opts)

################# POD Documentation ##################

__END__
=encoding utf8

=head1 NAME

biopop - Wrapper script for L<Bio::Perl>'s population genetics modules

=head1 SYNOPSIS

B<biopop> I<options> [I<alignment_file>]

B<biopop> [C<-h> | C<--help> | --C<v> | C<--version> C<--man>]

=head1 DESCRIPTION

Wrapper script for L<Bio::Perl>'s population genetics modules: use L<Bio::PopGen::Utilities>;
L<Bio::PopGen::Statistics>, and L<Bio::PopGen::Population>;

=head2 OPTIONS

=over 4

=item --distance, -d

Calculates a distance matrix for all pairwise distances of all sequences in the input alignment and prints it out.

Use B<--dist-method> to specify the method desired. The default in Bio::Align::DNAStatistics is "JukesCantor".

=item --dist-method, -D

Used with --distance to specify which distance method to use when getting the distance matrix.

Program quits if the distance method is invalid

=item --heterozygosity, -H

Foreach segregating site(s), the observed heterozygosity is returned.

=item --input, -i

Input file format. By default, this is 'clustalw'.

=item --mismatch, -m

Pairwise calculation of mismatches for all sequences in the alignment.

=item --numseq, -n

Input file format. By default, this is 'clustalw'.

=item --pi, -p

Nucleotide Diversity is a measure of genetic variation or differences. It is similar to expected heterozygosity. This method takes in an alignment and outputs an integer.

=item --stats, -s <comma separated list of values>

Specify the statistics you would like to gather from input data. e.g., "theta,pi" will calculate the theta and pi values.

Can also be specified by giving the option multiple times. e.g.,
 biopop --stats=pi --stats=theta

=item --snp_coding

Identify & print, for each 2-state SNP, codon position, aligned nucleotide position, syn/nonsyn, frequencies of each allleic state, for a coding alignment.

=item --varsites, -v

This method outputs the number of segregating or SNP sites within your alignment.

=back

=head3 Common Options

=over 4

=item --help, -h

Print a brief help message and exit.

=item --man

Print the manual page and exit.

=item --version, -V

Print current release version of this command and exit.

=back

=head1 SEE ALSO

=over 4

=item *

L<Bio::BPWrapper::PopManipulations>, the underlying Perl Module

=item *

L<Qiu Lab wiki page|http://diverge.hunter.cuny.edu/labwiki/Bioutils>

=item *

L<Github project wiki page|https://github.com/bioperl/p5-bpwrapper/wiki>

=item *

L<bioseq>: a wrapper of BioPerl class L<Bio::Seq> with additional methods

=back

=head1 CONTRIBUTORS

=over 4

=item *
 Yözen Hernández yzhernand at gmail dot com

=item *
L<Weigang Qiu | mailto:weigang@genectr.hunter.cuny.edu> (Maintainer)

=item *
Rocky Bernstein

=back

=cut
