Bio-MUST-Core

 view release on metacpan or  search on metacpan

lib/Bio/MUST/Core/IdList.pm  view on Meta::CPAN

package Bio::MUST::Core::IdList;
# ABSTRACT: Id list for selecting specific sequences
$Bio::MUST::Core::IdList::VERSION = '0.252040';
use Moose;
use namespace::autoclean;

use autodie;
use feature qw(say);

# use Smart::Comments;

use Carp;

use Bio::MUST::Core::Types;
use Bio::MUST::Core::Constants qw(:files);
use aliased 'Bio::MUST::Core::SeqId';
use aliased 'Bio::MUST::Core::Ali';
with 'Bio::MUST::Core::Roles::Commentable',
     'Bio::MUST::Core::Roles::Listable';


# public array
has 'ids' => (
    traits   => ['Array'],
    is       => 'ro',
    isa      => 'Bio::MUST::Core::Types::full_ids',
    default  => sub { [] },
    coerce   => 1,
    writer   => '_set_ids',
    handles  => {
        count_ids => 'count',
          all_ids => 'elements',
          add_id  => 'push',
          get_id  => 'get',
    },
);


# private hash for faster querying
has '_index_for' => (
    traits   => ['Hash'],
    is       => 'ro',
    isa      => 'HashRef[Num]',
    init_arg => undef,
    lazy     => 1,
    builder  => '_build_index_for',
    handles  => {
      count_indices   => 'count',
            is_listed => 'defined',
            index_for => 'get',
        set_index     => 'set',
    },
);


## no critic (ProhibitUnusedPrivateSubroutines)

# Note: we don't store SeqId objects in the list but dynamically build them
# to benefit from SeqId methods (e.g., auto-removal of first '_'). This is
# the most flexible approach without costing too much in CPU-time.

sub _build_index_for {
    my $self = shift;

    # build private hash from internal array



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