Bio::Biblio IO
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::Biblio::IO - Handling the bibliographic references
Package variables
Privates (from "my" definitions)
$entry = 0
Included modules
Bio::Root::IO
Bio::Root::Root
Inherit
Bio::Root::IO Bio::Root::Root
Synopsis
    use Bio::Biblio::IO;
# getting citations from a file $in = Bio::Biblio::IO->new ('-file' => 'myfile.xml' , '-format' => 'medlinexml'); --- OR --- # getting citations from a string $in = Bio::Biblio::IO->new ('-data' => '...' , '-format' => 'medlinexml'); --- OR --- # getting citations from a string if IO::String is installed use IO::String; $in = Bio::Biblio::IO->new ('-fh' => IO::String->new ($citation), '-format' => 'medlinexml'); $in = Bio::Biblio::IO->new(-fh => $io_handle , '-format' => 'medlinexml'); --- OR --- # getting citations from any IO handler $in = Bio::Biblio::IO->new('-fh' => $io_handle , '-format' => 'medlinexml'); # now, having $in, we can read all citations while ( my $citation = $in->next_bibref() ) { &do_something_with_citation ($citation); } --- OR --- # again reading all citation but now a callback defined in your # code is used (note that the reading starts already when new() # is called) $io = new Bio::Biblio::IO ('-format' => 'medlinexml', '-file' => $testfile, '-callback' => \&callback); sub callback { my $citation = shift; print $citation->{'_identifier'} . "\n"; }
Now, to actually get a citation in an XML format,
use Bio::Biblio module which returns an XML string:
    use Bio::Biblio;
my $xml = new Bio::Biblio->get_by_id ('94033980');
my $reader = Bio::Biblio::IO->new ('-data' => $xml,
'-format' => 'medlinexml');
while (my $citation = $reader->next_bibref()) { ... do something here with $citation }
And, finally, the resulting citation can be received in different
output formats:
    $io = new Bio::Biblio::IO ('-format' => 'medlinexml',
'-result' => 'raw');
--- OR ---
$io = new Bio::Biblio::IO ('-format' => 'medlinexml', '-result' => 'medline2ref'); --- OR --- $io = new Bio::Biblio::IO ('-format' => 'pubmedxml', '-result' => 'pubmed2ref');
Description
Bio::Biblio::IO is a handler module for accessing bibliographic
citations. The citations can be in different formats - assuming that
there is a corresponding module knowing that format in Bio::Biblio::IO
directory (e.g. Bio::Biblio::IO::medlinexml). The format (and the
module name) is given by the argument -format.
Once an instance of Bio::Biblio::IO class is available, the
citations can be read by calling repeatedly method next_bibref:
    while (my $citation = $reader->next_bibref()) {
... do something here with $citation
}
However, this may imply that all citations were already read into the
memory. If you expect a huge amount of citations to be read, you may
choose a callback option. Your subroutine is specified in the
new() method and is called everytime a new citation is available
(see an example above in SYNOPSIS).
The citations returned by next_bibref or given to your callback
routine can be of different formats depending on the argument
-result. One result type is raw and it is represented by a
simple, not blessed hash table:
    $io = new Bio::Biblio::IO ('-result' => 'raw');
What other result formats are available depends on the module who
reads the citations in the first place. At the moment, the following
ones are available:
    $io = new Bio::Biblio::IO ('-result' => 'medline2ref');
This is a default result format for reading citations by the
medlinexml module. The medlinexml module is again the default
one. Which means that you can almost omit arguments (you still need to
say where the citations come from):
    $io = new Bio::Biblio::IO ('-file' => 'data/medline_data.xml');
Another result format available is for PUBMED citations (which is a
super-set of the MEDLINE citations having few more tags):
    $io = new Bio::Biblio::IO ('-format' => 'pubmedxml',
'-result' => 'pubmed2ref',
'-data' => $citation);
Or, because pubmed2ref is a default one for PUBMED citations, you can say just:
    $io = new Bio::Biblio::IO ('-format' => 'pubmedxml',
'-data' => $citation);
Both medline2ref and pubmed2ref results are objects defined in
the directory Bio::Biblio.
Methods
DESTROY
No description
Code
READLINE
No description
Code
TIEHANDLE
No description
Code
_guess_formatDescriptionCode
_initialize
No description
Code
_load_format_moduleDescriptionCode
fh
No description
Code
new
No description
Code
newFh
No description
Code
next_bibrefDescriptionCode
Methods description
_guess_formatcode    nextTop
 Usage   : $class->_guess_format ($filename)
Returns : string with a guessed format of the input data (e.g. 'medlinexml')
Args : a file name whose extension can help to guess its format
It makes an expert guess what kind of data are in the given file
(but be prepare that $filename may be empty).
_load_format_modulecodeprevnextTop
 Usage   : $class->_load_format_module ($format)
Returns : 1 on success, undef on failure
Args : 'format' should contain the last part of the
name of a module who does the real implementation
It does (in run-time) a similar thing as
   require Bio::Biblio::IO::$format
It throws an exception if it fails to find and load the module
(for example, because of the compilation errors in the module).
next_bibrefcodeprevnextTop
 Usage   : $citation = stream->next_bibref
Function: Reads the next citation object from the stream and returns it.
Returns : a Bio::Biblio::Ref citation object, or something else
(depending on the '-result' argument given in the 'new()'
method).
Args : none
Methods code
DESTROYdescriptionprevnextTop
sub DESTROY {
    my $self = shift;

    $self->close();
}
READLINEdescriptionprevnextTop
sub READLINE {
  my $self = shift;
  return $self->{'biblio'}->next_bibref() unless wantarray;
  my (@list, $obj);
  push @list, $obj while $obj = $self->{'biblio'}->next_bibref();
  return @list;
}

1;
}
TIEHANDLEdescriptionprevnextTop
sub TIEHANDLE {
    my ($class,$val) = @_;
    return bless {'biblio' => $val}, $class;
}
_guess_formatdescriptionprevnextTop
sub _guess_format {
   my $class = shift;
   return unless $_ = shift;
   return 'medlinexml'   if (/\.(xml|medlinexml)$/i);
   return;
}
_initializedescriptionprevnextTop
sub _initialize {
    my ($self, @args) = @_;
    # initialize the IO part
$self->_initialize_io (@args);
}
_load_format_moduledescriptionprevnextTop
sub _load_format_module {
  my ($format) = @_;
  my ($module, $load, $m);

  $module = "_<Bio/Biblio/IO/$format.pm";
  $load = "Bio/Biblio/IO/$format.pm";

  return 1 if $main::{$module};
  eval {
    require $load;
  };
  if ( $@ ) {
    Bio::Root::Root->throw (<<END);
$load: $format cannot be found or loaded
Exception $@
For more information about the Biblio system please see the Bio::Biblio::IO docs.
END
  ;
    return;
  }
  return 1;
}
fhdescriptionprevnextTop
sub fh {
  my $self = shift;
  my $class = ref($self) || $self;
  my $s = Symbol::gensym;
  tie $$s,$class,$self;
  return $s;
}

# _initialize is chained for all Bio::Biblio::IO classes
}
newdescriptionprevnextTop
sub new {
    my ($caller, @args) = @_;
    my $class = ref ($caller) || $caller;
    
    # if $caller is an object, or if it is an underlying
# 'real-work-doing' class (e.g. Bio::Biblio::IO::medlinexml) then
# we want to call SUPER to create and bless an object
if( $class =~ /Bio::Biblio::IO::(\S+)/ ) { my ($self) = $class->SUPER::new (@args); $self->_initialize (@args); return $self; # this is called only the first time when somebody calls: 'new
# Bio::Biblio::IO (...)', and it actually loads a 'real-work-doing'
# module and call this new() method again (unless the loaded
# module has its own new() method)
} else { my %param = @args; @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
my $format = $param{'-format'} || $class->_guess_format( $param{-file} || $ARGV[0] ) || 'medlinexml'; $format = "\L$format"; # normalize capitalization to lower case
# load module with the real implementation - as defined in $format
return undef unless (&_load_format_module ($format)); # this will call this same method new() - but rather its
# upper (object) branche
return "Bio::Biblio::IO::$format"->new(@args); }
}
newFhdescriptionprevnextTop
sub newFh {
  my $class = shift;
  return unless my $self = $class->new(@_);
  return $self->fh;
}
next_bibrefdescriptionprevnextTop
sub next_bibref {
   my ($self) = shift;
   $self->throw ("Sorry, you cannot read from a generic Bio::Biblio::IO object.");
}

# -----------------------------------------------------------------------------
}
General documentation
SEE ALSOTop
    *(1)
    An example script examples/biblio.pl. It has many options and its
own help. The relevant options to this IO module are -f
(specifying what file to read) and -O (specifying what result
format to achieve).
    *(2)
    OpenBQS home page: http://industry.ebi.ac.uk/openBQS
    *(3)
    Comments to the Perl client: http://industry.ebi.ac.uk/openBQS/Client_perl.html
FEEDBACKTop
Mailing ListsTop
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/MailList.shtml - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.
Bug reports can be submitted via email or the web:
  bioperl-bugs@bioperl.org
http://bugzilla.bioperl.org/
AUTHORTop
Martin Senger (senger@ebi.ac.uk)
COPYRIGHTTop
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.
DISCLAIMERTop
This software is provided "as is" without warranty of any kind.
APPENDIXTop
The rest of the documentation details each of the object
methods. Internal methods are preceded with a _