blib/lib/Bio/Community/Types.pm

filter: Statementstmt 67.0% 67 / 100 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 34.2% 12 / 35 Podpod n/a totaltotal 54.2% 83 / 153 CC 10 SCAR 17.7
CC
10
Cov
60%
_gen_err_msg
33.4
_read_file
4.2
__ANON__
2.1
CRAP 5.9
« blib/lib/Bio/Community/IO/Driver/biom.pm ↑ Summary blib/lib/Bio/Community/Meta/Gamma.pm »
1 # BioPerl module for Bio::Community::Types
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Copyright 2011-2014 Florent Angly <florent.angly@gmail.com>
6 #
7 # You may distribute this module under the same terms as perl itself
8  
9  
10 =head1 NAME
11  
12 Bio::Community::Types - Data type definitions
13  
14 =head1 DESCRIPTION
15  
16 This module defines useful data types for use in Moose-based modules.
17  
18 =head1 AUTHOR
19  
20 Florent Angly L<florent.angly@gmail.com>
21  
22 =head1 SUPPORT AND BUGS
23  
24 User feedback is an integral part of the evolution of this and other Bioperl
25 modules. Please direct usage questions or support issues to the mailing list,
26 L<bioperl-l@bioperl.org>, rather than to the module maintainer directly. Many
27 experienced and reponsive experts will be able look at the problem and quickly
28 address it. Please include a thorough description of the problem with code and
29 data examples if at all possible.
30  
31 If you have found a bug, please report it on the BioPerl bug tracking system
32 to help us keep track the bugs and their resolution:
33 L<https://redmine.open-bio.org/projects/bioperl/>
34  
35 =head1 COPYRIGHT
36  
37 Copyright 2011-2014 by Florent Angly <florent.angly@gmail.com>
38  
39 This library is free software; you can redistribute it and/or modify
40 it under the same terms as Perl itself, either Perl version 5.10.1 or,
41 at your option, any later version of Perl 5 you may have available.
42  
43 =cut
44  
45  
46 package Bio::Community::Types;
47  
48 23 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 23 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 23 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 23 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53  
54 # Numbers
55  
56 subtype 'PositiveNum'
57 => as 'Num'
58 474 ▶ => where { $_ >= 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
59 0 ▶ => message { _gen_err_msg('a positive number', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
60  
61  
62 subtype 'StrictlyPositiveNum'
63 => as 'PositiveNum'
64 0 ▶ => where { $_ > 0 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 0 ▶ => message { _gen_err_msg('a strictly positive number', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
66  
67  
68 subtype 'PositiveInt'
69 => as 'Int'
70 1273 ▶ => where { $_ >= 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
71 0 ▶ => message { _gen_err_msg('a positive integer', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
72  
73  
74 subtype 'StrictlyPositiveInt'
75 => as 'PositiveInt'
76 494 ▶ => where { $_ > 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
77 0 ▶ => message { _gen_err_msg('a strictly positive integer', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
78  
79  
80 # A Count should be a positive integer. Sometimes, however, we only have access
81 # to the relative abundance (a float), and use it as a proxy for a count.
82 23 subtype 'Count'
83 => as 'PositiveNum';
84  
85  
86 # Number of ticks (at least three)
87 subtype 'NumTicks'
88 => as 'PositiveNum'
89 0 ▶ => where { $_ > 2 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 ▶ => message { _gen_err_msg('an integer greater than two', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
91  
92  
93 # Sort numerically
94 subtype 'NumericSort'
95 => as enum( [ qw(-1 0 1) ] )
96 0 ▶ => message { _gen_err_msg('0 (off), 1 (increasing) or -1 (decreasing)', $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
97  
98  
99 # Abundance representation
100 23 my @AbundanceRepr = qw(count absolute percentage fraction);
101 subtype 'AbundanceRepr'
102 => as enum( \@AbundanceRepr )
103 0 ▶ => message { _gen_err_msg(\@AbundanceRepr, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
104  
105  
106 # Rank: a strictly positive integer
107 23 subtype 'AbundanceRank'
108 => as 'StrictlyPositiveInt';
109  
110  
111 # Type of distance
112 23 my @DistanceType = qw(1-norm 2-norm euclidean p-norm infinity-norm hellinger
113 bray-curtis morisita-horn jaccard sorensen
114 shared permuted maxiphi unifrac);
115 subtype 'DistanceType'
116 => as enum( \@DistanceType )
117 0 ▶ => message { _gen_err_msg(\@DistanceType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
118  
119  
120 # Type of alpha diversity
121 23 my @AlphaType = qw(
122 observed menhinick chao1 margalef ace jack1 jack2
123 shannon_e brillouin_e hill_e mcintosh_e simpson_e buzas heip camargo
124 shannon brillouin hill mcintosh simpson simpson_r
125 simpson_d berger
126 );
127 subtype 'AlphaType'
128 => as enum( \@AlphaType )
129 0 ▶ => message { _gen_err_msg(\@AlphaType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
130  
131  
132 # Type of gamma diversity
133 23 my @GammaType = ( qw(
134 chao2 jack1_i jack2_i ice
135 ), @AlphaType
136 );
137 subtype 'GammaType'
138 => as enum( \@GammaType )
139 0 ▶ => message { _gen_err_msg(\@GammaType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
140  
141  
142 # Type of transformation
143 23 my @TransformationType = qw(identity binary relative hellinger chord);
144 subtype 'TransformationType'
145 => as enum( \@TransformationType )
146 0 ▶ => message { _gen_err_msg(\@TransformationType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
147  
148  
149 # Type of accumulation curve
150 23 my @AccumulationType = qw(rarefaction collector);
151 subtype 'AccumulationType'
152 => as enum( \@AccumulationType )
153 0 ▶ => message { _gen_err_msg(\@AccumulationType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
154  
155  
156 # Type of spacing
157 23 my @SpacingType = qw(linear logarithmic);
158 subtype 'SpacingType'
159 => as enum( \@SpacingType )
160 0 ▶ => message { _gen_err_msg(\@SpacingType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
161  
162  
163 # Members identification method
164 23 my @IdentifyMembersByType = qw(id desc);
165 subtype 'IdentifyMembersByType'
166 => as enum( \@IdentifyMembersByType )
167 0 ▶ => message { _gen_err_msg(\@IdentifyMembersByType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
168  
169  
170 # Duplicates identification method
171 23 my @IdentifyDupsByType = qw(desc taxon);
172 subtype 'IdentifyDupsByType'
173 => as enum( \@IdentifyDupsByType )
174 0 ▶ => message { _gen_err_msg(\@IdentifyDupsByType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
175  
176  
177 # Weight assignment method: a number, 'average', 'median', 'taxonomy'
178 23 my @WeightAssignStr = qw(file_average community_average ancestor);
179 subtype 'WeightAssignStr'
180 => as enum( \@WeightAssignStr )
181 0 ▶ => message { _gen_err_msg(\@WeightAssignStr, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
182 subtype 'WeightAssignType'
183 => as 'WeightAssignStr | Num'
184 0 ▶ => message { _gen_err_msg( ['a number', @WeightAssignStr], $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
185  
186  
187 # Biom matrix type
188 23 my @BiomMatrixType = qw(sparse dense);
189 subtype 'BiomMatrixType'
190 => as enum( \@BiomMatrixType )
191 0 ▶ => message { _gen_err_msg(\@BiomMatrixType, $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
192  
193  
194 # A readable file
195 subtype 'ReadableFile'
196 => as 'Str'
197 8 ▶ => where { (-e $_) && (-r $_) }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
-e $_ and -r $_ 8 0 8
198 0 ▶ => message { _gen_err_msg([], $_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
199  
200 23 subtype 'ArrayRefOfReadableFiles'
201 => as 'ArrayRef[ReadableFile]';
202  
203  
204 # A readable filehandle (and coercing it from a readable file)
205 23 subtype 'ReadableFileHandle'
206 => as 'FileHandle';
207  
208 coerce 'ReadableFileHandle'
209 => from 'Str'
210 0 ▶ => via { _read_file($_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
211  
212 23 subtype 'ArrayRefOfReadableFileHandles'
213 => as 'ArrayRef[ReadableFileHandle]';
214  
215 coerce 'ArrayRefOfReadableFileHandles'
216 => from 'ArrayRefOfReadableFiles'
217 5 ▶ => via { [ map { _read_file($_) } @{$_} ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
218  
219  
220 23 ▶func _read_file ($file) {
Subroutine BEGIN: called CC=1 SCAR=0.1
Subroutine _read_file: called CC=4 SCAR=14.3
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 8 8
if scalar @_ > 1 0 8 8
221 8 ▶ open my $fh, '<', $file or die "Could not open file '$_': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Could not open file '${_}': $!\n" 0 8 8
222 # $self->throw("Could not open file '$_': $!")
223 8 return $fh;
224 }
225  
226  
227 23 ▶func _gen_err_msg ($accepts, $got = '') {
Subroutine BEGIN: called CC=1 SCAR=4.6
Subroutine _gen_err_msg: not called CC=6 SCAR=35.1
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
scalar @_ > 1 ? : 0 0 0
if scalar @_ > 2 0 0 0
228 # Generate an error message. The input is:
229 # * an arrayref of the values accepted, or a string describing valid input
230 # * the value obtained instead of the
231 0 my $accept_str;
232 0 ▶ if (ref($accepts) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $accepts eq 'ARRAY') { } 0 0 0
233 0 ▶ if (scalar @$accepts > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$accepts > 1) 0 0 0
234 0 $accept_str = join(', ', @$accepts[0 .. scalar @$accepts - 2]);
235 }
236 0 $accept_str = $accept_str.' or '.$accepts->[-1];
237 } else {
238 0 $accept_str = $accepts;
239 }
240 0 return "'$got' was given, but valid input can only be $accept_str";
241 }
242  
243  
244 23 __PACKAGE__->meta->make_immutable;
245  
246 23 1;
247  
« blib/lib/Bio/Community/IO/Driver/biom.pm ↑ Summary blib/lib/Bio/Community/Meta/Gamma.pm »