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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxcombat
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: Scalable batch-effect correction based on reComBat
5
5
  Author: Olivier Coen
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maxcombat"
7
- version = "0.2.5"
7
+ version = "0.2.6"
8
8
  description = "Scalable batch-effect correction based on reComBat"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -0,0 +1,7 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ def get_version() -> str:
4
+ try:
5
+ return version("maxcombat")
6
+ except PackageNotFoundError:
7
+ return "unknown"
@@ -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
- ext = output_file.suffix
101
- if ext == ".csv":
102
- df.write_csv(output_file, include_header=True)
103
- if ext == ".tsv":
104
- df.write_csv(output_file, separator="\t", include_header=True)
105
- elif ext == ".parquet":
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: {ext}. Use .csv, .tsv, or .parquet."
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
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxcombat
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: Scalable batch-effect correction based on reComBat
5
5
  Author: Olivier Coen
6
6
  License: MIT
@@ -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
@@ -1,3 +0,0 @@
1
- """maxcombat: scalable version of reComBat (batch effect correction)."""
2
-
3
- __version__ = "0.2.5"
File without changes
File without changes
File without changes