File Coverage

lib/BoutrosLab/TSVStream/Format/VCF/Role.pm
Criterion Covered Total %
statement 118 118 100.0
branch 6 6 100.0
condition n/a
subroutine 38 38 100.0
pod 0 2 0.0
total 162 164 98.7


line stmt bran cond sub pod time code
1             # safe Perl
2 2     2   7 use warnings;
  2         2  
  2         53  
3 2     2   8 use strict;
  2         1  
  2         29  
4 2     2   6 use Carp;
  2         2  
  2         116  
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     2   716 use Moose::Role;
  2         5952  
  2         22  
31 2     2   7796 use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Chrom VCF_Ref Str_No_Whitespace VCF_KV_Str );
  2         5  
  2         15  
32 2     2   3617 use MooseX::Types::Moose qw( ArrayRef HashRef Int );
  2         3  
  2         7  
33 2     2   7345 use MooseX::ClassAttribute;
  2         99330  
  2         8  
34 2     2   370617 use namespace::autoclean;
  2         4  
  2         19  
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             default => sub { [qw(chrom pos id ref alt qual filter info)] }
51             );
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             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             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             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             has [qw(qual filter)] => ( is => 'rw', isa => Str_No_Whitespace );
105              
106             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             default => sub {
129             return {
130             pre_header => 1,
131             pre_comment => 0,
132             comment => 0,
133             pre_header_pattern => qr/^##/,
134             header_fix => sub {
135             my $line = shift;
136             my %newline;
137             ($newline{line} = $line->{line}) =~ s/^#\s*//;
138             $newline{fields} = [ @{ $line->{fields} } ];
139             $newline{fields}[0] =~ s/^#\s*//;
140             return \%newline;
141             },
142             };
143             }
144             );
145              
146             class_has '_writer_args' => (
147             is => 'ro',
148             isa => 'HashRef',
149             init_arg => undef,
150             default => sub {
151             return {
152             pre_header => 1,
153             pre_comment => 0,
154             comment => 0,
155             header_fix => sub {
156             my $headers = [ @{(shift)} ];
157             $headers->[0] =~ s/^/#/;
158             my @uc_headers = map { uc } @{$headers};
159             return \@uc_headers;
160             },
161             };
162             }
163             );
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     2   890 use Moose::Role;
  2         2  
  2         12  
199 2     2   8202 use namespace::autoclean;
  2         3  
  2         9  
200 2     2   125 use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Ref_Full VCF_Alt_Full );
  2         3  
  2         22  
201              
202             has 'ref' => ( is => 'rw', isa => VCF_Ref_Full );
203             has 'alt' => ( is => 'rw', isa => VCF_Alt_Full );
204              
205             package BoutrosLab::TSVStream::Format::VCF::Role::RecSNV;
206              
207 2     2   3672 use Moose::Role;
  2         3  
  2         8  
208 2     2   7804 use namespace::autoclean;
  2         3  
  2         8  
209 2     2   133 use BoutrosLab::TSVStream::Format::VCF::Types qw( VCF_Ref VCF_Alt );
  2         2  
  2         8  
210              
211             has 'ref' => ( is => 'rw', isa => VCF_Ref );
212             has 'alt' => ( is => 'rw', isa => VCF_Alt );
213              
214             package BoutrosLab::TSVStream::Format::VCF::Role::WithChr;
215              
216 2     2   2881 use Carp qw(croak);
  2         2  
  2         110  
217              
218 2     2   8 use Moose::Role;
  2         2  
  2         6  
219 2     2   6406 use namespace::autoclean;
  2         3  
  2         8  
220 2     2   1018 use BoutrosLab::TSVStream::Format::AnnovarInput::Types qw( AI_ChrHumanTagWithChr );
  2         4  
  2         8  
221              
222             sub chr {
223 4     4 0 65 my $self = shift;
224 4         121 my $chrom = my $chr = $self->chrom;
225 4 100       13 if ($chr =~ /^chr/i) {
226 3         10 $chr =~ s/^chr/chr/i;
227             }
228             else {
229 1         2 $chr = "chr$chr";
230             }
231 4 100       18 croak( "chrom ($chrom) failed to convert to AnnovarInput chr" )
232             unless is_AI_ChrHumanTagWithChr($chr);
233 2         14 return to_AI_ChrHumanTagWithChr($chr);
234             }
235              
236             package BoutrosLab::TSVStream::Format::VCF::Role::WithNoChr;
237              
238 2     2   3128 use Carp qw(croak);
  2         2  
  2         111  
239              
240 2     2   8 use Moose::Role;
  2         2  
  2         12  
241 2     2   6723 use namespace::autoclean;
  2         2  
  2         25  
242 2     2   123 use BoutrosLab::TSVStream::Format::AnnovarInput::Types qw( AI_ChrHumanTagNoChr );
  2         2  
  2         7  
243              
244             sub chr {
245 4     4 0 83 my $self = shift;
246 4         129 my $chrom = my $chr = $self->chrom;
247 4         13 $chr =~ s/^chr//i;
248 4 100       20 croak( "chrom ($chrom) failed to convert to AnnovarInput chr" )
249             unless is_AI_ChrHumanTagNoChr($chr);
250 2         22 return to_AI_ChrHumanTagNoChr($chr);
251             }
252              
253             package BoutrosLab::TSVStream::Format::VCF::Role::FullChr;
254              
255 2     2   3112 use Moose::Role;
  2         4  
  2         12  
256 2     2   6393 use namespace::autoclean;
  2         4  
  2         6  
257              
258             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     2   174 use Moose::Role;
  2         3  
  2         7  
265 2     2   6250 use namespace::autoclean;
  2         4  
  2         8  
266              
267             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     2   134 use Moose::Role;
  2         2  
  2         7  
274 2     2   6395 use namespace::autoclean;
  2         3  
  2         7  
275              
276             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     2   137 use Moose::Role;
  2         3  
  2         6  
282 2     2   6396 use namespace::autoclean;
  2         2  
  2         7  
283              
284             with 'BoutrosLab::TSVStream::Format::VCF::Role';
285              
286             sub start {
287 4     4   7 my $self = shift;
288 4         121 return $self->pos;
289             }
290              
291             sub end {
292 4     4   7 my $self = shift;
293 4         115 return $self->pos + length($self->ref) - 1;
294             }
295              
296             package BoutrosLab::TSVStream::Format::VCF::Role::AsAnnovarInputChr;
297              
298 2     2   260 use Moose::Role;
  2         2  
  2         7  
299 2     2   6398 use namespace::autoclean;
  2         4  
  2         6  
300              
301             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     2   127 use Moose::Role;
  2         3  
  2         6  
307 2     2   6325 use namespace::autoclean;
  2         4  
  2         6  
308              
309             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             1;
352