def run(self): exe = get_setting('CLUSTALW_PATH') tree_file = get_file('CLUSTALW_NEWTREE', None) if tree_file is None: tree_file = create_tmp() cline = ClustalwCommandline(exe, infile=self.input, newtree=tree_file) build_tree_out, build_tree_err = cline() result = { 'tree': Bio.Phylo.read(tree_file, 'newick'), 'tree_out': build_tree_out, 'tree_err': build_tree_err, } if self.only_tree: return result outfile = get_file('CLUSTALW_OUTFILE', None) if outfile is None: outfile = create_tmp() cline = ClustalwCommandline(exe, infile=self.input, outfile=outfile) ###Fix "p.checker_function = lambda x: os.path.exists" param = [i for i,p in enumerate(cline.parameters) if 'usetree' in p.names] cline.parameters[param[0]].checker_function = os.path.exists ### setattr(cline, 'usetree', tree_file) align_out, align_err = cline() result.update({ 'align_out': align_out, 'align_err': align_err, 'alignment': inout.AlignFileInput(file=outfile, format='clustal').read(), }) return result
def run_glimmer(self): input_file = create_tmp() inout.FileOutput(input_file).write(self.sequence) output_file = get_file("GLIMMER_OUTPUT", None) if output_file is None: output_file = create_tmp() exit_code = subprocess.call([get_file("GLIMMER_PATH"), input_file, self.icm_file, output_file] + self.extra) return exit_code, output_file
def summary(results): from settings import get_file from settings import get_setting data = get_setting('SUMMARY') file_path = get_file('SUMMARY_FILE') pipeline = get_setting('PIPELINE') with open(file_path,'w') as f: for number, key in data: f.write('\n==== step %d - %s (module %s) ====\n' % (number, key, pipeline[number][0])) f.write(format(results[number][key]))
def __init__(self, icm_file=None, sequence=None, extra=None, *args, **kwargs): super(Glimmer, self).__init__(*args, **kwargs) if sequence is None: sequence = inout.SingleSequenceFileInput().read() if icm_file is None: icm_file = get_file("ICM_FILE") if extra is None: extra = [] self.sequence = sequence self.icm_file = icm_file self.extra = list(extra)
def __init__(self, sequence=None, program="blastn", database="nr", queryextra={}, *args, **kwargs): super(BlastSearch, self).__init__(*args, **kwargs) if sequence is None: with open(get_file("INPUT_FILE")) as f: sequence = f.read() if isinstance(sequence, SeqRecord): sequence = sequence.seq if not isinstance(sequence, (Seq, basestring)): sequence = inout.StringOutput().write(sequence) self.sequence = sequence self.program = program self.database = database self.queryextra = queryextra
def __init__(self, file=None, *args, **kwargs): super(FileInputOutput, self).__init__(*args, **kwargs) if file is None: from settings import get_file file = get_file(self.default_file) self.file = file
def run(self): Bio.Phylo.draw_graphviz(self.tree) pylab.savefig(get_file('TREE_IMAGE')) return {}