Mercurial > repos > dereeper > roary_plots
comparison Roary/lib/Bio/Roary/SequenceLengths.pm @ 0:c47a5f61bc9f draft
Uploaded
author | dereeper |
---|---|
date | Fri, 14 May 2021 20:27:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c47a5f61bc9f |
---|---|
1 package Bio::Roary::SequenceLengths; | |
2 | |
3 # ABSTRACT: Take in a fasta file and create a hash with the length of each sequence | |
4 | |
5 =head1 SYNOPSIS | |
6 | |
7 Add labels to the groups | |
8 use Bio::Roary::SequenceLengths; | |
9 | |
10 my $obj = Bio::Roary::SequenceLengths->new( | |
11 fasta_file => 'abc.fa', | |
12 ); | |
13 $obj->sequence_lengths; | |
14 | |
15 =cut | |
16 | |
17 use Moose; | |
18 use Bio::SeqIO; | |
19 use Bio::Roary::Exceptions; | |
20 | |
21 has 'fasta_file' => ( is => 'ro', isa => 'Str', required => 1 ); | |
22 has 'sequence_lengths' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_sequence_lengths' ); | |
23 has '_input_seqio' => ( is => 'ro', isa => 'Bio::SeqIO', lazy => 1, builder => '_build__input_seqio' ); | |
24 | |
25 sub _build__input_seqio { | |
26 my ($self) = @_; | |
27 return Bio::SeqIO->new( -file => $self->fasta_file, -format => 'Fasta' ); | |
28 } | |
29 | |
30 sub _build_sequence_lengths { | |
31 my ($self) = @_; | |
32 | |
33 my %sequence_lengths; | |
34 while ( my $input_seq = $self->_input_seqio->next_seq() ) { | |
35 $sequence_lengths{ $input_seq->display_id } = $input_seq->length(); | |
36 } | |
37 return \%sequence_lengths; | |
38 } | |
39 | |
40 no Moose; | |
41 __PACKAGE__->meta->make_immutable; | |
42 | |
43 1; |