#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Bio::Phylo::CIPRES;
use Bio::Phylo::Util::Logger ':levels';

# process command line arguments
my $verbosity = INFO;
my $wd        = $ENV{'DATADIR'} || '.';
my $yml       = $wd . '/cipres_appinfo.yml';
my $tool; # MAFFT_XSEDE, IQTREE_XSEDE_1_01_01

# extra parameter switches
my %param     = ( 'vparam.runtime_' => 7.5 );
# for MAFFT, add:
# vparam.anysymbol_=1

# for IQTREE, add:
# vparam.specify_runtype_=2 (i.e. tree inference)
# vparam.specify_dnamodel_=HKY (i.e. HKY85 model)
# vparam.bootstrap_type_=bb (ultrafast bootstrap)
# vparam.use_bnni_=1 (with bnni)
# vparam.num_bootreps_=1000 (replicates)
# vparam.specify_numparts_=1 (partitions)

# outfile name(s)
my @outfile;
# for MAFFT: output.fasta

# some fasta file in either case
my $infile;

GetOptions(
	'infile=s'  => \$infile,
	'yaml=s'    => \$yml,
	'verbose+'  => \$verbosity,
	'outfile=s' => \@outfile,
	'tool=s'    => \$tool,
	'param=s'   => \%param,
	'wd=s'      => \$wd,
);

Bio::Phylo::Util::Logger->new( 
	'-level'    => $verbosity, 
	'-class'    => [ 'main', 'Bio::Phylo::CIPRES' ],
);

my %res = Bio::Phylo::CIPRES->new( 
	'infile'    => $infile, 
	'tool'      => $tool,
	'param'     => \%param,
	'outfile'   => \@outfile,
	'yml'       => $yml,	
)->run;

while ( my ( $name, $data ) = each %res ) {
	open my $fh, '>', "${wd}/${name}" or die "Can't open ${wd}/${name}: $!";
	print $fh $data;
}
