Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to insert exact matches #462

Open
jeromekelleher opened this issue Jan 15, 2025 · 0 comments
Open

Add command to insert exact matches #462

jeromekelleher opened this issue Jan 15, 2025 · 0 comments

Comments

@jeromekelleher
Copy link
Owner

We want to take the ARG and add back in the exact matches. This mostly does the job:

import pickle, bz2

mdb = sc2ts.MatchDb(...)

with mdb.conn:
    sql = f"SELECT * FROM samples WHERE hmm_cost == 0 AND match_date <= '{date}'"
    samples = []
    for row in mdb.conn.execute(sql):
        pkl = row.pop("pickle")
        sample = pickle.loads(bz2.decompress(pkl))
        samples.append(sample)

total_exact_matches = sum(ts_in.metadata["sc2ts"]["cumulative_stats"]["exact_matches"]["pango"].values())
assert total_exact_matches == len(samples)
tables = ts_in.dump_tables()

samples_strain = ts_in.metadata["sc2ts"]["samples_strain"]
L = tables.sequence_length
for sample in samples:
    sample.flags |= sc2ts.NODE_IS_EXACT_MATCH
    # FIXME - time is wrong here, will result in very long branches
    u = sc2ts.add_sample_to_tables(sample, tables)
    parent = sample.hmm_match.path[0].parent
    tables.edges.add_row(0, L, parent=parent, child=u)
    samples_strain.append(sample.strain)

md = tables.metadata
md["sc2ts"]["samples_strain"] = samples_strain
tables.metadata = md

tables.sort()
ts_out = tables.tree_sequence()
ts_out

The main thing that's wrong here is the node times for the newly inserted samples are wildly wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant