Bio-MUST-Apps-HmmCleaner

 view release on metacpan or  search on metacpan

lib/Bio/MUST/Apps/HmmCleaner.pm  view on Meta::CPAN

    isa         => 'Bool',
    default     => 0,
);


# BUILD

# launch on new but before the object construction
sub BUILD {
    ##### [HMMCLEANER] BUILD...
    my $self = shift;

    my $costs = $self->costs;
    carp "Your costs must be increasing" if ( ($$costs[0] > $$costs[1]) || ($$costs[1] > 0) || ($$costs[2] < 0) || ($$costs[2] > $$costs[3]) );

    carp 'Your MSA file is not aligned' unless ($self->ali->is_aligned);

    $self->_cleaners;

    ##### End of BUILD...
    return;
}


# BUILDER

## no critic (ProhibitUnusedPrivateSubroutines)

# delayed costs creation
sub _build_cost {
    return shift->_get_default_cost;
}

sub _build_outfile {
    my $self = shift;

    my $infile = $self->ali->filename;

    (my $outfile = $infile) =~ s/\.[^\.]+$//x;
    $outfile .= '_hmm';

    return $outfile;
}

# produce the cleaned sequences
sub _build_cleaners {
    #### [HMMCLEANER] building cleaners...

    my $self = shift;

    my $ali = $self->ali;
    my $ali_model = $self->ali_model;
    my $lookup = $ali->new_lookup;

    # Cleaners container
    my @cleaners;

    # arguments for Hmmer driver
    my $model_args = {
        '--plaplace'    => undef,
        '--fragthresh'  => "0.0",
        '--symfrac'     => $self->symfrac,
        #~ '--wnone'     => undef,
    };

    # arguments for Temporary fasta files
    my $alitemp_args = {
            degap       => 0,
            persistent  => ($self->debug_mode) ? 1 : 0,
            gapify      => ($self->consider_X) ? 'X' : '*', # if consider_X changing MISS Char to X ...
            clean       => 1,
    };

    # Creation of global profile
    my $hmmer;
    unless ($self->perseq_profile) {
        ### Global profile ...
        $hmmer = Bio::MUST::Drivers::Hmmer::Model::Temporary->new(
            seqs        => [$ali_model->all_seqs],
            model_args  => $model_args,
            args        => $alitemp_args,
        );
    }

    SEQ:
    for my $seq ($ali->all_seqs) {
        ##### [HMMCLEANER] actual sequence : $seq->foreign_id

        # Creation of perseq profile
        if ($self->perseq_profile) {
            ### Perseq profile ...
            my $lookup = $self->ali_model->new_lookup;  ## no critic (ProhibitReusedNames)
            my @new = map { $_->full_id } grep { $_->full_id ne $seq->full_id } $self->ali_model->all_seqs;
            my $list = IdList->new( ids => \@new);

            # ali without current seq
            my $shorted_ali = $list->reordered_ali($self->ali_model, $lookup);

            $hmmer = Bio::MUST::Drivers::Hmmer::Model::Temporary->new(
                seqs        => [ $shorted_ali->all_seqs ],
                model_args  => $model_args,
                args        => $alitemp_args,
            );
        }

        ##### [HMMCLEANER] HMM driver : $hmmer->model->filename

        # Creation of process
        my $process = Process->new(
            'ali'           => $self->ali,
            'seq'           => $seq,
            'model'         => $hmmer,
            'consider_X'    => $self->consider_X,
            'debug_mode'    => $self->debug_mode,
        );

        my $score = $process->score;
        undef $process;

        my $cleaner = Cleaner->new(
            'seq'           => $seq,



( run in 1.339 second using v1.01-cache-2.11-cpan-b16cb0d3907 )