#!/usr/bin/perl

=pod

=head1 NAME

=head1 SYNOPSIS

perform_muscle.pl -f <fastain> -aln <alignout>

=head1 DESCRIPTION

Call MUSCLE to perform multiple alignment. This is done in an extra perl script to be able to log to database.

=head1 AUTHOR

Katharina Imkeller

=head1 HISTORY

Written Jan 2014
Modified Mar 2014 (Documentation + logging with capture)

=cut

use strict;
use bcelldb_init;
use Getopt::Long;
use DBI;
use Capture::Tiny 'capture';

my $help=0;
my $fastain="";
my $alignout="";

&GetOptions("h!" => \$help,
	"f=s" => \$fastain,
	"aln=s"=> \$alignout,
);

$help=1 unless $fastain;
$help=1 unless $alignout;
exec('perldoc',$0) if $help;


### 0. Logging and database init

select LOG;

### 1. Call MUSCLE


my ($stdout, $stderr, $return) = capture {
  system "/usr/bin/muscle -in $fastain -maxiters 1 -quiet -out $alignout";
};

print "STDOUT: $stdout\n";
print "STDERR: $stderr\n";
print "Return: $return\n";




#!/usr/bin/perl

=pod

=head1 NAME

=head1 SYNOPSIS

perform_muscle.pl -f <fastain> -aln <alignout>

=head1 DESCRIPTION

Call MUSCLE to perform multiple alignment. This is done in an extra perl script to be able to log to database.

=head1 AUTHOR

Katharina Imkeller

=head1 HISTORY

Written Jan 2014
Modified Mar 2014 (Documentation + logging with capture)

=cut

use strict;
# use bcelldb_init;
use Getopt::Long;
# use DBI;
use Capture::Tiny 'capture';

my $help=0;
my $fastain="";
my $alignout="";

&GetOptions("h!" => \$help,
	"f=s" => \$fastain,
	"aln=s"=> \$alignout,
);

$help=1 unless $fastain;
$help=1 unless $alignout;
exec('perldoc',$0) if $help;


### 0. Logging and database init

# select LOG;

### 1. Call MUSCLE


my ($stdout, $stderr, $return) = capture {
  system "/usr/bin/muscle -in $fastain -maxiters 1 -quiet -out $alignout";
};
if ($return) {
	print "[perform_muscle.pl][ERROR] return code: " . $return . " STDOUT: \"" . $stdout . "\" STDERR: \"" . $stderr . "\"\n";
}


Remove DB access from muscule module
Remove DB access from muscule module

Unify logging output, log to console. Do not open non-required DB
connection.

'muscle' module is called once per alignment, causing thousands
of DB connections. However, it only uses this to log the muscle
exit status to the DB, which should go to console log anyhow.
