Skip to content

Commit

Permalink
CLI remove added
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Aug 3, 2022
1 parent fc067b2 commit eec62c2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sssom/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,5 +675,26 @@ def annotate(input: str, output: TextIO, replace_multivalued: bool, **kwargs):
)


@main.command()
@input_argument
@click.option(
"--remove-map",
type=click.Path(),
help="Mapping file path that needs to be removed from input.",
)
@output_option
def remove(input: str, output: TextIO, remove_map: str):
"""Remove mappings from an input mapping.
:param input: Input SSSOM tsv file.
:param output: Output path.
:param remove_map: Mapping to be removed.
"""
input_msdf = parse_sssom_table(input)
remove_msdf = parse_sssom_table(remove_map)
input_msdf.remove_mappings(remove_msdf)
write_table(input_msdf, output)


if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
partition,
ptable,
reconcile_prefixes,
remove,
sort,
split,
validate,
Expand All @@ -33,6 +34,8 @@
test_out_dir,
)

from .constants import data_dir


class SSSOMCLITestSuite(unittest.TestCase):
"""A test case for the dynamic CLI tests."""
Expand Down Expand Up @@ -64,6 +67,7 @@ def test_cli_single_input(self):
self.run_sort_rows_columns(runner, test)
self.run_filter(runner, test)
self.run_annotate(runner, test)
self.run_remove(runner, test)

self.assertTrue(len(test_cases) > 2)

Expand Down Expand Up @@ -336,3 +340,21 @@ def run_annotate(self, runner: CliRunner, test_case: SSSOMTestCase) -> Result:
)
self.run_successful(result, test_case)
return result

def run_remove(self, runner: CliRunner, test_case: SSSOMTestCase) -> Result:
"""Test removal of mappings."""
out_file = os.path.join(test_out_dir, "remove_map_test.tsv")
in_file = test_case.filepath
rm_file = os.path.join(data_dir, "basic3.tsv")
result = runner.invoke(
remove,
[
in_file,
"-o",
os.path.join(test_out_dir, out_file),
"--remove-map",
rm_file,
],
)
self.run_successful(result, test_case)
return result

0 comments on commit eec62c2

Please sign in to comment.