def process(args, raw_hud_lines): """ @param args: user options from the web or cmdline @param hud_lines: raw lines of a .hud file @return: results in convenient text form """ out = StringIO() names, data = hud.decode(raw_hud_lines) # normalize the names of the isolates if args.clean_isolates: names = [Carbone.clean_isolate_element(x) for x in names] # get the pcs C_full = np.array(data, dtype=float) pcs = eigenpop.get_scaled_eigenvectors(C_full, args.diploid_and_biallelic) # check for sufficient number of eigenvectors if len(pcs) < args.npcs: msg_a = 'the number of requested principal components ' msg_b = 'must be no more than the number of OTUs' raise ValueError(msg_a + msg_b) # create the R frame headers = ['otu'] + ['pc%d' % (i+1) for i in range(args.npcs)] print >> out, '\t'.join(headers) for i, name in enumerate(names): typed_row = [name] + [pcs[j][i] for j in range(args.npcs)] if args.add_indices: typed_row = [i+1] + typed_row row = [str(x) for x in typed_row] print >> out, '\t'.join(row) return out.getvalue()
def process(args, raw_hud_lines): """ @param args: user options from the web or cmdline @param hud_lines: raw lines of a .hud file @return: results in convenient text form """ out = StringIO() names, data = hud.decode(raw_hud_lines) # normalize the names of the isolates if args.clean_isolates: names = [Carbone.clean_isolate_element(x) for x in names] # get the pcs C_full = np.array(data, dtype=float) pcs = eigenpop.get_scaled_eigenvectors(C_full, args.diploid_and_biallelic) # check for sufficient number of eigenvectors if len(pcs) < args.npcs: msg_a = 'the number of requested principal components ' msg_b = 'must be no more than the number of OTUs' raise ValueError(msg_a + msg_b) # create the R frame headers = ['otu'] + ['pc%d' % (i + 1) for i in range(args.npcs)] print >> out, '\t'.join(headers) for i, name in enumerate(names): typed_row = [name] + [pcs[j][i] for j in range(args.npcs)] if args.add_indices: typed_row = [i + 1] + typed_row row = [str(x) for x in typed_row] print >> out, '\t'.join(row) return out.getvalue()