lib/Bio/MUST/Core/Types.pm

filter: Statementstmt 65.7% 50 / 76 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 46.6% 14 / 30 Podpod n/a totaltotal 52.8% 64 / 121 CC 5 SCAR 17.4
CC
5
Cov
57%
__ANON__
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 5.7
« lib/Bio/MUST/Core/Ali.pm ↑ Summary lib/Bio/MUST/Core/SeqId.pm »
1 package Bio::MUST::Core::Types;
2 # ABSTRACT: Distribution-wide Moose types for Bio::MUST::Core
3 18 $Bio::MUST::Core::Types::VERSION = '0.252040';
4 18 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use Path::Class qw(dir file);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # declare types without loading corresponding classes
12 18 class_type('Bio::MUST::Core::Ali');
13 18 class_type('Bio::MUST::Core::Ali::Stash');
14 18 class_type('Bio::MUST::Core::IdList');
15 18 class_type('Bio::MUST::Core::IdMapper');
16 18 class_type('Bio::MUST::Core::SeqId');
17  
18 # TODO: consider MooseX::Types
19  
20 # http://www.ebi.ac.uk/2can/tutorials/aa.html
21  
22 # A Ala Alanine
23 # R Arg Arginine
24 # N Asn Asparagine
25 # D Asp Aspartic acid
26 # C Cys Cysteine
27 # Q Gln Glutamine
28 # E Glu Glutamic acid
29 # G Gly Glycine
30 # H His Histidine
31 # J Xle Leucine or Isoleucine
32 # L Leu Leucine
33 # I ILe Isoleucine
34 # K Lys Lysine
35 # M Met Methionine
36 # F Phe Phenylalanine
37 # P Pro Proline
38 # O Pyl Pyrrolysine
39 # U Sec Selenocysteine
40 # S Ser Serine
41 # T Thr Threonine
42 # W Trp Tryptophan
43 # Y Tyr Tyrosine
44 # V Val Valine
45 # B Asx Aspartic acid or Asparagine
46 # Z Glx Glutamic acid or Glutamine
47 # X Xaa Any amino acid
48  
49 # IUB Meaning Complement
50 # A A T
51 # C C G
52 # G G C
53 # T/U T A
54 # M A/C K
55 # R A/G Y
56 # W A/T W
57 # S C/G S
58 # Y C/T R
59 # K G/T M
60 # V A/C/G B
61 # H A/C/T D
62 # D A/G/T H
63 # B C/G/T V
64 # X/N A/C/G/T X
65  
66  
67 # auto-build SeqId instance from bare string
68 # useful when the SeqId class is used as an attribute in another class
69 # TODO: check whether it is the best practice
70 coerce 'Bio::MUST::Core::SeqId'
71 => from 'Str'
72 10970 ▶ => via { Bio::MUST::Core::SeqId->new(full_id => $_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
73 18 ;
74  
75 # auto-build ArrayRef[full_id] from ArrayRef[SeqId] or ArrayRef[Seq]
76 # useful for IdList and IdMapper objects
77 18 subtype 'Bio::MUST::Core::Types::full_ids'
78 => as 'ArrayRef[Str]';
79  
80 coerce 'Bio::MUST::Core::Types::full_ids'
81 => from 'ArrayRef[Bio::MUST::Core::SeqId]'
82 0 ▶ => via { [ map { $_->full_id } @{$_} ] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
83  
84 => from 'ArrayRef[Bio::MUST::Core::Seq]'
85 0 ▶ => via { [ map { $_->full_id } @{$_} ] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 18 ;
87  
88 # quite tolerant subtype designed to preserve original casing
89 # however FASTA '-' symbols are converted to ALI '*' (and MACSE's '!' to 'x')
90 # during coercion whereas spaces and '?' are left untouched
91 # Note: \A are \z are absolutely required for converting hard-wrapped seqs
92 subtype 'Bio::MUST::Core::Types::Seq'
93 => as 'Str'
94 41586 ▶ => where { m{\A [\*\ A-Za-z\?]* \z}xms }
Subroutine __ANON__: called CC=1 SCAR=0.0
95 0 ▶ => message { 'Only IUPAC codes and gaps [*-<space>?] are allowed.' }
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 18 ;
97  
98 coerce 'Bio::MUST::Core::Types::Seq'
99 => from 'Str'
100 183 ▶ => via { tr|-!\n|*x|dr } # convert FASTA on the fly
Subroutine __ANON__: called CC=1 SCAR=0.0
101 18 ; # ('-' => '*', '!' => 'x' and delete \n)
102  
103 # subtype for a stringified NCBI Taxonomy lineage
104 subtype 'Bio::MUST::Core::Types::Lineage'
105 => as 'Str'
106 0 ▶ => where { tr/;// || m/\A cellular \s organisms/xms || m/\A Viruses/xms
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
tr/;// or /\A cellular \s organisms/msx or /\A Viruses/msx or /\A other \s sequences/msx or /\A unclassified \s sequences/msx 0 0 0
Condition0%0/9
tr/;// or /\A cellular \s organisms/msx or /\A Viruses/msx or /\A other \s sequences/msx
l!l&&r!l&&!r
000
tr/;// or /\A cellular \s organisms/msx or /\A Viruses/msx
l!l&&r!l&&!r
000
tr/;// or /\A cellular \s organisms/msx
l!l&&r!l&&!r
000
MC/DC0%0/4
tr/;// or /\A cellular \s organisms/msx or /\A Viruses/msx or /\A other \s sequences/msx
tr/;// /\A cellular \s organisms/msx /\A Viruses/msx /\A other \s sequences/msx
Truth table0%0/5
A or B or C or D
A= tr/;//B= /\A cellular \s organisms/msxC= /\A Viruses/msxD= /\A other \s sequences/msx
ABCDresult
1XXX1
01XX1
001X1
00011
00000
107 || m/\A other \s sequences/xms || m/\A unclassified \s sequences/xms }
108 18 ;
109  
110 18 class_type('Path::Class::Dir');
111 18 class_type('Path::Class::File');
112 18 class_type('File::Temp');
113  
114 # auto-build Ali/Stash from various source types...
115 # useful in Bio::MUST::Drivers modules
116  
117 coerce 'Bio::MUST::Core::Ali'
118 => from 'Bio::MUST::Core::Ali::Stash'
119 0 ▶ => via { Bio::MUST::Core::Ali->new( seqs => $_->seqs, guessing => 1 ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
120  
121 => from 'ArrayRef[Bio::MUST::Core::Seq]'
122 1 ▶ => via { Bio::MUST::Core::Ali->new( seqs => $_, guessing => 1 ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
123  
124 => from 'Path::Class::File'
125 4 ▶ => via { Bio::MUST::Core::Ali->load( $_->stringify ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
126  
127 => from 'Str'
128 0 ▶ => via { Bio::MUST::Core::Ali->load( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 18 ;
130  
131 coerce 'Bio::MUST::Core::Ali::Stash'
132 => from 'Path::Class::File'
133 0 ▶ => via { Bio::MUST::Core::Ali::Stash->load( $_->stringify ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
134  
135 => from 'Str'
136 0 ▶ => via { Bio::MUST::Core::Ali::Stash->load( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 18 ;
138  
139 coerce 'Bio::MUST::Core::IdList'
140 => from 'ArrayRef[Str]'
141 2 ▶ => via { Bio::MUST::Core::IdList->new( ids => $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
142  
143 => from 'ArrayRef[Bio::MUST::Core::SeqId]'
144 0 ▶ => via { Bio::MUST::Core::IdList->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
145 0 ids => [ map { $_->full_id } @{$_} ]
146 ) }
147  
148 => from 'ArrayRef[Bio::MUST::Core::Seq]'
149 0 ▶ => via { Bio::MUST::Core::IdList->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 0 ids => [ map { $_->full_id } @{$_} ]
151 ) }
152  
153 => from 'Path::Class::File'
154 0 ▶ => via { Bio::MUST::Core::IdList->load( $_->stringify ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
155  
156 => from 'Str'
157 0 ▶ => via { Bio::MUST::Core::IdList->load( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
158 18 ;
159  
160 # TODO: add coercion for IdMapper from HashRef[SeqId], HashRef[Seq]?
161  
162 coerce 'Bio::MUST::Core::IdMapper'
163 => from 'HashRef[Str]'
164 0 ▶ => via { Bio::MUST::Core::IdMapper->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 0 long_ids => [ keys %{$_} ],
166 0 abbr_ids => [ values %{$_} ],
167 ) }
168  
169 => from 'Path::Class::File'
170 0 ▶ => via { Bio::MUST::Core::IdMapper->load( $_->stringify ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
171  
172 => from 'Str'
173 0 ▶ => via { Bio::MUST::Core::IdMapper->load( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
174 18 ;
175  
176 # TODO: add tests for these coercions? templatize code?
177  
178 # subtype for 'dir' attributes
179 18 subtype 'Bio::MUST::Core::Types::Dir'
180 => as 'Path::Class::Dir'
181 ;
182  
183 # avoid the need for 'isa' unions such as 'Str|Path::Class::Dir'...
184 # ... and allow fixing '~/' paths on the fly (through glob)
185 coerce 'Bio::MUST::Core::Types::Dir'
186 => from 'Str'
187 18 ▶ => via { dir( glob $_ ) }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
188 18 ;
189  
190 # === in part borrowed from Bio::FastParsers to avoid dependency
191  
192 # subtype for 'file' attributes
193 18 subtype 'Bio::MUST::Core::Types::File'
194 => as 'Path::Class::File'
195 ;
196  
197 # avoid the need for 'isa' unions such as 'Str|Path::Class::File'...
198 # ... and allow fixing '~/' paths on the fly (through glob)
199 # ... and allow delegating to Path::Class::File methods (e.g., remove)
200 coerce 'Bio::MUST::Core::Types::File'
201 => from 'File::Temp' # useful for Drivers
202 0 ▶ => via { file( $_->filename ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
203  
204 => from 'Str'
205 94 ▶ => via { file( glob $_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
206 18 ;
207  
208 # ===
209  
210 18 ▶no Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 18 1;
212  
213 __END__
« lib/Bio/MUST/Core/Ali.pm ↑ Summary lib/Bio/MUST/Core/SeqId.pm »