def run(self): print(ui.header('dammit')) print(ui.header(__description__, level=2)) about = '\nby {0}\n\n**v{1}**, {2}\n'.format(', '.join(__authors__), __version__, __date__) print(about) return self.args.func()
def run(self, doit_args=None, verbose=True): '''Run the pipeline. Movees to the directory, loads the tasks into doit, and executes that tasks that are not up-to-date. Args: doit_args (list): Args that would be passed to the doit shell command. By default, just run. verbose (bool): If True, print UI stuff. Returns: int: Exit status of the doit command. ''' if verbose: print(ui.header('Run Tasks', level=4)) if doit_args is None: doit_args = ['run'] if self.n_threads > 1: doit_args.extend(['-n', str(self.n_threads)]) runner = DoitMain(self) with Move(self.directory): if self.profile is True: profile_fn = path.join(self.directory, 'profile.csv') with StartProfiler(filename=profile_fn): return runner.run(doit_args) else: return runner.run(doit_args)
def run_annotation(handler): '''Run the annotation pipeline from the given handler. Prints the appropriate output and exits of the pipeline is alredy completed. Args: handler (handler.TaskHandler): Handler with tasks for the pipeline. ''' print(ui.header('Annotation', level=3)) print(ui.header('Info', level=4)) info = {'Doit Database': handler.dep_file, 'Input Transcriptome': handler.files['transcriptome']} print(ui.listing(info)) msg = '*All annotation tasks up-to-date.*' uptodate, statuses = handler.print_statuses(uptodate_msg=msg) if not uptodate: return handler.run() else: print('**Pipeline is already completed!**') sys.exit(0)
def print_meta(handler): '''Print metadata about the database pipeline. Args: handler (handler.TaskHandler): The database task handler. ''' print(ui.header('Info', level=4)) info = {'Doit Database': handler.dep_file, 'Database Directory': handler.directory} print(ui.listing(info))
def install(handler): '''Run the database prep pipeline from the given handler. ''' print(ui.header('Database Install', level=3)) print_meta(handler) msg = '*All database tasks up-to-date.*' uptodate, statuses = handler.print_statuses(uptodate_msg=msg) if not uptodate: print('Installing...') return handler.run() else: print('Nothing to install!') return 0
def check_or_fail(handler): '''Check that the handler's tasks are complete, and if not, exit with status 2. ''' print(ui.header('Database Check', level=3)) print_meta(handler) msg = '*All database tasks up-to-date.*' uptodate, statuses = handler.print_statuses(uptodate_msg=msg) if not uptodate: print(ui.paragraph('Must install databases to continue. To do so,' ' run `dammit databases --install`. If you have' ' already installed them, make sure you\'ve given' ' the correct location to `--database-dir` or have' ' exported the $DAMMIT_DB_DIR environment' ' variable.')) sys.exit(2)
def handle_databases(self): log.start_logging() print(ui.header('submodule: databases', level=2)) handler = databases.get_handler(self.config_d) if self.args.quick: databases.build_quick_pipeline(handler, self.config_d, self.databases_d) else: databases.build_default_pipeline(handler, self.config_d, self.databases_d, with_uniref=self.args.full, with_nr=self.args.nr) if self.args.install: return databases.install(handler) else: databases.check_or_fail(handler)
def handle_annotate(self): log.start_logging() print(ui.header('submodule: annotate', level=2)) db_handler = databases.get_handler(self.config_d) if self.args.quick: databases.build_quick_pipeline(db_handler, self.config_d, self.databases_d) else: databases.build_default_pipeline(db_handler, self.config_d, self.databases_d, with_uniref=self.args.full, with_nr=self.args.nr) if self.config_d['force'] is True: utd_msg = '*All database tasks up-to-date.*' ood_msg = '*Some database tasks out-of-date; '\ 'FORCE is True, ignoring!' uptodate, statuses = db_handler.print_statuses( uptodate_msg=utd_msg, outofdate_msg=ood_msg) else: databases.check_or_fail(db_handler) annotate_handler = annotate.get_handler(self.config_d, db_handler.files) if self.args.quick: build_quick_pipeline(annotate_handler, self.config_d, db_handler.files) elif self.args.full: build_full_pipeline(annotate_handler, self.config_d, db_handler.files) elif self.args.nr: build_nr_pipeline(annotate_handler, self.config_d, db_handler.files) else: build_default_pipeline(annotate_handler, self.config_d, db_handler.files) return annotate.run_annotation(annotate_handler)
def description(self): return ui.header('dammit: ' + __description__)
def test_header(self): assert header('test') == '# test' assert header('test', level=0) == '# test' assert header('test', level=2) == '## test'