Skip to content

Commit 0e9f03d

Browse files
Add initialise command and test
1 parent 228b083 commit 0e9f03d

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

sc2ts/cli.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,38 @@ def add_provenance(ts, output_file):
181181
logger.info(f"Wrote {output_file}")
182182

183183

184+
@click.command()
185+
@click.argument("ts", type=click.Path(dir_okay=False))
186+
@click.argument("match_db", type=click.Path(dir_okay=False))
187+
@click.option(
188+
"--additional-problematic-sites",
189+
default=None,
190+
type=click.Path(exists=True, dir_okay=False),
191+
help="File containing the list of additional problematic sites to exclude.",
192+
)
193+
@click.option("-v", "--verbose", count=True)
194+
@click.option("-l", "--log-file", default=None, type=click.Path(dir_okay=False))
195+
def initialise(ts, match_db, additional_problematic_sites, verbose, log_file):
196+
"""
197+
Initialise a new base tree sequence to begin inference.
198+
"""
199+
setup_logging(verbose, log_file)
200+
201+
additional_problematic = []
202+
if additional_problematic_sites is not None:
203+
additional_problematic = (
204+
np.loadtxt(additional_problematic_sites).astype(int).tolist()
205+
)
206+
logger.info(
207+
f"Excluding additional {len(additional_problematic)} problematic sites"
208+
)
209+
210+
base_ts = inference.initial_ts(additional_problematic)
211+
base_ts.dump(ts)
212+
logger.info(f"New base ts at {ts}")
213+
inference.MatchDb.initialise(match_db)
214+
215+
184216
@click.command()
185217
@click.argument("alignments", type=click.Path(exists=True, dir_okay=False))
186218
@click.argument("metadata", type=click.Path(exists=True, dir_okay=False))
@@ -202,7 +234,6 @@ def add_provenance(ts, output_file):
202234
default=10,
203235
type=int,
204236
help="Minimum size of groups of reconsidered samples",
205-
show_default=True
206237
)
207238
@click.option(
208239
"--num-past-days",
@@ -477,6 +508,7 @@ def cli():
477508
cli.add_command(export_alignments)
478509
cli.add_command(export_metadata)
479510

511+
cli.add_command(initialise)
480512
cli.add_command(daily_extend)
481513
cli.add_command(validate)
482514
cli.add_command(annotate_recombinants)

sc2ts/inference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def initialise(db_path):
165165
conn.execute(
166166
"CREATE INDEX [ix_samples_match_date] on 'samples' " "([match_date]);"
167167
)
168+
logger.info(f"Created new MatchDb at {db_path}")
168169
return MatchDb(db_path)
169170

170171
def print_all(self):

tests/test_cli.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import click.testing as ct
3+
import pytest
4+
import tskit
5+
6+
import sc2ts
7+
from sc2ts import __main__ as main
8+
from sc2ts import cli
9+
10+
class TestInitialise:
11+
12+
def test_defaults(self, tmp_path):
13+
ts_path = tmp_path / "trees.ts"
14+
match_db_path = tmp_path / "match.db"
15+
runner = ct.CliRunner(mix_stderr=False)
16+
result = runner.invoke(
17+
cli.cli,
18+
f"initialise {ts_path} {match_db_path}",
19+
catch_exceptions=False,
20+
)
21+
assert result.exit_code == 0
22+
ts = tskit.load(ts_path)
23+
other_ts = sc2ts.initial_ts()
24+
other_ts.tables.assert_equals(ts.tables)
25+
match_db = sc2ts.MatchDb(match_db_path)
26+
assert len(match_db) == 0

tests/test_inference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ def test_high_recomb_mutation(self):
486486

487487

488488
class TestRealData:
489+
# def test_first_day(self, tmp_path, alignments_store, metadata_db):
489490
def test_first_day(self, tmp_path, alignments_store, metadata_db):
490491
ts = sc2ts.extend(
491492
alignment_store=alignments_store,

0 commit comments

Comments
 (0)