PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Bio/Pipeline/Runnable/EnsemblRunnable.pm

https://github.com/bioperl/bioperl-pipeline
Perl | 289 lines | 199 code | 73 blank | 17 comment | 13 complexity | d37ae508cd6fb2e6a691d87a10a12bc2 MD5 | raw file
Possible License(s): LGPL-2.0
  1. # Please direct questions and support issues to <bioperl-l@bioperl.org>
  2. #
  3. # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
  4. #
  5. # Copyright Shawn Hoon
  6. #
  7. # You may distribute this module under the same terms as perl itself
  8. #
  9. # POD documentation - main docs before the code
  10. #
  11. # =pod
  12. #
  13. # =head1 NAME
  14. #
  15. # Bio::Pipeline::Runnable::EnsemblRunnable
  16. #
  17. =head1 SYNOPSIS
  18. use Bio::Pipeline::Runnable::EnsemblRunnable;
  19. use Bio::SeqIO;
  20. my $seqio = Bio::SeqIO->new(-file=>$ARGV[0]);
  21. my $seq = $seqio->next_seq;
  22. my $database = "/data0/tmp_family/Fugu_rubripes.pep.fa";
  23. my $runner = Bio::Pipeline::Runnable::EnsemblRunnable->new(-module=>"Blast",
  24. -query=>$seq,
  25. -program=>'blastp',
  26. -database=>$database,
  27. -threshold=>'1e-6');
  28. my @output = $runner->run;
  29. =head1 DESCRIPTION
  30. The runnable that enables biopipe to run Ensembl runnables.
  31. =head1 FEEDBACK
  32. =head2 Mailing Lists
  33. User feedback is an integral part of the evolution of this and other
  34. Bioperl modules. Send your comments and suggestions preferably to one
  35. of the Bioperl mailing lists. Your participation is much appreciated.
  36. bioperl-pipeline@bioperl.org - General discussion
  37. http://bioperl.org/wiki/Mailing_lists - About the mailing lists
  38. =head2 Support
  39. Please direct usage questions or support issues to the mailing list:
  40. L<bioperl-l@bioperl.org>
  41. rather than to the module maintainer directly. Many experienced and
  42. reponsive experts will be able look at the problem and quickly
  43. address it. Please include a thorough description of the problem
  44. with code and data examples if at all possible.
  45. =head2 Reporting Bugs
  46. Report bugs to the Bioperl bug tracking system to help us keep track
  47. the bugs and their resolution. Bug reports can be submitted via email
  48. or the web:
  49. bioperl-bugs@bio.perl.org
  50. http://bugzilla.open-bio.org/
  51. =head1 AUTHOR - FuguI Team
  52. Email fugui@fugu-sg.org
  53. =head1 APPENDIX
  54. The rest of the documentation details each of the object methods. Internal metho
  55. ds are usually preceded with a _
  56. =cut
  57. # Let the code begin...
  58. package Bio::Pipeline::Runnable::EnsemblRunnable;
  59. use vars qw(@ISA $AUTOLOAD);
  60. use strict;
  61. use Bio::Root::Root;
  62. use Bio::Pipeline::DataType;
  63. use Bio::Pipeline::RunnableI;
  64. @ISA = qw(Bio::Pipeline::RunnableI);
  65. =head2 new
  66. Title : new
  67. Usage : $self->new()
  68. Function: return a new EnsemblRunnable wrapper
  69. Returns : L<Bio::Pipeline::Runnable::EnsemblRunnable>
  70. Args : -module the specific Ensembl Runnable to use
  71. Any other parameters that are passed to the
  72. Ensembl Runnable.
  73. =cut
  74. sub new {
  75. my ($class, @args) = @_;
  76. my $self = $class->SUPER::new(@args);
  77. my ($module) = $self->_rearrange([qw(MODULE)],@args);
  78. $module && $self->module($module);
  79. my %param = @args;
  80. @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
  81. foreach my $method (keys %param){
  82. my $copy = $method;
  83. $copy=~s/-//g;
  84. $self->$copy($param{$method});
  85. }
  86. return $self;
  87. }
  88. =head2 add_tag
  89. Title : add_tag
  90. Usage : $self->add_tag()
  91. Function: add to the list of methods that EnsemblRunnable expects
  92. this is to accomodate for some required parameters
  93. in the new method of the specific EnsemblRunnable
  94. Returns : Array of strings
  95. Args :
  96. =cut
  97. sub add_tag{
  98. my ($self,$tag) = @_;
  99. if($tag){
  100. push @{$self->{'_tag'}}, $tag;
  101. }
  102. return @{$self->{'_tag'}};
  103. }
  104. =head2 get_tags
  105. Title : get_tags
  106. Usage : $self->get_tags()
  107. Function: gets the list of tags
  108. Returns : Array of strings
  109. Args :
  110. =cut
  111. sub get_tags {
  112. my ($self) = @_;
  113. return @{$self->{'_tag'}};
  114. }
  115. =head2 AUTOLOAD
  116. Title : AUTOLOAD
  117. Usage :
  118. Function: Allow any get/sets
  119. Returns :
  120. Args :
  121. =cut
  122. sub AUTOLOAD {
  123. my $self = shift;
  124. my $val = shift;
  125. my $tag= $AUTOLOAD;
  126. $tag=~ s/.*:://;
  127. if($tag && $val){
  128. $self->add_tag($tag);
  129. $self->{$tag} = $val;
  130. }
  131. return $self->{$tag};
  132. }
  133. =head2 get_input_params
  134. Title : get_input_params
  135. Usage : $self->get_input_params()
  136. Function: returns an array of tag-value parameters
  137. Returns : Array of tag-value pairs
  138. Args :
  139. =cut
  140. sub get_input_params {
  141. my ($self) = @_;
  142. my @param;
  143. foreach my $tag ($self->get_tags){
  144. push @param, ("-".$tag,$self->$tag);
  145. }
  146. return @param;
  147. }
  148. =head2 module
  149. Title : module
  150. Usage : $self->module()
  151. Function: get/set for module, the name of the name of the ensembl runnable
  152. to use e.g Blast, Genscan, RepeatMasker etc
  153. Returns :
  154. Args :
  155. =cut
  156. sub module {
  157. my ($self,$mod) = @_;
  158. if($mod){
  159. $self->{'_module'} = $mod;
  160. }
  161. return $self->{'_module'};
  162. }
  163. =head2 run
  164. Title : run
  165. Usage : $self->run()
  166. Function: execute
  167. Returns :
  168. Args :
  169. =cut
  170. sub run {
  171. my ($self) = @_;
  172. my $module = $self->module;
  173. my @params;
  174. if($self->analysis && $self->analysis->parameters){
  175. @params = $self->parse_params($self->analysis->parameters);
  176. }
  177. push @params, $self->get_input_params();
  178. my $runnable = $self->load_runnable($self->module,@params);
  179. $runnable->run;
  180. my @output = $runnable->output;
  181. $self->output(\@output);
  182. return $self->output;
  183. }
  184. =head2 runnable
  185. Title : runnable
  186. Usage : $self->runnable()
  187. Function: get/set for runnable
  188. Returns :
  189. Args :
  190. =cut
  191. sub runnable {
  192. my ($self) = @_;
  193. if(!defined $self->{'_runnable'}){
  194. $self->load_runnable($self->module,@_);
  195. }
  196. return $self->{'_runnable'};
  197. }
  198. =head2 load_runnable
  199. Title : load_runnable
  200. Usage : $self->load_runnable($module)
  201. Function: loads the ensembl runnable
  202. Returns :
  203. Args :
  204. =cut
  205. sub load_runnable {
  206. my($self) = shift;
  207. my $module = shift;
  208. if(! defined $self->{'_runnable'}){
  209. my $namespace = "Bio/EnsEMBL/Pipeline/Runnable/$module";
  210. require "$namespace.pm";
  211. $namespace=~s/\//\::/g;
  212. $self->{"_runnable"} = (${namespace}->new(@_));
  213. }
  214. return $self->{"_runnable"};
  215. }
  216. 1;