def test_pypeline__two_chained_pipelines_mock_functions__expected_correctly_value( self): # FIXTURE expected = object() test_method = Mock(return_value=expected) sub_pipeline = Pypeline().append(test_method, 'first', 'second', third='third').append( test_method, something_else=True) pipeline = Pypeline().append_context(sub_pipeline).append_context( sub_pipeline) # EXERCISE result = pipeline.do() # VERIFY self.assertIsNone(result) self.assertEqual(4, test_method.call_count) # first self.assertEqual(call('first', 'second', third='third'), test_method.mock_calls[0]) self.assertEqual(call(expected, something_else=True), test_method.mock_calls[1]) self.assertEqual(call('first', 'second', third='third'), test_method.mock_calls[2]) self.assertEqual(call(expected, something_else=True), test_method.mock_calls[3])
def test_pypeline__two_chained_simple_functions_arg_list__expected_correctly_value( self): # FIXTURE pipeline = Pypeline().append(math.pow, 2, 2).append(operator.add, 5) # EXERCISE result = pipeline.do() # VERIFY self.assertEqual(9, result) # add(pow(2**2), 5)
def test_pypeline__two_chained_simple_functions_kwargs_and_arg_list__expected_correctly_value( self): # FIXTURE pow = lambda x, y: math.pow(x, y) # pow take no kwarg add = lambda a, b: operator.add(a, b) # add take no kwargs pipeline = Pypeline().append(pow, 2, y=2).append(add, 5) # EXERCISE result = pipeline.do() # VERIFY self.assertEqual(9, result) # add(pow(2,y=2), 5)
#!/usr/bin/env python from pypeline import Pypeline, ProcessPypeStep, PythonPypeStep if __name__ == '__main__' : pipeline = Pypeline(log='simple_example.log', ignore_failure=True) steps = [] # step 1 - list the current directory ls_fn = 'ls_out.txt' steps.append(ProcessPypeStep('Get directory file list','ls -1d > %s'%ls_fn)) # step 2 - do a word count wc_fn = 'wc_out.txt' steps.append(ProcessPypeStep('Get wordcount','wc %s > %s'%(ls_fn,wc_fn))) # step 3 - sort the file and output steps.append(ProcessPypeStep('Sort wordcount','sort -n %s'%wc_fn)) # step 4 - cleanup files def rm_stuff() : import glob from subprocess import call txt_fns = glob.glob('*.txt') for fn in txt_fns : call('rm %s'%fn,shell=True) return True steps.append(PythonPypeStep('Cleanup',rm_stuff)) # step 5 - intentionally fail
control_fn = None if len(args) > 3 : control_fn = args[2] org_settings = get_org_settings(organism) refseq_fn = org_settings['annotation_path'] exp_fpath,exp_fname,exp_fbase,exp_fext = get_file_parts(experiment_fn) exp_wrk_dir = os.path.abspath('.exp_%s_%s'%(exp_fbase,opts.exp_name)) if control_fn : cnt_fpath,cnt_fname,cnt_fbase,cnt_fext = get_file_parts(control_fn) cnt_wrk_dir = os.path.abspath('.cnt_%s_%s'%(cnt_fbase,opts.exp_name)) # the pipeline pipeline = Pypeline() steps = [] # split up files calls = ["mkdir %s"%exp_wrk_dir, "split_file.py %s --outdir=%s %s"%(opts.split_args,exp_wrk_dir,experiment_fn),] if control_fn : calls.extend(["mkdir %s"%cnt_wrk_dir, "split_file.py %s --outdir=%s %s"%(opts.split_args,cnt_wrk_dir,control_fn), ]) steps.append(PPS('Split files',calls,env=os.environ)) # convert to BED format exp_bed_fn = "%s_exp.bed"%exp_fbase calls = ["split_qsub.py %s --ext=.bed gerald_to_bed.py --util-args=\"%s\" %s/*.[0-9][0-9][0-9][0-9]"%(opts.qsub_args,opts.bed_args,exp_wrk_dir),
org_settings = get_org_settings(organism) refgene_fn = org_settings['refgene_anno_path'] kg_ref = org_settings['known_gene_anno_path'] kg_xref = org_settings['known_gene_xref_path'] exp_fpath,exp_fname,exp_fbase,exp_fext = get_file_parts(experiment_fn) exp_wrk_dir = os.path.abspath('.exp_%s_%s'%(exp_fbase,opts.exp_name)) if control_fn : cnt_fpath,cnt_fname,cnt_fbase,cnt_fext = get_file_parts(control_fn) cnt_wrk_dir = os.path.abspath('.cnt_%s_%s'%(cnt_fbase,opts.exp_name)) # the pipeline #log_fn = os.path.join(opts.exp_name+'_pipeline.log') pipeline = Pypeline('Analysis pipeline for %s'%opts.exp_name) steps = [] #if opts.parallelize : # # split up files # calls = ["mkdir %s"%exp_wrk_dir, # "split_file.py %s --outdir=%s %s"%(opts.split_args,exp_wrk_dir,experiment_fn),] # if control_fn : # calls.extend(["mkdir %s"%cnt_wrk_dir, # "split_file.py %s --outdir=%s %s"%(opts.split_args,cnt_wrk_dir,control_fn), # ]) # steps.append(PPS('Split files',calls,env=os.environ)) ############################################################################ # run macs