Bio-MUST-Apps-HmmCleaner

 view release on metacpan or  search on metacpan

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

);

has 'shifts' => (
    is          => 'ro',
    isa         => 'ArrayRef[Int]', # Future 'Bio::MUST::Core::SeqMask' or not
    lazy        => 1,
    writer      => '_set_shifts',
    builder     => '_build_shifts',
);

has 'costs' => (
    traits        => ['Array'],
    is            => 'ro',
    isa            => 'ArrayRef[Num]',
    required    => 1,
    writer      => '_set_costs',
    handles        => {
        _get_cost => 'get',
    }

);

has 'consider_X' => (
    is          => 'ro',
    isa         => 'Bool',
    default     => 1,
);

has 'is_protein' => (
    is          => 'ro',
    isa         => 'Bool',
    default     => 1,
);


# BUILDER

## no critic (ProhibitUnusedPrivateSubroutines)

sub _build_nogap_seq {
    my $self = shift;
    my $seq = $self->seq;
    my $nogap_seq = ($self->consider_X) ? $seq->clone->gapify('X')->degap : $seq->clone->gapify->degap;
    ##### [CLEANER] Nogap seq : $nogap_seq->seq
    return $nogap_seq;
}

sub _build_nogap_shifts {
    return shift->_get_nogap_shifts;
}

sub _build_shifts {
    return shift->_get_shifts;
}

## use critic


# METHOD

sub update {
    my $self = shift;
    my $threshold = shift;
    my $costs = shift;

    $self->_set_costs($costs);
    $self->_set_threshold($threshold);
    # watch out, the order is important here
    $self->_set_nogap_shifts($self->_get_nogap_shifts);
    $self->_set_shifts($self->_get_shifts);

    return 1;
}

sub get_nogap_result {
    my $self = shift;

    #~ my $nogap_result = _erasezone($self, $self->nogap_seq->seq, $self->nogap_mask);
    #~ #### $nogap_result
    #~ return Seq->new( seq_id => $self->nogap_seq->full_id, seq => $nogap_result );

    return $self->_apply_mask($self->nogap_seq, $self->get_nogap_seqmask);

}

sub get_result {
    my $self = shift;

    #~ my $result = _erasezone( $self, $self->seq->seq, $self->mask );
    #~ #### $result
    #~ return Seq->new( seq_id => $self->seq->full_id, seq => $result );

    return $self->_apply_mask($self->seq, $self->get_seqmask);
}

# PRIVATE SUB

sub _get_nogap_shifts {
    my $self = shift;

    my $concat_scoreseq = $self->score;

    # this function return a list of shifts between good and bad positions, ArrayRef
    ##### [CLEANER] Finding shifts...
    my $shifts = _findingShifts($self, $concat_scoreseq);
    ###### [CLEANER] $shifts

    return $shifts;
}


sub _get_shifts {
    my $self = shift;
    my $shifts = $self->nogap_shifts;

    ##### [CLEANER] Looking for gaps in full sequence...
    my @gaps_n_seqs;
    my $push = 0;

    my $regex = ($self->consider_X)
              ? $GAP



( run in 1.188 second using v1.01-cache-2.11-cpan-39bf76dae61 )