lib/BoutrosLab/TSVStream/Format/VCF/Role.pm

filter: Statementstmt 100% 154 / 154 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 43 / 43 Podpod 0.0% 0 / 2 totaltotal 99.0% 203 / 205 CC 4 SCAR 1.6
CC
4
Cov
100%
chr
3.0
chr
2.0
BEGIN
1.0
CRAP 1.2
« lib/BoutrosLab/TSVStream/IO/Role/Base/Dyn.pm ↑ Summary lib/BoutrosLab/TSVStream/IO/Role/Writer/Dyn.pm »
1 # safe Perl
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 BoutrosLab::TSVStream::Format::VCF::Role
9  
10 =head1 SYNOPSIS
11  
12 Collection of roles that implement VCF format capable objects.
13 This role provides the common attributes for VCF format.
14 It also supplies methods that allow a VCF object act as a AnnovarInput
15 object.
16  
17 =head1 DESCRIPTION
18  
19 These roles are combined with an IO/Base role to provide one of the
20 two standard variants (Fixed and Dyn - depending upon whether you wish
21 to allow only the default set of fields or to allow additional trailing
22 fields following the default ones.)
23  
24 See BoutrosLab::TSVStream::Format::Human::Fixed for an example.
25  
26 =cut
27  
28 package BoutrosLab::TSVStream::Format::VCF::Role::Base;
29  
30 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Chrom VCF_Ref Str_No_Whitespace VCF_KV_Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use MooseX::Types::Moose qw( ArrayRef HashRef Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use MooseX::ClassAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =head1 Class Attributes
37  
38 =head2 _fields
39  
40 The B<_fields> attribute is required by the IO roles to determine
41 which fields are to be read or written. In this case, the fields
42 are C<chrom>, C<start>, C<end>, C<ref>, and C<alt>, which are described
43 as attributes below.
44  
45 =cut
46  
47 class_has '_fields' => (
48 is => 'ro',
49 isa => 'ArrayRef',
50 4 ▶ default => sub { [qw(chrom pos id ref alt qual filter info)] }
Subroutine __ANON__: called CC=1 SCAR=0.0
51 2 );
52  
53 =head1 Attributes
54  
55 =head2 chrom
56  
57 The B<chrom> attribute provides the name of the chromosome that is
58 being specified. There are different names used for different
59 species of organism; and for different ways of processing the same
60 organism; so this attribute is provided in a separate role.
61  
62 =cut
63  
64 2 has 'chrom' => ( is => 'rw', isa => VCF_Chrom );
65  
66 =head2 pos
67  
68 The B<pos> attribute is an integer that provide the start
69 position within the chromosome that is being described.
70  
71 =cut
72  
73 2 has 'pos' => ( is => 'rw', isa => 'Int' );
74  
75 =head2 id
76  
77 The B<id> attribute is a string, not yet supported (in this module} for any specific use.
78  
79 =cut
80  
81 2 has 'id' => ( is => 'rw', isa => Str_No_Whitespace );
82  
83 =head2 ref
84  
85 =head2 alt
86  
87 The B<ref> and B<alt> attributes describe amino acid sequences.
88 They can either contain the string I<'-'>, or a sequence of acids
89 (C<'A'>, C<'C'>, C<'G'>, and C<'T'> of at most 500 acids. (E.G.:
90 CGATCGAT)
91  
92 =cut
93  
94 =head2 qual
95  
96 =head2 filter
97  
98 =head2 info
99  
100 The B<qual>, B<filter>, and B<ifno> attributes are strings, not yet supported (in this module} for any specific use.
101  
102 =cut
103  
104 2 has [qw(qual filter)] => ( is => 'rw', isa => Str_No_Whitespace );
105  
106 2 has 'info' => (
107 is => 'rw',
108 isa => VCF_KV_Str,
109 coerce => 1
110 );
111  
112 =head2 _reader_args
113  
114 =head2 _writer_args
115  
116 =head2 info
117  
118 The B<_reader_args> and B<_writer_args> attributes are internal settings.
119 They cause the reader and writer be given special args required for handling
120 VCF format files properly.
121  
122 =cut
123  
124 class_has '_reader_args' => (
125 is => 'ro',
126 isa => 'HashRef',
127 init_arg => undef,
128 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
129 return {
130 pre_header => 1,
131 pre_comment => 0,
132 comment => 0,
133 pre_header_pattern => qr/^##/,
134 12 ▶ header_fix => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
135 12 my $line = shift;
136 12 my %newline;
137 12 ($newline{line} = $line->{line}) =~ s/^#\s*//;
138 12 $newline{fields} = [ @{ $line->{fields} } ];
139 12 $newline{fields}[0] =~ s/^#\s*//;
140 12 return \%newline;
141 },
142 4 };
143 }
144 2 );
145  
146 class_has '_writer_args' => (
147 is => 'ro',
148 isa => 'HashRef',
149 init_arg => undef,
150 4 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
151 return {
152 pre_header => 1,
153 pre_comment => 0,
154 comment => 0,
155 4 ▶ header_fix => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
156 4 my $headers = [ @{(shift)} ];
157 4 $headers->[0] =~ s/^/#/;
158 4 my @uc_headers = map { uc } @{$headers};
159 4 return \@uc_headers;
160 },
161 4 };
162 }
163 2 );
164  
165 #### Methods
166  
167 =head1 WRAPPER ROLES
168  
169 =head2 BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInputChr
170  
171 =head2 BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInputNoChr
172  
173 These wrapper roles provide a wrapper around the basic VCF role that
174 allows a vcf format record to be used as if it were an AnnovarInput
175 (or AnnovarInput...NoChr) format record. This is done by providing
176 B<start>, B<end>, and B<chr> methods that match the attributes that
177 are normally present in an AnnovarInput record.
178  
179 =head3 start
180  
181 =head3 end
182  
183 The B<start> and B<end> attributes are integers that provide the start
184 and end position within the chromosome that is being described. The
185 B<start> value is just a synonym for the B<pos> attribute. The B<end>
186 attribute is computed from the B<pos> value and the length of the
187 B<ref> attribute.
188  
189 =head3 chr
190  
191 The B<chr> attribute is the B<chrom> attribute with a leading 'chr'
192 string either forced or removed.
193  
194 =cut
195  
196 package BoutrosLab::TSVStream::Format::VCF::Role::Full;
197  
198 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
199 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
200 2 ▶use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Ref_Full VCF_Alt_Full );
Subroutine BEGIN: called CC=1 SCAR=0.0
201  
202 2 has 'ref' => ( is => 'rw', isa => VCF_Ref_Full );
203 2 has 'alt' => ( is => 'rw', isa => VCF_Alt_Full );
204  
205 package BoutrosLab::TSVStream::Format::VCF::Role::RecSNV;
206  
207 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
208 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 2 ▶use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Ref VCF_Alt );
Subroutine BEGIN: called CC=1 SCAR=0.0
210  
211 2 has 'ref' => ( is => 'rw', isa => VCF_Ref );
212 2 has 'alt' => ( is => 'rw', isa => VCF_Alt );
213  
214 package BoutrosLab::TSVStream::Format::VCF::Role::WithChr;
215  
216 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
217  
218 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
219 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
220 2 ▶use BoutrosLab::TSVStream::Format::AnnovarInput::Types qw( AI_ChrHumanTagWithChr );
Subroutine BEGIN: called CC=1 SCAR=0.0
221  
222 4 ▶sub chr {
Subroutine chr: called CC=3 SCAR=11.0
Pod undocumented
223 4 my $self = shift;
224 4 my $chrom = my $chr = $self->chrom;
225 4 ▶ if ($chr =~ /^chr/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chr =~ /^chr/i) { } 3 1 4
226 3 $chr =~ s/^chr/chr/i;
227 }
228 else {
229 1 $chr = "chr$chr";
230 }
231 4 ▶ croak( "chrom ($chrom) failed to convert to AnnovarInput chr" )
Branch: 1 branch
BranchTrueFalseTotal
unless is_AI_ChrHumanTagWithChr($chr) 2 2 4
232 unless is_AI_ChrHumanTagWithChr($chr);
233 2 return to_AI_ChrHumanTagWithChr($chr);
234 }
235  
236 package BoutrosLab::TSVStream::Format::VCF::Role::WithNoChr;
237  
238 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
239  
240 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
241 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
242 2 ▶use BoutrosLab::TSVStream::Format::AnnovarInput::Types qw( AI_ChrHumanTagNoChr );
Subroutine BEGIN: called CC=1 SCAR=0.0
243  
244 4 ▶sub chr {
Subroutine chr: called CC=2 SCAR=6.9
Pod undocumented
245 4 my $self = shift;
246 4 my $chrom = my $chr = $self->chrom;
247 4 $chr =~ s/^chr//i;
248 4 ▶ croak( "chrom ($chrom) failed to convert to AnnovarInput chr" )
Branch: 1 branch
BranchTrueFalseTotal
unless is_AI_ChrHumanTagNoChr($chr) 2 2 4
249 unless is_AI_ChrHumanTagNoChr($chr);
250 2 return to_AI_ChrHumanTagNoChr($chr);
251 }
252  
253 package BoutrosLab::TSVStream::Format::VCF::Role::FullChr;
254  
255 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
256 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
257  
258 2 with 'BoutrosLab::TSVStream::Format::VCF::Role::Base',
259 'BoutrosLab::TSVStream::Format::VCF::Role::Full',
260 'BoutrosLab::TSVStream::Format::VCF::Role::WithChr';
261  
262 package BoutrosLab::TSVStream::Format::VCF::Role::FullNoChr;
263  
264 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
265 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
266  
267 2 with 'BoutrosLab::TSVStream::Format::VCF::Role::Base',
268 'BoutrosLab::TSVStream::Format::VCF::Role::Full',
269 'BoutrosLab::TSVStream::Format::VCF::Role::WithNoChr';
270  
271 package BoutrosLab::TSVStream::Format::VCF::Role;
272  
273 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
274 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
275  
276 2 with 'BoutrosLab::TSVStream::Format::VCF::Role::Base',
277 'BoutrosLab::TSVStream::Format::VCF::Role::RecSNV';
278  
279 package BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInput;
280  
281 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
282 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
283  
284 2 with 'BoutrosLab::TSVStream::Format::VCF::Role';
285  
286 4 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
287 4 my $self = shift;
288 4 return $self->pos;
289 }
290  
291 4 ▶sub end {
Subroutine end: called CC=1 SCAR=0.0
292 4 my $self = shift;
293 4 return $self->pos + length($self->ref) - 1;
294 }
295  
296 package BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInputChr;
297  
298 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
299 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
300  
301 2 with 'BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInput',
302 'BoutrosLab::TSVStream::Format::VCF::Role::WithChr';
303  
304 package BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInputNoChr;
305  
306 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
307 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
308  
309 2 with 'BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInput',
310 'BoutrosLab::TSVStream::Format::VCF::Role::WithNoChr';
311  
312 =head1 SEE ALSO
313  
314 =over
315  
316 =item BoutrosLab::TSVStream::Format
317  
318 This describes how IO-capable objects (such as ones created using
319 a subrole of this role) are defined.
320  
321 =item BoutrosLab::TSVStream::IO
322  
323 This describes of how readers and writers convert objects to or
324 from a text stream.
325  
326 =item - BoutrosLab::TSVStream::Format::VCF::Fixed
327  
328 =item - BoutrosLab::TSVStream::Format::VCF::Dyn
329  
330 These are the two variants for the object specification for VCF
331 objects. Those are the modules that you will typically B<use>
332 and refer to in your program.
333  
334 Fixed/Dyn specifies whether only the standard fields are expected,
335 or if a dynamic list of additional fields may occur.
336  
337 =back
338  
339 =head1 AUTHOR
340  
341 John Macdonald - Boutros Lab
342  
343 =head1 ACKNOWLEDGEMENTS
344  
345 Paul Boutros, Phd, PI - Boutros Lab
346  
347 The Ontario Institute for Cancer Research
348  
349 =cut
350  
351 2 1;
352  
« lib/BoutrosLab/TSVStream/IO/Role/Base/Dyn.pm ↑ Summary lib/BoutrosLab/TSVStream/IO/Role/Writer/Dyn.pm »