PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Bio/Pipeline/InputCreate.pm

https://github.com/bioperl/bioperl-pipeline
Perl | 428 lines | 308 code | 104 blank | 16 comment | 34 complexity | 1b2c55d8733e9f6b12537c6d9694a3c0 MD5 | raw file
Possible License(s): LGPL-2.0
  1. #
  2. # BioPerl module for Bio::Pipeline::InputCreate
  3. #
  4. # Please direct questions and support issues to <bioperl-l@bioperl.org>
  5. #
  6. # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
  7. #
  8. #
  9. # You may distribute this module under the same terms as perl itself
  10. #
  11. # POD documentation - main docs before the code
  12. #
  13. =head1 NAME
  14. Bio::Pipeline::InputCreate
  15. =head1 SYNOPSIS
  16. use Bio::Pipeline::InputCreate;
  17. my $inc = Bio::Pipeline::InputCreate->new('-module'=>'setup_genewise','-rank'=>1,'-dbadaptor'=>$self->db);
  18. $inc->run();
  19. =head1 DESCRIPTION
  20. Object used for encapsulating "hacky" processing needed to setup
  21. input and job tables. Pluggable into DataMonger object
  22. =head1 FEEDBACK
  23. =head2 Mailing Lists
  24. User feedback is an integral part of the evolution of this and other
  25. Bioperl modules. Send your comments and suggestions preferably to one
  26. of the Bioperl mailing lists. Your participation is much appreciated.
  27. bioperl-l@bioperl.org - General discussion
  28. http://bioperl.org/wiki/Mailing_lists - About the mailing lists
  29. =head2 Support
  30. Please direct usage questions or support issues to the mailing list:
  31. L<bioperl-l@bioperl.org>
  32. rather than to the module maintainer directly. Many experienced and
  33. reponsive experts will be able look at the problem and quickly
  34. address it. Please include a thorough description of the problem
  35. with code and data examples if at all possible.
  36. =head2 Reporting Bugs
  37. Report bugs to the Bioperl bug tracking system to help us keep track
  38. the bugs and their resolution. Bug reports can be submitted via email
  39. or the web:
  40. bioperl-bugs@bio.perl.org
  41. http://bugzilla.open-bio.org/
  42. =head1 AUTHOR - Shawn Hoon
  43. Email shawnh@fugu-sg.org
  44. =head1 APPENDIX
  45. The rest of the documentation details each of the object methods. Internal metho
  46. ds are usually preceded with a _
  47. =cut
  48. package Bio::Pipeline::InputCreate;
  49. use vars qw(@ISA);
  50. use strict;
  51. use Bio::Root::Root;
  52. use Bio::Pipeline::Input;
  53. use Bio::Pipeline::Job;
  54. use Bio::Pipeline::Runnable::DataMonger;
  55. @ISA = qw(Bio::Root::Root);
  56. =head2 new
  57. Title : new
  58. Usage : my $inc = Bio::Pipeline::InputCreate->new('-module'=>$module,'-rank'=>$rank,'-dbadaptor'=>$self->db,'-rule_group_id'=>$rgd)
  59. Function: constructor for InputCreate object
  60. Returns : a new InputCreate object
  61. Args : module, the list of inputcreate modules found in Bio::Pipeline::Filter::*
  62. rank specifies the order in which to apply the inputcreate in relation to others
  63. dbadaptor provides the handle to the pipeline database
  64. rule_group_id the rule group id of the jobs to be created by InputCreate
  65. =cut
  66. sub new {
  67. my ($caller ,@args) = @_;
  68. my $class = ref($caller) || $caller;
  69. # or do we want to call SUPER on an object if $caller is an
  70. # object?
  71. if( $class =~ /Bio::Pipeline::InputCreate::(\S+)/ ) {
  72. my ($self) = $class->SUPER::new(@args);
  73. $self->_initialize(@args);
  74. return $self;
  75. }
  76. else {
  77. my %param = @args;
  78. @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
  79. my $module= $param{'-module'};
  80. my $rank= $param{'-rank'};
  81. my $rule_group_id = $param{'-rule_group_id'};
  82. $module || Bio::Root::Root->throw("You must provid a InputCreate module found in Bio::Pipeline::InputCreate::*");
  83. $module = "\L$module"; # normalize capitalization to lower case
  84. return undef unless ($class->_load_inputcreate_module($module));
  85. my ($self) = "Bio::Pipeline::InputCreate::$module"->new(@args);
  86. $self->module($module);
  87. $self->rank($rank);
  88. $self->rule_group_id($rule_group_id);
  89. return $self;
  90. }
  91. }
  92. sub _initialize {
  93. my ($self,@args) = @_;
  94. my ($infile_suffix,$infile_dir,$dbadaptor) = $self->_rearrange([qw(INFILE_SUFFIX INFILE_DIR DBADAPTOR)],@args);
  95. $self->infile_suffix($infile_suffix) if $infile_suffix;
  96. $self->infile_dir($infile_dir) if $infile_dir;
  97. #$dbadaptor || $self->throw("InputCreate needs a dbadaptor to create new jobs and inputs");
  98. $self->dbadaptor($dbadaptor);
  99. }
  100. =head2 infile_dir
  101. Title : infile_dir
  102. Usage : $self->infile_dir()
  103. Function: get/set
  104. holds the directory in which input files are
  105. found
  106. Returns : a string
  107. Args : a string (optional)
  108. =cut
  109. sub infile_dir {
  110. my ($self, $infile_dir) = @_;
  111. if($infile_dir) {
  112. $self->{'_infile_dir'} = $infile_dir;
  113. }
  114. return $self->{'_infile_dir'};
  115. }
  116. =head2 infile
  117. Title : infile
  118. Usage : $self->infile()
  119. Function: get/set
  120. holds the directory in which input files are
  121. found
  122. Returns : a string
  123. Args : a string (optional)
  124. =cut
  125. sub infile{
  126. my ($self, $infile) = @_;
  127. if($infile) {
  128. $infile = Bio::Root::IO->catfile($self->infile_dir,$infile) if $self->infile_dir;
  129. $infile = $infile.$self->infile_suffix if $self->infile_suffix;
  130. $self->{'_infile'} = $infile;
  131. }
  132. return $self->{'_infile'};
  133. }
  134. =head2 infile_suffix
  135. Title : infile_suffix
  136. Usage : $self->infile_suffix()
  137. Function: get/set
  138. holds the file extension of the input file
  139. Returns : a string
  140. Args : a string (optional)
  141. =cut
  142. sub infile_suffix {
  143. my ($self,$val) = @_;
  144. if($val){
  145. $val = $val=~/^\.\S*/ ? $val : ".$val";
  146. $self->{'_infile_suffix'} = $val;
  147. }
  148. return $self->{'_infile_suffix'};
  149. }
  150. =head2 _load_inputcreate_module
  151. Title : _load_inputcreate_module
  152. Usage : $inc->_load_inputcreate_module("setup_genewise");
  153. Function: loads the input create module
  154. Returns : a new InputCreate object
  155. Args : module, the name of the module found in Bio::Pipeline::InputCreate
  156. =cut
  157. sub _load_inputcreate_module {
  158. my ($self, $module) = @_;
  159. $module = "Bio::Pipeline::InputCreate::" . $module;
  160. my $ok;
  161. eval {
  162. $ok = $self->_load_module($module);
  163. };
  164. if ($@) {
  165. print STDERR <<END;
  166. $self: $module cannot be found
  167. Exception $@
  168. For more information about the Bio::Pipeline::InputCreate system please see the pipeline docs
  169. This includes ways of checking for formats at compile time, not run time
  170. END
  171. ;
  172. }
  173. return $ok;
  174. }
  175. =head2 create_input
  176. Title : create_input
  177. Usage : $inc->create_input("inputname","3");
  178. Function: utility method for creating Bio::Pipeline::Input objects
  179. Returns : L<Bio::Pipeline::Input>
  180. Args : name: the name of the input
  181. ioh : the iohandler dbID of the input
  182. =cut
  183. sub create_input {
  184. my ($self,$name,$ioh,$tag) = @_;
  185. $name || $self->throw("Need an input name to create input");
  186. my $input_obj = Bio::Pipeline::Input->new(-name => $name,
  187. -tag => $tag,
  188. -input_handler => $ioh);
  189. return $input_obj;
  190. }
  191. =head2 create_job
  192. Title : create_job
  193. Usage : $inc->create_job($analysis,[$input1,$input2]);
  194. Function: utility method for creating Bio::Pipeline::Job objects
  195. Returns : L<Bio::Pipeline::Job >
  196. Args : analysis: a L<Bio::Pipeline::Analysis> object
  197. inputs: an array ref to the list of input belonging to the job
  198. =cut
  199. sub create_job {
  200. my ($self,$analysis,$input_objs) = @_;
  201. my $job = Bio::Pipeline::Job->new(-analysis => $analysis,
  202. -adaptor => $self->dbadaptor->get_JobAdaptor,
  203. -rule_group_id=>$self->rule_group_id,
  204. -inputs => $input_objs);
  205. return $job;
  206. }
  207. =head2 datatypes
  208. Title : datatypes
  209. Usage : $inc->datatypes
  210. Function: abstract method for returing the datatypes required by InputCreate object
  211. Returns :
  212. Args :
  213. =cut
  214. sub datatypes {
  215. my ($self) = @_;
  216. $self->throw_not_implemented();
  217. }
  218. sub rule_group_id {
  219. my ($self, $rule_group_id) = @_;
  220. if($rule_group_id) {
  221. $self->{'_rule_group_id'} = $rule_group_id;
  222. }
  223. return $self->{'_rule_group_id'};
  224. }
  225. =head2 dbID
  226. Title : dbID
  227. Usage : $inc->dbID
  228. Function: get set method for the dbID that the inputcreate dbID takes
  229. Returns :
  230. Args :
  231. =cut
  232. sub dbID {
  233. my ($self,$dbID) = @_;
  234. if($dbID){
  235. $self->{'_dbID'} = $dbID;
  236. }
  237. return $self->{'_dbID'};
  238. }
  239. =head2 module
  240. Title : module
  241. Usage : $inc->module
  242. Function: get set method for the module that the inputcreate module takes
  243. Returns :
  244. Args :
  245. =cut
  246. sub module {
  247. my ($self,$module) = @_;
  248. if($module){
  249. $self->{'_module'} = $module;
  250. }
  251. return $self->{'_module'};
  252. }
  253. =head2 rank
  254. Title : rank
  255. Usage : $inc->rank
  256. Function: get set method for the rank that the inputcreate module takes
  257. Returns :
  258. Args :
  259. =cut
  260. sub rank {
  261. my ($self,$rank) = @_;
  262. if($rank){
  263. $self->{'_rank'} = $rank;
  264. }
  265. return $self->{'_rank'};
  266. }
  267. =head2 arguments
  268. Title : arguments
  269. Usage : $inc->arguments
  270. Function: get set method for the arguments that the inputcreate module takes
  271. Returns :
  272. Args :
  273. =cut
  274. sub arguments {
  275. my ($self,$arguments) = @_;
  276. if($arguments){
  277. $self->{'_arguments'} = $arguments;
  278. }
  279. return $self->{'_arguments'};
  280. }
  281. =head2 run
  282. Title : run
  283. Usage : $self->run();
  284. Function: abstract method for running the module
  285. Returns :
  286. Args :
  287. =cut
  288. sub run {
  289. my ($self) = @_;
  290. $self->throw_not_implemented();
  291. }
  292. =head2 dbadaptor
  293. Title : dbadaptor
  294. Usage : $self->dbadaptor();
  295. Function: get/set for dbadaptor
  296. Returns :
  297. Args :
  298. =cut
  299. sub dbadaptor {
  300. my ($self,$dbadaptor) = @_;
  301. if($dbadaptor){
  302. $self->{'_dbadaptor'} = $dbadaptor;
  303. }
  304. return $self->{'_dbadaptor'};
  305. }
  306. sub parse_params {
  307. my ($self,$string,$dash) = @_;
  308. $string = " $string"; #add one space for first param
  309. my @param_str = split(/\s-/,$string);
  310. shift @param_str;
  311. #parse the parameters
  312. my @params;
  313. foreach my $p(@param_str){
  314. my ($tag,$value) = $p=~/(\S+)\s+(.*)/;
  315. if($dash){
  316. push @params, ("-".$tag,$value);
  317. }
  318. else {
  319. push @params, ($tag,$value);
  320. }
  321. }
  322. return @params;
  323. }
  324. 1;