Exemplo n.º 1
0
def convert(results, garbage):
  N = len(results.get('struct'))
  clusters = [[]] + list(results.get('clusters'))
  ntree = neutree.Neutree(
    structs = results.get('struct'),
    phis = results.get('phi'),
    counts = results.get('count'),
    logscores = results.get('llh'),
    clusterings = [clusters for idx in range(N)],
    garbage = garbage,
  )
  return ntree
Exemplo n.º 2
0
def write_neutree(results, garbage, neutree_fn):
    adjms = [R['adjm'] for R in results]
    structs = [util.convert_adjmatrix_to_parents(A) for A in adjms]
    llhs = [R['llh'] for R in results]
    clusterings = [R['clusters'] for R in results]
    phis = [R['phi'] for R in results]
    N = len(structs)
    counts = np.ones(N)
    ntree = neutree.Neutree(
        structs=structs,
        phis=phis,
        counts=counts,
        logscores=llhs,
        clusterings=clusterings,
        garbage=garbage,
    )
    neutree.save(ntree, neutree_fn)
Exemplo n.º 3
0
def convert(sampid, params_fn, trees_fn, neutree_fn):
    adjms, llhs, phis, clusterings = pastri_util.load_results(
        sampid, params_fn, trees_fn)
    if len(adjms) == 0:
        return
    structs = [util.convert_adjmatrix_to_parents(A) for A in adjms]
    N = len(structs)
    params = inputparser.load_params(params_fn)
    ntree = neutree.Neutree(
        structs=structs,
        phis=phis,
        counts=np.ones(N),
        logscores=llhs,
        clusterings=clusterings,
        garbage=params['garbage'],
    )
    neutree.save(ntree, neutree_fn)
Exemplo n.º 4
0
def convert(params_fn, calder_mats_fn, calder_trees_fn, neutree_fn):
    params = inputparser.load_params(params_fn)

    mats, row_labels, col_labels = _load_mats(calder_mats_fn)
    assert row_labels['Fhat'][0] == 'samples'
    svids = row_labels['Fhat'][1:]
    assert svids == common.sort_vids(svids)

    struct = _load_struct(svids, calder_trees_fn)
    ntree = neutree.Neutree(
        structs=[struct],
        phis=[mats['Fhat']],
        counts=np.array([1]),
        logscores=np.array([0.]),
        clusterings=[params['clusters']],
        garbage=params['garbage'],
    )
    neutree.save(ntree, neutree_fn)
Exemplo n.º 5
0
def convert_results(results, base_clusters, garbage, use_supervars):
    tidxs = sorted(results.tree_summary.keys())
    llhs = np.array([results.tree_summary[tidx]['llh'] for tidx in tidxs])
    adjms = []
    phis = []
    clusterings = []

    for idx, (tidx, mutass) in enumerate(results.load_all_mut_assignments()):
        # Ensure trees are provided in sorted order.
        assert idx == tidx
        if use_supervars:
            full_mutass = replace_supervar_with_variants(base_clusters, mutass)
        else:
            full_mutass = {cid: mutass[cid]['ssms'] for cid in mutass.keys()}
        adjm = common.convert_adjlist_to_adjmatrix(
            results.tree_summary[tidx]['structure'])
        phi = extract_phi(results.tree_summary[tidx]['populations'])
        pwgs_clusters = [
            full_mutass[cidx] if cidx in full_mutass else []
            for cidx in range(len(adjm))
        ]
        adjms.append(adjm)
        phis.append(phi)
        clusterings.append(pwgs_clusters)

    structs = [util.convert_adjmatrix_to_parents(A) for A in adjms]
    counts = np.ones(len(structs))
    ntree = neutree.Neutree(
        structs=structs,
        phis=phis,
        counts=counts,
        logscores=llhs,
        clusterings=clusterings,
        garbage=garbage,
    )
    return ntree