3 # BioPerl module for Bio::Tools::EUtilities::Info
5 # Cared for by Chris Fields
7 # Copyright Chris Fields
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 # Part of the EUtilities BioPerl package
17 Bio::Tools::EUtilities::Info - interface class for storing einfo data
21 #### should not create instance directly; Bio::Tools::EUtilities does this ####
23 my $info = Bio::Tools::EUtilities->new(-eutil => 'einfo',
24 -file => 'einfo.xml');
25 # can also use '-response' (for HTTP::Response objects) or '-fh' (for filehandles)
27 # print available databases (if data is present)
29 print join(', ',$info->get_available_databases),"\n";
33 my $db = $info->get_database; # in case you forgot...
34 my $desc = $info->get_description;
35 my $nm = $info->get_menu_name;
36 my $ct = $info->get_record_count;
37 my $dt = $info->get_last_update;
39 # EUtilDataI interface methods
41 my $eutil = $info->eutil;
42 my $type = $info->datatype;
44 # iterate through Field and Link objects
46 while (my $field = $info->next_Field) {
47 print "Field code: ",$field->get_field_code,"\n";
48 print "Field name: ",$field->get_field_name,"\n";
49 print "Field desc: ",$field->get_field_description,"\n";
50 print "DB : ",$field->get_database,"\n";
51 print "Term ct : ",$field->get_term_count,"\n";
52 for my $att (qw(is_date is_singletoken is_hierarchy is_hidden is_numerical)) {
53 print "\tField $att\n" if $field->$att;
57 my @fields = $info->get_Fields; # grab them all (useful for grep)
59 while (my $link = $info->next_LinkInfo) {
60 print "Link name: ",$link->get_link_name,"\n";
61 print "Link desc: ",$link->get_link_description,"\n";
62 print "DBFrom: ",$link->get_dbfrom,"\n"; # same as get_database()
63 print "DBTo: ",$link->get_dbto,"\n"; # database linked to
66 my @links = $info->get_LinkInfo; # grab them all (useful for grep)
68 $info->rewind(); # rewinds all iterators
69 $info->rewind('links'); # rewinds Link iterator
70 $info->rewind('fields'); # rewinds Field iterator
74 This class handles data output (XML) from einfo.
76 einfo is capable of returning two types of information: 1) a list of all
77 available databases (when called w/o parameters) and 2) information about a
78 specific database. The latter information includes the database description,
79 record count, and date/time stamp for the last update, among other things. It
80 also includes a list of fields (indices by which record data is stored which can
81 be used in queries) and links (crossrefs between related records in other
82 databases at NCBI). Data from the latter two are stored in two small subclasses
83 (Field and Link) which can be iterated through or retrieved all at once, as
84 demonstrated above. NOTE: Methods described for the Link and Field subclasses
85 are unique to those classes (as they retrieve data unique to those data types).
87 Further documentation for Link and Field subclass methods is included below.
89 For more information on einfo see:
91 http://eutils.ncbi.nlm.nih.gov/entrez/query/static/einfo_help.html
97 User feedback is an integral part of the evolution of this and other Bioperl
98 modules. Send your comments and suggestions preferably to one of the Bioperl
99 mailing lists. Your participation is much appreciated.
101 bioperl-l@lists.open-bio.org - General discussion
102 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
104 =head2 Reporting Bugs
106 Report bugs to the Bioperl bug tracking system to help us keep track the bugs
107 and their resolution. Bug reports can be submitted via the web.
109 http://bugzilla.open-bio.org/
113 Email cjfields at uiuc dot edu
117 The rest of the documentation details each of the object methods. Internal
118 methods are usually preceded with a _
122 # Let the code begin...
124 package Bio
::Tools
::EUtilities
::Info
;
128 use base
qw(Bio::Tools::EUtilities Bio::Tools::EUtilities::EUtilDataI);
130 use Bio
::Tools
::EUtilities
::Info
::LinkInfo
;
131 use Bio
::Tools
::EUtilities
::Info
::FieldInfo
;
136 Usage : $info->rewind() # rewinds all (default)
137 $info->rewind('links') # rewinds only links
138 Function : 'rewinds' (resets) specified interators (all if no arg)
140 Args : [OPTIONAL] String:
141 'all' - all iterators (default)
142 'linkinfo' - LinkInfo objects only
143 'fieldinfo' - FieldInfo objects only
148 # private EUtilDataI method
151 my ($self, $simple) = @_;
152 if (exists $simple->{DbList
} &&
153 exists $simple->{DbList
}->{DbName
}) {
154 $self->{'_available_databases'} = $simple->{DbList
}->{DbName
};
156 # start setting internal variables
157 if (exists $simple->{DbInfo
}) {
158 for my $key (sort keys %{ $simple->{DbInfo
} }) {
160 ($key eq 'FieldList') ?
$simple->{DbInfo
}->{$key}->{Field
} :
161 ($key eq 'LinkList' ) ?
$simple->{DbInfo
}->{$key}->{Link
} :
162 $simple->{DbInfo
}->{$key};
163 if ($key eq 'FieldList' || $key eq 'LinkList') {
164 for my $chunk (@
{$data}) {
165 if (exists $simple->{DbInfo
}->{DbName
}) {
166 $chunk->{DbFrom
} = $simple->{DbInfo
}->{DbName
};
168 my $type = ($key eq 'FieldList') ?
'FieldInfo' : 'LinkInfo';
169 my $obj = "Bio::Tools::EUtilities::Info::$type"->new(
172 -verbose
=> $self->verbose);
173 $obj->_add_data($chunk);
174 push @
{ $self->{'_'.lc $type} }, $obj;
177 $self->{'_'.lc $key} = $data;
181 map { $self->{'_'.lc $_} = $simple->{$_} unless ref $simple->{$_}} keys %$simple;
188 Usage : $foo->to_string()
189 Function : converts current object to string
191 Args : (optional) simple data for text formatting
192 Note : Used generally for debugging and for various print methods
198 my $string = $self->SUPER::to_string
;
199 if (my @dbs = $self->get_databases) {
200 $string .= sprintf("%-20s:%s\n\n", 'DB',
201 $self->_text_wrap('', ' 'x20
.':', join(', ',@dbs)));
203 while (my $fi = $self->next_FieldInfo) {
204 $string .= $fi->to_string."\n";
206 while (my $li = $self->next_LinkInfo) {
207 $string .= $li->to_string."\n";