Skip to content

Commit cc1ac00

Browse files
committed
attempt at switch for calculating population frequencies
1 parent ba65e4f commit cc1ac00

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

tsqc/__main__.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
logger = daiquiri.getLogger("tsqc")
2222

2323

24-
def load_data(path):
24+
def load_data(path, calc_population_frequencies):
2525
logger.info(f"Loading {path}")
2626
try:
2727
ts = tskit.load(path)
28+
2829
except tskit.FileFormatError:
2930
ts = tszip.decompress(path)
3031

31-
tsm = model.TSModel(ts, path.name)
32+
tsm = model.TSModel(ts, calc_population_frequencies, path.name)
3233
return tsm
3334

3435

@@ -152,13 +153,26 @@ def setup_logging(log_level, no_log_filter):
152153
is_flag=True,
153154
help="Do not filter the output log (advanced debugging only)",
154155
)
155-
def main(path, port, show, log_level, no_log_filter, annotations_file):
156+
@click.option(
157+
"--calc-population-frequencies",
158+
default=False,
159+
help="Calculate population frequencies for sample nodes",
160+
)
161+
def main(
162+
path,
163+
port,
164+
show,
165+
log_level,
166+
no_log_filter,
167+
annotations_file,
168+
calc_population_frequencies,
169+
):
156170
"""
157171
Run the tsqc server.
158172
"""
159173
setup_logging(log_level, no_log_filter)
160174

161-
tsm = load_data(pathlib.Path(path))
175+
tsm = load_data(pathlib.Path(path), calc_population_frequencies)
162176
if annotations_file:
163177
config.ANNOTATIONS_FILE = annotations_file
164178

tsqc/model.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class TSModel:
356356
convenience methods for analysing the tree sequence.
357357
"""
358358

359-
def __init__(self, ts, name=None):
359+
def __init__(self, ts, calc_population_frequencies, name=None):
360360
self.ts = ts
361361
self.name = name
362362

@@ -366,6 +366,7 @@ def __init__(self, ts, name=None):
366366
self.nodes_num_mutations = np.bincount(
367367
self.ts.mutations_node, minlength=self.ts.num_nodes
368368
)
369+
self.calc_population_frequencies = calc_population_frequencies
369370

370371
@property
371372
def file_uuid(self):
@@ -456,7 +457,7 @@ def mutations_df(self):
456457
self.mutations_inherited_state = inherited_state
457458

458459
population_data = {}
459-
if ts.num_populations > 0:
460+
if ts.num_populations > 0 and self.calc_population_frequencies:
460461
pop_mutation_count = compute_population_mutation_counts(ts)
461462
for pop in ts.populations():
462463
name = f"pop{pop.id}"

0 commit comments

Comments
 (0)