def get_response_content(fs): headers, sequences = Phylip.decode(fs.phylip.splitlines()) if fs.name not in headers: raise ValueError('the name was not found') new_pairs = [(h, s) for h, s in zip(headers, sequences) if h != fs.name] new_headers, new_sequences = zip(*new_pairs) return Phylip.encode(new_headers, new_sequences) + '\n'
def process(fs, raw_lines): headers, sequences = Phylip.decode(raw_lines) binary_rows = Carbone.get_binary_rows(sequences) if fs.hud: return hud.encode(headers, binary_rows) + '\n' elif fs.phy: binary_seqs = [''.join(str(x) for x in row) for row in binary_rows] return Phylip.encode(headers, binary_seqs) + '\n'
def run_in_tmp(fs, nexus): """ @param fs: fieldstorage-like user options @param nexus: the nexus object that defines the tree and alignment @return: from_paml """ # create the control object config = Paml.PamlConfig() config.set_hky() # create the baseml.ctl control file ctl_string = config.to_ctl_string() with open(Paml.baseml_ctl, 'wt') as fout: print >> fout, ctl_string # create the nexus object that defines the tree and alignment nexus = Nexus.get_sample_nexus_object() # create the baseml.newick tree file with open(Paml.baseml_newick, 'wt') as fout: print >> fout, nexus.tree.get_newick_string() # create the baseml.phylip alignment file s_phylip = Phylip.get_alignment_string_non_interleaved(nexus.alignment) with open(Paml.baseml_phylip, 'wt') as fout: print >> fout, s_phylip # run PAML args = [Config.baseml_exe_path, Paml.baseml_ctl] from_paml, to_paml = popen2.popen4(args) return from_paml
def run_hky(tree, alignment): """ @param tree: a tree object @param alignment: an alignment object @return: messages from the program but not the results """ # create the baseml.ctl control file config = PamlConfig() config.set_hky() config.to_ctl_string() with open(baseml_ctl, 'wt') as fout: print >> fout, config.to_ctl_string() # create the nexus object that defines the tree and alignment nexus = Nexus.get_sample_nexus_object() # create the baseml.newick tree file with open(baseml_newick, 'wt') as fout: print >> fout, nexus.tree.get_newick_string() # create the baseml.phylip alignment file phylip_string = Phylip.get_alignment_string_non_interleaved( nexus.alignment) with open(baseml_phylip, 'wt') as fout: print >> fout, phylip_string # change the current directory to the data directory with Util.remember_cwd(): os.chdir(Config.data_path) # run PAML exe_path = Config.baseml_exe_path ctl_path = baseml_ctl #cmd = '%s %s > /dev/null' % (exe_path, ctl_path) #os.system(cmd) from_paml, to_paml = popen2.popen4([exe_path, ctl_path]) #p = subprocess.Popen([cmd, arg], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) # change back to the old directory return from_paml.read()
def run_hky(tree, alignment): """ @param tree: a tree object @param alignment: an alignment object @return: messages from the program but not the results """ # create the baseml.ctl control file config = PamlConfig() config.set_hky() config.to_ctl_string() with open(baseml_ctl, "wt") as fout: print >> fout, config.to_ctl_string() # create the nexus object that defines the tree and alignment nexus = Nexus.get_sample_nexus_object() # create the baseml.newick tree file with open(baseml_newick, "wt") as fout: print >> fout, nexus.tree.get_newick_string() # create the baseml.phylip alignment file phylip_string = Phylip.get_alignment_string_non_interleaved(nexus.alignment) with open(baseml_phylip, "wt") as fout: print >> fout, phylip_string # change the current directory to the data directory with Util.remember_cwd(): os.chdir(Config.data_path) # run PAML exe_path = Config.baseml_exe_path ctl_path = baseml_ctl # cmd = '%s %s > /dev/null' % (exe_path, ctl_path) # os.system(cmd) from_paml, to_paml = popen2.popen4([exe_path, ctl_path]) # p = subprocess.Popen([cmd, arg], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) # change back to the old directory return from_paml.read()
def get_response_content(fs): headers, sequences = Phylip.decode(fs.phylip.splitlines()) phylip_columns = zip(*sequences) counts = [len(set(col)) for col in phylip_columns] header_low_high = [] k = 0 if fs.from_zero else 1 for i, count in enumerate(counts): if not (count == 1 and fs.remove): low = k high = k + (count - 1) header_low_high.append((i+(1 if fs.from_one else 0), low, high)) k += count out = StringIO() for triple in header_low_high: print >> out, 'locus%s.phy\t%d-%d' % triple return out.getvalue()
def get_response_content(fs): # get the combo info combo_triples = list(gen_combo_line_triples(fs.combo.splitlines())) names, lows, highs = zip(*combo_triples) ranges = zip(lows, highs) if lows[0] != 1: raise ValueError('expected the first lower bound to be 1') for (low, high), (nlow, nhigh) in iterutils.pairwise(ranges): if high + 1 != nlow: raise ValueError( 'expected the next lower bound ' 'to be one more than the current upper bound') # get the phylip info headers, sequences = Phylip.decode(fs.phylip.splitlines()) phylip_columns = zip(*sequences) counts = [len(set(col)) for col in phylip_columns] # validate the compatibility between the combo and phylip data if highs[-1] != len(phylip_columns): raise ValueError( 'expected the last upper bound to be ' 'equal to the number of columns of the phylip alignment') # get the sum of counts in each combination group combo_counts = [] for i, (low, high) in enumerate(ranges): combo_count = 0 # note that low and high are 1-based and inclusive for j in range(low-1, high): combo_count += counts[j] combo_counts.append(combo_count) # write the new combo log out = StringIO() print >> out, 'Loci combined' print >> out k = 0 for name, count in zip(names, combo_counts): low = k + 1 high = k + count print >> out, '%s\t%d-%d' % (name, low, high) k += count return out.getvalue()
def get_response_content(fs): headers, sequences = Phylip.decode(fs.phylip.splitlines()) new_pairs = sorted(zip(headers, sequences)) new_headers, new_sequences = zip(*new_pairs) return Phylip.encode(new_headers, new_sequences) + '\n'
def get_response_content(fs): headers, data_rows = hud.decode(fs.table.splitlines()) sequences = [''.join(str(x) for x in row) for row in data_rows] return Phylip.encode(headers, sequences)