<commit_before>#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
use Getopt::Long;
use List::Util 'reduce';
use Bio::SearchIO;
use Bio::Phylo::Util::Logger ':levels';
use Bio::Phylo::PhyLoTA::Config;
use Bio::Phylo::PhyLoTA::Domain::MarkersAndTaxa;
use Bio::Phylo::PhyLoTA::Service::SequenceGetter;
use Bio::Phylo::PhyLoTA::Service::ParallelService 'mpi'; # can be either 'pthreads' or 'mpi';

=head1 NAME

merge_alignments.pl - merges alignments by orthology

=head1 SYNOPSIS

 $ merge_alignments.pl --list=<list> --workdir=<dir> [--verbose] > <merged list>

=head1 DESCRIPTION

Given an input C<list> of alignment locations, assess their orthology (presently, on the
basis of all-vs-all BLAST searches) and profile align the orthologous clusters. The list
of so produced merged alignments is printed to STDOUT and the alignments themselves are
written to C<workdir>.

=cut

# process command line arguments
my $verbosity = WARN;
my ( $list, $workdir );
GetOptions(
	'verbose+'  => \$verbosity,
	'list=s'    => \$list,
	'workdir=s' => \$workdir,
);

# instantiate helper objects
my $service = Bio::Phylo::PhyLoTA::Service::SequenceGetter->new;
my $mts     = Bio::Phylo::PhyLoTA::Domain::MarkersAndTaxa->new;
my $config  = Bio::Phylo::PhyLoTA::Config->new;
my $log     = Bio::Phylo::Util::Logger->new(
	'-level' => $verbosity,
	'-class' => 'main',
);

my $dbname = File::Spec->catfile( $workdir, 'seeds.fa' );
$log->info("creating database file $dbname");

# read list of alignments
my @alignments;
{
	$log->info("going to read file list $list");
	my %seen; # for some reason there might be duplicates
	open my $fh, '<', $list or die $!;
	while(<$fh>) {
		chomp;
		$seen{$_}++;
	}
	@alignments = keys %seen;
}

# write seed sequences
$log->info("going to write sequences to $dbname");
open my $fh, '>', $dbname or die $!;
for my $aln ( @alignments ) {
	if ( $aln =~ /(\d+)\.fa/ ) {
		my $gi = $1;
		my $seq = $service->find_seq($gi);
		print $fh '>', $gi, "\n", $seq->seq, "\n";
		print $fh "alignment\n";
	}	
}
$log->info("read ".scalar(@alignments)." alignments");
<commit_msg>adding ParallelService to list of logged classes<commit_after>#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
use Getopt::Long;
use List::Util 'reduce';
use Bio::SearchIO;
use Bio::Phylo::Util::Logger ':levels';
use Bio::Phylo::PhyLoTA::Config;
use Bio::Phylo::PhyLoTA::Domain::MarkersAndTaxa;
use Bio::Phylo::PhyLoTA::Service::SequenceGetter;
use Bio::Phylo::PhyLoTA::Service::ParallelService 'mpi'; # can be either 'pthreads' or 'mpi';

=head1 NAME

merge_alignments.pl - merges alignments by orthology

=head1 SYNOPSIS

 $ merge_alignments.pl --list=<list> --workdir=<dir> [--verbose] > <merged list>

=head1 DESCRIPTION

Given an input C<list> of alignment locations, assess their orthology (presently, on the
basis of all-vs-all BLAST searches) and profile align the orthologous clusters. The list
of so produced merged alignments is printed to STDOUT and the alignments themselves are
written to C<workdir>.

=cut

# process command line arguments
my $verbosity = WARN;
my ( $list, $workdir );
GetOptions(
	'verbose+'  => \$verbosity,
	'list=s'    => \$list,
	'workdir=s' => \$workdir,
);

# instantiate helper objects
my $service = Bio::Phylo::PhyLoTA::Service::SequenceGetter->new;
my $mts     = Bio::Phylo::PhyLoTA::Domain::MarkersAndTaxa->new;
my $config  = Bio::Phylo::PhyLoTA::Config->new;
my $log     = Bio::Phylo::Util::Logger->new(
	'-level' => $verbosity,
	'-class' => [qw(
		main
		Bio::Phylo::PhyLoTA::Service::ParallelService
	)]
);

my $dbname = File::Spec->catfile( $workdir, 'seeds.fa' );
$log->info("creating database file $dbname");

# read list of alignments
my @alignments;
{
	$log->info("going to read file list $list");
	my %seen; # for some reason there might be duplicates
	open my $fh, '<', $list or die $!;
	while(<$fh>) {
		chomp;
		$seen{$_}++;
	}
	@alignments = keys %seen;
}

# write seed sequences
$log->info("going to write sequences to $dbname");
open my $fh, '>', $dbname or die $!;
for my $aln ( @alignments ) {
	if ( $aln =~ /(\d+)\.fa/ ) {
		my $gi = $1;
		my $seq = $service->find_seq($gi);
		print $fh '>', $gi, "\n", $seq->seq, "\n";
		print $fh "alignment\n";
	}	
}
$log->info("read ".scalar(@alignments)." alignments");

{'fraction_non_alphanumeric': 0.17936694021101993, 'fraction_numerical': 0.0018757327080890973, 'mean_word_length': 4.9332406119610575, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3425831', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1559, 'n_words': 430}