-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from jeromekelleher/rejig-progress-ui
Rejig progress UI for inference
- Loading branch information
Showing
6 changed files
with
153 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ dependencies = [ | |
"scipy", | ||
"click", | ||
"zarr<2.18", | ||
"humanize", | ||
"resource", | ||
] | ||
dynamic = ["version"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
|
||
from . core import __version__ | ||
from .core import __version__ | ||
|
||
# FIXME | ||
from . core import * | ||
from . alignments import * | ||
from . metadata import * | ||
from . inference import * | ||
from .core import * | ||
from .alignments import * | ||
from .metadata import * | ||
from .inference import * | ||
from .validation import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import numpy as np | ||
|
||
import tqdm | ||
|
||
from . import alignments | ||
from . import core | ||
|
||
|
||
def _validate_samples(ts, samples, alignment_store, show_progress): | ||
strains = [ts.node(u).metadata["strain"] for u in samples] | ||
G = np.zeros((ts.num_sites, len(samples)), dtype=np.int8) | ||
keep_sites = ts.sites_position.astype(int) | ||
strains_iter = enumerate(strains) | ||
with tqdm.tqdm( | ||
strains_iter, | ||
desc="Read", | ||
total=len(strains), | ||
position=1, | ||
leave=False, | ||
disable=not show_progress, | ||
) as bar: | ||
for j, strain in bar: | ||
ma = alignments.encode_and_mask(alignment_store[strain]) | ||
G[:, j] = ma.alignment[keep_sites] | ||
|
||
vars_iter = ts.variants(samples=samples, alleles=tuple(core.ALLELES)) | ||
with tqdm.tqdm( | ||
vars_iter, | ||
desc="Check", | ||
total=ts.num_sites, | ||
position=1, | ||
leave=False, | ||
disable=not show_progress, | ||
) as bar: | ||
for var in bar: | ||
original = G[var.site.id] | ||
non_missing = original != -1 | ||
if not np.all(var.genotypes[non_missing] == original[non_missing]): | ||
raise ValueError("Data mismatch") | ||
|
||
|
||
def validate(ts, alignment_store, show_progress=False): | ||
""" | ||
Check that all the samples in the specified tree sequence are correctly | ||
representing the original alignments. | ||
""" | ||
samples = ts.samples()[1:] | ||
chunk_size = 10**3 | ||
offset = 0 | ||
num_chunks = ts.num_samples // chunk_size | ||
for chunk_index in tqdm.tqdm( | ||
range(num_chunks), position=0, disable=not show_progress | ||
): | ||
chunk = samples[offset : offset + chunk_size] | ||
offset += chunk_size | ||
_validate_samples(ts, chunk, alignment_store, show_progress) | ||
|
||
if ts.num_samples % chunk_size != 0: | ||
chunk = samples[offset:] | ||
_validate_samples(ts, chunk, alignment_store, show_progress) |