« blib/lib/BoutrosLab/TSVStream/Format/VCF/Role.pm
↑ Summary
lib/BoutrosLab/TSVStream/IO/Role/Reader/Dyn.pm »
| 1 | # safe Perl | ||||||||||||||||||||
| 2 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | BoutrosLab::TSVStream::Format::VCF::Types | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Collection of types used in VCF format fields. Used internally in | ||||||||||||||||||||
| 13 | BoutrosLab::TSVStream::Format::VCF::Role. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | package BoutrosLab::TSVStream::Format::VCF::Types; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 6 | use MooseX::Types -declare => [ | |||||||||||||||||||
| 20 | qw( | ||||||||||||||||||||
| 21 | Str_No_Whitespace | ||||||||||||||||||||
| 22 | VCF_Chrom | ||||||||||||||||||||
| 23 | VCF_Ref | ||||||||||||||||||||
| 24 | VCF_Ref_Full | ||||||||||||||||||||
| 25 | VCF_Alt | ||||||||||||||||||||
| 26 | VCF_Alt_Full | ||||||||||||||||||||
| 27 | VCF_KV_Str | ||||||||||||||||||||
| 28 | ) | ||||||||||||||||||||
| 29 | 6 | ▶ | ]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 6 | ▶ | use MooseX::Types::Moose qw( Int Str ArrayRef HashRef ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | subtype Str_No_Whitespace, | ||||||||||||||||||||
| 34 | as Str, | ||||||||||||||||||||
| 35 | 48 | ▶ | where { /^\S+$/ }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 0 | ▶ | message {"may not contain whitespace characters"}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 6 | subtype VCF_Chrom, as Str_No_Whitespace; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | subtype VCF_Ref, | ||||||||||||||||||||
| 41 | as Str, | ||||||||||||||||||||
| 42 | 6 | ▶ | where { /^-$/ || /^[CGAT]+$/i }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | ▶ | message {"VCF_Ref must be '-' (dash), or a series of 'CGAT' characters"}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 6 | subtype VCF_Ref_Full, | |||||||||||||||||||
| 46 | as Str, | ||||||||||||||||||||
| 47 | # where { /^-$/ || /^[CGAT]+$/i }, | ||||||||||||||||||||
| 48 | # message {"VCF_Ref must be '-' (dash), or a series of 'CGAT' characters"} | ||||||||||||||||||||
| 49 | ; | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | subtype VCF_Alt, | ||||||||||||||||||||
| 52 | as Str, | ||||||||||||||||||||
| 53 | 19 | ▶ | where { /^-$/ || /^[CGAT]+(?:,[CGAT]+)*$/i }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 0 | ▶ | message {"VCF_Alt must be '-' (dash), or one or more comma-separated series of 'CGAT' characters"}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 6 | subtype VCF_Alt_Full, | |||||||||||||||||||
| 57 | as Str, | ||||||||||||||||||||
| 58 | # where { /^-$/ || /^[CGAT]+(?:,[CGAT]+)*$/i }, | ||||||||||||||||||||
| 59 | # message {"VCF_Alt must be '-' (dash), or one or more comma-separated series of 'CGAT' characters"} | ||||||||||||||||||||
| 60 | ; | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 6 | subtype VCF_KV_Str, | |||||||||||||||||||
| 63 | as 'BoutrosLab::TSVStream::Format::VCF::Types::KeyValueString'; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | coerce VCF_KV_Str, | ||||||||||||||||||||
| 66 | from Str, | ||||||||||||||||||||
| 67 | 12 | ▶ | via { BoutrosLab::TSVStream::Format::VCF::Types::KeyValueString->new($_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | package BoutrosLab::TSVStream::Format::VCF::Types::KeyValueString; | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | use overload | ||||||||||||||||||||
| 73 | 6 | ▶ | '""' => 'stringify'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub new { | ||||||||||||||||||||
| 76 | 12 | ▶ | my ($class, $data) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.7
| |||||||||||||||||||||
| 77 | 12 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 78 | 12 | my $data_hash = {}; | |||||||||||||||||||
| 79 | 12 | ▶ | if (ref($data)) { # copy if it is already a HashRef (or KeyValueString object) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 0 | ▶ | while (my ($key, $value) = each %$data) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | $data_hash->{$key} = $value; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | else { # split up a Str | ||||||||||||||||||||
| 85 | 12 | my @split = split(';', $data); | |||||||||||||||||||
| 86 | 12 | foreach my $kv_pair (@split) { | |||||||||||||||||||
| 87 | 24 | my ($key, $value) = split('=', $kv_pair); | |||||||||||||||||||
| 88 | 24 | $data_hash->{$key} = $value; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | 12 | return bless $data_hash, $class; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | sub clone { | ||||||||||||||||||||
| 95 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 96 | 0 | return $self->new($self); | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | sub stringify { | ||||||||||||||||||||
| 100 | 8 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
stringify: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 101 | 8 | my $str = ''; | |||||||||||||||||||
| 102 | 8 | foreach my $key (sort keys %{$self}) { | |||||||||||||||||||
| 103 | 16 | my $val = $self->{$key}; | |||||||||||||||||||
| 104 | 16 | $str .= $key; | |||||||||||||||||||
| 105 | 16 | ▶ | $str .= "=$val" if defined $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 16 | $str .= ";"; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | 8 | $str =~ s/;$//; | |||||||||||||||||||
| 109 | 8 | return $str; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head1 AUTHOR | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | John Macdonald - Boutros Lab | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | Paul Boutros, Phd, PI - Boutros Lab | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | The Ontario Institute for Cancer Research | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 6 | 1; | |||||||||||||||||||
| 126 | |||||||||||||||||||||