Skip to content

Commit bb19058

Browse files
committed
Revise docs content and site configuration
Overhaul the documentation site content and config: update README and MDX docs (overview, getting-started, API) with new examples that prefer package-root imports (from metbit import ...), add authoring notes and a maintenance checklist, and improve quick-start/workflow guidance. Adjust site code and styles: fix a stray CSS character, remove the Roboto font import, update layout metadata/title, and tweak top-level app/page text and links. Update Next.js tooling: change next-env.d.ts import, enhance next.config.js (turbopack root and path utilities), and refresh various project config files. Also include changes to the Python package (metbit/__init__.py and related modules), setup.py, and tests to align public exports and examples with the revised docs.
1 parent 9330c8d commit bb19058

21 files changed

Lines changed: 602 additions & 284 deletions

docs/README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
Metbit Docs (Next.js)
2-
=====================
1+
# metbit documentation site
32

4-
This is a Next.js + React documentation app for Metbit, using the App Router and MDX for authoring content.
3+
This is the Next.js documentation app for `metbit`. It uses the App Router and MDX pages for guides and API reference content.
4+
5+
## Structure
56

6-
Structure
7-
---------
87
- `app/` — App Router
98
- `page.tsx` — Landing page
109
- `docs/` — Docs section with a sidebar layout
1110
- `overview/page.mdx`
1211
- `getting-started/page.mdx`
12+
- `api/` — API reference pages
1313
- `globals.css` — global and docs layout styles
1414
- `next.config.js` — MDX-enabled config
1515
- `package.json` — scripts and dependencies
1616

17-
Run Locally
18-
-----------
17+
## Run locally
18+
1919
1. From repo root: `cd docs`
2020
2. Install: `npm install`
2121
3. Dev server: `npm run dev`
2222
4. Open: http://localhost:3000
2323

24-
Notes
25-
-----
24+
## Authoring notes
25+
2626
- Add new docs by creating folders under `app/docs/<slug>/page.mdx`.
27-
- MDX allows mixing markdown with React components.
28-
- Icons come from `react-icons` for consistent visuals.
27+
- API pages live under `app/docs/api/<slug>/page.mdx`.
28+
- Prefer root imports in examples, for example `from metbit import pca, opls_da`.
29+
- Use subpackage imports only when documenting advanced internals, for example `from metbit.nmr.alignment import PeakAligner`.
30+
- Keep code examples runnable with current package exports.
31+
- MDX allows mixing Markdown with React components.
32+
- Icons come from `react-icons`.
33+
34+
## Maintenance checklist
2935

36+
- Update quick-start examples when public imports change in `metbit/__init__.py`.
37+
- Keep the API index aligned with public exports and important subpackage utilities.
38+
- Run `npm run build` before publishing the docs site.

docs/app/docs/api/page.mdx

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,47 @@
11
# API Reference
22

3-
Browse the public API exposed by `metbit` (sorted by category).
3+
Browse the main public APIs exposed by `metbit`. The preferred import style is:
44

5-
## Data Processing
5+
```python
6+
from metbit import pca, opls_da, nmr_preprocessing, Normalization
7+
```
68

7-
- [calibrate](/docs/api/calibrate)
8-
- [nmr_preprocessing](/docs/api/nmr_preprocess)
9-
- [Normalise](/docs/api/utility)
10-
- [Normalization](/docs/api/spec_norm)
11-
- [peak_chops](/docs/api/peak_processe)
9+
Advanced users can also import from subpackages such as `metbit.analysis`, `metbit.nmr`, `metbit.preprocessing`, `metbit.stats`, and `metbit.apps`.
1210

13-
## Statistical Models
11+
## NMR Data Processing
12+
13+
- [nmr_preprocessing](/docs/api/nmr_preprocess) - read Bruker FID folders and generate processed spectra.
14+
- [calibrate](/docs/api/calibrate) - calibrate chemical-shift axes.
15+
- [baseline_correct and bline](/docs/api/baseline) - baseline correction helpers.
16+
- [detect_multiplets, icoshift_align, and PeakAligner](/docs/api/peak_processe) - peak detection and interval alignment utilities.
17+
- [peak_chops](/docs/api/peak_processe) - peak-region extraction.
18+
- [denoise_spec](/docs/api/denoise_spec) - spectral denoising helpers.
1419

15-
- [lazy_opls_da](/docs/api/lazy_opls_da)
16-
- [opls_da](/docs/api/metbit)
17-
- [pca](/docs/api/metbit)
18-
- [UnivarStats](/docs/api/utility)
20+
## Normalization and Pretreatment
1921

20-
## Data Visualization
22+
- [Normalization](/docs/api/spec_norm) - static PQN, SNV, MSC, and combined normalization methods.
23+
- [Normalise](/docs/api/utility) - class-based normalization utilities.
24+
- [scaler](/docs/api/scaler) - scaling utilities used by statistical models.
25+
- [pretreatment](/docs/api/pretreatment) - preprocessing and transformation helpers.
2126

22-
- [annotate_peak](/docs/api/annotate_peak)
23-
- [get_intensity](/docs/api/take_intensity)
24-
- [pickie_peak](/docs/api/ui_picky_peak)
25-
- [STOCSY](/docs/api/STOCSY)
26-
- [STOCSY_app](/docs/api/ui_stocsy)
27+
## Statistical Models
2728

29+
- [pca](/docs/api/metbit) - PCA model with interactive scores, loading, variance, and trajectory plots.
30+
- [opls_da](/docs/api/metbit) - OPLS-DA model with cross-validation, permutation testing, VIP, loading, S-plot, and scores plotting.
31+
- [lazy_opls_da](/docs/api/lazy_opls_da) - convenience workflow for OPLS-DA analysis.
32+
- [OPLS](/docs/api/opls) - lower-level OPLS model implementation.
33+
- [PLS](/docs/api/pls) - lower-level PLS model implementation.
34+
- [CrossValidation](/docs/api/cross_validation) - cross-validation helpers.
35+
- [VIP helpers](/docs/api/vip) - Variable Importance in Projection utilities.
36+
- [UnivarStats](/docs/api/utility) - univariate statistical analysis helpers.
37+
38+
## Visualization and Interactive Apps
39+
40+
- [STOCSY](/docs/api/STOCSY) - Statistical Total Correlation Spectroscopy.
41+
- [STOCSY_app](/docs/api/ui_stocsy) - interactive Dash STOCSY app.
42+
- [pickie_peak](/docs/api/ui_picky_peak) - interactive peak-picking app.
43+
- [annotate_peak](/docs/api/annotate_peak) - peak annotation helper.
44+
- [get_intensity](/docs/api/take_intensity) - peak intensity extraction.
45+
- [plotting](/docs/api/plotting) - reusable plotting helpers.
46+
- [boxplot](/docs/api/boxplot) - boxplot visualization utilities.
47+
- [pca_ellipse](/docs/api/pca_ellipse) - confidence ellipse plotting.
Lines changed: 87 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div className="prose">
22
<div className="hero">
33
<h1 className="heroTitle">Getting Started</h1>
4-
<p className="heroSubtitle">Install Metbit from PyPI and run your first analysis.</p>
4+
<p className="heroSubtitle">Install metbit, prepare your data, and run the first PCA or OPLS-DA model.</p>
55
</div>
66

77
<div className="callout info">
8-
<strong>Requirements:</strong> Python 3.9+ (3.10/3.11 recommended), pip or conda/mamba with pip.
8+
<strong>Requirements:</strong> Python 3.10+ is recommended. The package depends on the scientific Python stack, Plotly, Dash, nmrglue, and pybaselines.
99
</div>
1010

1111
<h2>Install</h2>
@@ -15,58 +15,110 @@
1515
<summary><b>Use a virtual environment</b></summary>
1616
<pre><code>{`python -m venv .venv
1717
source .venv/bin/activate # Windows: .venv\\Scripts\\activate
18+
python -m pip install --upgrade pip
1819
pip install metbit`}</code></pre>
1920
</details>
2021

21-
<h2>Minimal Example</h2>
22+
<h2>Import public APIs</h2>
23+
<p>Most commonly used classes and functions are exported from the package root.</p>
24+
<pre><code>{`from metbit import (
25+
nmr_preprocessing,
26+
Normalization,
27+
Normalise,
28+
pca,
29+
opls_da,
30+
STOCSY,
31+
)`}</code></pre>
32+
33+
<h2>Option 1: Start from a feature table</h2>
34+
<p>Use this route when your spectra are already represented as a table where rows are samples and columns are spectral variables.</p>
2235
<div className="twoCol">
2336
<div>
2437
<ol className="steps">
25-
<li>Load your data (X = features, y = classes)</li>
26-
<li>Fit OPLS‑DA and compute VIP scores</li>
27-
<li>Visualize important features</li>
38+
<li>Load a CSV file with a class or group column.</li>
39+
<li>Separate <code>X</code> features from <code>y</code> labels.</li>
40+
<li>Normalize the feature table.</li>
41+
<li>Fit PCA for exploration or OPLS-DA for binary class modeling.</li>
2842
</ol>
2943
</div>
3044
<div>
3145
<pre><code>{`import pandas as pd
32-
from metbit.metbit import opls_da
46+
from metbit import Normalization, pca, opls_da
47+
48+
df = pd.read_csv("spectra.csv")
49+
y = df["Group"]
50+
X = df.drop(columns=["Group"])
51+
features = X.columns.astype(float)
3352
34-
df = pd.read_csv('your_data.csv')
35-
y = df['Group']
36-
X = df.drop(columns=['Group'])
53+
X_norm = Normalization.pqn_normalization(X)
54+
55+
pca_model = pca(
56+
X=X_norm,
57+
label=y,
58+
features_name=features,
59+
n_components=2,
60+
scaling_method="pareto",
61+
)
62+
pca_model.fit()
63+
pca_model.plot_pca_scores().show()
3764
38-
model = opls_da(
39-
X, y,
40-
features_name=list(X.columns), n_components=2,
41-
scaling_method='pareto', kfold=3,
42-
estimator='opls', random_state=94, auto_ncomp=True
65+
opls_model = opls_da(
66+
X=X_norm,
67+
y=y,
68+
features_name=features,
69+
n_components=2,
70+
scaling_method="pareto",
71+
kfold=3,
72+
estimator="opls",
73+
auto_ncomp=True,
4374
)
44-
model.fit()
45-
fig = model.vip_plot(threshold=1.0)
46-
fig.show()`}</code></pre>
75+
opls_model.fit()
76+
opls_model.plot_oplsda_scores().show()
77+
opls_model.vip_plot(threshold=1.0).show()`}</code></pre>
4778
</div>
4879
</div>
4980

50-
<h2>Preprocessing (optional)</h2>
51-
<div className="callout">
52-
Use Metbit utilities to prepare spectra before modeling.
53-
</div>
54-
<pre><code>{`from metbit.nmr_preprocess import nmr_preprocessing
55-
from metbit.utility import Normalise
81+
<h2>Option 2: Start from Bruker FID folders</h2>
82+
<p>Use <code>nmr_preprocessing</code> when your input is a Bruker project folder containing one or more sample directories with <code>fid</code> files.</p>
83+
<pre><code>{`from metbit import nmr_preprocessing, Normalization
84+
85+
nmr = nmr_preprocessing(
86+
data_path="path/to/bruker_project",
87+
bin_size=0.0005,
88+
auto_phasing=True,
89+
fn_="acme",
90+
baseline_correction=True,
91+
baseline_type="corrector",
92+
calibration=True,
93+
calib_type="tsp",
94+
align=False,
95+
)
96+
97+
X = nmr.get_data()
98+
ppm = nmr.get_ppm()
99+
metadata = nmr.get_metadata()
56100
57-
prep = nmr_preprocessing(...)
58-
X = prep.X # DataFrame`}</code></pre>
101+
X_norm = Normalization.pqn_normalization(X)`}</code></pre>
59102

60-
<h2>Next Steps</h2>
61-
<p>
62-
<a className="btn" href="/docs/api">Browse Full API →</a>
63-
<span style={{ marginLeft: 8 }} />
64-
<a className="btn secondary" href="/docs/overview">Explore Overview</a>
65-
</p>
103+
<h2>Recommended project structure</h2>
104+
<pre><code>{`project/
105+
data/
106+
raw_bruker/
107+
processed/
108+
notebooks/
109+
results/
110+
figures/
111+
tables/
112+
scripts/
113+
run_preprocessing.py
114+
run_models.py`}</code></pre>
66115

116+
<h2>Common next steps</h2>
67117
<ul>
68-
<li>nmr_preprocess: <a href="/docs/api/nmr_preprocess">/docs/api/nmr_preprocess</a></li>
69-
<li>Modeling (opls_da, pca): <a href="/docs/api/metbit">/docs/api/metbit</a></li>
70-
<li>Utilities (Normalise, UnivarStats): <a href="/docs/api/utility">/docs/api/utility</a></li>
118+
<li>Preprocessing and Bruker import: <a href="/docs/api/nmr_preprocess">/docs/api/nmr_preprocess</a></li>
119+
<li>Normalization: <a href="/docs/api/spec_norm">/docs/api/spec_norm</a></li>
120+
<li>PCA and OPLS-DA: <a href="/docs/api/metbit">/docs/api/metbit</a></li>
121+
<li>STOCSY exploration: <a href="/docs/api/STOCSY">/docs/api/STOCSY</a></li>
122+
<li>Dash apps: <a href="/docs/api/ui_stocsy">/docs/api/ui_stocsy</a> and <a href="/docs/api/ui_picky_peak">/docs/api/ui_picky_peak</a></li>
71123
</ul>
72124
</div>

docs/app/docs/overview/page.mdx

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,70 @@
22

33
<div className="prose">
44
<div className="hero">
5-
<h1 className="heroTitle">Metbit — Python API</h1>
6-
<p className="heroSubtitle">Preprocess spectra, build PCA/OPLS-DA models, and visualize results with clean, high‑level functions.</p>
5+
<h1 className="heroTitle">metbit Python API</h1>
6+
<p className="heroSubtitle">A scriptable workflow for NMR metabolomics: read Bruker data, preprocess spectra, normalize and align peaks, model with PCA/OPLS-DA, and inspect interactive outputs.</p>
77
</div>
88

9-
<div className="callout success"><strong>Install</strong> with <code>pip install metbit</code> and jump into a typical workflow below.</div>
9+
<div className="callout success"><strong>Install</strong> with <code>pip install metbit</code>. Most users can import public APIs directly from <code>metbit</code>.</div>
1010

11-
<h2>Key Features</h2>
11+
<h2>Core workflow</h2>
1212
<div className="grid" style={{gridTemplateColumns:'repeat(2,minmax(0,1fr))'}}>
13-
<div className="card"><h3>Data Processing</h3><p>Baseline, calibration, normalization, preprocessing.</p><p><a href="/docs/api/nmr_preprocess">nmr_preprocess</a> • <a href="/docs/api/spec_norm">spec_norm</a> • <a href="/docs/api/scaler">scaler</a></p></div>
14-
<div className="card"><h3>Statistical Models</h3><p>PCA/OPLS-DA, cross‑validation, VIP.</p><p><a href="/docs/api/metbit">metbit</a> • <a href="/docs/api/opls">opls</a> • <a href="/docs/api/pls">pls</a></p></div>
15-
<div className="card"><h3>Visualization</h3><p>Scores/loadings, boxplots, STOCSY, ellipses.</p><p><a href="/docs/api/plotting">plotting</a> • <a href="/docs/api/boxplot">boxplot</a> • <a href="/docs/api/STOCSY">STOCSY</a></p></div>
16-
<div className="card"><h3>Utilities</h3><p>Univariate stats, VIP helpers, paths.</p><p><a href="/docs/api/utility">utility</a></p></div>
13+
<div className="card"><h3>Data ingestion</h3><p>Read Bruker FID folders and build a sample-by-ppm matrix.</p><p><a href="/docs/api/nmr_preprocess">nmr_preprocessing</a></p></div>
14+
<div className="card"><h3>Preprocessing</h3><p>Apply baseline correction, calibration, normalization, and alignment.</p><p><a href="/docs/api/baseline">baseline_correct</a> • <a href="/docs/api/calibrate">calibrate</a> • <a href="/docs/api/spec_norm">Normalization</a></p></div>
15+
<div className="card"><h3>Statistical modeling</h3><p>Use PCA for exploration and OPLS-DA for binary supervised modeling with validation.</p><p><a href="/docs/api/metbit">pca</a> • <a href="/docs/api/metbit">opls_da</a> • <a href="/docs/api/vip">VIP</a></p></div>
16+
<div className="card"><h3>Interactive exploration</h3><p>Inspect scores, loadings, VIP plots, STOCSY correlations, and local Dash apps.</p><p><a href="/docs/api/STOCSY">STOCSY</a> • <a href="/docs/api/ui_stocsy">STOCSY_app</a> • <a href="/docs/api/ui_picky_peak">pickie_peak</a></p></div>
1717
</div>
1818

1919
<h2>Typical Workflow</h2>
2020
<div className="twoCol">
2121
<div>
2222
<ol className="steps">
23-
<li>Preprocess your spectra (optional)</li>
24-
<li>Fit an OPLS‑DA model</li>
25-
<li>Assess VIP and visualize results</li>
23+
<li>Preprocess raw Bruker folders or load an existing feature table.</li>
24+
<li>Normalize spectra and keep the ppm axis as feature names.</li>
25+
<li>Fit PCA for exploration or OPLS-DA for binary classification.</li>
26+
<li>Review scores, loadings, permutation results, VIP scores, or STOCSY correlations.</li>
2627
</ol>
2728
</div>
2829
<div>
2930
<pre><code>{`import pandas as pd
30-
from metbit.nmr_preprocess import nmr_preprocessing
31-
from metbit.metbit import opls_da
31+
from metbit import Normalization, opls_da
3232
33-
prep = nmr_preprocessing(...)
34-
X, y = prep.X, prep.y
33+
df = pd.read_csv("spectra.csv")
34+
y = df["Group"]
35+
X = df.drop(columns=["Group"])
36+
features = X.columns.astype(float)
37+
38+
X_norm = Normalization.pqn_normalization(X)
3539
3640
model = opls_da(
37-
X, y,
38-
features_name=list(X.columns), n_components=2,
39-
scaling_method='pareto', kfold=3,
40-
estimator='opls', random_state=94, auto_ncomp=True
41+
X=X_norm,
42+
y=y,
43+
features_name=features,
44+
n_components=2,
45+
scaling_method="pareto",
46+
kfold=3,
47+
estimator="opls",
48+
random_state=42,
49+
auto_ncomp=True,
4150
)
4251
model.fit()
43-
vip_fig = model.vip_plot(threshold=1.0)
44-
vip_fig.show()`}</code></pre>
52+
model.plot_oplsda_scores().show()
53+
model.vip_plot(threshold=1.0).show()`}</code></pre>
4554
</div>
4655
</div>
4756

57+
<h2>Import paths</h2>
58+
<p>The preferred import style is from the package root:</p>
59+
<pre><code>{`from metbit import (
60+
nmr_preprocessing,
61+
Normalization,
62+
Normalise,
63+
pca,
64+
opls_da,
65+
STOCSY,
66+
)`}</code></pre>
67+
<p>Advanced users can also import from subpackages such as <code>metbit.nmr</code>, <code>metbit.preprocessing</code>, <code>metbit.analysis</code>, <code>metbit.stats</code>, and <code>metbit.apps</code>.</p>
68+
4869
<h2>Where Next</h2>
4970
<p>
5071
<a className="btn" href="/docs/getting-started">Get Started →</a>

docs/app/globals.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ main { max-width: 980px; margin: 24px auto; padding: 0 16px; }
183183
.btn:active { transform: translateY(1px) scale(.98); }
184184
.btn.secondary { background: var(--card); color: var(--text) !important; border-color: var(--border); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
185185
.btn.secondary:hover { filter: brightness(1.02); }
186-
.
187186
.btn:focus-visible, .ctaBtn:focus-visible { outline: 3px solid var(--primary-600); outline-offset: 2px; }
188187

189188
/* Hero blocks for Getting Started / Overview */

0 commit comments

Comments
 (0)