$Bio::MUST::Apps::Leel::AliProcessor::VERSION
=
'0.213470'
;
has
'run_proc'
=> (
is
=>
'ro'
,
isa
=>
'Bio::MUST::Apps::Leel::RunProcessor'
,
required
=> 1,
);
has
'+ali'
=> (
handles
=> {
protein_for
=>
'get_seq_with_id'
,
},
);
has
'cds_ali'
=> (
is
=>
'ro'
,
isa
=>
'Bio::MUST::Core::Ali'
,
init_arg
=>
undef
,
lazy
=> 1,
builder
=>
'_build_cds_ali'
,
);
sub
_build_cds_ali {
return
Ali->new(
file
=>
shift
->ali->filename );
}
sub
_build_integrator {
return
Local->new(
ali
=>
shift
->cds_ali );
}
sub
_check_ali_by_translation {
my
$self
=
shift
;
my
$rp
=
$self
->run_proc;
my
$gc_fac
= Factory->new;
my
%code_for
=
map
{
$_
->{org} =>
$gc_fac
->code_for(
$_
->{code} )
}
$rp
->all_orgs;
my
$cds_ali
=
$self
->cds_ali;
my
@got_seqs
=
sort
{
$a
->full_id cmp
$b
->full_id }
map
{
$code_for
{
$_
->full_org }->translate(
$_
, 1)->gapify
}
$cds_ali
->all_seqs;
my
$ali
=
$self
->ali;
my
@exp_seqs
=
sort
{
$a
->full_id cmp
$b
->full_id }
map
{
$_
->gapify
}
$ali
->all_seqs;
my
$got_ali
= Ali->new(
seqs
=> \
@got_seqs
)->uniformize;
my
$exp_ali
= Ali->new(
seqs
=> \
@exp_seqs
)->uniformize;
unless
(eq_deeply
$got_ali
,
$exp_ali
) {
carp
'[ALI] Warning: round-trip check failed;'
.
' writing -got and -exp files!'
;
my
$cds_ali
=
$self
->cds_ali;
my
$outfile
=
$cds_ali
->filename;
$outfile
= file(
$rp
->out_dir, basename(
$outfile
) )
if
$rp
->out_dir;
$got_ali
->store( secure_outfile(
$outfile
,
'-got'
) );
$exp_ali
->store( secure_outfile(
$outfile
,
'-exp'
) );
}
return
;
}
sub
BUILD {
my
$self
=
shift
;
my
$rp
=
$self
->run_proc;
my
$ali
=
$self
->ali;
unless
(
$ali
->count_seqs) {
return
;
}
for
my
$org
(
$rp
->all_orgs) {
OrgProcessor->new(
ali_proc
=>
$self
, %{
$org
} );
}
unless
(
$rp
eq
'off'
) {
$self
->integrator->make_indels;
if
(
$rp
->round_trip_mode eq
'on'
) {
$self
->_check_ali_by_translation;
}
}
my
$cds_ali
=
$self
->cds_ali;
my
$outfile
= insert_suffix(
$cds_ali
->filename,
$rp
->out_suffix);
$outfile
= file(
$rp
->out_dir, basename(
$outfile
) )
if
$rp
->out_dir;
$cds_ali
->store( secure_outfile(
$outfile
) );
return
;
}
__PACKAGE__->meta->make_immutable;
1;