| 1 | package WWW::Search::PharmGKB; | ||
| 2 | |||
| 3 | 2 | ▶ | use SOAP::Lite; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 4 | import SOAP::Data 'type'; | ||
| 5 | use English; | ||
| 6 | use Carp; | ||
| 7 | use vars qw($VERSION); | ||
| 8 | use Data::Dumper; | ||
| 9 | |||
| 10 | $VERSION = '2.03'; | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $class = shift; | ||
| 14 | my $self = bless { | ||
| 15 | proxy => 'http://www.pharmgkb.org/services/PharmGKBItem', | ||
| 16 | uri => 'PharmGKBItem', | ||
| 17 | readable => 1, | ||
| 18 | }, | ||
| 19 | $class; | ||
| 20 | return $self; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub gene_search { | ||
| 24 | |||
| 25 | my $self = shift; | ||
| 26 | my($gene) = @_; | ||
| 27 | my $result_obj = {}; | ||
| 28 | my $pharm_ids = $self->_search($gene, 'Gene'); | ||
| 29 | if($pharm_ids) { | ||
| 30 | |||
| 31 | foreach my $gene_id(@{$pharm_ids}) { | ||
| 32 | my $local_hash = {}; | ||
| 33 | my $soap_service = SOAP::Lite | ||
| 34 | -> readable ($self->{readable}) | ||
| 35 | -> uri($self->{uri}) | ||
| 36 | -> proxy($self->{proxy}) | ||
| 37 | -> searchGene ($gene_id); | ||
| 38 | my $search_result = $soap_service->result; | ||
| 39 | $local_hash->{'alternate_names'} = ''; | ||
| 40 | $local_hash->{'drugs'} = ''; | ||
| 41 | $local_hash->{'diseases'} = ''; | ||
| 42 | $local_hash->{'phenotypes'} = ''; | ||
| 43 | $local_hash->{'pathways'} = ''; | ||
| 44 | $local_hash->{'alternate_symbols'} = ''; | ||
| 45 | $local_hash->{'name'} = ''; | ||
| 46 | $local_hash->{symbol} = ''; | ||
| 47 | |||
| 48 | my @pathways = (); | ||
| 49 | if($search_result->{'geneRelatedPathways'}) { | ||
| 50 | my $pathway_result = $search_result->{'geneRelatedPathways'}; | ||
| 51 | |||
| 52 | for(my $i = 0; $i <scalar(@{$pathway_result}); $i+= 2) { | ||
| 53 | push(@pathways, {$pathway_result->[$i] => $pathway_result->[$i+1]}); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | $local_hash->{'pathways'} = \@pathways; | ||
| 57 | if($search_result->{geneName}) { | ||
| 58 | $local_hash->{name} = $search_result->{geneName}; | ||
| 59 | } | ||
| 60 | if($search_result->{geneSymbol}) { | ||
| 61 | $local_hash->{symbol} = $search_result->{geneSymbol}; | ||
| 62 | } | ||
| 63 | if($search_result->{'geneAlternateNames'}) { | ||
| 64 | $local_hash->{'alternate_names'} = $search_result->{'geneAlternateNames'}; | ||
| 65 | } | ||
| 66 | if($search_result->{'geneRelatedDrugs'}) { | ||
| 67 | $local_hash->{'drugs'} = $search_result->{'geneRelatedDrugs'}; | ||
| 68 | } | ||
| 69 | if($search_result->{'geneRelatedDiseases'}) { | ||
| 70 | $local_hash->{'diseases'} = $search_result->{'geneRelatedDiseases'}; | ||
| 71 | } | ||
| 72 | if($search_result->{'geneAlternateSymbols'}) { | ||
| 73 | $local_hash->{'alternate_symbols'} = $search_result->{'geneAlternateSymbols'}; | ||
| 74 | } | ||
| 75 | if($search_result->{'geneRelatedPhenotypeDatasets'}) { | ||
| 76 | $local_hash->{'phenotypes'} = $search_result->{'geneRelatedPhenotypeDatasets'}; | ||
| 77 | } | ||
| 78 | |||
| 79 | $result_obj->{$gene_id} = $local_hash; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | else { | ||
| 83 | print "Gene $gene was not found in PharmGKB!\n"; | ||
| 84 | } | ||
| 85 | return $result_obj; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub disease_search { | ||
| 89 | |||
| 90 | my $self = shift; | ||
| 91 | my($disease) = @_; | ||
| 92 | my $result_obj = {}; | ||
| 93 | my $pharm_ids; | ||
| 94 | if($disease) { | ||
| 95 | $pharm_ids = $self->_search($disease, 'Disease'); | ||
| 96 | } | ||
| 97 | else { | ||
| 98 | print "\'$disease\' is weird. I can't search that\n"; | ||
| 99 | return 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | if($pharm_ids) { | ||
| 103 | |||
| 104 | foreach my $disease_id(@{$pharm_ids}) { | ||
| 105 | my $local_hash = {}; | ||
| 106 | my $soap_service = SOAP::Lite | ||
| 107 | -> readable (1) | ||
| 108 | -> uri($self->{uri}) | ||
| 109 | -> proxy($self->{proxy}) | ||
| 110 | -> searchDisease ($disease_id); | ||
| 111 | |||
| 112 | |||
| 113 | my $search_result = $soap_service->result; | ||
| 114 | $local_hash->{'names'} = ''; | ||
| 115 | $local_hash->{'drugs'} = ''; | ||
| 116 | $local_hash->{'genes'} = ''; | ||
| 117 | $local_hash->{'phenotypes'} = ''; | ||
| 118 | $local_hash->{'pathways'} = ''; | ||
| 119 | |||
| 120 | my @pathways = (); | ||
| 121 | if($search_result->{'diseaseRelatedPathways'}) { | ||
| 122 | my $pathway_result = $search_result->{'diseaseRelatedPathways'}; | ||
| 123 | |||
| 124 | for(my $i = 0; $i <scalar(@{$pathway_result}); $i+= 2) { | ||
| 125 | push(@pathways, {$pathway_result->[$i] => $pathway_result->[$i+1]}); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | $local_hash->{'pathways'} = \@pathways; | ||
| 129 | if($search_result->{'diseaseAlternateNames'}) { | ||
| 130 | $local_hash->{'names'} = $search_result->{'diseaseAlternateNames'}; | ||
| 131 | } | ||
| 132 | if($search_result->{'diseaseRelatedDrugs'}) { | ||
| 133 | $local_hash->{'drugs'} = $search_result->{'diseaseRelatedDrugs'}; | ||
| 134 | } | ||
| 135 | if($search_result->{'diseaseRelatedGenes'}) { | ||
| 136 | $local_hash->{'genes'} = $search_result->{'diseaseRelatedGenes'}; | ||
| 137 | } | ||
| 138 | if($search_result->{'diseaseRelatedPhenotypeDatasets'}) { | ||
| 139 | $local_hash->{'phenotypes'} = $search_result->{'diseaseRelatedPhenotypeDatasets'}; | ||
| 140 | } | ||
| 141 | |||
| 142 | $result_obj->{$disease_id} = $local_hash; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | else { | ||
| 146 | print "Disease $disease was not found in PharmGKB!\n"; | ||
| 147 | } | ||
| 148 | return $result_obj; | ||
| 149 | } | ||
| 150 | |||
| 151 | sub drug_search { | ||
| 152 | my $self = shift; | ||
| 153 | my($drug) = @_; | ||
| 154 | my $result_obj = {}; | ||
| 155 | my $pharm_ids; | ||
| 156 | if($drug) { | ||
| 157 | $pharm_ids = $self->_search($drug, 'Drug'); | ||
| 158 | } | ||
| 159 | else { | ||
| 160 | print "\'$drug\' is weird. I can't search that\n"; | ||
| 161 | return 0; | ||
| 162 | } | ||
| 163 | if($pharm_ids) { | ||
| 164 | foreach my $drug_id(@{$pharm_ids}) { | ||
| 165 | my $local_hash = {}; | ||
| 166 | my $soap_service = SOAP::Lite | ||
| 167 | -> readable (1) | ||
| 168 | -> uri($self->{uri}) | ||
| 169 | -> proxy($self->{proxy}) | ||
| 170 | -> searchDrug ($drug_id); | ||
| 171 | |||
| 172 | my $search_result = $soap_service->result; | ||
| 173 | $local_hash->{'generic_names'} = ''; | ||
| 174 | $local_hash->{'trade_names'} = ''; | ||
| 175 | $local_hash->{'category'} = ''; | ||
| 176 | $local_hash->{'classification'} = ''; | ||
| 177 | $local_hash->{'genes'} = ''; | ||
| 178 | $local_hash->{'diseases'} = ''; | ||
| 179 | $local_hash->{'phenotypes'} = ''; | ||
| 180 | $local_hash->{'pathways'} = ''; | ||
| 181 | $local_hash->{'name'} = ''; | ||
| 182 | my @pathways = (); | ||
| 183 | if($search_result->{'drugRelatedPathways'}) { | ||
| 184 | my $pathway_result = $search_result->{'drugRelatedPathways'}; | ||
| 185 | |||
| 186 | for(my $i = 0; $i < scalar(@{$pathway_result}); $i+= 2) { | ||
| 187 | push(@pathways, {$pathway_result->[$i] => $pathway_result->[$i+1]}); | ||
| 188 | } | ||
| 189 | } | ||
| 190 | $local_hash->{'pathways'} = \@pathways; | ||
| 191 | if($search_result->{'drugName'}) { | ||
| 192 | $local_hash->{'name'} = $search_result->{'drugName'}; | ||
| 193 | } | ||
| 194 | if($search_result->{'drugGenericNames'}) { | ||
| 195 | $local_hash->{'generic_names'} = $search_result->{'drugGenericNames'}; | ||
| 196 | } | ||
| 197 | if($search_result->{'drugTradeNames'}) { | ||
| 198 | $local_hash->{'trade_names'} = $search_result->{'drugTradeNames'}; | ||
| 199 | } | ||
| 200 | if($search_result->{'drugCategory'}) { | ||
| 201 | $local_hash->{'category'} = $search_result->{'drugCategory'}; | ||
| 202 | } | ||
| 203 | if($search_result->{'drugVaClassifications'}){ | ||
| 204 | $local_hash->{'classification'} = $search_result->{'drugVaClassifications'}; | ||
| 205 | } | ||
| 206 | if($search_result->{'drugRelatedGenes'}) { | ||
| 207 | $local_hash->{'genes'} = $search_result->{'drugRelatedGenes'}; | ||
| 208 | } | ||
| 209 | if($search_result->{'drugRelatedDiseases'}) { | ||
| 210 | $local_hash->{'diseases'} = $search_result->{'drugRelatedDiseases'}; | ||
| 211 | } | ||
| 212 | if($search_result->{'drugRelatedPhenotypeDatasets'}) { | ||
| 213 | $local_hash->{'phenotypes'} = $search_result->{'drugRelatedPhenotypeDatasets'}; | ||
| 214 | } | ||
| 215 | |||
| 216 | $result_obj->{$drug_id} = $local_hash; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | else { | ||
| 220 | print "Drug $drug was not found in PharmGKB!\n"; | ||
| 221 | } | ||
| 222 | return $result_obj; | ||
| 223 | } | ||
| 224 | |||
| 225 | sub publication_search { | ||
| 226 | |||
| 227 | my $self = shift; | ||
| 228 | my($search_term) = @_; | ||
| 229 | my $pharm_ids; | ||
| 230 | my $result_obj = {}; | ||
| 231 | if($search_term) { | ||
| 232 | $pharm_ids = $self->_search($search_term, 'Publication'); | ||
| 233 | } | ||
| 234 | else { | ||
| 235 | print "\'$search_term\' is weird. I can't search that\n"; | ||
| 236 | return 0; | ||
| 237 | } | ||
| 238 | if($pharm_ids) { | ||
| 239 | foreach my $id(@{$pharm_ids}) { | ||
| 240 | my $local_hash = {}; | ||
| 241 | my $soap_service = SOAP::Lite | ||
| 242 | -> readable ($self->{readable}) | ||
| 243 | -> uri($self->{uri}) | ||
| 244 | -> proxy($self->{proxy}) | ||
| 245 | -> searchPublication ($id); | ||
| 246 | |||
| 247 | my $search_result = $soap_service->result; | ||
| 248 | $local_hash->{'grant_id'} = ''; | ||
| 249 | $local_hash->{'journal'} = ''; | ||
| 250 | $local_hash->{'title'} = ''; | ||
| 251 | $local_hash->{'month'} = ''; | ||
| 252 | $local_hash->{'abstract'} = ''; | ||
| 253 | $local_hash->{'authors'} = ''; | ||
| 254 | $local_hash->{'volume'} = ''; | ||
| 255 | $local_hash->{'page'} = ''; | ||
| 256 | $local_hash->{'cross_reference'} = ''; | ||
| 257 | $local_hash->{'year'} = ''; | ||
| 258 | if($search_result) { | ||
| 259 | if($search_result->{publicationGrantIds}) { | ||
| 260 | $local_hash->{'grants_id'} = $search_result->{publicationGrantIds}; | ||
| 261 | } | ||
| 262 | if($search_result->{publicationJournal}) { | ||
| 263 | $local_hash->{journal} = $search_result->{publicationJournal}; | ||
| 264 | } | ||
| 265 | if($search_result->{publicationName}) { | ||
| 266 | $local_hash->{title} = $search_result->{publicationName}; | ||
| 267 | } | ||
| 268 | if($search_result->{publicationMonth}) { | ||
| 269 | $local_hash->{month} = $search_result->{publicationMonth}; | ||
| 270 | } | ||
| 271 | if($search_result->{publicationAbstract}) { | ||
| 272 | $local_hash->{'abstract'} = $search_result->{publicationAbstract}; | ||
| 273 | } | ||
| 274 | if($search_result->{publicationAuthors}) { | ||
| 275 | $local_hash->{authors} = $search_result->{publicationAuthors}; | ||
| 276 | } | ||
| 277 | if($search_result->{publicationVolume}) { | ||
| 278 | $local_hash->{volume} = $search_result->{publicationVolume}; | ||
| 279 | } | ||
| 280 | if($search_result->{publicationPage}) { | ||
| 281 | $local_hash->{page} = $search_result->{publicationPage}; | ||
| 282 | } | ||
| 283 | if($search_result->{publicationAnnotationCrossReference}) { | ||
| 284 | my $references = $search_result->{publicationAnnotationCrossReference}; | ||
| 285 | my @references_array = (); | ||
| 286 | for(my $i=0; $i < scalar(@{$references});$i+=2) { | ||
| 287 | push(@references_array, {$references->[$i] => $references->[$i+1]}); | ||
| 288 | } | ||
| 289 | $local_hash->{'cross_reference'} = \@references_array; | ||
| 290 | } | ||
| 291 | if($search_result->{publicationYear}) { | ||
| 292 | $local_hash->{year} = $search_result->{publicationYear}; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | $result_obj->{$id} = $local_hash; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | else { | ||
| 299 | print "No results found for $search_term\n"; | ||
| 300 | } | ||
| 301 | return $result_obj; | ||
| 302 | } | ||
| 303 | |||
| 304 | |||
| 305 | sub _search { | ||
| 306 | my $self = shift; | ||
| 307 | my($search_term, $key) = @_; | ||
| 308 | my @pharm_id = (); | ||
| 309 | |||
| 310 | my $soap_service = SOAP::Lite | ||
| 311 | -> readable ($self->{readable}) | ||
| 312 | -> uri('SearchService') | ||
| 313 | -> proxy('http://www.pharmgkb.org/services/SearchService') | ||
| 314 | -> search ($search_term); | ||
| 315 | my $search_result = $soap_service->result; | ||
| 316 | foreach my $search_obj(@{$search_result}) { | ||
| 317 | if($search_obj->[1] =~ m/$key/ig) { | ||
| 318 | push(@pharm_id, $search_obj->[0]); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | return \@pharm_id; | ||
| 322 | |||
| 323 | } | ||
| 324 | |||
| 325 | 1; | ||
| 326 | |||
| 327 | |||
| 328 | =head1 NAME | ||
| 329 | |||
| 330 | WWW::Search::PharmGKB - Search and retrieve information from the PharmGKB database | ||
| 331 | |||
| 332 | =head1 VERSION | ||
| 333 | |||
| 334 | Version 2.02 | ||
| 335 | |||
| 336 | =cut | ||
| 337 | |||
| 338 | =head1 SYNOPSIS | ||
| 339 | |||
| 340 | This module will not work. The PharmGKB API doesn't exist anymore. PLEASE DO NOT USE. | ||
| 341 | |||
| 342 | =cut | ||
| 343 | |||
| 344 | =head1 AUTHOR | ||
| 345 | |||
| 346 | Arun Venkataraman, C<< <arvktr at gmail.com> >> | ||
| 347 | |||
| 348 | =head1 BUGS | ||
| 349 | |||
| 350 | Please report any bugs or feature requests to C<bug-www-search-pharmgkb at rt.cpan.org>, or through | ||
| 351 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Search-PharmGKB>. I will be notified, and then you'll | ||
| 352 | automatically be notified of progress on your bug as I make changes. | ||
| 353 | |||
| 354 | |||
| 355 | |||
| 356 | |||
| 357 | =head1 SUPPORT | ||
| 358 | |||
| 359 | You can find documentation for this module with the perldoc command. | ||
| 360 | |||
| 361 | perldoc WWW::Search::PharmGKB | ||
| 362 | |||
| 363 | You can also look for information at: | ||
| 364 | |||
| 365 | =over 4 | ||
| 366 | |||
| 367 | =item * RT: CPAN's request tracker | ||
| 368 | |||
| 369 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Search-PharmGKB> | ||
| 370 | |||
| 371 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 372 | |||
| 373 | L<http://annocpan.org/dist/WWW-Search-PharmGKB> | ||
| 374 | |||
| 375 | =item * CPAN Ratings | ||
| 376 | |||
| 377 | L<http://cpanratings.perl.org/d/WWW-Search-PharmGKB> | ||
| 378 | |||
| 379 | =item * Search CPAN | ||
| 380 | |||
| 381 | L<http://search.cpan.org/dist/WWW-Search-PharmGKB> | ||
| 382 | |||
| 383 | =back | ||
| 384 | |||
| 385 | You can contact the author for any issues or suggestions you come accross using this module. | ||
| 386 | |||
| 387 | =head1 ACKNOWLEDGEMENTS | ||
| 388 | |||
| 389 | This module is based on the perl client written by Andrew MacBride (andrew@helix.stanford.edu) for PharmGKB's web services. | ||
| 390 | |||
| 391 | =head1 COPYRIGHT & LICENSE | ||
| 392 | |||
| 393 | Copyright 2010 Arun Venkataraman C<arvktr@cpan.org>, all rights reserved. | ||
| 394 | |||
| 395 | This program is free software; you can redistribute it and/or modify it | ||
| 396 | under the same terms as Perl itself. | ||
| 397 | |||
| 398 | |||
| 399 | =cut | ||