Skip to content

Commit

Permalink
Fix integration tests + return dict in _get_stats
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-pwn committed Oct 15, 2024
1 parent e2347d6 commit 94e9f90
Show file tree
Hide file tree
Showing 9 changed files with 505 additions and 556 deletions.
13 changes: 11 additions & 2 deletions metagraph/integration_tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ def setUpClass(cls):
def _get_stats(graph_path):
stats_command = METAGRAPH + ' stats ' + graph_path + ' --mmap'
res = subprocess.run(stats_command.split(), stdout=PIPE, stderr=PIPE)
assert(res.returncode == 0)
if res.returncode != 0:
raise AssertionError(f"Command '{stats_command}' failed with return code {res.returncode} and error: {res.stderr.decode()}")
stats_command = METAGRAPH + ' stats ' + graph_path + MMAP_FLAG
res = subprocess.run(stats_command.split(), stdout=PIPE, stderr=PIPE)
return res
parsed = dict()
parsed['returncode'] = res.returncode
res = res.stdout.decode().split('\n')[2:]
for line in res:
if ': ' in line:
x, y = map(str.strip, line.split(':', 1))
assert(x not in parsed or parsed[x] == y)
parsed[x] = y
return parsed

@staticmethod
def _build_graph(input, output, k, repr, mode='basic', extra_params=''):
Expand Down
108 changes: 48 additions & 60 deletions metagraph/integration_tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ def test_simple_align_all_graphs(self, representation):
k=11, repr=representation,
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16438', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16438', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align --align-only-forwards -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand Down Expand Up @@ -68,11 +67,10 @@ def test_simple_align_map_all_graphs(self, representation):
k=11, repr=representation,
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16438', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16438', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align -i {graph} --map --count-kmers {reads}'.format(
exe=METAGRAPH,
Expand All @@ -99,11 +97,10 @@ def test_simple_align_map_all_graphs_subk(self, representation):
k=11, repr=representation,
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16438', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16438', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align -i {graph} --map --count-kmers --align-length 10 {reads}'.format(
exe=METAGRAPH,
Expand Down Expand Up @@ -134,11 +131,10 @@ def test_simple_align_map_canonical_all_graphs(self, representation):
k=11, repr=representation, mode='canonical',
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 32782', params_str[1])
self.assertEqual('mode: canonical', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('32782', params['nodes (k)'])
self.assertEqual('canonical', params['mode'])

stats_command = '{exe} align -i {graph} --map --count-kmers {reads}'.format(
exe=METAGRAPH,
Expand All @@ -165,11 +161,10 @@ def test_simple_align_json_all_graphs(self, representation):
k=11, repr=representation,
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16438', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16438', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align --align-only-forwards -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand All @@ -189,11 +184,10 @@ def test_simple_align_fwd_rev_comp_all_graphs(self, representation):
k=11, repr=representation,
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16438', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16438', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand Down Expand Up @@ -222,11 +216,10 @@ def test_simple_align_canonical_all_graphs(self, representation):
k=11, repr=representation, mode='canonical',
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 32782', params_str[1])
self.assertEqual('mode: canonical', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('32782', params['nodes (k)'])
self.assertEqual('canonical', params['mode'])

stats_command = '{exe} align -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand Down Expand Up @@ -256,11 +249,10 @@ def test_simple_align_canonical_subk_succinct(self, representation):
k=11, repr=representation, mode='canonical',
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 32782', params_str[1])
self.assertEqual('mode: canonical', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('32782', params['nodes (k)'])
self.assertEqual('canonical', params['mode'])

stats_command = '{exe} align -i {graph} --align-min-exact-match 0.0 --align-min-seed-length 10 {reads}'.format(
exe=METAGRAPH,
Expand All @@ -286,11 +278,10 @@ def test_simple_align_primary_all_graphs(self, representation):
k=11, repr=representation, mode='primary',
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT.primary' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16391', params_str[1])
self.assertEqual('mode: primary', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT.primary' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16391', params['nodes (k)'])
self.assertEqual('primary', params['mode'])

stats_command = '{exe} align -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand Down Expand Up @@ -320,11 +311,10 @@ def test_simple_align_primary_subk_succinct(self, representation):
k=11, repr=representation, mode='primary',
extra_params="--mask-dummy")

res = self._get_stats(self.tempdir.name + '/genome.MT.primary' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16391', params_str[1])
self.assertEqual('mode: primary', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT.primary' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16391', params['nodes (k)'])
self.assertEqual('primary', params['mode'])

stats_command = '{exe} align -i {graph} --align-min-exact-match 0.0 --align-min-seed-length 10 {reads}'.format(
exe=METAGRAPH,
Expand All @@ -349,11 +339,10 @@ def test_simple_align_fwd_rev_comp_json_all_graphs(self, representation):
output=self.tempdir.name + '/genome.MT',
k=11, repr=representation)

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16461', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16461', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align --json -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand All @@ -375,11 +364,10 @@ def test_simple_align_edit_distance_all_graphs(self, representation):
output=self.tempdir.name + '/genome.MT',
k=11, repr=representation)

res = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
params_str = res.stdout.decode().split('\n')[2:]
self.assertEqual('k: 11', params_str[0])
self.assertEqual('nodes (k): 16461', params_str[1])
self.assertEqual('mode: basic', params_str[2])
params = self._get_stats(self.tempdir.name + '/genome.MT' + graph_file_extension[representation])
self.assertEqual('11', params['k'])
self.assertEqual('16461', params['nodes (k)'])
self.assertEqual('basic', params['mode'])

stats_command = '{exe} align --json --align-edit-distance -i {graph} --align-min-exact-match 0.0 {reads}'.format(
exe=METAGRAPH,
Expand Down
Loading

0 comments on commit 94e9f90

Please sign in to comment.