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 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 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, 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'