Bio::ClusterIO
dbsnp
Toolbar
Summary
Bio::ClusterIO::dbsnp - dbSNP input stream
Package variables
No package variables defined.
Included modules
Data::Dumper
IO::File
Time::HiRes qw ( tv_interval gettimeofday )
XML::SAX
Inherit
Synopsis
Do not use this module directly. Use it via the Bio::ClusterIO class.
Description
Parse dbSNP XML files, one refSNP entry at a time. Note this handles dbSNPp
output generated by NBCI's eutils and does NOT parse output derived from
SNP's XML format (found at
ftp://ftp.ncbi.nih.gov/snp/).
Methods
Methods description
Title : next_cluster Usage : $dbsnp = $stream->next_cluster() Function: returns the next refSNP in the stream Returns : Bio::Variation::SNP object representing composite refSNP and its component subSNP(s). Args : NONE |
Title : start_document Usage : $parser->start_document; Function: SAX method to indicate starting to parse a new document. Creates a Bio::Variation::SNP Returns : none Args : none |
Title : end_document Usage : $parser->end_document; Function: SAX method to indicate finishing parsing a new document Returns : none Args : none |
Title : start_element Usage : $parser->start_element($data) Function: SAX method to indicate starting a new element Returns : none Args : hash ref for data |
Title : end_element Usage : $parser->end_element($data) Function: Signals finishing an element Returns : none Args : hash ref for data |
Title : characters Usage : $parser->characters($data) Function: Signals new characters to be processed Returns : characters read Args : hash ref with the key 'Data' |
Title : use_tempfile Usage : $obj->use_tempfile($newval) Function: Get/Set boolean flag on whether or not use a tempfile Example : Returns : value of use_tempfile Args : newvalue (optional) |
Methods code
sub _initialize
{ my ($self,@args) = @_;
$self->SUPER::_initialize(@args);
my ($usetempfile) = $self->_rearrange([qw(TEMPFILE)],@args);
defined $usetempfile && $self->use_tempfile($usetempfile);
my $parserfactory = XML::SAX::ParserFactory->parser(
Handler => $self);
$self->{'_xmlparser'} = $parserfactory;
$DEBUG = 1 if( ! defined $DEBUG && $self->verbose > 0);} |
sub next_cluster
{ my $self = shift;
my $data = '';
my($tfh);
if( $self->use_tempfile ) {
$tfh = IO::File->new_tmpfile or $self->throw("Unable to open temp file: $!");
$tfh->autoflush(1);
}
my $start = 1;
while( defined( $_ = $self->_readline ) ){
if($_ !~ m{<Rs[^>]*>} && $start){
next;
} elsif($_ =~ m{<Rs[^>]*>} && $start){
$start = 0;
}
if( defined $tfh ) {
print $tfh $_;
} else {
$data .= $_;
}
last if $_ =~ m{</Rs>};
}
return if $start;
my %parser_args;
if( defined $tfh ) {
seek($tfh,0,0);
%parser_args = ('Source' => { 'ByteStream' => $tfh },
'Handler' => $self);
} else {
%parser_args = ('Source' => { 'String' => $data },
'Handler' => $self);
}
my $starttime;
my $result;
if( $DEBUG ) { $starttime = [ Time::HiRes::gettimeofday() ]; }
eval {
$result = $self->{'_xmlparser'}->parse(%parser_args);
};
if( $@ ) {
$self->warn("error in parsing a report:\n $@");
$result = undef;
}
if( $DEBUG ) {
$self->debug( sprintf("parsing took %f seconds\n", Time::HiRes::tv_interval($starttime)));
}
return $self->refsnp;} |
sub refsnp
{ return shift->{refsnp};} |
sub end_document
{ my ($self,@args) = @_; } |
sub start_element
{ my ($self,$data) = @_;
my $nm = $data->{'Name'};
my $at = $data->{'Attributes'}->{'{}value'};
if($nm eq 'Ss'){
$self->refsnp->add_subsnp;
return;
}
if(my $type = $MAPPING{$nm}){
if(ref $type eq 'HASH'){
$self->{will_handle} = (keys %$type)[0];
$self->{last_data} = $at->{Value};
} else {
$self->{will_handle} = $type;
$self->{last_data} = undef;
}
} else {
undef $self->{will_handle};
}} |
sub end_element
{ my ($self,$data) = @_;
my $nm = $data->{'Name'};
my $at = $data->{'Attributes'};
my $method = $self->{will_handle};
if($method){
if($nm =~ /^Rs/ or $nm =~ /^NSE-SeqLoc/ or $nm =~ /^FxnSet/){
$self->refsnp->$method($self->{last_data});
} elsif ($nm =~ /^Ss/){
$self->refsnp->subsnp->$method($self->{last_data});
}
}} |
sub characters
{ my ($self,$data) = @_;
$self->{last_data} = $data->{Data}
if $data->{Data} =~ /\S/;
} |
sub use_tempfile
{ my ($self,$value) = @_;
if( defined $value) {
$self->{'_use_tempfile'} = $value;
}
return $self->{'_use_tempfile'};
}
1;} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via the
web:
https://redmine.open-bio.org/projects/bioperl/
Allen Day <allenday@ucla.edu>
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _