blib/lib/Bio/Community/IO/Driver/gaas.pm

filter: Statementstmt 99.1% 116 / 117 Branchbran 55.5% 30 / 54 Conditioncond 44.4% 12 / 27 MC/DCmcdc 11.7% 2 / 17 Subroutinesub 100% 26 / 26 Podpod n/a totaltotal 77.1% 186 / 241 CC 37 SCAR 15.6
CC
37
Cov
80%
write_member
9.3
next_member
8.6
_write_community_init
5.6
CRAP 4.8
« blib/lib/Bio/Community/IO/Driver/qiime.pm ↑ Summary blib/lib/Bio/Community/Alpha.pm »
1 # BioPerl module for Bio::Community::IO::Driver::gaas
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::IO::Driver::gaas - Driver to read and write files in the GAAS format
13  
14 =head1 SYNOPSIS
15  
16 my $in = Bio::Community::IO->new( -file => 'gaas_communities.txt', -format => 'gaas' );
17  
18 # See Bio::Community::IO for more information
19  
20 =head1 DESCRIPTION
21  
22 This Bio::Community::IO::Driver::gaas driver reads and writes files in the format
23 generated by GAAS (http://sourceforge.net/projects/gaas/). GAAS creates one such
24 file per community. Here is an example:
25  
26 # tax_name tax_id rel_abund
27 Streptococcus pyogenes phage 315.1 198538 0.791035649011735
28 Goatpox virus Pellor 376852 0.196094208626593
29 Lumpy skin disease virus NI-2490 376849 0.0128701423616715
30  
31 For each Bio::Community::Member $member generated from a GAAS file, $member->id()
32 contains the content of the tax_id field, while $member->desc() reflects the
33 tax_name field.
34  
35 Note that GAAS format does not include counts for the community members but
36 relative abundances only. Thus, the get_members_count() method of the
37 Bio::Community objects generated using this driver is a relative abundance
38 (a decimal number) instead of the usual integers used for counts.
39  
40 =head1 CONSTRUCTOR
41  
42 See L<Bio::Community::IO>.
43  
44 =head1 AUTHOR
45  
46 Florent Angly L<florent.angly@gmail.com>
47  
48 =head1 SUPPORT AND BUGS
49  
50 User feedback is an integral part of the evolution of this and other Bioperl
51 modules. Please direct usage questions or support issues to the mailing list,
52 L<bioperl-l@bioperl.org>, rather than to the module maintainer directly. Many
53 experienced and reponsive experts will be able look at the problem and quickly
54 address it. Please include a thorough description of the problem with code and
55 data examples if at all possible.
56  
57 If you have found a bug, please report it on the BioPerl bug tracking system
58 to help us keep track the bugs and their resolution:
59 L<https://redmine.open-bio.org/projects/bioperl/>
60  
61 =head1 COPYRIGHT
62  
63 Copyright 2011-2014 by Florent Angly <florent.angly@gmail.com>
64  
65 This library is free software; you can redistribute it and/or modify
66 it under the same terms as Perl itself, either Perl version 5.10.1 or,
67 at your option, any later version of Perl 5 you may have available.
68  
69 =cut
70  
71  
72 package Bio::Community::IO::Driver::gaas;
73  
74 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 2 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 2 ▶use Bio::Community::Member;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 2 extends 'Bio::Community::IO';
80 2 with 'Bio::Community::Role::IO';
81  
82  
83 2 our $multiple_communities = 0; # the format supports one community per file
84 2 our $explicit_ids = 1; # IDs are explicitly recorded
85 2 our $default_sort_members = -1; # sorted by decreasing abundance
86 2 our $default_abundance_type = 'fraction'; # fractional number between 0 and 1
87 2 our $default_missing_string = 0; # empty members get a '0'
88  
89  
90 2 has '_count' => (
91 is => 'rw',
92 isa => 'PositiveInt',
93 required => 0,
94 init_arg => undef,
95 default => 0,
96 lazy => 1,
97 );
98  
99  
100 2 ▶method next_member () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine next_member: called CC=8 SCAR=21.5
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 20 20
101 # Read next line
102 20 my $line;
103 20 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^#/ || $line =~ /^\s*$/ and do { do { $line = $self->_readline; unless (defined $line) { return undef; } } } 8 15 23
Condition100%3/3
$line =~ /^#/ or $line =~ /^\s*$/
l!l&&r!l&&!r
5315
MC/DC100%2/2
$line =~ /^#/ or $line =~ /^\s*$/
$line =~ /^#/ $line =~ /^\s*$/
Truth table100%3/3
A or B
A= $line =~ /^#/B= $line =~ /^\s*$/
ABresult
1X1
011
000
104 28 $line = $self->_readline;
105 28 ▶ if (not defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 5 23 28
106 5 return undef;
107 }
108 } while ( ($line =~ m/^#/) || ($line =~ m/^\s*$/) ); # skip comment and empty lines
109  
110 # Parse and validate the line
111 15 chomp $line;
112 15 my ($name, $taxid, $rel_ab) = split "\t", $line;
113  
114 15 ▶ if ( (not defined $name ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and defined $taxid and defined $rel_ab) 0 15 15
Condition33%2/6
defined $name and defined $taxid and defined $rel_ab
!ll&&!rl&&r
0015
defined $name and defined $taxid
!ll&&!rl&&r
0015
MC/DC0%0/3
defined $name and defined $taxid and defined $rel_ab
defined $name defined $taxid defined $rel_ab
Truth table25%1/4
A and B and C
A= defined $nameB= defined $taxidC= defined $rel_ab
ABCresult
0XX0
10X0
1100
1111
115 (not defined $taxid ) ||
116 (not defined $rel_ab) ) {
117 0 $self->throw("Error: The following line does not follow the GAAS format.\n-->$line<--\n");
118 }
119  
120 15 my $member = Bio::Community::Member->new( -id => $taxid, -desc => $name );
121 15 $self->_attach_taxon($member, $taxid, 0);
122 ### TODO:handle things differently if GAAS did not use a taxonomy file??
123 15 $self->_attach_weights($member);
124  
125 # Note that a relative abundance is returned, not a count
126 15 return $member, $rel_ab;
127 }
128  
129  
130 2 ▶method _next_community_init () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _next_community_init: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 10 10
131 10 my $count = $self->_count;
132 10 $count++;
133 10 ▶ if ($count <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count <= 1) { } 5 5 10
134 5 $self->_count($count);
135 5 return ''; # name of community
136 } else {
137 5 return undef;
138 }
139 }
140  
141  
142 2 ▶method _next_community_finish () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _next_community_finish: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 5 5
143 5 return 1;
144 }
145  
146  
147 2 ▶method _next_metacommunity_init () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _next_metacommunity_init: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 5 5
148 5 my $name = ''; # no provision for metacommunity name in this format
149 5 return $name;
150 }
151  
152  
153 2 ▶method _next_metacommunity_finish () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _next_metacommunity_finish: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 4 4
154 4 return 1;
155 }
156  
157  
158 2 ▶method write_member (Bio::Community::Member $member, Count $count) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine write_member: called CC=8 SCAR=22.3
Branch: 5 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 6 6
unless ($Method::Signatures::mutc{"cache"}{"Bio::Community::Member"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Member"))->check($member) 0 6 6
unless scalar @_ > 1 0 6 6
unless ($Method::Signatures::mutc{"cache"}{"Count"} ||= "Method::Signatures"->_make_constraint("Count"))->check($count) 0 6 6
if scalar @_ > 2 0 6 6
Condition50%3/6
$Method::Signatures::mutc{"cache"}{"Bio::Community::Member"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Member")
l!l&&r!l&&!r
600
$Method::Signatures::mutc{"cache"}{"Count"} ||= "Method::Signatures"->_make_constraint("Count")
l!l&&r!l&&!r
510
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Bio::Community::Member"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Member")
$Method::Signatures::mutc{"cache"}{"Bio::Community::Member"} "Method::Signatures"->_make_constraint("Bio::Community::Member")
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Count"} ||= "Method::Signatures"->_make_constraint("Count")
$Method::Signatures::mutc{"cache"}{"Count"} "Method::Signatures"->_make_constraint("Count")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Bio::Community::Member"}B= "Method::Signatures"->_make_constraint("Bio::Community::Member")
ABresult
1X1
011
000
Truth table66%2/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Count"}B= "Method::Signatures"->_make_constraint("Count")
ABresult
1X1
011
000
159 6 my $line = $member->desc."\t".$member->id."\t".$count."\n";
160 6 $self->_print( $line );
161 6 return 1;
162 }
163  
164  
165 2 ▶method _write_community_init (Bio::Community $community) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine _write_community_init: called CC=5 SCAR=17.3
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 2 2
unless ($Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community"))->check($community) 0 2 2
if scalar @_ > 1 0 2 2
Condition33%1/3
$Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community")
l!l&&r!l&&!r
200
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community")
$Method::Signatures::mutc{"cache"}{"Bio::Community"} "Method::Signatures"->_make_constraint("Bio::Community")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Bio::Community"}B= "Method::Signatures"->_make_constraint("Bio::Community")
ABresult
1X1
011
000
166 2 return 1;
167 }
168  
169  
170 2 ▶method _write_headers () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _write_headers: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 2 2
171 2 my $header_line = "# tax_name\ttax_id\trel_abund\n";
172 # But it could also be "# seq_name\tseq_id\trel_abund\n";
173 2 $self->_print( $header_line );
174 }
175  
176  
177 2 ▶method _write_community_finish (Bio::Community $community) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine _write_community_finish: called CC=5 SCAR=17.3
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 2 2
unless ($Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community"))->check($community) 0 2 2
if scalar @_ > 1 0 2 2
Condition33%1/3
$Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community")
l!l&&r!l&&!r
200
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Bio::Community"} ||= "Method::Signatures"->_make_constraint("Bio::Community")
$Method::Signatures::mutc{"cache"}{"Bio::Community"} "Method::Signatures"->_make_constraint("Bio::Community")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Bio::Community"}B= "Method::Signatures"->_make_constraint("Bio::Community")
ABresult
1X1
011
000
178 2 return 1;
179 }
180  
181  
182 2 ▶method _write_metacommunity_init (Bio::Community::Meta $meta) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine _write_metacommunity_init: called CC=5 SCAR=17.1
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 2 2
unless ($Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta"))->check($meta) 0 2 2
if scalar @_ > 1 0 2 2
Condition33%1/3
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
l!l&&r!l&&!r
200
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} "Method::Signatures"->_make_constraint("Bio::Community::Meta")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"}B= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
ABresult
1X1
011
000
183 # Write first column header
184 2 $self->_write_headers;
185 2 return 1;
186 }
187  
188  
189 2 ▶method _write_metacommunity_finish (Bio::Community::Meta $meta) {
Subroutine BEGIN: called CC=1 SCAR=0.3
Subroutine _write_metacommunity_finish: called CC=5 SCAR=17.3
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 2 2
unless ($Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta"))->check($meta) 0 2 2
if scalar @_ > 1 0 2 2
Condition33%1/3
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
l!l&&r!l&&!r
200
MC/DC0%0/2
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} ||= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
$Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"} "Method::Signatures"->_make_constraint("Bio::Community::Meta")
Truth table33%1/3
A ||= B
A= $Method::Signatures::mutc{"cache"}{"Bio::Community::Meta"}B= "Method::Signatures"->_make_constraint("Bio::Community::Meta")
ABresult
1X1
011
000
190 2 return 1;
191 }
192  
193  
194  
195 2 __PACKAGE__->meta->make_immutable;
196  
197 2 1;
« blib/lib/Bio/Community/IO/Driver/qiime.pm ↑ Summary blib/lib/Bio/Community/Alpha.pm »