Skip to content

Commit

Permalink
feat: improve dump cli
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Aug 4, 2024
1 parent 4b041d2 commit eeba313
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/source/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
CLI
====

.. click:: momics.cli.dump:dump
:prog: momics dump
:show-nested:

1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx_click.ext",
"recommonmark",
]

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ docs = [
"recommonmark",
"Sphinx>=1.6",
"sphinx-autobuild",
"sphinx-click",
"furo",
]

Expand Down
26 changes: 16 additions & 10 deletions src/momics/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,31 @@ def add_chroms(self, chr_lengths: dict, genome_version: str = ""):
array.meta["genome_assembly_version"] = genome_version
array.meta["timestamp"] = datetime.now().isoformat()

def __init__(self, path: str):
def __init__(self, path: str, create=True):
"""
Initialize the Momics class.
Parameters
----------
path : str
Path to a `.momics` repository.
create : bool
If not found, should the repository be initiated?
"""

self.path = path
genome_path = os.path.join(path, "genome")
seq_path = os.path.join(path, "genome", "sequence")
coverage_path = os.path.join(path, "coverage")
features_path = os.path.join(path, "features")

if not os.path.exists(path):
tiledb.group_create(path)
tiledb.group_create(genome_path)
tiledb.group_create(coverage_path)
tiledb.group_create(features_path)
tiledb.group_create(seq_path)
if create:
genome_path = os.path.join(path, "genome")
seq_path = os.path.join(path, "genome", "sequence")
coverage_path = os.path.join(path, "coverage")
features_path = os.path.join(path, "features")
tiledb.group_create(path)
tiledb.group_create(genome_path)
tiledb.group_create(coverage_path)
tiledb.group_create(features_path)
tiledb.group_create(seq_path)
else:
raise OSError("`momics repository not found.")
6 changes: 3 additions & 3 deletions src/momics/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
@click.option(
"--table",
"-t",
help="Which table to dump.",
help="Which supporting table to dump.",
type=click.Choice(["chroms", "tracks"]),
default="chroms",
show_default=True,
)
def dump(momics, table):
if table == "tracks":
print(api.Momics(momics).tracks())
print(api.Momics(momics, create=False).tracks())
if table == "chroms":
print(api.Momics(momics).chroms())
print(api.Momics(momics, create=False).chroms())

0 comments on commit eeba313

Please sign in to comment.