lib/Bio/MUST/Core/Ali/Temporary.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 33.3% 1 / 3 totaltotal 87.9% 51 / 58 CC 3 SCAR 6.9
CC
3
Cov
91%
type
6.0
DEMOLISH
2.0
BEGIN
1.0
CRAP 2.0
« script/tseq2ali.pl ↑ Summary lib/Bio/MUST/Core/SeqMask/Pmsf.pm »
1 package Bio::MUST::Core::Ali::Temporary;
2 # ABSTRACT: Thin wrapper for a temporary mapped Ali written on disk
3 18 $Bio::MUST::Core::Ali::Temporary::VERSION = '0.252040';
4 18 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 ▶use Path::Class qw(file);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 ▶use Bio::MUST::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Note: tried to implement it as a subclass of Bio::MUST::Core::Ali but this
15 # led to issues: (1) coercions became a nightmare and (2) the temp_fasta was
16 # written as soon as the Ali was created and thus was empty
17  
18 # TODO: allows to specify the directory for the temp file (File::Temp tmpdir)
19 # TODO: allows to specify a template for the temp file name?
20  
21 # ATTRIBUTES
22  
23  
24 18 has 'seqs' => (
25 is => 'ro',
26 isa => 'Bio::MUST::Core::Ali',
27 required => 1,
28 coerce => 1,
29 handles => [
30 qw(count_comments all_comments get_comment
31 guessing all_seq_ids has_uniq_ids is_protein is_aligned
32 get_seq get_seq_with_id first_seq all_seqs filter_seqs count_seqs
33 gapmiss_regex
34 )
35 ], # comment-related methods needed by IdList
36 );
37  
38  
39 18 has 'args' => (
40 is => 'ro',
41 isa => 'HashRef',
42 lazy => 1,
43 builder => '_build_args',
44 );
45  
46  
47 18 has 'file' => (
48 is => 'ro',
49 isa => 'Bio::MUST::Core::Types::File',
50 init_arg => undef,
51 coerce => 1,
52 writer => '_set_file',
53 handles => {
54 remove => 'remove',
55 filename => 'stringify',
56 },
57 );
58  
59  
60 18 has 'mapper' => (
61 is => 'ro',
62 isa => 'Bio::MUST::Core::IdMapper',
63 init_arg => undef,
64 writer => '_set_mapper',
65 handles => [ qw(all_long_ids all_abbr_ids long_id_for abbr_id_for) ],
66 );
67  
68 18 with 'Bio::MUST::Core::Roles::Aliable';
69  
70 ## no critic (ProhibitUnusedPrivateSubroutines)
71  
72 3 ▶sub _build_args {
Subroutine _build_args: called CC=1 SCAR=0.0
73 3 return { clean => 1, degap => 1 };
74 }
75  
76 ## use critic
77  
78 5 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
79 5 my $self = shift;
80  
81 # remove persistent key (if any) from args before temp_fasta call
82 # TODO: work out whether this is really needed
83 5 my %args = %{ $self->args };
84 5 delete $args{persistent};
85  
86 # create temporary FASTA file and setup associated IdMapper
87 5 my $ali = $self->seqs;
88 5 my ($filename, $mapper) = $ali->temp_fasta( \%args );
89 5 $self->_set_file($filename);
90 5 $self->_set_mapper($mapper);
91  
92 5 return;
93 }
94  
95 5 ▶sub DEMOLISH {
Subroutine DEMOLISH: called CC=2 SCAR=6.9
Pod undocumented
96 5 my $self = shift;
97  
98 $self->remove
99 5 ▶ unless $self->args->{persistent};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->args->{"persistent"} 4 1 5
100  
101 5 return;
102 }
103  
104 # ACCESSORS
105  
106  
107 # MISC METHODS
108  
109  
110 0 ▶sub type {
Subroutine type: not called CC=2 SCAR=17.9
Pod documented
111 0 my $self = shift;
112 0 ▶ return $self->is_protein ? 'prot' : 'nucl';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_protein ? : 0 0 0
113 }
114  
115 18 __PACKAGE__->meta->make_immutable;
116 18 1;
117  
118 __END__
« script/tseq2ali.pl ↑ Summary lib/Bio/MUST/Core/SeqMask/Pmsf.pm »