Bio::Biblio::IO
medlinexml
Summary
Bio::Biblio::IO::medlinexml - A converter of XML files with MEDLINE citations
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Do not use this object directly, it is recommended to access it and use
it through the
Bio::Biblio::IO module:
use Bio::Biblio::IO;
my $io = new Bio::Biblio::IO (-format => 'medlinexml');
Description
This object reads bibliographic citations in XML/MEDLINE format and
converts them into Bio::Biblio::RefI objects. It is an
implementation of methods defined in Bio::Biblio::IO.
Methods
| _initialize | No description | Code |
| _parse | No description | Code |
| next_bibref | No description | Code |
| handle_doc_start | No description | Code |
| handle_doc_end | No description | Code |
| handle_char | No description | Code |
| handle_start | No description | Code |
| handle_end | No description | Code |
| _process_citation | No description | Code |
| _add_element | No description | Code |
| _data2obj | No description | Code |
| _obj2obj | No description | Code |
| _eq_hash_elem | No description | Code |
| _debug_object_stack | No description | Code |
Methods description
None available.
Methods code
sub _initialize
{ my ($self, @args) = @_;
my %param = @args;
@param { map { lc $_ } keys %param } = values %param;
my $new_key;
foreach my $key (keys %param) {
($new_key = $key) =~ s/^-/_/;
$self->{ lc $new_key } = $param { $key };
}
my $result = $self->{'_result'} || 'medline2ref';
$result = "\L$result";
unless ($result eq 'raw') {
if (defined &Bio::Biblio::IO::_load_format_module ($result)) {
$Convert = "Bio::Biblio::IO::$result"->new (@args);
}
}
$self->{'_xml_parser'} = new XML::Parser (Handlers => {Init =>\& handle_doc_start,
Start =>\& handle_start,
End =>\& handle_end,
Char =>\& handle_char,
Final =>\& handle_doc_end})
unless $self->{'_xml_parser'};
if ($Callback = $self->{'_callback'}) {
$self->_parse;
}} |
sub _parse
{ my ($self) = shift;
if (defined $self->{'_file'}) {
$self->{'_xml_parser'}->parsefile ($self->{'_file'});
} elsif (defined $self->{'_fh'}) {
my $fh = $self->{'_fh'};
if (ref ($fh) and UNIVERSAL::isa ($fh, 'IO::Handler')) {
$self->{'_xml_parser'}->parse ($fh);
} else {
my $data;
$data .= $_ while <$fh>;
$self->{'_xml_parser'}->parse ($data);
}
} elsif ($self->{'_data'}) {
$self->{'_xml_parser'}->parse ($self->{'_data'});
} else {
$self->throw ("XML source to be parsed is unknown. Should be given in the new().");
}
if (@Citations) {
$self->{'_citations'} = [];
foreach my $cit (@Citations) {
push (@{ $self->{'_citations'} }, $cit);
undef $cit;
}
undef @Citations;
}} |
sub next_bibref
{ my ($self) = @_;
$self->throw ("Method 'next_bibref' should not be called when a '-callback' argument given.")
if $self->{'_callback'};
$self->_parse unless $self->{'_citations'};
shift (@{ $self->{'_citations'} });} |
sub handle_doc_start
{ @Citations = ();
@ObjectStack = ();
@PCDataStack = ();} |
sub handle_doc_end
{ undef @ObjectStack;
undef @PCDataStack;} |
sub handle_char
{ my ($expat, $str) = @_;
return if $#PCDataStack < 0;
$PCDataStack [$#PCDataStack] .= $str;} |
sub handle_start
{ my ($expat, $e, %attrs) = @_;
if ($e eq 'QualifierName' or
$e eq 'SubHeading') {
my %p = ();
$p{'majorTopic'} = "Y" if $attrs{'MajorTopicYN'};
push (@ObjectStack,\% p);
}
if ($e eq 'GeneralNote') {
my %p = ();
$p{'owner'} = $attrs{'Owner'} if $attrs{'Owner'};
push (@ObjectStack,\% p);
}
if ($e eq 'OtherID') {
my %p = ();
$p{'source'} = $attrs{'Source'};
push (@ObjectStack,\% p);
}
if ($e eq 'LastName' or
$e eq 'FirstName' or
$e eq 'MidleName' or
$e eq 'Initials' or
$e eq 'ForeName' or
$e eq 'Suffix') {
my $peek = $ObjectStack[$#ObjectStack];
push (@ObjectStack, {'type' => 'PersonalName'})
unless (ref $peek and &_eq_hash_elem ($peek, 'type', 'PersonalName'));
}
if (exists $PCDATA_NAMES{$e}) {
push (@PCDataStack, '');
} elsif (exists $SIMPLE_TREATMENT{$e}) {
push (@ObjectStack, {});
} elsif ($e eq 'PersonalNameSubject') {
push (@ObjectStack, {'type' => 'PersonalName'});
} elsif ($e eq 'DescriptorName' or
$e eq 'Descriptor') {
if (&_eq_hash_elem (\%attrs, 'MajorTopicYN', "Y")) {
my $peek = $ObjectStack[$#ObjectStack];
$$peek{'descriptorMajorTopic'} = "Y";
}
} elsif ($e eq 'MedlineCitation' ||
$e eq 'NCBIArticle') {
my %p = ( 'type' => 'MedlineCitation' );
$p{'owner'} = $attrs{'Owner'} if $attrs{'Owner'};
$p{'status'} = $attrs{'Status'} if $attrs{'Status'};
push (@ObjectStack,\% p);
} elsif ($e eq 'GrantList') {
if (&_eq_hash_elem (\%attrs, 'CompleteYN', "N")) {
my $peek = $ObjectStack[$#ObjectStack];
$$peek{'grantListComplete'} = "N";
}
} elsif ($e eq 'DataBankList') {
if (&_eq_hash_elem (\%attrs, 'CompleteYN', "N")) {
my $peek = $ObjectStack[$#ObjectStack];
$$peek{'dataBankListComplete'} = "N";
}
} elsif ($e eq 'AuthorList') {
if (&_eq_hash_elem (\%attrs, 'CompleteYN', "N")) {
my $peek = $ObjectStack[$#ObjectStack];
$$peek{'authorListComplete'} = "N";
}
} elsif ($e eq 'OtherAbstract') {
my %p = ();
$p{'type'} = $attrs{'Type'} if $attrs{'Type'};
push (@ObjectStack,\% p);
} } |
sub handle_end
{ my ($expat, $e) = @_;
if ($e eq 'QualifierName' or
$e eq 'SubHeading') {
my $p = pop @ObjectStack; $$p{'subHeading'} = pop @PCDataStack;
&_add_element ('subHeadings', $p);
return;
} elsif ($e eq 'GeneralNote') {
my $p = pop @ObjectStack; $$p{'generalNote'} = pop @PCDataStack;
&_add_element ('generalNotes', $p);
return;
} elsif ($e eq 'OtherID') {
my $p = pop @ObjectStack; $$p{'otherID'} = pop @PCDataStack;
&_add_element ('otherIDs', $p);
return;
}
if (exists $POP_DATA_AND_PEEK_OBJ{$e}) {
&_data2obj ("\l$e");
} elsif (exists $POP_OBJ_AND_PEEK_OBJ{$e}) {
&_obj2obj ("\l$e");
} elsif (exists $POP_AND_ADD_ELEMENT{$e}) {
&_add_element ($POP_AND_ADD_ELEMENT{$e}, pop @ObjectStack);
} elsif (exists $POP_AND_ADD_DATA_ELEMENT{$e}) {
&_add_element ($POP_AND_ADD_DATA_ELEMENT{$e});
} elsif ($e eq 'Author' or
$e eq 'Investigator') {
my $pAuthor;
my $p = pop @ObjectStack; if (&_eq_hash_elem ($p, 'type', 'PersonalName')) {
$pAuthor = pop @ObjectStack;
$$pAuthor{'personalName'} = $p;
} else {
$pAuthor = $p;
}
my $peek = $ObjectStack[$#ObjectStack]; if (&_eq_hash_elem ($peek, 'type', 'MedlineCitation')) {
&_add_element ('investigators', $pAuthor);
} else {
&_add_element ('authors', $pAuthor);
}
} elsif ($e eq 'MedlineJournalInfo') {
&_obj2obj ('journalInfo');
} elsif ($e eq 'PMID') {
my $peek = $ObjectStack[$#ObjectStack]; if (&_eq_hash_elem ($peek, 'type', 'DeleteCitation')) {
&_add_element ('PMIDs');
} else {
$$peek{'PMID'} = pop @PCDataStack;
}
} elsif ($e eq 'MedlineID') {
my $peek = $ObjectStack[$#ObjectStack]; if (&_eq_hash_elem ($peek, 'type', 'DeleteCitation')) {
&_add_element ('MedlineIDs');
} else {
$$peek{'medlineID'} = pop @PCDataStack;
}
} elsif ($e eq 'Affiliation') {
my $peek = $ObjectStack[$#ObjectStack];
if (&_eq_hash_elem ($peek, 'type', 'PersonalName')) {
my $peek2 = $ObjectStack[$#ObjectStack - 1];
$$peek2{'affiliation'} = pop @PCDataStack;
} else {
$$peek{'affiliation'} = pop @PCDataStack;
}
} elsif ($e eq 'DeleteCitation') {
pop @ObjectStack;
} elsif ($e eq 'MedlineCitation') {
&_process_citation (pop @ObjectStack);
} elsif (exists $PCDATA_NAMES{$e}) {
pop @PCDataStack;
warn ("An unexpected element found: $e");
}
} |
sub _process_citation
{ my ($citation) = @_;
$citation = $Convert->convert ($citation) if defined $Convert;
if ($Callback) {
&$Callback ($citation);
} else {
push (@Citations, $citation);
}} |
sub _add_element
{ my ($key, $element) = @_;
my $peek = $ObjectStack[$#ObjectStack];
$$peek{$key} = [] unless $$peek{$key};
push (@{ $$peek{$key} }, (defined $element ? $element : pop @PCDataStack));} |
sub _data2obj
{ my ($key) = @_;
my $peek = $ObjectStack[$#ObjectStack];
$$peek{$key} = pop @PCDataStack;} |
sub _obj2obj
{ my ($key) = @_;
my $p = pop @ObjectStack;
my $peek = $ObjectStack[$#ObjectStack];
$$peek{$key} = $p;} |
sub _eq_hash_elem
{ my ($rh, $key, $value) = @_;
return (defined $$rh{$key} and $$rh{$key} eq $value);} |
| _debug_object_stack | description | prev | next | Top |
sub _debug_object_stack
{ my ($action, $element) = @_;
if ($action =~ /^START/o) {
$DEBUGSTACK{$element} = (@ObjectStack+0);
} else {
return if $element eq 'LastName';
print "Element $element starts on " .
$DEBUGSTACK{$element} . 'and ends on ' . (@ObjectStack+0) . "\n"
if $DEBUGSTACK{$element} != (@ObjectStack+0);
}} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
http://bugzilla.open-bio.org/
Copyright (c) 2002 European Bioinformatics Institute. All Rights Reserved.
This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
This software is provided "as is" without warranty of any kind.
The main documentation details are to be found in
Bio::Biblio::IO.
Here is the rest of the object methods. Internal methods are preceded
with an underscore _.
Usage : print $Bio::Biblio::IO::medlinexml::VERSION;
print $Bio::Biblio::IO::medlinexml::Revision;