maxcombat 0.1.2__tar.gz → 0.1.4__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.

Potentially problematic release.


This version of maxcombat might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxcombat
3
- Version: 0.1.2
4
- Summary: Scalable batch-effect correction largely based on reComBat
3
+ Version: 0.1.4
4
+ Summary: Scalable batch-effect correction based on reComBat
5
5
  Author: Olivier Coen
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/OlivierCoen/maxcombat
@@ -9,7 +9,12 @@ Project-URL: Repository, https://github.com/OlivierCoen/maxcombat
9
9
  Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
13
18
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
19
  Requires-Python: >=3.10
15
20
  Description-Content-Type: text/markdown
@@ -26,13 +31,20 @@ Dynamic: license-file
26
31
 
27
32
  # maxcombat
28
33
 
29
- [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/)
30
- [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)]()
34
+ | | |
35
+ | --- | --- |
36
+ | Testing | [![CI - Test](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml/badge.svg)](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml)
37
+ | Package | [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/) [![PyPI Latest Release](https://img.shields.io/pypi/v/maxcombat.svg)](https://pypi.org/project/maxcombat/) [![Bioconda Latest Release](https://anaconda.org/bioconda/maxcombat/badges/version.svg)](https://anaconda.org/bioconda/maxcombat/) [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)](https://img.shields.io/pypi/pyversions/maxcombat)
31
38
 
32
- Scalable batch-effect correction largely based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
39
+
40
+ Scalable batch-effect correction based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
33
41
 
34
42
  This package is meant as a drop-in replacement for `reComBat`, whenever users need a high level of scalability.
35
43
 
44
+ ## Citation
45
+
46
+ If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
47
+
36
48
  ## Features
37
49
 
38
50
  - NumPy-only: no pandas dependency, arrays in, arrays out
@@ -58,23 +70,22 @@ conda install -c bioconda maxcombat
58
70
 
59
71
 
60
72
  ```python
61
- import numpy as np
62
- from maxcombat import ReComBat
73
+ from maxcombat import MaxCombat
63
74
 
64
75
  data = ... # (n_genes, n_samples) array
65
76
  batches = ... # (n_samples,) array of batch labels
66
77
 
67
- model = ReComBat(model="elastic_net")
78
+ model = MaxCombat() # default model: elastic_net
68
79
  corrected = model.fit_transform(data, batches)
69
80
  ```
70
81
 
71
82
  Optional: with covariates and a reference batch:
72
83
  ```python
73
- X = ... # (n_samples, k) covariates of desired variation, already encoded
74
- C = ... # (n_samples, k) covariates of unwanted variation, already encoded
84
+ x_covariates = ... # (n_samples, k) covariates of desired variation, already encoded
85
+ c_covariates = ... # (n_samples, k) covariates of unwanted variation, already encoded
75
86
 
76
- model = ReComBat(model="elastic_net", reference_batch="batch_1")
77
- corrected = model.fit_transform(data, batches, X=X, C=C)
87
+ model = MaxCombat(model="elastic_net", reference_batch="batch_1")
88
+ corrected = model.fit_transform(data, batches, X=x_covariates, C=c_covariates)
78
89
  ```
79
90
 
80
91
  Categorical covariates must be one-hot encoded beforehand
@@ -83,7 +94,7 @@ covariates are passed as is.
83
94
 
84
95
  Non-parametric empirical Bayes (leave-one-out, more expensive):
85
96
  ```python
86
- model = ReComBat(parametric=False, model="linear", n_jobs=8)
97
+ model = MaxCombat(parametric=False, model="linear", n_jobs=8)
87
98
  ```
88
99
 
89
100
  ### From the command line
@@ -124,18 +135,12 @@ maxcombat \
124
135
 
125
136
  `--no-optimize-params` (optional): skip the empirical Bayes optimization.
126
137
 
127
- `--cpus` : parallelism for the numerical backends / joblib.
138
+ `--cpus` : parallelism for the numerical backends / joblib (controls the `n_jobs` argument in `MaxCombat`)
128
139
 
129
140
  `--clip-negative-values` (optional): clip negative values to 0 after correction (useful for specific downstream analyses requiring only positive values)
130
141
 
131
142
  `--out-f32` (optional): convert corrected data to float32 before export
132
143
 
133
-
134
- ## Citation
135
-
136
- If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
137
-
138
144
  ## License
139
145
 
140
- MIT. This package incorporates code from reComBat (BSD-3-Clause),
141
- see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
146
+ MIT (see [LICENSE](LICENSE)). This package incorporates code from reComBat (BSD-3-Clause), see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -1,12 +1,19 @@
1
1
  # maxcombat
2
2
 
3
- [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/)
4
- [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)]()
3
+ | | |
4
+ | --- | --- |
5
+ | Testing | [![CI - Test](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml/badge.svg)](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml)
6
+ | Package | [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/) [![PyPI Latest Release](https://img.shields.io/pypi/v/maxcombat.svg)](https://pypi.org/project/maxcombat/) [![Bioconda Latest Release](https://anaconda.org/bioconda/maxcombat/badges/version.svg)](https://anaconda.org/bioconda/maxcombat/) [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)](https://img.shields.io/pypi/pyversions/maxcombat)
5
7
 
6
- Scalable batch-effect correction largely based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
8
+
9
+ Scalable batch-effect correction based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
7
10
 
8
11
  This package is meant as a drop-in replacement for `reComBat`, whenever users need a high level of scalability.
9
12
 
13
+ ## Citation
14
+
15
+ If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
16
+
10
17
  ## Features
11
18
 
12
19
  - NumPy-only: no pandas dependency, arrays in, arrays out
@@ -32,23 +39,22 @@ conda install -c bioconda maxcombat
32
39
 
33
40
 
34
41
  ```python
35
- import numpy as np
36
- from maxcombat import ReComBat
42
+ from maxcombat import MaxCombat
37
43
 
38
44
  data = ... # (n_genes, n_samples) array
39
45
  batches = ... # (n_samples,) array of batch labels
40
46
 
41
- model = ReComBat(model="elastic_net")
47
+ model = MaxCombat() # default model: elastic_net
42
48
  corrected = model.fit_transform(data, batches)
43
49
  ```
44
50
 
45
51
  Optional: with covariates and a reference batch:
46
52
  ```python
47
- X = ... # (n_samples, k) covariates of desired variation, already encoded
48
- C = ... # (n_samples, k) covariates of unwanted variation, already encoded
53
+ x_covariates = ... # (n_samples, k) covariates of desired variation, already encoded
54
+ c_covariates = ... # (n_samples, k) covariates of unwanted variation, already encoded
49
55
 
50
- model = ReComBat(model="elastic_net", reference_batch="batch_1")
51
- corrected = model.fit_transform(data, batches, X=X, C=C)
56
+ model = MaxCombat(model="elastic_net", reference_batch="batch_1")
57
+ corrected = model.fit_transform(data, batches, X=x_covariates, C=c_covariates)
52
58
  ```
53
59
 
54
60
  Categorical covariates must be one-hot encoded beforehand
@@ -57,7 +63,7 @@ covariates are passed as is.
57
63
 
58
64
  Non-parametric empirical Bayes (leave-one-out, more expensive):
59
65
  ```python
60
- model = ReComBat(parametric=False, model="linear", n_jobs=8)
66
+ model = MaxCombat(parametric=False, model="linear", n_jobs=8)
61
67
  ```
62
68
 
63
69
  ### From the command line
@@ -98,18 +104,12 @@ maxcombat \
98
104
 
99
105
  `--no-optimize-params` (optional): skip the empirical Bayes optimization.
100
106
 
101
- `--cpus` : parallelism for the numerical backends / joblib.
107
+ `--cpus` : parallelism for the numerical backends / joblib (controls the `n_jobs` argument in `MaxCombat`)
102
108
 
103
109
  `--clip-negative-values` (optional): clip negative values to 0 after correction (useful for specific downstream analyses requiring only positive values)
104
110
 
105
111
  `--out-f32` (optional): convert corrected data to float32 before export
106
112
 
107
-
108
- ## Citation
109
-
110
- If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
111
-
112
113
  ## License
113
114
 
114
- MIT. This package incorporates code from reComBat (BSD-3-Clause),
115
- see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
115
+ MIT (see [LICENSE](LICENSE)). This package incorporates code from reComBat (BSD-3-Clause), see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maxcombat"
7
- version = "0.1.2"
8
- description = "Scalable batch-effect correction largely based on reComBat"
7
+ version = "0.1.4"
8
+ description = "Scalable batch-effect correction based on reComBat"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
11
11
  authors = [{ name = "Olivier Coen" }]
@@ -14,7 +14,12 @@ classifiers = [
14
14
  "Development Status :: 4 - Beta",
15
15
  "Intended Audience :: Science/Research",
16
16
  "License :: OSI Approved :: MIT License",
17
- "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
18
23
  "Topic :: Scientific/Engineering :: Bio-Informatics",
19
24
  ]
20
25
  dependencies = [
@@ -37,3 +42,13 @@ Repository = "https://github.com/OlivierCoen/maxcombat"
37
42
 
38
43
  [tool.setuptools.packages.find]
39
44
  where = ["src"]
45
+ include = ["maxcombat*"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = [
49
+ "tests",
50
+ ]
51
+ markers = [
52
+ "cli: cli tests, used in bioconda CI",
53
+ "tutorial: tests aiming at reproducing results from the original reComBat, using tutorial data"
54
+ ]
@@ -1,3 +1,3 @@
1
1
  """maxcombat: scalable version of reComBat (batch effect correction)."""
2
2
 
3
- __version__ = "0.1.0"
3
+ __version__ = "0.1.4"
@@ -7,6 +7,7 @@ from __future__ import annotations
7
7
 
8
8
  import argparse
9
9
  import logging
10
+ import sys
10
11
  import os
11
12
  from multiprocessing import cpu_count
12
13
  from pathlib import Path
@@ -22,7 +23,7 @@ DEFAULT_NJOBS = 8
22
23
  # --------------------------------------------------------------
23
24
 
24
25
  def parse_args() -> argparse.Namespace:
25
- parser = argparse.ArgumentParser(description="maxcombat: scalable batch-effect correction largely based on reComBat")
26
+ parser = argparse.ArgumentParser(description="maxcombat: scalable batch-effect correction based on reComBat")
26
27
  parser.add_argument(
27
28
  "--counts", type=Path, dest="count_file", required=True,
28
29
  help="Parquet gathering all count data (genes as rows, samples as columns)"
@@ -80,7 +81,7 @@ def parse_args() -> argparse.Namespace:
80
81
  help="CSV with a 'sample' column plus covariates of unwanted variation (e.g. RIN, sex). Categorical columns are one-hot encoded (first level dropped)",
81
82
  )
82
83
  parser.add_argument(
83
- "--out-f32", dest="cast_output_to_float32",
84
+ "--out-f32", action="store_true", dest="cast_output_to_float32",
84
85
  help="Cast corrected data to float32 before export to save memory",
85
86
  )
86
87
  parser.add_argument(
@@ -110,10 +111,9 @@ os.environ.update({
110
111
  "POLARS_MAX_THREADS": str(n_cpus),
111
112
  })
112
113
 
113
- import numpy as np # noqa: E402
114
114
  import polars as pl # noqa: E402
115
115
 
116
- from maxcombat.core import ReComBat # noqa: E402
116
+ from maxcombat.core import MaxCombat, SingleBatchException # noqa: E402
117
117
  from maxcombat.utils import parse_table, build_covariates, parse_config, export
118
118
 
119
119
 
@@ -124,7 +124,11 @@ from maxcombat.utils import parse_table, build_covariates, parse_config, export
124
124
  def main() -> None:
125
125
 
126
126
 
127
- logging.basicConfig(level=logging.INFO, format="[%(levelname)s] %(message)s")
127
+ logging.basicConfig(
128
+ level=logging.INFO,
129
+ stream=sys.stdout,
130
+ format="[%(levelname)s] %(message)s"
131
+ )
128
132
  logger = logging.getLogger("maxcombat-cli")
129
133
 
130
134
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -154,24 +158,20 @@ def main() -> None:
154
158
  # BATCH CORRECTION
155
159
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156
160
 
157
- if np.unique(batches).size == 1:
158
- logger.info("Only one batch found. Skipping batch correction.")
159
- corrected = data
160
-
161
- else:
162
- model = ReComBat(
163
- parametric=args.parametric, # False if --no-parametric is provided
164
- model=args.model,
165
- config=parse_config(args.config_file),
166
- conv_criterion=args.conv_criterion,
167
- max_iter=args.max_iter,
168
- mean_only=args.mean_only,
169
- optimize_params=args.optimize_params,
170
- reference_batch=args.reference_batch,
171
- clip_negative_values=args.clip_negative_values,
172
- n_jobs=n_cpus
173
- )
174
-
161
+ model = MaxCombat(
162
+ parametric=args.parametric, # False if --no-parametric is provided
163
+ model=args.model,
164
+ config=parse_config(args.config_file),
165
+ conv_criterion=args.conv_criterion,
166
+ max_iter=args.max_iter,
167
+ mean_only=args.mean_only,
168
+ optimize_params=args.optimize_params,
169
+ reference_batch=args.reference_batch,
170
+ clip_negative_values=args.clip_negative_values,
171
+ n_jobs=n_cpus
172
+ )
173
+
174
+ try:
175
175
  corrected = model.fit_transform(
176
176
  data,
177
177
  batches,
@@ -179,13 +179,16 @@ def main() -> None:
179
179
  C=c_covariates,
180
180
  sample_names=samples
181
181
  ) # (n_genes, n_samples)
182
-
183
182
  # update new samples, removing orphans that were dropped
184
183
  samples = [s for s, k in zip(samples, model.keep_mask_) if k]
185
- assert corrected.shape[1] == len(samples)
186
-
187
- # post-processing (clipping negative values if needed)
188
- corrected = model.post_process(corrected)
184
+ except SingleBatchException:
185
+ logger.warning("Only one batch was found. No correction will be performed.")
186
+ corrected = data
187
+
188
+ assert corrected.shape[1] == len(samples)
189
+
190
+ # post-processing (clipping negative values if needed)
191
+ corrected = model.post_process(corrected)
189
192
 
190
193
  # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
194
  # POSTPROCESSING AND EXPORT
@@ -72,7 +72,11 @@ DEFAULT_CONFIG = {
72
72
  DEFAULT_NJOBS = 8
73
73
 
74
74
 
75
- class ReComBat:
75
+ class SingleBatchException(Exception):
76
+ pass
77
+
78
+
79
+ class MaxCombat:
76
80
  """Regularised ComBat batch-effect corrector.
77
81
 
78
82
  Parameters
@@ -140,7 +144,7 @@ class ReComBat:
140
144
  X: Array | None = None,
141
145
  C: Array | None = None,
142
146
  sample_names: npt.NDArray[Any] | list | None = None,
143
- ) -> "ReComBat":
147
+ ) -> "MaxCombat":
144
148
  """Fit maxcombat.
145
149
 
146
150
  Samples that are alone in their batch (orphans) are dropped
@@ -163,7 +167,7 @@ class ReComBat:
163
167
  orphans = find_orphan_samples(batches)
164
168
  keep = np.ones(batches.shape[0], dtype=bool)
165
169
  keep[orphans] = False
166
-
170
+
167
171
  if orphans.size:
168
172
  for idx in orphans:
169
173
  name = sample_names[idx] if sample_names is not None else f"#{idx}"
@@ -313,7 +317,7 @@ class ReComBat:
313
317
  raise ValueError(f"The design matrix {name} contains NaN values.")
314
318
  data_sxg = data.T # (n_samples, n_genes)
315
319
  if np.unique(batches).size < 2:
316
- raise ValueError("There should be at least two batches in the dataset.")
320
+ raise SingleBatchException("There should be at least two batches in the dataset.")
317
321
  return data_sxg
318
322
 
319
323
  @staticmethod
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxcombat
3
- Version: 0.1.2
4
- Summary: Scalable batch-effect correction largely based on reComBat
3
+ Version: 0.1.4
4
+ Summary: Scalable batch-effect correction based on reComBat
5
5
  Author: Olivier Coen
6
6
  License: MIT
7
7
  Project-URL: Homepage, https://github.com/OlivierCoen/maxcombat
@@ -9,7 +9,12 @@ Project-URL: Repository, https://github.com/OlivierCoen/maxcombat
9
9
  Classifier: Development Status :: 4 - Beta
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
13
18
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
19
  Requires-Python: >=3.10
15
20
  Description-Content-Type: text/markdown
@@ -26,13 +31,20 @@ Dynamic: license-file
26
31
 
27
32
  # maxcombat
28
33
 
29
- [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/)
30
- [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)]()
34
+ | | |
35
+ | --- | --- |
36
+ | Testing | [![CI - Test](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml/badge.svg)](https://github.com/OlivierCoen/maxcombat/actions/workflows/ci.yml)
37
+ | Package | [![Version](https://img.shields.io/pypi/v/recombat)](https://pypi.org/project/maxcombat/) [![PyPI Latest Release](https://img.shields.io/pypi/v/maxcombat.svg)](https://pypi.org/project/maxcombat/) [![Bioconda Latest Release](https://anaconda.org/bioconda/maxcombat/badges/version.svg)](https://anaconda.org/bioconda/maxcombat/) [![PythonVersion](https://img.shields.io/pypi/pyversions/maxcombat)](https://img.shields.io/pypi/pyversions/maxcombat)
31
38
 
32
- Scalable batch-effect correction largely based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
39
+
40
+ Scalable batch-effect correction based on [reComBat](https://github.com/BorgwardtLab/reComBat) (Michael F. Adamer, BSD-3-Clause).
33
41
 
34
42
  This package is meant as a drop-in replacement for `reComBat`, whenever users need a high level of scalability.
35
43
 
44
+ ## Citation
45
+
46
+ If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
47
+
36
48
  ## Features
37
49
 
38
50
  - NumPy-only: no pandas dependency, arrays in, arrays out
@@ -58,23 +70,22 @@ conda install -c bioconda maxcombat
58
70
 
59
71
 
60
72
  ```python
61
- import numpy as np
62
- from maxcombat import ReComBat
73
+ from maxcombat import MaxCombat
63
74
 
64
75
  data = ... # (n_genes, n_samples) array
65
76
  batches = ... # (n_samples,) array of batch labels
66
77
 
67
- model = ReComBat(model="elastic_net")
78
+ model = MaxCombat() # default model: elastic_net
68
79
  corrected = model.fit_transform(data, batches)
69
80
  ```
70
81
 
71
82
  Optional: with covariates and a reference batch:
72
83
  ```python
73
- X = ... # (n_samples, k) covariates of desired variation, already encoded
74
- C = ... # (n_samples, k) covariates of unwanted variation, already encoded
84
+ x_covariates = ... # (n_samples, k) covariates of desired variation, already encoded
85
+ c_covariates = ... # (n_samples, k) covariates of unwanted variation, already encoded
75
86
 
76
- model = ReComBat(model="elastic_net", reference_batch="batch_1")
77
- corrected = model.fit_transform(data, batches, X=X, C=C)
87
+ model = MaxCombat(model="elastic_net", reference_batch="batch_1")
88
+ corrected = model.fit_transform(data, batches, X=x_covariates, C=c_covariates)
78
89
  ```
79
90
 
80
91
  Categorical covariates must be one-hot encoded beforehand
@@ -83,7 +94,7 @@ covariates are passed as is.
83
94
 
84
95
  Non-parametric empirical Bayes (leave-one-out, more expensive):
85
96
  ```python
86
- model = ReComBat(parametric=False, model="linear", n_jobs=8)
97
+ model = MaxCombat(parametric=False, model="linear", n_jobs=8)
87
98
  ```
88
99
 
89
100
  ### From the command line
@@ -124,18 +135,12 @@ maxcombat \
124
135
 
125
136
  `--no-optimize-params` (optional): skip the empirical Bayes optimization.
126
137
 
127
- `--cpus` : parallelism for the numerical backends / joblib.
138
+ `--cpus` : parallelism for the numerical backends / joblib (controls the `n_jobs` argument in `MaxCombat`)
128
139
 
129
140
  `--clip-negative-values` (optional): clip negative values to 0 after correction (useful for specific downstream analyses requiring only positive values)
130
141
 
131
142
  `--out-f32` (optional): convert corrected data to float32 before export
132
143
 
133
-
134
- ## Citation
135
-
136
- If you use `maxcombat` for your analysis, please cite [the original reComBat paper](https://academic.oup.com/bioinformaticsadvances/article/2/1/vbac071/6728137?login=false).
137
-
138
144
  ## License
139
145
 
140
- MIT. This package incorporates code from reComBat (BSD-3-Clause),
141
- see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
146
+ MIT (see [LICENSE](LICENSE)). This package incorporates code from reComBat (BSD-3-Clause), see [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
@@ -8,8 +8,8 @@ All input files are synthetic and written to tmp_path.
8
8
  from __future__ import annotations
9
9
 
10
10
  import json
11
+ import pytest
11
12
  import subprocess
12
- import sys
13
13
  from pathlib import Path
14
14
 
15
15
  import numpy as np
@@ -61,7 +61,7 @@ DEFAULT_BATCHES = {f"S{i:02d}": "batch1" for i in range(5)} | {
61
61
  # Nominal case
62
62
  # ----------------------------------------------------------------------
63
63
 
64
-
64
+ @pytest.mark.cli
65
65
  def test_cli_nominal_run(tmp_path):
66
66
  """A normal invocation corrects the data, drops the orphan sample and
67
67
  writes both the Parquet output and the sidecar count files."""
@@ -95,11 +95,48 @@ def test_cli_nominal_run(tmp_path):
95
95
  assert (values >= 0).all() # --clip-negative-values
96
96
 
97
97
 
98
+ @pytest.mark.cli
99
+ def test_cli_custom_config(tmp_path):
100
+ """A normal invocation corrects the data, drops the orphan sample and
101
+ writes both the Parquet output and the sidecar count files."""
102
+ counts, samples = _make_counts(tmp_path)
103
+ design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
104
+ out = tmp_path / "test.corrected.parquet"
105
+ config = tmp_path / "config.json"
106
+ config.write_text(json.dumps({"alpha": 1e-10, "l1_ratio": 0.1, "tol": 0.5}))
107
+
108
+ proc, _stdout, stderr = run_cli(
109
+ "--counts", str(counts),
110
+ "--design", str(design),
111
+ "--gene-id-colname", "gene_id",
112
+ "--config", str(config),
113
+ "--out", str(out),
114
+ )
115
+
116
+ assert proc.returncode == 0, f"CLI failed:\n{stderr}"
117
+ assert out.exists()
118
+
98
119
  # ----------------------------------------------------------------------
99
- # Error cases
120
+ # Orphan samples + errors
100
121
  # ----------------------------------------------------------------------
101
122
 
123
+ @pytest.mark.cli
124
+ def test_cli_two_batches_with_one_orphan_sample(tmp_path):
125
+ """Twot batches, including one with only one sample."""
126
+ counts, samples = _make_counts(tmp_path, n_samples=4)
127
+ batches = {"S00": "batch1", "S01": "batch1", "S02": "batch1", "S03": "lonely"}
128
+ design = _make_design(tmp_path, samples, batches)
129
+ out = tmp_path / "corrected.parquet"
130
+
131
+ proc, _stdout, stderr = run_cli(
132
+ "--counts", str(counts),
133
+ "--design", str(design),
134
+ "--out", str(out)
135
+ )
136
+ assert proc.returncode == 0, f"CLI failed:\n{stderr}"
137
+
102
138
 
139
+ @pytest.mark.cli
103
140
  def test_cli_missing_sample_in_design_fails(tmp_path):
104
141
  """A sample present in the counts but absent from the design must abort
105
142
  with a clear message and a non-zero exit code, without writing output."""
@@ -108,22 +145,29 @@ def test_cli_missing_sample_in_design_fails(tmp_path):
108
145
  out = tmp_path / "out.parquet"
109
146
 
110
147
  proc, _stdout, stderr = run_cli(
111
- "--counts", str(counts), "--design", str(design), "--out", str(out),
148
+ "--counts", str(counts),
149
+ "--design", str(design),
150
+ "--out", str(out),
151
+ "--optimize-params",
152
+ "--mean-only"
112
153
  )
113
154
  assert proc.returncode != 0
114
155
  assert "data has a different number of samples than batches" in stderr
115
156
  assert not out.exists()
116
157
 
117
158
 
159
+ @pytest.mark.cli
118
160
  def test_cli_invalid_model_rejected_by_argparse(tmp_path):
119
161
  """An unknown --model value is rejected by argparse with exit code 2."""
120
162
  counts, samples = _make_counts(tmp_path)
121
163
  design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
164
+ out = tmp_path / "corrected.csv"
122
165
 
123
166
  proc, _stdout, stderr = run_cli(
124
- "--counts", str(counts), "--design", str(design),
167
+ "--counts", str(counts),
168
+ "--design", str(design),
125
169
  "--model", "svm", # not one of ALLOWED_MODELS
126
- "--out", str(tmp_path / "out.parquet"),
170
+ "--out", str(out),
127
171
  )
128
172
  assert proc.returncode == 1
129
173
  assert "Unknown model" in stderr
@@ -134,31 +178,53 @@ def test_cli_invalid_model_rejected_by_argparse(tmp_path):
134
178
  # ----------------------------------------------------------------------
135
179
 
136
180
 
181
+ @pytest.mark.cli
137
182
  def test_cli_with_covariates_and_reference_batch(tmp_path):
138
183
  """--x-covariates, --c-covariates and --reference-batch run end to end."""
139
184
  counts, samples = _make_counts(tmp_path)
140
185
  design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
141
186
 
142
187
  x_cov = tmp_path / "x.csv"
143
- pl.DataFrame({"sample": samples,
144
- "condition": ["treated" if i % 2 else "control" for i in range(10)]}
145
- ).write_csv(x_cov)
188
+ pl.DataFrame(
189
+ {"sample": samples,
190
+ "condition": ["treated" if i % 2 else "control" for i in range(10)]}
191
+ ).write_csv(x_cov)
146
192
  c_cov = tmp_path / "c.csv"
147
193
  pl.DataFrame({"sample": samples, "rin": np.linspace(6, 9, 10)}).write_csv(c_cov)
148
- out = tmp_path / "corrected.parquet"
194
+ out = tmp_path / "corrected.tsv"
149
195
 
150
196
  proc, _stdout, stderr = run_cli(
151
197
  "--counts", str(counts), "--design", str(design),
152
198
  "--x-covariates", str(x_cov), "--c-covariates", str(c_cov),
153
199
  "--reference-batch", "batch1",
154
200
  "--model", "ridge",
201
+ "--max-iter", "100",
202
+ "--conv-criterion", "1e-3",
203
+ "--no-optimize-params",
204
+ "--out-f32",
155
205
  "--out", str(out),
156
206
  )
157
207
  assert proc.returncode == 0, f"CLI failed:\n{stderr}"
158
208
 
159
- result = pl.read_parquet(out)
209
+ result = pl.read_csv(out, separator="\t")
160
210
  values = result.drop("gene_id").to_numpy()
161
211
  assert values.shape == (30, 10)
162
212
  # reference batch must be returned unchanged
163
213
  original = pl.read_parquet(counts).drop("gene_id").to_numpy()
164
- np.testing.assert_allclose(values[:, :5], original[:, :5], rtol=1e-6, atol=1e-8)
214
+ np.testing.assert_allclose(values[:, :5], original[:, :5], rtol=1e-6, atol=1e-8)
215
+
216
+
217
+ @pytest.mark.cli
218
+ def test_cli_no_parametric(tmp_path):
219
+ """Test CLI with no parametric model."""
220
+ counts, samples = _make_counts(tmp_path)
221
+ design = _make_design(tmp_path, samples, DEFAULT_BATCHES)
222
+ out = tmp_path / "corrected.parquet"
223
+
224
+ proc, _stdout, stderr = run_cli(
225
+ "--counts", str(counts),
226
+ "--design", str(design),
227
+ "--no-parametric",
228
+ "--out", str(out)
229
+ )
230
+ assert proc.returncode == 0, f"CLI failed:\n{stderr}"
@@ -11,7 +11,7 @@ from __future__ import annotations
11
11
 
12
12
  import numpy as np
13
13
 
14
- from maxcombat.core import ReComBat, find_orphan_samples
14
+ from maxcombat.core import MaxCombat, find_orphan_samples
15
15
 
16
16
  BASE_RECOMBAT_KWARGS = {"verbose": False}
17
17
 
@@ -33,7 +33,7 @@ def _batch_mean_dispersion(data: np.ndarray, batches: np.ndarray) -> float:
33
33
  def test_fit_transform_tutorial_data(tutorial_dataset):
34
34
  """maxcombat runs on the full tutorial dataset and returns the same shape."""
35
35
  data, batches = tutorial_dataset["data"], tutorial_dataset["batches"]
36
- model = ReComBat(**BASE_RECOMBAT_KWARGS)
36
+ model = MaxCombat(**BASE_RECOMBAT_KWARGS)
37
37
  corrected = model.fit_transform(data, batches, sample_names=tutorial_dataset["sample_names"])
38
38
 
39
39
  # orphan samples are dropped inside fit(); compare against the kept samples
@@ -48,7 +48,7 @@ def test_batch_effect_is_reduced(tutorial_dataset):
48
48
  keep = np.isin(np.arange(batches.shape[0]), find_orphan_samples(batches), invert=True)
49
49
  data, batches = data[:, keep], batches[keep]
50
50
 
51
- model = ReComBat(**BASE_RECOMBAT_KWARGS)
51
+ model = MaxCombat(**BASE_RECOMBAT_KWARGS)
52
52
  corrected = model.fit_transform(data, batches)
53
53
 
54
54
  before = _batch_mean_dispersion(data, batches)
@@ -66,7 +66,7 @@ def test_reference_batch_left_unadjusted(tutorial_dataset):
66
66
  values, counts = np.unique(batches, return_counts=True)
67
67
  reference_batch = values[np.argmax(counts)]
68
68
 
69
- model = ReComBat(reference_batch=reference_batch, **BASE_RECOMBAT_KWARGS)
69
+ model = MaxCombat(reference_batch=reference_batch, **BASE_RECOMBAT_KWARGS)
70
70
  corrected = model.fit_transform(data, batches)
71
71
 
72
72
  reference_samples = batches == reference_batch
@@ -85,7 +85,7 @@ def test_reference_batch_left_unadjusted(tutorial_dataset):
85
85
  def test_clip_negative_values_option(tutorial_dataset_small):
86
86
  """The clip_negative_values option must return an all-non-negative matrix."""
87
87
  data, batches = tutorial_dataset_small["data"], tutorial_dataset_small["batches"]
88
- model = ReComBat(clip_negative_values=True, **BASE_RECOMBAT_KWARGS)
88
+ model = MaxCombat(clip_negative_values=True, **BASE_RECOMBAT_KWARGS)
89
89
  corrected = model.fit_transform(data, batches)
90
90
  corrected = model.post_process(corrected)
91
91
  assert (corrected >= 0).all()
@@ -103,7 +103,7 @@ def test_non_parametric_on_small_subset(tutorial_dataset_small):
103
103
  keep = np.isin(np.arange(batches.shape[0]), find_orphan_samples(batches), invert=True)
104
104
  data, batches = data[:, keep], batches[keep]
105
105
 
106
- model = ReComBat(parametric=False, model="ridge", config={"alpha": 1e-10})
106
+ model = MaxCombat(parametric=False, model="ridge", config={"alpha": 1e-10})
107
107
  corrected = model.fit_transform(data, batches)
108
108
 
109
109
  assert corrected.shape == data.shape
File without changes
File without changes