| 1 | package Bio::ASN1::EntrezGene; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | our $AUTHORITY = 'cpan:BIOPERLML'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | $Bio::ASN1::EntrezGene::VERSION = '1.72'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Regular expression-based Perl Parser for NCBI Entrez Gene. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # AUTHOR: Dr. Mingyi Liu <mingyiliu@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # OWNER: 2005 Mingyi Liu | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # OWNER: 2005 GPC Biotech AG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # OWNER: 2005 Altana Research Institute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # LICENSE: Perl_5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | $class = ref($class) if(ref($class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my $self = { maxerrstr => 20, @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | map { $self->input_file($self->{$_}) if($self->{$_}) } qw(file -file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | map { $self->fh($self->{$_}) if($self->{$_}) } qw(fh -fh); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | sub maxerrstr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
maxerrstr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->{maxerrstr} = $value if $value > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $self->{maxerrstr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | my ($self, $input, $compact, $noreset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | $input || croak "must have input!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | $self->{input} = $input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | $self->{filename} = "input" unless $self->{filename}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $self->{linenumber} = 1 unless $self->{linenumber} && $noreset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"linenumber"} and $noreset
MC/DC0%0/2
$self->{"linenumber"} and $noreset
$self->{"linenumber"}
$noreset
Truth table33%1/3
A and B
A= $self->{"linenumber"}B= $noreset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | $self->{depth} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | $result = $self->_parse(); # no need to reset $self->{depth} or linenumber | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | if($@) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if($@ !~ /^Data Error:/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | croak "non-conforming data broke parser on line $self->{linenumber} in $self->{filename}\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | "possible cause includes randomly inserted brackets in input file before line $self->{linenumber}\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "first $self->{maxerrstr} (or till end of input) characters including the non-conforming data:\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | substr($self->{input}, pos($self->{input}), $self->{maxerrstr}) . "\nRaw error mesg: $@\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | else { die $@ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | trimdata($result, $compact); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sub input_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_file: called CC=4 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # in case user's Perl system can't handle large file. Assuming Unix, otherwise raise error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | local *IN; # older styled code to enable module to work with perl 5.005_03 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | open(*IN, $filename) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
open *IN, $filename or $! =~ /too large/i and open *IN, "cat $filename |"
$! =~ /too large/i and open *IN, "cat $filename |"
MC/DC0%0/3
open *IN, $filename or $! =~ /too large/i and open *IN, "cat $filename |"
open *IN, $filename
$! =~ /too large/i
open *IN, "cat $filename |"
Truth table25%1/4
A or B and C
A= open *IN, $filenameB= $! =~ /too large/iC= open *IN, "cat $filename |"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ($! =~ /too large/i && open(*IN, "cat $filename |")) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | croak "can't open $filename! -- $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $self->{fh} = *IN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $self->{filename} = $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $self->{linenumber} = 0; # reset line number | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | sub next_seq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | my ($self, $compact) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_seq: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | $self->{fh} || croak "you must pass in a file name or handle through new() or input_file() first before calling next_seq!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | local $/ = "Entrezgene ::= {"; # set record separator | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | while($_ = readline($self->{fh})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | next unless /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | my $tmp = (/^\s*Entrezgene(-Set)? ::= ({.*)/si)? $2 : "{" . $_; # get rid of the 'Entrezgene ::= ' at the beginning of Entrez Gene record | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | return $self->parse($tmp, $compact, 1); # 1 species no resetting line number | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub _parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 567 | ▶ | my ($self, $flag) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=26 SCAR=34.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 567 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 567 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # changing orders of regex if/elsif statements made little difference. current order is close to optimal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 3023 | ▶ | if($self->{input} =~ /\G[ \t]*,?[ \t]*\n/cg) # cleanup leftover | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1228 | $self->{linenumber}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1228 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1795 | ▶ | if($self->{input} =~ /\G[ \t]*}/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 421 | ▶ | if(!($self->{depth}--) && $self->{input} =~ /\S/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->{"depth"}-- and $self->{"input"} =~ /\S/
MC/DC0%0/2
not $self->{"depth"}-- and $self->{"input"} =~ /\S/
not $self->{"depth"}--
$self->{"input"} =~ /\S/
Truth table33%1/3
not(A) and B
A= not $self->{"depth"}--B= $self->{"input"} =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | croak "Data Error: extra (mismatched) '}' found on line $self->{linenumber} in $self->{filename}!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 421 | return $data | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | elsif($self->{input} =~ /\G[ \t]*{/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 173 | $self->{depth}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 173 | push(@$data, $self->_parse()) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | elsif($self->{input} =~ /\G[ \t]*([\w-]+)(\s*)/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1188 | my ($id, $lines) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # we're prepared for NCBI to make the format even worse: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # note: to count line numbers right for text files on different OS, I'm sacrificing much speed (maybe I shouldn't worry so much) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1188 | ▶ | $self->{linenumber} += $lines =~ s/\n//g || $lines =~ s/\r//g; # count by *NIX/Win or Mac | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$lines =~ s/\n//g || $lines =~ s/\r//g
MC/DC50%1/2
$lines =~ s/\n//g || $lines =~ s/\r//g
$lines =~ s/\n//g
$lines =~ s/\r//g
Truth table66%2/3
A || B
A= $lines =~ s/\n//gB= $lines =~ s/\r//g
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1188 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # we put \s* in lookahead for linenumber counting purpose (which slows things down) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1188 | ▶ | if(($self->{input} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cg && ++$tmp) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
$self->{"input"} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cg and ++$tmp or $self->{"input"} =~ /\G([\w-]+)(?=\s*[,}])/cg
$self->{"input"} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cg and ++$tmp
MC/DC66%2/3
$self->{"input"} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cg and ++$tmp or $self->{"input"} =~ /\G([\w-]+)(?=\s*[,}])/cg
$self->{"input"} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cg
++$tmp
$self->{"input"} =~ /\G([\w-]+)(?=\s*[,}])/cg
Truth table60%3/5
A and B or C
A= $self->{"input"} =~ /\G"((?:[^"]+|"")*)"(?=\s*[,}])/cgB= ++$tmpC= $self->{"input"} =~ /\G([\w-]+)(?=\s*[,}])/cg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $self->{input} =~ /\G([\w-]+)(?=\s*[,}])/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 796 | my $value = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 796 | ▶ | if($tmp) # slight speed optimization, not really necessary since regex is fast enough | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 261 | $value =~ s/""/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 261 | ▶ | $self->{linenumber} += $value =~ s/\n//g || $value =~ s/\r//g; # count by *NIX/Win or Mac | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$value =~ s/\n//g || $value =~ s/\r//g
MC/DC50%1/2
$value =~ s/\n//g || $value =~ s/\r//g
$value =~ s/\n//g
$value =~ s/\r//g
Truth table66%2/3
A || B
A= $value =~ s/\n//gB= $value =~ s/\r//g
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 261 | $value =~ s/[\r\n]+//g; # in case it's Win format | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 796 | ▶ | if(ref($data->{$id})) { push(@{$data->{$id}}, $value) } # hash value is not a terminal (or have multiple values), create array to avoid multiple same-keyed hash overwrite each other | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | elsif($data->{$id}) { $data->{$id} = [$data->{$id}, $value] } # hash value has a second terminal value now! | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 790 | else { $data->{$id} = $value } # the first terminal value | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | elsif($self->{input} =~ /\G\{/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 248 | $self->{depth}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 248 | push(@{$data->{$id}}, $self->_parse()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | elsif($self->{input} =~ /\G(?=[,}])/cg) { push(@$data, $id) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | else # must be "id value value" format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 144 | $self->{depth}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 144 | push(@{$data->{$id}}, $self->_parse(1)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1188 | ▶ | if($flag) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 144 | ▶ | if(!($self->{depth}--) && $self->{input} =~ /\S/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->{"depth"}-- and $self->{"input"} =~ /\S/
MC/DC0%0/2
not $self->{"depth"}-- and $self->{"input"} =~ /\S/
not $self->{"depth"}--
$self->{"input"} =~ /\S/
Truth table33%1/3
not(A) and B
A= not $self->{"depth"}--B= $self->{"input"} =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | croak "Data Error: extra (mismatched) '}' found on line $self->{linenumber} in $self->{filename}!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 144 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif($self->{input} =~ /\G[ \t]*"((?:[^"]+|"")*)"(?=\s*[,}])/cg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 11 | my $value = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | $value =~ s/""/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | ▶ | $self->{linenumber} += $value =~ s/\n//g || $value =~ s/\r//g; # count by *NIX/Win or Mac | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$value =~ s/\n//g || $value =~ s/\r//g
MC/DC0%0/2
$value =~ s/\n//g || $value =~ s/\r//g
$value =~ s/\n//g
$value =~ s/\r//g
Truth table33%1/3
A || B
A= $value =~ s/\n//gB= $value =~ s/\r//g
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | $value =~ s/[\r\n]+//g; # in case it's Win format | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 11 | push(@$data, $value) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | else # end of input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | my ($pos, $len) = (pos($self->{input}), length($self->{input})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | ▶ | if($pos != $len && $self->{input} =~ /\G\s*\S/cg) # problem with parsing, must be non-conforming data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
$pos != $len and $self->{"input"} =~ /\G\s*\S/cg
MC/DC0%0/2
$pos != $len and $self->{"input"} =~ /\G\s*\S/cg
$pos != $len
$self->{"input"} =~ /\G\s*\S/cg
Truth table33%1/3
A and B
A= $pos != $lenB= $self->{"input"} =~ /\G\s*\S/cg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | croak "Data Error: none conforming data found on line $self->{linenumber} in $self->{filename}!\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | "first $self->{maxerrstr} (or till end of input) characters including the non-conforming data:\n" . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | substr($self->{input}, $pos, $self->{maxerrstr}) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | elsif($self->{depth} > 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | croak "Data Error: missing '}' found at end of input in $self->{filename}!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif($self->{depth} < 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | croak "Data Error: extra (mismatched) '}' found at end of input in $self->{filename}!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # following copied directly from my Pipeline::Util::util just to make this module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # more self-sufficient. Changes should be made over in that module though. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # trims arrayrefs that points to one-element array to slims the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # data structure down (calls Pipeline::Util::util::trimdata) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # something like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # 'comments' => ARRAY(0x898be94) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # 0 ARRAY(0x883fc54) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # 0 ARRAY(0x886aef4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # 0 HASH(0x884d554) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # 'heading' => 'LocusTagLink' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # 'source' => ARRAY(0x8810714) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # 0 ARRAY(0x8a7df18) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # 0 ARRAY(0x889f940) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # 0 HASH(0x886ada4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # 'src' => ARRAY(0x88454fc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # 0 ARRAY(0x8845598) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # 0 HASH(0x898c0ec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # 'db' => 'HGNC' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # 'tag' => ARRAY(0x898bfb4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # 0 HASH(0x898c164) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # 'id' => 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # becomes this if $flag == 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # 'comments' => ARRAY(0x8840014) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # 0 HASH(0x884d8a4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # 'heading' => 'LocusTagLink' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # 'source' => HASH(0x8a9869c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # 'src' => HASH(0x884534c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # 'db' => 'HGNC' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # 'tag' => HASH(0x88453c4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # 'id' => 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # so now $hash->{comments}->[0]->[0]->[0]->{source}->[0]->[0]->[0]->{src}->[0]->[0]->{tag}->[0]->{id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # becomes $hash->{comments}->[0]->{source}->{src}->{tag}->{id} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # this may create problem as array might suddenly change to hash depending on whether it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # has multiple elements or not. So set $flag to 2 or 0/undef would disallow trimming that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # would lead to data type change, thus resulting in data structure like: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # 'comments' => ARRAY(0x88617e8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # 0 HASH(0x889d578) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # 'heading' => 'LocusTagLink' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # 'source' => ARRAY(0x8912244) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # 0 HASH(0x8a5d648) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # 'src' => ARRAY(0x8a2203c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # 0 HASH(0x8a1af10) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # 'db' => 'HGNC' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # 'tag' => ARRAY(0x8a1add8) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # 0 HASH(0x8a1af88) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # 'id' => 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # still not the safest, but saves some hassle writing code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sub trimdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 830 | ▶ | my ($ref, $flag) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trimdata: called CC=16 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 830 | ▶ | $flag = 2 unless $flag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 830 | ▶ | return if $flag == 3 || !ref($ref); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$flag == 3 or not ref $ref
MC/DC0%0/2
$flag == 3 or not ref $ref
$flag == 3
not ref $ref
Truth table33%1/3
A or not(B)
A= $flag == 3B= not ref $ref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 830 | ▶ | if(ref($ref) ne 'ARRAY') # allows for object refs | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 456 | my @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 456 | eval { @keys = keys %$ref }; # let's be careful and check if it can work as a hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 456 | ▶ | return if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 456 | foreach my $key (@keys) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1161 | my $tmp = $ref->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1161 | ▶ | while(ref($tmp) eq 'ARRAY' && @$tmp == 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $tmp eq "ARRAY" and @$tmp == 1
MC/DC100%2/2
ref $tmp eq "ARRAY" and @$tmp == 1
ref $tmp eq "ARRAY"
@$tmp == 1
Truth table100%3/3
A and B
A= ref $tmp eq "ARRAY"B= @$tmp == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 456 | ▶ | last if($flag == 2 && ref($tmp->[0]) ne 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flag == 2 and ref $tmp->[0] ne "ARRAY"
MC/DC50%1/2
$flag == 2 and ref $tmp->[0] ne "ARRAY"
$flag == 2
ref $tmp->[0] ne "ARRAY"
Truth table66%2/3
A and B
A= $flag == 2B= ref $tmp->[0] ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 109 | $tmp = $tmp->[0] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1161 | $ref->{$key} = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1161 | ▶ | trimdata($ref->{$key}, $flag) if(ref($ref->{$key})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # since the only situations where we would get an array of array is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # when ASN file has a bracket of brackets (otherwise we'd get at least | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # a hash), it makes sense to reduce the arrayrefs to one level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 374 | foreach my $item (@$ref) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 474 | my $tmp = $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 474 | ▶ | while(ref($tmp) eq 'ARRAY' && @$tmp == 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $tmp eq "ARRAY" and @$tmp == 1
MC/DC0%0/2
ref $tmp eq "ARRAY" and @$tmp == 1
ref $tmp eq "ARRAY"
@$tmp == 1
Truth table33%1/3
A and B
A= ref $tmp eq "ARRAY"B= @$tmp == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $tmp = $tmp->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 474 | $item = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 474 | ▶ | trimdata($item, $flag) if(ref($item)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | sub fh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | ▶ | my ($self, $filehandle) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fh: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | if($filehandle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | $self->{fh} = $filehandle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | $self->{linenumber} = 0; # reset line number | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | return $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | sub rawdata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rawdata: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | return "Entrezgene ::= $self->{input}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||