ClusterIO/dbsnp.pm

filter: Statementstmt 90.8% 89 / 98 Branchbran 72.7% 32 / 44 Conditioncond 80.0% 12 / 15 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 100% 17 / 17 Podpod 87.5% 7 / 8 totaltotal 85.3% 163 / 191 CC 28 SCAR 22.3
CC
28
Cov
85%
next_cluster
21.5
end_element
6.0
_initialize
4.4
CRAP 9.3
« ClusterIO/unigene.pm ↑ Summary ClusterIO.pm »
1 # BioPerl module for Bio::ClusterIO::dbsnp
2 #
3 # Copyright Allen Day <allenday@ucla.edu>, Stan Nelson <snelson@ucla.edu>
4 # Human Genetics, UCLA Medical School, University of California, Los Angeles
5  
6 # POD documentation - main docs before the code
7  
8 =head1 NAME
9  
10 Bio::ClusterIO::dbsnp - dbSNP input stream
11  
12 =head1 SYNOPSIS
13  
14 Do not use this module directly. Use it via the Bio::ClusterIO class.
15  
16 =head1 DESCRIPTION
17  
18 Parse dbSNP XML files, one refSNP entry at a time. Note this handles dbSNPp
19 output generated by NBCI's eutils and does NOT parse output derived from
20 SNP's XML format (found at ftp://ftp.ncbi.nih.gov/snp/).
21  
22 =head1 FEEDBACK
23  
24 =head2 Mailing Lists
25  
26 User feedback is an integral part of the evolution of this and other
27 Bioperl modules. Send your comments and suggestions preferably to one
28 of the Bioperl mailing lists. Your participation is much appreciated.
29  
30 bioperl-l@bioperl.org - General discussion
31 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
32  
33 =head2 Support
34  
35 Please direct usage questions or support issues to the mailing list:
36  
37 I<bioperl-l@bioperl.org>
38  
39 rather than to the module maintainer directly. Many experienced and
40 reponsive experts will be able look at the problem and quickly
41 address it. Please include a thorough description of the problem
42 with code and data examples if at all possible.
43  
44 =head2 Reporting Bugs
45  
46 Report bugs to the Bioperl bug tracking system to help us keep track
47 the bugs and their resolution. Bug reports can be submitted via the
48 web:
49  
50 https://github.com/bioperl/bioperl-live/issues
51  
52 =head1 AUTHOR
53  
54 Allen Day E<lt>allenday@ucla.eduE<gt>
55  
56 =head1 APPENDIX
57  
58 The rest of the documentation details each of the object
59 methods. Internal methods are usually preceded with a _
60  
61 =cut
62  
63 # Let the code begin...
64 package Bio::ClusterIO::dbsnp;
65 2 $Bio::ClusterIO::dbsnp::VERSION = '1.7.3';
66 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 2 ▶use Bio::Variation::SNP;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 ▶use XML::SAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 2 ▶use Time::HiRes qw(tv_interval gettimeofday);
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 2 ▶use base qw(Bio::ClusterIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 2 our $DEBUG = 0;
77  
78 2 our %MAPPING = (
79 #the ones commented out i haven't written methods for yet... -Allen
80 'Rs_rsId' => 'id',
81 # 'Rs_taxId' => 'tax_id',
82 # 'Rs_organism' => 'organism',
83 'Rs_snpType' => {'type' => 'value'},
84 'Rs_sequence_observed' => 'observed',
85 'Rs_sequence_seq5' => 'seq_5',
86 'Rs_sequence_seq3' => 'seq_3',
87 # 'Rs_sequence_exemplarSs' => 'exemplar_subsnp',
88 'Rs_create_build' => 'ncbi_build',
89 #?? 'Rs_update_build' => 'ncbi_build',
90 # 'NSE-rs_ncbi-num-chr-hits' => 'ncbi_chr_hits',
91 # 'NSE-rs_ncbi-num-ctg-hits' => 'ncbi_ctg_hits',
92 # 'NSE-rs_ncbi-num-seq-loc' => 'ncbi_seq_loc',
93 # 'NSE-rs_ncbi-mapweight' => 'ncbi_mapweight',
94 # 'NSE-rs_ucsc-build-id' => 'ucsc_build',
95 # 'NSE-rs_ucsc-num-chr-hits' => 'ucsc_chr_hits',
96 # 'NSE-rs_ucsc-num-seq-loc' => 'ucsc_ctg_hits',
97 # 'NSE-rs_ucsc-mapweight' => 'ucsc_mapweight',
98  
99 'Rs_het_value' => 'heterozygous',
100 'Rs_het-stdError' => 'heterozygous_SE',
101 'Rs_validation' => {'validated' => 'value'}, #??
102 # 'NSE-rs_genotype' => {'genotype' => 'value'},
103  
104 'Ss_handle' => 'handle',
105 'Ss_batchId' => 'batch_id',
106 'Ss_locSnpId' => 'id',
107 # 'Ss_locSnpId' => 'loc_id',
108 # 'Ss_orient' => {'orient' => 'value'},
109 # 'Ss_buildId' => 'build',
110 'Ss_methodClass' => {'method' => 'value'},
111 # 'NSE-ss_accession_E' => 'accession',
112 # 'NSE-ss_comment_E' => 'comment',
113 # 'NSE-ss_genename' => 'gene_name',
114 # 'NSE-ss_assay-5_E' => 'seq_5',
115 # 'NSE-ss_assay-3_E' => 'seq_3',
116 # 'NSE-ss_observed' => 'observed',
117  
118 # 'NSE-ss-popinfo_type' => 'pop_type',
119 # 'NSE-ss-popinfo_batch-id' => 'pop_batch_id',
120 # 'NSE-ss-popinfo_pop-name' => 'pop_name',
121 # 'NSE-ss-popinfo_samplesize' => 'pop_samplesize',
122 # 'NSE-ss_popinfo_est-het' => 'pop_est_heterozygous',
123 # 'NSE-ss_popinfo_est-het-se-sq' => 'pop_est_heterozygous_se_sq',
124  
125 # 'NSE-ss-alleleinfo_type' => 'allele_type',
126 # 'NSE-ss-alleleinfo_batch-id' => 'allele_batch_id',
127 # 'NSE-ss-alleleinfo_pop-id' => 'allele_pop_id',
128 # 'NSE-ss-alleleinfo_snp-allele' => 'allele_snp',
129 # 'NSE-ss-alleleinfo_other-allele' => 'allele_other',
130 # 'NSE-ss-alleleinfo_freq' => 'allele_freq',
131 # 'NSE-ss-alleleinfo_count' => 'allele_count',
132  
133 # 'NSE-rsContigHit_contig-id' => 'contig_hit',
134 # 'NSE-rsContigHit_accession' => 'accession_hit',
135 # 'NSE-rsContigHit_version' => 'version',
136 # 'NSE-rsContigHit_chromosome' => 'chromosome_hit',
137  
138 # 'NSE-rsMaploc_asn-from' => 'asn_from',
139 # 'NSE-rsMaploc_asn-to' => 'asn_to',
140 # 'NSE-rsMaploc_loc-type' => {'loc_type' => 'value'},
141 # 'NSE-rsMaploc_hit-quality' => {'hit_quality' => 'value'},
142 # 'NSE-rsMaploc_orient' => {'orient' => 'value'},
143 # 'NSE-rsMaploc_physmap-str' => 'phys_from',
144 # 'NSE-rsMaploc_physmap-int' => 'phys_to',
145  
146 'FxnSet_geneId' => 'locus_id', # does the code realise that there can be multiple of these
147 'FxnSet_symbol' => 'symbol',
148 'FxnSet_mrnaAcc' => 'mrna',
149 'FxnSet_protAcc' => 'protein',
150 'FxnSet_fxnClass' => {'functional_class' => 'value'},
151  
152 #...
153 #...
154 #there are lots more, but i don't need them at the moment... -Allen
155 );
156  
157 1 ▶sub _initialize{
Subroutine _initialize: called CC=4 SCAR=14.8
158 1 my ($self,@args) = @_;
159 1 $self->SUPER::_initialize(@args);
160 1 my ($usetempfile) = $self->_rearrange([qw(TEMPFILE)],@args);
161 1 ▶ defined $usetempfile && $self->use_tempfile($usetempfile);
Branch: 1 branch
BranchTrueFalseTotal
defined $usetempfile and $self->use_tempfile($usetempfile) 1 0 1
162
163 # start up the parser factory
164 1 my $parserfactory = XML::SAX::ParserFactory->parser(
165 Handler => $self);
166 1 $self->{'_xmlparser'} = $parserfactory;
167 1 ▶ $DEBUG = 1 if( ! defined $DEBUG && $self->verbose > 0);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $Bio::ClusterIO::dbsnp::DEBUG and $self->verbose > 0 0 1 1
Condition33%1/3
not defined $Bio::ClusterIO::dbsnp::DEBUG and $self->verbose > 0
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $Bio::ClusterIO::dbsnp::DEBUG and $self->verbose > 0
not defined $Bio::ClusterIO::dbsnp::DEBUG $self->verbose > 0
Truth table33%1/3
not(A) and B
A= not defined $Bio::ClusterIO::dbsnp::DEBUGB= $self->verbose > 0
ABresult
0X0
100
111
168 }
169  
170 =head2 next_cluster
171  
172 Title : next_cluster
173 Usage : $dbsnp = $stream->next_cluster()
174 Function: returns the next refSNP in the stream
175 Returns : Bio::Variation::SNP object representing composite refSNP
176 and its component subSNP(s).
177 Args : NONE
178  
179 =cut
180  
181 ###
182 #Adapted from Jason's blastxml.pm
183 ###
184  
185 # you shouldn't have to preparse this; the XML is well-formed and refers
186 # accurately to a remote DTD/schema
187  
188 1 ▶sub next_cluster {
Subroutine next_cluster: called CC=15 SCAR=30.7
Pod documented
189 1 my $self = shift;
190 1 my $data = '';
191 1 my($tfh);
192  
193 1 ▶ if( $self->use_tempfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_tempfile) 0 1 1
194 0 ▶ $tfh = IO::File->new_tmpfile or $self->throw("Unable to open temp file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$tfh = "IO::File"->new_tmpfile or $self->throw("Unable to open temp file: $!") 0 0 0
195 0 $tfh->autoflush(1);
196 }
197  
198 1 my $start = 1;
199 1 ▶ while( defined( $_ = $self->_readline ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 393 0 393
200 #skip to beginning of refSNP entry
201 393 ▶ if($_ !~ m{<Rs[^>]*>} && $start){
Branch: 2 branches
BranchTrueFalseTotal
if (not $_ =~ /<Rs[^>]*>/ and $start) { } 9 384 393
elsif ($_ =~ /<Rs[^>]*>/ and $start) { } 1 737 738
Condition100%3/3
not $_ =~ /<Rs[^>]*>/ and $start
!ll&&!rl&&r
303549
MC/DC100%2/2
not $_ =~ /<Rs[^>]*>/ and $start
not $_ =~ /<Rs[^>]*>/ $start
Truth table100%3/3
not(A) and B
A= not $_ =~ /<Rs[^>]*>/B= $start
ABresult
0X0
100
111
202 9 next;
203 ▶ } elsif($_ =~ m{<Rs[^>]*>} && $start){
Condition100%3/3
$_ =~ /<Rs[^>]*>/ and $start
!ll&&!rl&&r
354291
MC/DC100%2/2
$_ =~ /<Rs[^>]*>/ and $start
$_ =~ /<Rs[^>]*>/ $start
Truth table100%3/3
A and B
A= $_ =~ /<Rs[^>]*>/B= $start
ABresult
0X0
100
111
204 1 $start = 0;
205 }
206  
207 #slurp up the data
208 384 ▶ if( defined $tfh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tfh) { } 0 384 384
209 0 print $tfh $_;
210 } else {
211 384 $data .= $_;
212 }
213  
214 #and stop at the end of the refSNP entry
215 384 ▶ last if $_ =~ m{</Rs>};
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ m[</Rs>] 1 383 384
216 }
217  
218 #if we didn't find a start tag
219 1 ▶ return if $start;
Branch: 1 branch
BranchTrueFalseTotal
if $start 0 1 1
220  
221 1 my %parser_args;
222 1 ▶ if( defined $tfh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tfh) { } 0 1 1
223 0 seek($tfh,0,0);
224 0 %parser_args = ('Source' => { 'ByteStream' => $tfh },
225 'Handler' => $self);
226 } else {
227 1 %parser_args = ('Source' => { 'String' => $data },
228 'Handler' => $self);
229 }
230  
231 1 my $starttime;
232 my $result;
233  
234 0 ▶ if( $DEBUG ) { $starttime = [ Time::HiRes::gettimeofday() ]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ClusterIO::dbsnp::DEBUG) 0 1 1
235  
236 1 eval {
237 1 $result = $self->{'_xmlparser'}->parse(%parser_args);
238 };
239  
240 1 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
241 0 $self->warn("error in parsing a report:\n $@");
242 0 $result = undef;
243 }
244  
245 1 ▶ if( $DEBUG ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Bio::ClusterIO::dbsnp::DEBUG) 0 1 1
246 0 $self->debug( sprintf("parsing took %f seconds\n", Time::HiRes::tv_interval($starttime)));
247 }
248  
249 1 return $self->refsnp;
250 }
251  
252 =head2 SAX methods
253  
254 =cut
255  
256 =head2 start_document
257  
258 Title : start_document
259 Usage : $parser->start_document;
260 Function: SAX method to indicate starting to parse a new document.
261 Creates a Bio::Variation::SNP
262 Returns : none
263 Args : none
264  
265 =cut
266  
267 1 ▶sub start_document{
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
268 1 my ($self) = @_;
269 1 $self->{refsnp} = Bio::Variation::SNP->new;
270 }
271  
272 45 ▶sub refsnp {
Subroutine refsnp: called CC=1 SCAR=0.0
Pod undocumented
273 45 return shift->{refsnp};
274 }
275  
276 =head2 end_document
277  
278 Title : end_document
279 Usage : $parser->end_document;
280 Function: SAX method to indicate finishing parsing a new document
281 Returns : none
282 Args : none
283  
284 =cut
285  
286 1 ▶sub end_document{
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
287 1 my ($self,@args) = @_;
288 }
289  
290 =head2 start_element
291  
292 Title : start_element
293 Usage : $parser->start_element($data)
294 Function: SAX method to indicate starting a new element
295 Returns : none
296 Args : hash ref for data
297  
298 =cut
299  
300 300 ▶sub start_element{
Subroutine start_element: called CC=4 SCAR=13.9
Pod documented
301 300 my ($self,$data) = @_;
302 300 my $nm = $data->{'Name'};
303 300 my $at = $data->{'Attributes'}->{'{}value'};
304
305 #$self->debug(Dumper($at)) if $nm = ;
306
307 300 ▶ if($nm eq 'Ss'){
Branch: 1 branch
BranchTrueFalseTotal
if ($nm eq "Ss") 5 295 300
308 5 $self->refsnp->add_subsnp;
309 5 return;
310 }
311
312 295 ▶ if(my $type = $MAPPING{$nm}){
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $Bio::ClusterIO::dbsnp::MAPPING{$nm}) { } 36 259 295
313 36 ▶ if(ref $type eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type eq 'HASH') { } 9 27 36
314 #okay, this is nasty. what can you do?
315 9 $self->{will_handle} = (keys %$type)[0];
316 9 $self->{last_data} = $at->{Value};
317 } else {
318 27 $self->{will_handle} = $type;
319 27 $self->{last_data} = undef;
320 }
321 } else {
322 259 undef $self->{will_handle};
323 }
324 }
325  
326 =head2 end_element
327  
328 Title : end_element
329 Usage : $parser->end_element($data)
330 Function: Signals finishing an element
331 Returns : none
332 Args : hash ref for data
333  
334 =cut
335  
336 300 ▶sub end_element {
Subroutine end_element: called CC=6 SCAR=17.9
Pod documented
337 300 my ($self,$data) = @_;
338 300 my $nm = $data->{'Name'};
339 300 my $at = $data->{'Attributes'};
340  
341 300 my $method = $self->{will_handle};
342 300 ▶ if($method){
Branch: 1 branch
BranchTrueFalseTotal
if ($method) 49 251 300
343 49 ▶ if($nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/ or $nm =~ /^FxnSet/){
Branch: 2 branches
BranchTrueFalseTotal
if ($nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/ or $nm =~ /^FxnSet/) { } 19 30 49
elsif ($nm =~ /^Ss/) { } 20 10 30
Condition83%5/6
$nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/ or $nm =~ /^FxnSet/
l!l&&r!l&&!r
91030
$nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/
l!l&&r!l&&!r
9040
MC/DC66%2/3
$nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/ or $nm =~ /^FxnSet/
$nm =~ /^Rs/ $nm =~ /^NSE-SeqLoc/ $nm =~ /^FxnSet/
Truth table75%3/4
A or B or C
A= $nm =~ /^Rs/B= $nm =~ /^NSE-SeqLoc/C= $nm =~ /^FxnSet/
ABCresult
1XX1
01X1
0011
0000
344 19 $self->refsnp->$method($self->{last_data});
345 } elsif ($nm =~ /^Ss/){
346 20 $self->refsnp->subsnp->$method($self->{last_data});
347 }
348 }
349 }
350  
351 =head2 characters
352  
353 Title : characters
354 Usage : $parser->characters($data)
355 Function: Signals new characters to be processed
356 Returns : characters read
357 Args : hash ref with the key 'Data'
358  
359 =cut
360  
361 547 ▶sub characters{
Subroutine characters: called CC=2 SCAR=6.9
Pod documented
362 547 my ($self,$data) = @_;
363 $self->{last_data} = $data->{Data}
364 547 ▶ if $data->{Data} =~ /\S/; #whitespace is meaningless -ad
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"Data"} =~ /\S/ 195 352 547
365 }
366  
367 =head2 use_tempfile
368  
369 Title : use_tempfile
370 Usage : $obj->use_tempfile($newval)
371 Function: Get/Set boolean flag on whether or not use a tempfile
372 Example :
373 Returns : value of use_tempfile
374 Args : newvalue (optional)
375  
376 =cut
377  
378 2 ▶sub use_tempfile{
Subroutine use_tempfile: called CC=2 SCAR=6.9
Pod documented
379 2 my ($self,$value) = @_;
380 2 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 1 2
381 1 $self->{'_use_tempfile'} = $value;
382 }
383 2 return $self->{'_use_tempfile'};
384 }
385  
386 2 1;
« ClusterIO/unigene.pm ↑ Summary ClusterIO.pm »