| 1 | # | ||
| 2 | # BioPerl module for FAST::Bio::Search::Result::GenericResult | ||
| 3 | # | ||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||
| 5 | # | ||
| 6 | # Cared for by Jason Stajich <jason@bioperl.org> | ||
| 7 | # | ||
| 8 | # Copyright Jason Stajich | ||
| 9 | # | ||
| 10 | # You may distribute this module under the same terms as perl itself | ||
| 11 | |||
| 12 | # POD documentation - main docs before the code | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | FAST::Bio::Search::Result::GenericResult - Generic Implementation of | ||
| 17 | FAST::Bio::Search::Result::ResultI interface applicable to most search | ||
| 18 | results. | ||
| 19 | |||
| 20 | =head1 SYNOPSIS | ||
| 21 | |||
| 22 | |||
| 23 | # typically one gets Results from a SearchIO stream | ||
| 24 | use FAST::Bio::SearchIO; | ||
| 25 | my $io = FAST::Bio::SearchIO->new(-format => 'blast', | ||
| 26 | -file => 't/data/HUMBETGLOA.tblastx'); | ||
| 27 | while( my $result = $io->next_result ) { | ||
| 28 | # process all search results within the input stream | ||
| 29 | while( my $hit = $result->next_hit ) { | ||
| 30 | # insert code here for hit processing | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | use FAST::Bio::Search::Result::GenericResult; | ||
| 35 | my @hits = (); # would be a list of FAST::Bio::Search::Hit::HitI objects | ||
| 36 | # typically these are created from a FAST::Bio::SearchIO stream | ||
| 37 | my $result = FAST::Bio::Search::Result::GenericResult->new | ||
| 38 | ( -query_name => 'HUMBETGLOA', | ||
| 39 | -query_accession => '' | ||
| 40 | -query_description => 'Human haplotype C4 beta-globin gene, complete cds.' | ||
| 41 | -query_length => 3002 | ||
| 42 | -database_name => 'ecoli.aa' | ||
| 43 | -database_letters => 4662239, | ||
| 44 | -database_entries => 400, | ||
| 45 | -parameters => { 'e' => '0.001' }, | ||
| 46 | -statistics => { 'kappa' => 0.731 }, | ||
| 47 | -algorithm => 'blastp', | ||
| 48 | -algorithm_version => '2.1.2', | ||
| 49 | ); | ||
| 50 | |||
| 51 | my $id = $result->query_name(); | ||
| 52 | |||
| 53 | my $desc = $result->query_description(); | ||
| 54 | |||
| 55 | my $name = $result->database_name(); | ||
| 56 | |||
| 57 | my $size = $result->database_letters(); | ||
| 58 | |||
| 59 | my $num_entries = $result->database_entries(); | ||
| 60 | |||
| 61 | my $gap_ext = $result->get_parameter('e'); | ||
| 62 | |||
| 63 | my @params = $result->available_parameters; | ||
| 64 | |||
| 65 | my $kappa = $result->get_statistic('kappa'); | ||
| 66 | |||
| 67 | my @statnames = $result->available_statistics; | ||
| 68 | |||
| 69 | # TODO: Show how to configure a SearchIO stream so that it generates | ||
| 70 | # GenericResult objects. | ||
| 71 | |||
| 72 | |||
| 73 | =head1 DESCRIPTION | ||
| 74 | |||
| 75 | This object is an implementation of the FAST::Bio::Search::Result::ResultI | ||
| 76 | interface and provides a generic place to store results from a | ||
| 77 | sequence database search. | ||
| 78 | |||
| 79 | Unless you're writing a parser, you won't ever need to create a | ||
| 80 | GenericResult or any other ResultI-implementing object. If you use | ||
| 81 | the SearchIO system, ResultI objects are created automatically from | ||
| 82 | a SearchIO stream which returns FAST::Bio::Search::Result::ResultI objects. | ||
| 83 | |||
| 84 | For documentation on what you can do with GenericResult (and other ResultI | ||
| 85 | objects), please see the API documentation in | ||
| 86 | L<FAST::Bio::Search::Result::ResultI|FAST::Bio::Search::Result::ResultI>. | ||
| 87 | |||
| 88 | =head1 FEEDBACK | ||
| 89 | |||
| 90 | =head2 Mailing Lists | ||
| 91 | |||
| 92 | User feedback is an integral part of the evolution of this and other | ||
| 93 | Bioperl modules. Send your comments and suggestions preferably to | ||
| 94 | the Bioperl mailing list. Your participation is much appreciated. | ||
| 95 | |||
| 96 | bioperl-l@bioperl.org - General discussion | ||
| 97 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||
| 98 | |||
| 99 | =head2 Support | ||
| 100 | |||
| 101 | Please direct usage questions or support issues to the mailing list: | ||
| 102 | |||
| 103 | I<bioperl-l@bioperl.org> | ||
| 104 | |||
| 105 | rather than to the module maintainer directly. Many experienced and | ||
| 106 | reponsive experts will be able look at the problem and quickly | ||
| 107 | address it. Please include a thorough description of the problem | ||
| 108 | with code and data examples if at all possible. | ||
| 109 | |||
| 110 | =head2 Reporting Bugs | ||
| 111 | |||
| 112 | Report bugs to the Bioperl bug tracking system to help us keep track | ||
| 113 | of the bugs and their resolution. Bug reports can be submitted via the | ||
| 114 | web: | ||
| 115 | |||
| 116 | https://redmine.open-bio.org/projects/bioperl/ | ||
| 117 | |||
| 118 | =head1 AUTHOR - Jason Stajich and Steve Chervitz | ||
| 119 | |||
| 120 | Email jason@bioperl.org | ||
| 121 | Email sac@bioperl.org | ||
| 122 | |||
| 123 | =head1 CONTRIBUTORS | ||
| 124 | |||
| 125 | Sendu Bala, bix@sendu.me.uk | ||
| 126 | |||
| 127 | =head1 APPENDIX | ||
| 128 | |||
| 129 | The rest of the documentation details each of the object methods. | ||
| 130 | Internal methods are usually preceded with a _ | ||
| 131 | |||
| 132 | =cut | ||
| 133 | |||
| 134 | |||
| 135 | # Let the code begin... | ||
| 136 | |||
| 137 | |||
| 138 | package FAST::Bio::Search::Result::GenericResult; | ||
| 139 | use strict; | ||
| 140 | |||
| 141 | use FAST::Bio::Search::GenericStatistics; | ||
| 142 | use FAST::Bio::Tools::Run::GenericParameters; | ||
| 143 | |||
| 144 | # bug #1420 | ||
| 145 | #use overload | ||
| 146 | # '""' => \&to_string; | ||
| 147 | |||
| 148 | use base qw(FAST::Bio::Root::Root FAST::Bio::Search::Result::ResultI); | ||
| 149 | |||
| 150 | =head2 new | ||
| 151 | |||
| 152 | Title : new | ||
| 153 | Usage : my $obj = FAST::Bio::Search::Result::GenericResult->new(); | ||
| 154 | Function: Builds a new FAST::Bio::Search::Result::GenericResult object | ||
| 155 | Returns : FAST::Bio::Search::Result::GenericResult | ||
| 156 | Args : -query_name => Name of query Sequence | ||
| 157 | -query_accession => Query accession number (if available) | ||
| 158 | -query_description => Description of query sequence | ||
| 159 | -query_length => Length of query sequence | ||
| 160 | -database_name => Name of database | ||
| 161 | -database_letters => Number of residues in database | ||
| 162 | -database_entries => Number of entries in database | ||
| 163 | -hits => array ref of FAST::Bio::Search::Hit::HitI objects | ||
| 164 | -parameters => hash ref of search parameters (key => value) | ||
| 165 | -statistics => hash ref of search statistics (key => value) | ||
| 166 | -algorithm => program name (blastx) | ||
| 167 | -algorithm_version => version of the algorithm (2.1.2) | ||
| 168 | -algorithm_reference => literature reference string for this algorithm | ||
| 169 | -rid => value of the BLAST Request ID (eg. RID: ZABJ4EA7014) | ||
| 170 | -hit_factory => FAST::Bio::Factory::ObjectFactoryI capable of making | ||
| 171 | FAST::Bio::Search::Hit::HitI objects | ||
| 172 | |||
| 173 | =cut | ||
| 174 | |||
| 175 | sub new { | ||
| 176 | my($class,@args) = @_; | ||
| 177 | |||
| 178 | my $self = $class->SUPER::new(@args); | ||
| 179 | |||
| 180 | $self->{'_hits'} = []; | ||
| 181 | $self->{'_hitindex'} = 0; | ||
| 182 | $self->{'_statistics'} = FAST::Bio::Search::GenericStatistics->new(); | ||
| 183 | $self->{'_parameters'} = FAST::Bio::Tools::Run::GenericParameters->new(); | ||
| 184 | |||
| 185 | my ($qname,$qacc,$qdesc,$qlen, $qgi, | ||
| 186 | $dbname,$dblet,$dbent,$params, | ||
| 187 | $stats, $hits, $algo, $algo_v, | ||
| 188 | $prog_ref, $algo_r, $rid, $hit_factory) = $self->_rearrange([qw(QUERY_NAME | ||
| 189 | QUERY_ACCESSION | ||
| 190 | QUERY_DESCRIPTION | ||
| 191 | QUERY_LENGTH | ||
| 192 | QUERY_GI | ||
| 193 | DATABASE_NAME | ||
| 194 | DATABASE_LETTERS | ||
| 195 | DATABASE_ENTRIES | ||
| 196 | PARAMETERS | ||
| 197 | STATISTICS | ||
| 198 | HITS | ||
| 199 | ALGORITHM | ||
| 200 | ALGORITHM_VERSION | ||
| 201 | PROGRAM_REFERENCE | ||
| 202 | ALGORITHM_REFERENCE | ||
| 203 | RID | ||
| 204 | HIT_FACTORY | ||
| 205 | )],@args); | ||
| 206 | |||
| 207 | $algo_r ||= $prog_ref; | ||
| 208 | defined $algo && $self->algorithm($algo); | ||
| 209 | defined $algo_v && $self->algorithm_version($algo_v); | ||
| 210 | defined $algo_r && $self->algorithm_reference($algo_r); | ||
| 211 | |||
| 212 | defined $rid && $self->rid($rid); | ||
| 213 | |||
| 214 | defined $qname && $self->query_name($qname); | ||
| 215 | defined $qacc && $self->query_accession($qacc); | ||
| 216 | defined $qdesc && $self->query_description($qdesc); | ||
| 217 | defined $qlen && $self->query_length($qlen); | ||
| 218 | defined $qgi && $self->query_gi($qgi); | ||
| 219 | defined $dbname && $self->database_name($dbname); | ||
| 220 | defined $dblet && $self->database_letters($dblet); | ||
| 221 | defined $dbent && $self->database_entries($dbent); | ||
| 222 | |||
| 223 | defined $hit_factory && $self->hit_factory($hit_factory); | ||
| 224 | |||
| 225 | if( defined $params ) { | ||
| 226 | if( ref($params) !~ /hash/i ) { | ||
| 227 | $self->throw("Must specify a hash reference with the parameter '-parameters"); | ||
| 228 | } | ||
| 229 | while( my ($key,$value) = each %{$params} ) { | ||
| 230 | $self->{'_parameters'}->set_parameter($key => $value); | ||
| 231 | # $self->add_parameter($key,$value); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | if( defined $stats ) { | ||
| 235 | if( ref($stats) !~ /hash/i ) { | ||
| 236 | $self->throw("Must specify a hash reference with the parameter '-statistics"); | ||
| 237 | } | ||
| 238 | while( my ($key,$value) = each %{$stats} ) { | ||
| 239 | $self->{'_statistics'}->set_statistic($key => $value); | ||
| 240 | # $self->add_statistic($key,$value); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | if( defined $hits ) { | ||
| 245 | $self->throw("Must define arrayref of Hits when initializing a $class\n") unless ref($hits) =~ /array/i; | ||
| 246 | |||
| 247 | foreach my $s ( @$hits ) { | ||
| 248 | $self->add_hit($s); | ||
| 249 | } | ||
| 250 | } | ||
| 251 | return $self; | ||
| 252 | } | ||
| 253 | |||
| 254 | =head2 algorithm | ||
| 255 | |||
| 256 | Title : algorithm | ||
| 257 | Usage : my $r_type = $hsp->algorithm | ||
| 258 | Function: Obtain the name of the algorithm used to obtain the Result | ||
| 259 | Returns : string (e.g., BLASTP) | ||
| 260 | Args : [optional] scalar string to set value | ||
| 261 | |||
| 262 | =cut | ||
| 263 | |||
| 264 | sub algorithm{ | ||
| 265 | my ($self,$value) = @_; | ||
| 266 | my $previous = $self->{'_algorithm'}; | ||
| 267 | if( defined $value || ! defined $previous ) { | ||
| 268 | $value = $previous = '' unless defined $value; | ||
| 269 | $self->{'_algorithm'} = $value; | ||
| 270 | } | ||
| 271 | return $previous; | ||
| 272 | } | ||
| 273 | |||
| 274 | =head2 algorithm_version | ||
| 275 | |||
| 276 | Title : algorithm_version | ||
| 277 | Usage : my $r_version = $hsp->algorithm_version | ||
| 278 | Function: Obtain the version of the algorithm used to obtain the Result | ||
| 279 | Returns : string (e.g., 2.1.2) | ||
| 280 | Args : [optional] scalar string to set algorithm version value | ||
| 281 | |||
| 282 | =cut | ||
| 283 | |||
| 284 | sub algorithm_version{ | ||
| 285 | my ($self,$value) = @_; | ||
| 286 | my $previous = $self->{'_algorithm_version'}; | ||
| 287 | if( defined $value || ! defined $previous ) { | ||
| 288 | $value = $previous = '' unless defined $value; | ||
| 289 | $self->{'_algorithm_version'} = $value; | ||
| 290 | } | ||
| 291 | |||
| 292 | return $previous; | ||
| 293 | } | ||
| 294 | |||
| 295 | =head2 FAST::Bio::Search::Result::ResultI interface methods | ||
| 296 | |||
| 297 | FAST::Bio::Search::Result::ResultI implementation | ||
| 298 | |||
| 299 | =head2 next_hit | ||
| 300 | |||
| 301 | Title : next_hit | ||
| 302 | Usage : while( $hit = $result->next_hit()) { ... } | ||
| 303 | Function: Returns the next available Hit object, representing potential | ||
| 304 | matches between the query and various entities from the database. | ||
| 305 | Returns : a FAST::Bio::Search::Hit::HitI object or undef if there are no more. | ||
| 306 | Args : none | ||
| 307 | |||
| 308 | |||
| 309 | =cut | ||
| 310 | |||
| 311 | sub next_hit { | ||
| 312 | my ($self,@args) = @_; | ||
| 313 | my $index = $self->_nexthitindex; | ||
| 314 | return if $index > scalar @{$self->{'_hits'}}; | ||
| 315 | |||
| 316 | my $hit = $self->{'_hits'}->[$index]; | ||
| 317 | if (ref($hit) eq 'HASH') { | ||
| 318 | my $factory = $self->hit_factory || $self->throw("Tried to get a Hit, but it was a hash ref and we have no hit factory"); | ||
| 319 | $hit = $factory->create_object(%{$hit}); | ||
| 320 | $self->{'_hits'}->[$index] = $hit; | ||
| 321 | delete $self->{_hashes}->{$index}; | ||
| 322 | } | ||
| 323 | return $hit; | ||
| 324 | } | ||
| 325 | |||
| 326 | =head2 query_name | ||
| 327 | |||
| 328 | Title : query_name | ||
| 329 | Usage : $id = $result->query_name(); | ||
| 330 | Function: Get the string identifier of the query used by the | ||
| 331 | algorithm that performed the search. | ||
| 332 | Returns : a string. | ||
| 333 | Args : [optional] new string value for query name | ||
| 334 | |||
| 335 | =cut | ||
| 336 | |||
| 337 | sub query_name { | ||
| 338 | my ($self,$value) = @_; | ||
| 339 | my $previous = $self->{'_queryname'}; | ||
| 340 | if( defined $value || ! defined $previous ) { | ||
| 341 | $value = $previous = '' unless defined $value; | ||
| 342 | $self->{'_queryname'} = $value; | ||
| 343 | } | ||
| 344 | return $previous; | ||
| 345 | } | ||
| 346 | |||
| 347 | =head2 query_accession | ||
| 348 | |||
| 349 | Title : query_accession | ||
| 350 | Usage : $id = $result->query_accession(); | ||
| 351 | Function: Get the accession (if available) for the query sequence | ||
| 352 | Returns : a string | ||
| 353 | Args : [optional] new string value for accession | ||
| 354 | |||
| 355 | =cut | ||
| 356 | |||
| 357 | sub query_accession { | ||
| 358 | my ($self,$value) = @_; | ||
| 359 | my $previous = $self->{'_queryacc'}; | ||
| 360 | if( defined $value || ! defined $previous ) { | ||
| 361 | $value = $previous = '' unless defined $value; | ||
| 362 | $self->{'_queryacc'} = $value; | ||
| 363 | } | ||
| 364 | return $previous; | ||
| 365 | } | ||
| 366 | |||
| 367 | =head2 query_gi | ||
| 368 | |||
| 369 | Title : query_gi | ||
| 370 | Usage : $acc = $hit->query_gi(); | ||
| 371 | Function: Retrieve the NCBI Unique ID (aka the GI #), | ||
| 372 | if available, for the query | ||
| 373 | Returns : a scalar string (empty string if not set) | ||
| 374 | Args : none | ||
| 375 | |||
| 376 | =cut | ||
| 377 | |||
| 378 | sub query_gi { | ||
| 379 | my ($self,$value) = @_; | ||
| 380 | if( defined $value ) { | ||
| 381 | $self->{'_query_gi'} = $value; | ||
| 382 | } else { | ||
| 383 | $self->{'_query_gi'} = $self->query_name =~ m{^gi\|(\d+)} ? $1 : ''; | ||
| 384 | } | ||
| 385 | return $self->{'_query_gi'}; | ||
| 386 | } | ||
| 387 | |||
| 388 | =head2 query_length | ||
| 389 | |||
| 390 | Title : query_length | ||
| 391 | Usage : $id = $result->query_length(); | ||
| 392 | Function: Get the length of the query sequence | ||
| 393 | used in the search. | ||
| 394 | Returns : a number | ||
| 395 | Args : [optional] new integer value for query length | ||
| 396 | |||
| 397 | =cut | ||
| 398 | |||
| 399 | sub query_length { | ||
| 400 | my ($self,$value) = @_; | ||
| 401 | my $previous = $self->{'_querylength'}; | ||
| 402 | if( defined $value || ! defined $previous ) { | ||
| 403 | $value = $previous = 0 unless defined $value; | ||
| 404 | $self->{'_querylength'} = $value; | ||
| 405 | } | ||
| 406 | return $previous; | ||
| 407 | } | ||
| 408 | |||
| 409 | =head2 query_description | ||
| 410 | |||
| 411 | Title : query_description | ||
| 412 | Usage : $id = $result->query_description(); | ||
| 413 | Function: Get the description of the query sequence | ||
| 414 | used in the search. | ||
| 415 | Returns : a string | ||
| 416 | Args : [optional] new string for the query description | ||
| 417 | |||
| 418 | =cut | ||
| 419 | |||
| 420 | sub query_description { | ||
| 421 | my ($self,$value) = @_; | ||
| 422 | my $previous = $self->{'_querydesc'}; | ||
| 423 | if( defined $value || ! defined $previous ) { | ||
| 424 | $value = $previous = '' unless defined $value; | ||
| 425 | $self->{'_querydesc'} = $value; | ||
| 426 | } | ||
| 427 | return $previous; | ||
| 428 | } | ||
| 429 | |||
| 430 | |||
| 431 | =head2 database_name | ||
| 432 | |||
| 433 | Title : database_name | ||
| 434 | Usage : $name = $result->database_name() | ||
| 435 | Function: Used to obtain the name of the database that the query was searched | ||
| 436 | against by the algorithm. | ||
| 437 | Returns : a scalar string | ||
| 438 | Args : [optional] new string for the db name | ||
| 439 | |||
| 440 | =cut | ||
| 441 | |||
| 442 | sub database_name { | ||
| 443 | my ($self,$value) = @_; | ||
| 444 | my $previous = $self->{'_dbname'}; | ||
| 445 | if( defined $value || ! defined $previous ) { | ||
| 446 | $value = $previous = '' unless defined $value; | ||
| 447 | $self->{'_dbname'} = $value; | ||
| 448 | } | ||
| 449 | return $previous; | ||
| 450 | } | ||
| 451 | |||
| 452 | =head2 database_letters | ||
| 453 | |||
| 454 | Title : database_letters | ||
| 455 | Usage : $size = $result->database_letters() | ||
| 456 | Function: Used to obtain the size of database that was searched against. | ||
| 457 | Returns : a scalar integer (units specific to algorithm, but probably the | ||
| 458 | total number of residues in the database, if available) or undef if | ||
| 459 | the information was not available to the Processor object. | ||
| 460 | Args : [optional] new scalar integer for number of letters in db | ||
| 461 | |||
| 462 | |||
| 463 | =cut | ||
| 464 | |||
| 465 | sub database_letters { | ||
| 466 | my ($self,$value) = @_; | ||
| 467 | my $previous = $self->{'_dbletters'}; | ||
| 468 | if( defined $value || ! defined $previous ) { | ||
| 469 | $value = $previous = '' unless defined $value; | ||
| 470 | $self->{'_dbletters'} = $value; | ||
| 471 | } | ||
| 472 | return $previous; | ||
| 473 | } | ||
| 474 | |||
| 475 | =head2 database_entries | ||
| 476 | |||
| 477 | Title : database_entries | ||
| 478 | Usage : $num_entries = $result->database_entries() | ||
| 479 | Function: Used to obtain the number of entries contained in the database. | ||
| 480 | Returns : a scalar integer representing the number of entities in the database | ||
| 481 | or undef if the information was not available. | ||
| 482 | Args : [optional] new integer for the number of sequence entries in the db | ||
| 483 | |||
| 484 | |||
| 485 | =cut | ||
| 486 | |||
| 487 | sub database_entries { | ||
| 488 | my ($self,$value) = @_; | ||
| 489 | my $previous = $self->{'_dbentries'}; | ||
| 490 | if( defined $value || ! defined $previous ) { | ||
| 491 | $value = $previous = '' unless defined $value; | ||
| 492 | $self->{'_dbentries'} = $value; | ||
| 493 | } | ||
| 494 | return $previous; | ||
| 495 | } | ||
| 496 | |||
| 497 | =head2 get_parameter | ||
| 498 | |||
| 499 | Title : get_parameter | ||
| 500 | Usage : my $gap_ext = $report->get_parameter('gapext') | ||
| 501 | Function: Returns the value for a specific parameter used | ||
| 502 | when running this report | ||
| 503 | Returns : string | ||
| 504 | Args : name of parameter (string) | ||
| 505 | |||
| 506 | =cut | ||
| 507 | |||
| 508 | sub get_parameter { | ||
| 509 | my ($self,$name) = @_; | ||
| 510 | return $self->{'_parameters'}->get_parameter($name); | ||
| 511 | } | ||
| 512 | |||
| 513 | =head2 available_parameters | ||
| 514 | |||
| 515 | Title : available_parameters | ||
| 516 | Usage : my @params = $report->available_paramters | ||
| 517 | Function: Returns the names of the available parameters | ||
| 518 | Returns : Return list of available parameters used for this report | ||
| 519 | Args : none | ||
| 520 | |||
| 521 | =cut | ||
| 522 | |||
| 523 | sub available_parameters{ | ||
| 524 | my ($self) = @_; | ||
| 525 | return $self->{'_parameters'}->available_parameters; | ||
| 526 | } | ||
| 527 | |||
| 528 | |||
| 529 | =head2 get_statistic | ||
| 530 | |||
| 531 | Title : get_statistic | ||
| 532 | Usage : my $gap_ext = $report->get_statistic('kappa') | ||
| 533 | Function: Returns the value for a specific statistic available | ||
| 534 | from this report | ||
| 535 | Returns : string | ||
| 536 | Args : name of statistic (string) | ||
| 537 | |||
| 538 | =cut | ||
| 539 | |||
| 540 | sub get_statistic{ | ||
| 541 | my ($self,$key) = @_; | ||
| 542 | return $self->{'_statistics'}->get_statistic($key); | ||
| 543 | } | ||
| 544 | |||
| 545 | =head2 available_statistics | ||
| 546 | |||
| 547 | Title : available_statistics | ||
| 548 | Usage : my @statnames = $report->available_statistics | ||
| 549 | Function: Returns the names of the available statistics | ||
| 550 | Returns : Return list of available statistics used for this report | ||
| 551 | Args : none | ||
| 552 | |||
| 553 | =cut | ||
| 554 | |||
| 555 | sub available_statistics{ | ||
| 556 | my ($self) = @_; | ||
| 557 | return $self->{'_statistics'}->available_statistics; | ||
| 558 | } | ||
| 559 | |||
| 560 | =head2 FAST::Bio::Search::Report | ||
| 561 | |||
| 562 | FAST::Bio::Search::Result::GenericResult specific methods | ||
| 563 | |||
| 564 | =head2 add_hit | ||
| 565 | |||
| 566 | Title : add_hit | ||
| 567 | Usage : $report->add_hit($hit) | ||
| 568 | Function: Adds a HitI to the stored list of hits | ||
| 569 | Returns : Number of HitI currently stored | ||
| 570 | Args : FAST::Bio::Search::Hit::HitI | ||
| 571 | |||
| 572 | =cut | ||
| 573 | |||
| 574 | sub add_hit { | ||
| 575 | my ($self,$s) = @_; | ||
| 576 | if (ref($s) eq 'HASH' || $s->isa('FAST::Bio::Search::Hit::HitI') ) { | ||
| 577 | push @{$self->{'_hits'}}, $s; | ||
| 578 | } | ||
| 579 | else { | ||
| 580 | $self->throw("Passed in " .ref($s)." as a Hit which is not a FAST::Bio::Search::HitI."); | ||
| 581 | } | ||
| 582 | |||
| 583 | if (ref($s) eq 'HASH') { | ||
| 584 | $self->{_hashes}->{$#{$self->{'_hits'}}} = 1; | ||
| 585 | } | ||
| 586 | return scalar @{$self->{'_hits'}}; | ||
| 587 | } | ||
| 588 | |||
| 589 | =head2 hit_factory | ||
| 590 | |||
| 591 | Title : hit_factory | ||
| 592 | Usage : $hit->hit_factory($hit_factory) | ||
| 593 | Function: Get/set the factory used to build HitI objects if necessary. | ||
| 594 | Returns : FAST::Bio::Factory::ObjectFactoryI | ||
| 595 | Args : FAST::Bio::Factory::ObjectFactoryI | ||
| 596 | |||
| 597 | =cut | ||
| 598 | |||
| 599 | sub hit_factory { | ||
| 600 | my $self = shift; | ||
| 601 | if (@_) { $self->{_hit_factory} = shift } | ||
| 602 | return $self->{_hit_factory} || return; | ||
| 603 | } | ||
| 604 | |||
| 605 | =head2 rewind | ||
| 606 | |||
| 607 | Title : rewind | ||
| 608 | Usage : $result->rewind; | ||
| 609 | Function: Allow one to reset the Hit iterator to the beginning | ||
| 610 | Since this is an in-memory implementation | ||
| 611 | Returns : none | ||
| 612 | Args : none | ||
| 613 | |||
| 614 | =cut | ||
| 615 | |||
| 616 | sub rewind{ | ||
| 617 | my ($self) = @_; | ||
| 618 | $self->{'_hitindex'} = 0; | ||
| 619 | } | ||
| 620 | |||
| 621 | |||
| 622 | =head2 _nexthitindex | ||
| 623 | |||
| 624 | Title : _nexthitindex | ||
| 625 | Usage : private | ||
| 626 | |||
| 627 | =cut | ||
| 628 | |||
| 629 | sub _nexthitindex{ | ||
| 630 | my ($self,@args) = @_; | ||
| 631 | return $self->{'_hitindex'}++; | ||
| 632 | } | ||
| 633 | |||
| 634 | |||
| 635 | =head2 add_parameter | ||
| 636 | |||
| 637 | Title : add_parameter | ||
| 638 | Usage : $report->add_parameter('gapext', 11); | ||
| 639 | Function: Adds a parameter | ||
| 640 | Returns : none | ||
| 641 | Args : key - key value name for this parama | ||
| 642 | value - value for this parameter | ||
| 643 | |||
| 644 | =cut | ||
| 645 | |||
| 646 | sub add_parameter { | ||
| 647 | my ($self,$key,$value) = @_; | ||
| 648 | $self->{'_parameters'}->set_parameter($key => $value); | ||
| 649 | } | ||
| 650 | |||
| 651 | |||
| 652 | =head2 add_statistic | ||
| 653 | |||
| 654 | Title : add_statistic | ||
| 655 | Usage : $report->add_statistic('lambda', 2.3); | ||
| 656 | Function: Adds a parameter | ||
| 657 | Returns : none | ||
| 658 | Args : key - key value name for this parama | ||
| 659 | value - value for this parameter | ||
| 660 | |||
| 661 | =cut | ||
| 662 | |||
| 663 | sub add_statistic { | ||
| 664 | my ($self,$key,$value) = @_; | ||
| 665 | $self->{'_statistics'}->set_statistic($key => $value); | ||
| 666 | return; | ||
| 667 | } | ||
| 668 | |||
| 669 | |||
| 670 | =head2 num_hits | ||
| 671 | |||
| 672 | Title : num_hits | ||
| 673 | Usage : my $hitcount= $result->num_hits | ||
| 674 | Function: returns the number of hits for this query result | ||
| 675 | Returns : integer | ||
| 676 | Args : none | ||
| 677 | |||
| 678 | =cut | ||
| 679 | |||
| 680 | sub num_hits{ | ||
| 681 | my ($self) = shift; | ||
| 682 | if (not defined $self->{'_hits'}) { | ||
| 683 | $self->throw("Can't get Hits: data not collected."); | ||
| 684 | } | ||
| 685 | return scalar(@{$self->{'_hits'}}); | ||
| 686 | } | ||
| 687 | |||
| 688 | |||
| 689 | =head2 hits | ||
| 690 | |||
| 691 | Title : hits | ||
| 692 | Usage : my @hits = $result->hits | ||
| 693 | Function: Returns the available hits for this Result | ||
| 694 | Returns : Array of L<FAST::Bio::Search::Hit::HitI> objects | ||
| 695 | Args : none | ||
| 696 | |||
| 697 | |||
| 698 | =cut | ||
| 699 | |||
| 700 | sub hits { | ||
| 701 | my ($self) = shift; | ||
| 702 | |||
| 703 | foreach my $i (keys %{$self->{_hashes} || {}}) { | ||
| 704 | my $factory = $self->hit_factory || $self->throw("Tried to get a Hit, but it was a hash ref and we have no hit factory"); | ||
| 705 | $self->{'_hits'}->[$i] = $factory->create_object(%{$self->{'_hits'}->[$i]}); | ||
| 706 | delete $self->{_hashes}->{$i}; | ||
| 707 | } | ||
| 708 | |||
| 709 | my @hits = (); | ||
| 710 | if (ref $self->{'_hits'}) { | ||
| 711 | @hits = @{$self->{'_hits'}}; | ||
| 712 | } | ||
| 713 | return @hits; | ||
| 714 | } | ||
| 715 | |||
| 716 | =head2 algorithm_reference | ||
| 717 | |||
| 718 | Title : algorithm_reference | ||
| 719 | Usage : $obj->algorithm_reference($newval) | ||
| 720 | Function: | ||
| 721 | Returns : string containing literature reference for the algorithm | ||
| 722 | Args : newvalue string (optional) | ||
| 723 | Comments: Formerly named program_reference(), which is still supported | ||
| 724 | for backwards compatibility. | ||
| 725 | |||
| 726 | =cut | ||
| 727 | |||
| 728 | sub algorithm_reference{ | ||
| 729 | my ($self,$value) = @_; | ||
| 730 | if( defined $value) { | ||
| 731 | $self->{'algorithm_reference'} = $value; | ||
| 732 | } | ||
| 733 | return $self->{'algorithm_reference'}; | ||
| 734 | } | ||
| 735 | |||
| 736 | =head2 program_reference | ||
| 737 | |||
| 738 | Title : program_reference | ||
| 739 | Usage : $obj->program_reference() | ||
| 740 | Function: | ||
| 741 | Returns : string containing literature reference for the algorithm | ||
| 742 | Args : | ||
| 743 | Comments: Deprecated - use algorithm_reference() instead. | ||
| 744 | |||
| 745 | =cut | ||
| 746 | |||
| 747 | sub program_reference { shift->algorithm_reference(@_); } | ||
| 748 | |||
| 749 | =head2 rid | ||
| 750 | |||
| 751 | Title : rid | ||
| 752 | Usage : $obj->rid($newval) | ||
| 753 | Function: | ||
| 754 | Returns : value of the BLAST Request ID (eg. RID: ZABJ4EA7014) | ||
| 755 | Args : newvalue (optional) | ||
| 756 | Comments: The default implementation in ResultI returns an empty string | ||
| 757 | rather than throwing a NotImplemented exception, since | ||
| 758 | the RID may not always be available and is not critical. | ||
| 759 | See: (1) http://www.ncbi.nlm.nih.gov/Class/MLACourse/Modules/BLAST/rid.html | ||
| 760 | (2) http://www.ncbi.nlm.nih.gov/staff/tao/URLAPI/new/node63.html | ||
| 761 | =cut | ||
| 762 | |||
| 763 | sub rid{ | ||
| 764 | my ($self,$value) = @_; | ||
| 765 | if( defined $value) { | ||
| 766 | $self->{'rid'} = $value; | ||
| 767 | } | ||
| 768 | return $self->{'rid'}; | ||
| 769 | } | ||
| 770 | |||
| 771 | =head2 no_hits_found | ||
| 772 | |||
| 773 | See documentation in L<FAST::Bio::Search::Result::ResultI::no_hits_found()|FAST::Bio::Search::Result::ResultI> | ||
| 774 | |||
| 775 | =cut | ||
| 776 | |||
| 777 | sub no_hits_found { | ||
| 778 | my $self = shift; | ||
| 779 | |||
| 780 | # Watch the double negative! | ||
| 781 | # result = 0 means "yes hits were found" | ||
| 782 | # result = 1 means "no hits were found" | ||
| 783 | |||
| 784 | return $self->{'_no_hits_found'}; | ||
| 785 | } | ||
| 786 | |||
| 787 | |||
| 788 | =head2 set_no_hits_found | ||
| 789 | |||
| 790 | See documentation in L<FAST::Bio::Search::Result::ResultI::set_no_hits_found()|FAST::Bio::Search::Result::ResultI> | ||
| 791 | |||
| 792 | =cut | ||
| 793 | |||
| 794 | sub set_no_hits_found { | ||
| 795 | my $self = shift; | ||
| 796 | $self->{'_no_hits_found'} = 1; | ||
| 797 | } | ||
| 798 | |||
| 799 | |||
| 800 | =head2 to_string | ||
| 801 | |||
| 802 | Title : to_string | ||
| 803 | Usage : print $blast->to_string; | ||
| 804 | Function: Returns a string representation for the Blast result. | ||
| 805 | Primarily intended for debugging purposes. | ||
| 806 | Example : see usage | ||
| 807 | Returns : A string of the form: | ||
| 808 | [GenericResult] <analysis_method> query=<name> <description> db=<database | ||
| 809 | e.g.: | ||
| 810 | [GenericResult] BLASTP query=YEL060C vacuolar protease B, db=PDBUNIQ | ||
| 811 | Args : None | ||
| 812 | |||
| 813 | =cut | ||
| 814 | |||
| 815 | sub to_string { | ||
| 816 | my $self = shift; | ||
| 817 | my $str = ref($self) . ", algorithm= " . $self->algorithm . ", query=" . $self->query_name . " " . $self->query_description .", db=" . $self->database_name; | ||
| 818 | return $str; | ||
| 819 | } | ||
| 820 | |||
| 821 | 1; |