maxcombat 0.2.5__tar.gz → 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maxcombat-0.2.5/src/maxcombat.egg-info → maxcombat-0.2.6}/PKG-INFO +1 -1
- {maxcombat-0.2.5 → maxcombat-0.2.6}/pyproject.toml +1 -1
- maxcombat-0.2.6/src/maxcombat/__init__.py +7 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat/cli.py +8 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat/utils.py +24 -8
- {maxcombat-0.2.5 → maxcombat-0.2.6/src/maxcombat.egg-info}/PKG-INFO +1 -1
- {maxcombat-0.2.5 → maxcombat-0.2.6}/tests/test_cli.py +61 -0
- maxcombat-0.2.5/src/maxcombat/__init__.py +0 -3
- {maxcombat-0.2.5 → maxcombat-0.2.6}/LICENSE +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/README.md +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/setup.cfg +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat/core.py +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat.egg-info/SOURCES.txt +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat.egg-info/dependency_links.txt +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat.egg-info/entry_points.txt +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat.egg-info/requires.txt +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/src/maxcombat.egg-info/top_level.txt +0 -0
- {maxcombat-0.2.5 → maxcombat-0.2.6}/tests/test_tutorial_data.py +0 -0
|
@@ -11,6 +11,8 @@ import sys
|
|
|
11
11
|
from multiprocessing import cpu_count
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
|
+
from . import get_version
|
|
15
|
+
|
|
14
16
|
# ------------------------------------------------------------
|
|
15
17
|
# CONSTANTS
|
|
16
18
|
# ------------------------------------------------------------
|
|
@@ -24,6 +26,7 @@ DEFAULT_NJOBS = 8
|
|
|
24
26
|
|
|
25
27
|
def parse_args() -> argparse.Namespace:
|
|
26
28
|
parser = argparse.ArgumentParser(
|
|
29
|
+
prog="maxcombat",
|
|
27
30
|
description="maxcombat: scalable batch-effect correction based on reComBat"
|
|
28
31
|
)
|
|
29
32
|
parser.add_argument(
|
|
@@ -130,6 +133,11 @@ def parse_args() -> argparse.Namespace:
|
|
|
130
133
|
type=int,
|
|
131
134
|
help="Number of threads for numpy/polars. Defaults to min(8, <number of available cores>",
|
|
132
135
|
)
|
|
136
|
+
parser.add_argument(
|
|
137
|
+
"--version",
|
|
138
|
+
action="version",
|
|
139
|
+
version=f"%(prog)s {get_version()}"
|
|
140
|
+
)
|
|
133
141
|
return parser.parse_args()
|
|
134
142
|
|
|
135
143
|
|
|
@@ -97,14 +97,30 @@ def parse_config(config_file: Path | None) -> dict | None:
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
def export(df: pl.DataFrame, output_file: Path) -> None:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
"""Export a DataFrame to .csv, .tsv, or .parquet.
|
|
101
|
+
|
|
102
|
+
CSV/TSV output can be compressed by appending .gz or .zst
|
|
103
|
+
to the filename, e.g. "data.csv.gz".
|
|
104
|
+
"""
|
|
105
|
+
compression = "uncompressed"
|
|
106
|
+
extension = output_file.suffix
|
|
107
|
+
|
|
108
|
+
if extension in (".gz", ".zst"):
|
|
109
|
+
compression = "gzip" if extension == ".gz" else "zstd"
|
|
110
|
+
extension = output_file.suffixes[-2] # true extension, e.g. ".csv" in "x.csv.gz"
|
|
111
|
+
|
|
112
|
+
if extension == ".parquet":
|
|
113
|
+
if compression != "uncompressed":
|
|
114
|
+
raise ValueError("Compression is only supported for .csv and .tsv.")
|
|
106
115
|
df.write_parquet(output_file)
|
|
116
|
+
|
|
117
|
+
elif extension in (".csv", ".tsv"):
|
|
118
|
+
separator = "\t" if extension == ".tsv" else ","
|
|
119
|
+
kwargs = dict(separator=separator, include_header=True, compression=compression) # noqa C408
|
|
120
|
+
df.write_csv(output_file, **kwargs)
|
|
121
|
+
|
|
107
122
|
else:
|
|
108
123
|
raise ValueError(
|
|
109
|
-
f"Unhandled output format: {
|
|
110
|
-
|
|
124
|
+
f"Unhandled output format: {extension}. Use .csv, .tsv, or .parquet. "
|
|
125
|
+
"Compression is supported for .csv and .tsv by appending .gz or .zst."
|
|
126
|
+
)
|
|
@@ -314,3 +314,64 @@ def test_cli_no_parametric(tmp_path):
|
|
|
314
314
|
"1",
|
|
315
315
|
)
|
|
316
316
|
assert proc.returncode == 0, f"CLI failed:\n{stderr}"
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
# ----------------------------------------------------------------------
|
|
320
|
+
# Output file compression
|
|
321
|
+
# ----------------------------------------------------------------------
|
|
322
|
+
|
|
323
|
+
@pytest.mark.cli
|
|
324
|
+
def test_cli_gzipped_output_file(tmp_path):
|
|
325
|
+
"""Test CLI when asked to write gzipped output file."""
|
|
326
|
+
counts, samples = _make_counts(tmp_path)
|
|
327
|
+
design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
|
|
328
|
+
out = tmp_path / "corrected.csv.gz"
|
|
329
|
+
|
|
330
|
+
proc, _stdout, stderr = run_cli(
|
|
331
|
+
"--counts",
|
|
332
|
+
str(counts),
|
|
333
|
+
"--design",
|
|
334
|
+
str(design),
|
|
335
|
+
"--out",
|
|
336
|
+
str(out),
|
|
337
|
+
)
|
|
338
|
+
assert proc.returncode == 0, f"CLI failed:\n{stderr}"
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
@pytest.mark.cli
|
|
342
|
+
def test_cli_zstd_compressed_output_file(tmp_path):
|
|
343
|
+
"""Test CLI when asked to write zstd-compressed output file."""
|
|
344
|
+
counts, samples = _make_counts(tmp_path)
|
|
345
|
+
design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
|
|
346
|
+
out = tmp_path / "corrected.tsv.zst"
|
|
347
|
+
|
|
348
|
+
proc, _stdout, stderr = run_cli(
|
|
349
|
+
"--counts",
|
|
350
|
+
str(counts),
|
|
351
|
+
"--design",
|
|
352
|
+
str(design),
|
|
353
|
+
"--out",
|
|
354
|
+
str(out),
|
|
355
|
+
)
|
|
356
|
+
assert proc.returncode == 0, f"CLI failed:\n{stderr}"
|
|
357
|
+
|
|
358
|
+
# ----------------------------------------------------------------------
|
|
359
|
+
# Version
|
|
360
|
+
# ----------------------------------------------------------------------
|
|
361
|
+
|
|
362
|
+
@pytest.mark.cli
|
|
363
|
+
def test_version(tmp_path):
|
|
364
|
+
"""Test CLI when asked version."""
|
|
365
|
+
# setting counts and design anyway, and testing whether they are truely ignored
|
|
366
|
+
counts, samples = _make_counts(tmp_path)
|
|
367
|
+
design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
|
|
368
|
+
|
|
369
|
+
proc, stdout, _stderr = run_cli(
|
|
370
|
+
"--counts",
|
|
371
|
+
str(counts),
|
|
372
|
+
"--design",
|
|
373
|
+
str(design),
|
|
374
|
+
"--version",
|
|
375
|
+
)
|
|
376
|
+
assert proc.returncode == 0
|
|
377
|
+
assert "maxcombat" in stdout
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|