Bio-FastParsers
view release on metacpan or search on metacpan
lib/Bio/FastParsers/Hmmer/Standard/Target.pm view on Meta::CPAN
package Bio::FastParsers::Hmmer::Standard::Target;
# ABSTRACT: Internal class for standard HMMER parser
# CONTRIBUTOR: Arnaud DI FRANCO <arnaud.difranco@gmail.com>
$Bio::FastParsers::Hmmer::Standard::Target::VERSION = '0.221230';
use Moose;
use namespace::autoclean;
use List::AllUtils qw(indexes);
use aliased 'Bio::FastParsers::Hmmer::Standard::Domain';
# public attributes
# TODO: check if this an empty ArrayRef would not make more sense than Maybe
# We dont want smth else than a Domain in this ArrayRef
# so it is more a matter of precision than sense
has 'domains' => (
traits => ['Array'],
is => 'ro',
isa => 'ArrayRef[Maybe[Bio::FastParsers::Hmmer::Standard::Domain]]',
required => 1,
handles => {
next_domain => 'shift',
get_domain => 'get',
all_domains => 'elements',
count_domains => 'count',
},
);
with 'Bio::FastParsers::Roles::Targetable';
# parse Target block (raw)...
# ... and retrieve attrs from the corresponding line of hit table (Hit)
around BUILDARGS => sub {
my ($orig, $class, $inargs) = @_;
# retrieve lines still to parse as @raw...
my @raw = @{ $inargs->{raw} };
# recycle the anonymous HashRef already containing old Hit information
# as the foundation for the new Target object
my %outargs = %{ $inargs->{hit} };
# add Target name
( $outargs{target_name} = $raw[0] ) =~ s/[\>\s+]//xmsg;
# split Domain blocks
my @domain_indexes = indexes { m/^\s+==/xms } @raw;
# set as empty ArrayRef as --domE option can report Target without domain
$outargs{domains} = [];
if (@domain_indexes) {
my @summary = grep {
$_ =~ m/^\s+\d/xms
} @raw[ 1 .. $domain_indexes[0]-1 ];
for (my $i = 0; $i < @domain_indexes; $i++) {
my @block = defined $domain_indexes[$i+1]
? @raw[ $domain_indexes[$i] .. $domain_indexes[$i+1] ]
: splice @raw, $domain_indexes[$i]
;
push @{ $outargs{domains} },
Domain->new( { raw => \@block, summary => $summary[$i] } );
}
( run in 1.740 second using v1.01-cache-2.11-cpan-2398b32b56e )