3 # BioPerl module for Bio::DB::EUtilities::Query
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::DB::EUtilities::Query
21 #### should not create instance directly; Bio::Tools::EUtilities does this ####
23 # can also use '-response' (for HTTP::Response objects) or '-fh' (for filehandles)
24 my $info = Bio::Tools::EUtilities->new(-eutil => 'esearch',
25 -file => 'esearch.xml');
29 # esearch with history
33 # espell (just for completeness, really)
43 User feedback is an integral part of the
44 evolution of this and other Bioperl modules. Send
45 your comments and suggestions preferably to one
46 of the Bioperl mailing lists. Your participation
49 bioperl-l@lists.open-bio.org - General discussion
50 http://www.bioperl.org/wiki/Mailing_lists - About the mailing lists
54 Report bugs to the Bioperl bug tracking system to
55 help us keep track the bugs and their resolution.
56 Bug reports can be submitted via the web.
58 http://bugzilla.open-bio.org/
62 Email cjfields at uiuc dot edu
66 The rest of the documentation details each of the
67 object methods. Internal methods are usually
72 # Let the code begin...
74 package Bio
::Tools
::EUtilities
::Query
;
77 use Bio
::Tools
::EUtilities
::Query
::GlobalQuery
;
78 use Bio
::Tools
::EUtilities
::History
;
80 use base
qw(Bio::Tools::EUtilities);
82 =head1 Bio::Tools::EUtilities::Query methods
86 # private EUtilDataI method
90 'espell' => 'spelling',
91 'esearch' => 'singledbquery',
92 'egquery' => 'multidbquery',
97 my ($self, $qdata) = @_;
98 my $eutil = $self->eutil;
99 if (!$qdata || ref($qdata) !~ /HASH/i) {
100 $self->throw("Bad $eutil data");
102 if (exists $qdata->{WebEnv
}) {
103 my $cookie = Bio
::Tools
::EUtilities
::History
->new(-eutil
=> $eutil,
104 -verbose
=> $self->verbose);
105 $cookie->_add_data($qdata);
106 push @
{$self->{'_histories'}}, $cookie;
108 my $type = exists $TYPE{$eutil} ?
$TYPE{$eutil} :
109 $self->throw("Unrecognized eutil $eutil");
110 $self->datatype($type); # reset type based on what's present
111 for my $key (sort keys %$qdata) {
112 if ($key eq 'eGQueryResult' && exists $qdata->{$key}->{ResultItem
}) {
113 for my $gquery (@
{ $qdata->{eGQueryResult
}->{ResultItem
} }) {
114 $self->{'_term'} = $gquery->{Term
} = $qdata->{Term
};
115 my $qd = Bio
::Tools
::EUtilities
::Query
::GlobalQuery
->new(-eutil
=> 'egquery',
116 -datatype
=> 'globalquery',
117 -verbose
=> $self->verbose);
118 $qd->_add_data($gquery);
119 push @
{ $self->{'_globalqueries'} }, $qd;
122 if ($key eq 'IdList' &&
123 exists $qdata->{IdList
}->{Id
}) {
124 $self->{'_id'} = $qdata->{IdList
}->{Id
};
125 delete $qdata->{IdList
};
127 if ($key eq 'TranslationSet' &&
128 exists $qdata->{TranslationSet
}->{Translation
}) {
129 $self->{'_translation'} = $qdata->{TranslationSet
}->{Translation
};
130 delete $qdata->{TranslationSet
};
132 next if (ref $qdata->{$key} eq 'HASH' && !keys %{$qdata->{$key}});
133 $self->{'_'.lc $key} = $qdata->{$key};
142 Usage : $foo->to_string()
143 Function : converts current object to string
145 Args : (optional) simple data for text formatting
146 Note : Used generally for debugging and for the print_* methods
153 'DB' => [1, join(', ',$self->get_databases) || ''],
154 'Query' => [2, $self->get_term || ''],
155 'IDs' => [4, join(', ',$self->get_ids) || ''],
157 my $string = $self->SUPER::to_string
;
158 if ($self->eutil eq 'esearch') {
159 $data{'Count'} = [3, $self->get_count ];
160 $data{'Translation From'} = [5, $self->get_translation_from || ''];
161 $data{'Translation To'} = [6, $self->get_translation_to || ''];
162 $data{'RetStart'} = [7, $self->get_retstart];
163 $data{'RetMax'} = [8, $self->get_retmax];
164 $data{'Translation'} = [9, $self->get_query_translation || ''];
166 if ($self->eutil eq 'espell') {
167 $data{'Corrected'} = [3, $self->get_corrected_query || ''];
168 $data{'Replaced'} = [4, join(',',$self->get_replaced_terms) || ''];
170 for my $k (sort {$data{$a}->[0] <=> $data{$b}->[0]} keys %data) {
171 $string .= sprintf("%-20s:%s\n",$k, $self->_text_wrap('',' 'x
20 .':', $data{$k}->[1]));
173 while (my $h = $self->next_History) {
174 $string .= $h->to_string;
176 while (my $gq = $self->next_GlobalQuery) {
177 $string .= $gq->to_string;