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