blib/lib/BoutrosLab/TSVStream/Format/AnnovarInput/Types.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 78 CC 4 SCAR 22.2
CC
4
Cov
0%
_human_chr
20.0
_apply_chr_subtypes
2.0
BEGIN
2.0
CRAP 9.2
1 # safe Perl
2 use warnings;
3 use strict;
4 use Carp;
5  
6 =head1 NAME
7  
8 BoutrosLab::TSVStream::Format::AnnovarInput::Types
9  
10 =head1 SYNOPSIS
11  
12 Collection of types used in AnnovarInput format fields. Used internally in
13 BoutrosLab::TSVStream::Format::AnnovarInput::Role.
14  
15 =cut
16  
17 package BoutrosLab::TSVStream::Format::AnnovarInput::Types;
18  
19 use MooseX::Types -declare => [
20 qw(
21 AI_Ref
22 AI_ChrHuman
23 AI_ChrHumanNoChr
24 AI_ChrHumanWithChr
25 AI_ChrHumanTag
26 AI_ChrHumanTagNoChr
27 AI_ChrHumanTagWithChr
28 )
29 ];
30  
31 use MooseX::Types::Moose qw( Int Str ArrayRef );
32 # use Type::Utils -all;
33  
34 subtype AI_Ref,
35 as Str,
36 where { /^-$/ || /^[CGAT]+(?:,[CGAT]+)*$/i },
37 message {"AI_Ref must be '-' (dash), or one or more series of 'CGAT' characters separated by ','"};
38  
39 sub _human_chr {
40 my ($val, $allow_tag) = @_;
41 return 1 if $allow_tag && $val =~ /^(?:chr)?Un_\S+$/;
42 return 0 unless my ( $l, $v, $tag ) = $val =~ /^(?:chr)?(?:([XYM])|(\d+))(_\S+)?$/;
43 return 1 if ($l || ( 1 <= $v && $v <= 22 )) && ($allow_tag || !$tag);
44 return 0;
45 }
46  
47 sub _apply_chr_subtypes {
48 my ($type, $wc, $nc) = @_;
49  
50 subtype $wc,
51 as $type,
52 where { /^chr/ };
53 subtype $nc,
54 as $type,
55 where { /^(?!chr)/ };
56 coerce $nc, from $wc, via { s/^chr//; $_ };
57 coerce $wc, from $nc, via { s/^/chr/; $_ };
58 }
59  
60 my $notagmessage = " - must be '1'..'22', 'X', 'Y', or 'M'. (A leading 'chr' string is optional.)";
61  
62 subtype AI_ChrHuman,
63 as Str,
64 where { _human_chr($_) },
65 message { "$notagmessage Found: $_" };
66  
67 _apply_chr_subtypes( AI_ChrHuman, AI_ChrHumanWithChr, AI_ChrHumanNoChr );
68  
69 my $tagmessage = " - must be '1'..'22', 'X', 'Y', or 'M'; optionally followed a tag; or 'Un' followed by a (required) tag. A tag must start with an underscore. (A leading 'chr' string is optional.)";
70  
71 subtype AI_ChrHumanTag,
72 as Str,
73 where { _human_chr($_, 1) },
74 message { "$tagmessage Found: $_" };
75  
76 _apply_chr_subtypes( AI_ChrHumanTag, AI_ChrHumanTagWithChr, AI_ChrHumanTagNoChr );
77  
78 =head1 AUTHOR
79  
80 John Macdonald - Boutros Lab
81  
82 =head1 ACKNOWLEDGEMENTS
83  
84 Paul Boutros, Phd, PI - Boutros Lab
85  
86 The Ontario Institute for Cancer Research
87  
88 =cut
89  
90 1;
91