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::FieldInfo - class for storing einfo field 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)
28 print join(', ',$info->get_available_databases),"\n";
31 my $db = $info->get_database; # in case you forgot...
32 my $desc = $info->get_description;
33 my $nm = $info->get_menu_name;
34 my $ct = $info->get_record_count;
35 my $dt = $info->get_last_update;
36 # EUtilDataI interface methods
37 my $eutil = $info->eutil;
38 my $type = $info->type;
40 # iterate through Field and Link objects
41 while (my $field = $info->next_Field) {
42 print "Field code: ",$field->get_field_code,"\n";
43 print "Field name: ",$field->get_field_name,"\n";
44 print "Field desc: ",$field->get_field_description,"\n";
45 print "DB : ",$field->get_database,"\n";
46 print "Term ct : ",$field->get_term_count,"\n";
47 for my $att (qw(is_date is_singletoken is_hierarchy is_hidden is_numerical)) {
48 print "\tField $att\n" if $field->$att;
52 my @fields = $info->get_Fields; # grab them all (useful for grep)
54 while (my $link = $info->next_Link) {
55 print "Link name: ",$link->get_link_name,"\n";
56 print "Link desc: ",$link->get_link_description,"\n";
57 print "DBFrom: ",$link->get_dbfrom,"\n"; # same as get_database()
58 print "DBTo: ",$link->get_dbto,"\n"; # database linked to
61 my @links = $info->get_Links; # grab them all (useful for grep)
63 $info->rewind(); # rewinds all iterators
64 $info->rewind('links'); # rewinds Link iterator
65 $info->rewind('fields'); # rewinds Field iterator
69 This class handles data output (XML) from einfo.
71 einfo is capable of returning two types of information: 1) a list of all
72 available databases (when called w/o parameters) and 2) information about a
73 specific database. The latter information includes the database description,
74 record count, and date/time stamp for the last update, among other things. It
75 also includes a list of fields (indices by which record data is stored which can
76 be used in queries) and links (crossrefs between related records in other
77 databases at NCBI). Data from the latter two are stored in two small subclasses
78 (Field and Link) which can be iterated through or retrieved all at once, as
79 demonstrated above. NOTE: Methods described for the Link and Field subclasses
80 are unique to those classes (as they retrieve data unique to those data types).
82 Further documentation for Link and Field subclass methods is included below.
84 For more information on einfo see:
86 http://eutils.ncbi.nlm.nih.gov/entrez/query/static/einfo_help.html
92 User feedback is an integral part of the evolution of this and other Bioperl
93 modules. Send your comments and suggestions preferably to one of the Bioperl
94 mailing lists. Your participation is much appreciated.
96 bioperl-l@lists.open-bio.org - General discussion
97 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
101 Report bugs to the Bioperl bug tracking system to help us keep track the bugs
102 and their resolution. Bug reports can be submitted via the web.
104 http://bugzilla.open-bio.org/
108 Email cjfields at uiuc dot edu
112 The rest of the documentation details each of the object methods. Internal
113 methods are usually preceded with a _
117 # Let the code begin...
119 package Bio
::Tools
::EUtilities
::Info
::FieldInfo
;
120 use base
qw(Bio::Root::Root Bio::Tools::EUtilities::EUtilDataI);
127 Note : *** should not be called by end-users ***
128 Usage : my $ct = Bio::Tools::EUtilities::Info::FieldInfo;
129 Function : returns new FieldInfo instance
130 Returns : Bio::Tools::EUtilities::Info::FieldInfo instance
131 Args : none (all data added via _add_data, most methods are getters only)
136 my ($class, @args) = @_;
137 my $self = $class->SUPER::new
(@args);
138 $self->eutil('einfo');
139 $self->datatype('fieldinfo');
146 Usage : my $ct = $field->term_count;
147 Function : returns number of terms for field
153 sub get_term_count
{ return shift->{'_termcount'} }
155 =head2 get_field_name
157 Title : get_field_name
158 Usage : my $nm = $field->get_field_name;
159 Function : returns the full name of the field
165 sub get_field_name
{ return shift->{'_fullname'} }
169 Title : get_full_name
170 Note : alias of get_field_name()
174 *get_full_name
= \
&get_field_name
;
176 =head2 get_field_code
178 Title : get_field_code
179 Usage : $field->get_field_code()
180 Function : returns field code (abbreviation) used for queries
186 sub get_field_code
{ return shift->{'_name'} }
188 =head2 get_field_description
190 Title : get_field_description
191 Usage : $field->get_field_description
192 Function : returns field description
195 Note : alias of get_description()
199 sub get_field_description
{ return shift->{'_description'} }
204 Usage : if ($field->is_date) {...}
205 Function : returns true if field contains date information
213 ($self->{'_isdate'} && $self->{'_isdate'} eq 'Y') ?
return 1 : return 0;
216 =head2 is_singletoken
218 Title : is_singletoken
219 Usage : if ($field->is_singletoken) {...}
220 Function : returns true if field has single value in docsums
228 ($self->{'_singletoken'} && $self->{'_singletoken'} eq 'Y') ?
return 1 : return 0;
234 Usage : if ($field->is_hierarchy) {...}
235 Function : returns true if field contains hierarchal values
243 ($self->{'hierarchy'} && $self->{'hierarchy'} eq 'Y') ?
return 1 : return 0;
249 Usage : if ($field->is_hidden) {...}
250 Function : returns true if field is hidden in docsums
258 ($self->{'_ishidden'} && $self->{'_ishidden'} eq 'Y') ?
return 1 : return 0;
264 Usage : if ($field->is_numerical) {...}
265 Function : returns true if field contains a numerical value
273 ($self->{'_isnumerical'} && $self->{'_isnumerical'} eq 'Y') ?
return 1 : return 0;
276 # private EUtilDataI method
279 my ($self, $simple) = @_;
280 map { $self->{'_'.lc $_} = $simple->{$_} unless ref $simple->{$_}} keys %$simple;
286 Usage : $foo->to_string()
287 Function : converts current object to string
289 Args : (optional) simple data for text formatting
290 Note : Used generally for debugging and for various print methods
297 my %tags = (1 => ['get_field_code' => 'Field Code'],
298 2 => ['get_field_name' => 'Field Name'],
299 3 => ['get_field_description' => 'Description'],
300 4 => ['get_term_count' => 'Term Count']);
302 for my $tag (sort {$a <=> $b} keys %tags) {
303 my ($m, $nm) = ($tags{$tag}->[0], $tags{$tag}->[1]);
304 $string .= sprintf("%-20s%s\n", $nm,
305 $self->_text_wrap('', ' 'x20
.':', ":".$self->$m));
307 $string .= sprintf("%-20s%s\n", "Attributes",
308 $self->_text_wrap('', ' 'x20
.':', ":".join(',', grep {$self->$_} qw(is_date
309 is_singletoken is_hierarchy is_hidden is_numerical))));