Skip to content

Commit e3486f9

Browse files
committed
Code refactor
1 parent 0c42a0b commit e3486f9

596 files changed

Lines changed: 3190 additions & 969386 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ htmlcov/
2222
/metbit/__pycache__
2323
*.pyc
2424
*.pyc
25+
.claude

metbit/__init__.py

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,71 @@
11
# -*- coding: utf-8 -*-
22

3-
# Public classes/functions re-exported for convenience
4-
from .metbit import opls_da, pca
5-
from .utility import UnivarStats, Normalise
6-
from .lazy_opls_da import lazy_opls_da
7-
8-
# Backwards-compat star imports (intended public surface)
9-
from .spec_norm import * # noqa: F401,F403
10-
from .peak_processe import peak_chops
11-
from .STOCSY import STOCSY
12-
from .ui_stocsy import STOCSY_app
13-
from .ui_picky_peak import pickie_peak
14-
from .take_intensity import * # noqa: F401,F403
15-
from .nmr_preprocess import nmr_preprocessing
16-
from .calibrate import calibrate
17-
from .annotate_peak import annotate_peak
18-
from .baseline import baseline_correct, bline
19-
from .alignment import detect_multiplets, icoshift_align, PeakAligner
20-
213
# Package metadata
224
__author__ = "aeiwz"
235
__email__ = "theerayut_aeiw_123@hotmail.com"
246
__maintainer__ = "aeiwz"
257
__status__ = "Development"
268
__copyright__ = "Copyright 2024, Theerayut"
9+
__version__ = "9.0.0-dev"
10+
11+
# Core analysis
12+
from metbit.analysis.opls_da import opls_da
13+
from metbit.analysis.pca import pca
14+
from metbit.analysis.stocsy import STOCSY
15+
16+
# NMR processing
17+
from metbit.nmr.preprocess import nmr_preprocessing
18+
from metbit.nmr.calibrate import calibrate
19+
from metbit.nmr.alignment import detect_multiplets, icoshift_align, PeakAligner
20+
from metbit.nmr.peaks import peak_chops
21+
22+
# Statistics
23+
from metbit.stats.normalise import Normalise
24+
from metbit.stats.univariate import UnivarStats
25+
26+
# Preprocessing
27+
from metbit.preprocessing.baseline import baseline_correct, bline
28+
from metbit.preprocessing.normalize import Normalization
29+
30+
# Dash apps (optional heavy deps)
31+
try:
32+
from metbit.apps.annotate import annotate_peak
33+
except Exception:
34+
pass
35+
36+
try:
37+
from metbit.apps.stocsy_app import STOCSY_app
38+
except Exception:
39+
pass
2740

28-
# Optional version string to keep in sync with setup.py
29-
__version__ = "8.7.7"
41+
try:
42+
from metbit.apps.peak_picker import pickie_peak
43+
except Exception:
44+
pass
45+
46+
# Legacy flat-layout class not yet moved to a sub-package
47+
try:
48+
from metbit.lazy_opls_da import lazy_opls_da
49+
except Exception:
50+
pass
3051

31-
# Explicit export list for primary API (star imports remain for compatibility)
3252
__all__ = [
3353
"opls_da",
3454
"pca",
35-
"UnivarStats",
36-
"Normalise",
37-
"lazy_opls_da",
38-
"peak_chops",
3955
"STOCSY",
40-
"STOCSY_app",
41-
"pickie_peak",
4256
"nmr_preprocessing",
4357
"calibrate",
44-
"annotate_peak",
45-
"baseline_correct",
46-
"bline",
4758
"detect_multiplets",
4859
"icoshift_align",
4960
"PeakAligner",
61+
"peak_chops",
62+
"Normalise",
63+
"UnivarStats",
64+
"baseline_correct",
65+
"bline",
66+
"Normalization",
67+
"annotate_peak",
68+
"STOCSY_app",
69+
"pickie_peak",
70+
"lazy_opls_da",
5071
]
568 Bytes
Binary file not shown.
100 Bytes
Binary file not shown.

metbit/_compat.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Backwards-compatibility re-exports from sub-package paths.
2+
# Importing from old flat paths (e.g. `from metbit.nmr_preprocess import ...`)
3+
# still works via the originals; this module provides the NEW canonical paths
4+
# so external consumers can start migrating to the sub-package imports.
5+
6+
# --- nmr/ ---
7+
from .nmr.preprocess import ( # noqa: F401
8+
nmr_preprocessing,
9+
read_fid,
10+
remove_digital_filter,
11+
generate_ppm_scale,
12+
phasing,
13+
)
14+
from .nmr.calibrate import calibrate # noqa: F401
15+
from .nmr.alignment import ( # noqa: F401
16+
detect_multiplets,
17+
icoshift_align,
18+
PeakAligner,
19+
Multiplet,
20+
)
21+
from .nmr.denoise import Denoise # noqa: F401
22+
from .nmr.peaks import peak_chops # noqa: F401
23+
24+
# --- models/ ---
25+
from .models.base import nipals # noqa: F401
26+
from .models.pls import PLS # noqa: F401
27+
from .models.opls import OPLS # noqa: F401
28+
from .models.vip import vip_scores # noqa: F401
29+
from .models.cross_validation import CrossValidation # noqa: F401
30+
31+
# --- preprocessing/ ---
32+
from .preprocessing.scaler import Scaler as SimpleScaler # noqa: F401
33+
from .preprocessing.scaler_ext import Scaler # noqa: F401
34+
from .preprocessing.normalize import Normalization # noqa: F401
35+
from .preprocessing.baseline import baseline_correct, bline # noqa: F401
36+
37+
# --- analysis/ ---
38+
from .analysis.stocsy import STOCSY # noqa: F401
39+
40+
# --- viz/ ---
41+
from .viz.ellipse import confidence_ellipse # noqa: F401
42+
43+
# --- higher-level classes (canonical sub-package paths) ---
44+
from .analysis.opls_da import opls_da # noqa: F401
45+
from .analysis.pca import pca # noqa: F401
46+
47+
try:
48+
from .lazy_opls_da import lazy_opls_da # noqa: F401
49+
except Exception:
50+
pass
51+
52+
# --- utility classes (canonical sub-package paths) ---
53+
from .stats.univariate import UnivarStats # noqa: F401
54+
from .stats.normalise import Normalise # noqa: F401
55+
56+
# --- Dash apps (optional heavy deps) ---
57+
try:
58+
from .apps.annotate import annotate_peak # noqa: F401
59+
except Exception:
60+
pass
61+
62+
try:
63+
from .apps.stocsy_app import STOCSY_app # noqa: F401
64+
except Exception:
65+
pass
66+
67+
try:
68+
from .apps.peak_picker import pickie_peak # noqa: F401
69+
except Exception:
70+
pass

metbit/_internal/pairs.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import pandas as pd
4+
5+
6+
class lazypair:
7+
"""Utility for generating all pairwise groupings and related dataset splits."""
8+
9+
def __init__(self, dataset: pd.DataFrame, column_name: str):
10+
if not isinstance(dataset, pd.DataFrame):
11+
raise ValueError("meta should be a pandas dataframe")
12+
if not isinstance(column_name, str):
13+
raise ValueError("column_name should be a string")
14+
if column_name not in dataset.columns:
15+
raise KeyError(f"{column_name} not found in dataset")
16+
if dataset[column_name].nunique() < 2:
17+
raise ValueError("Group should contain at least 2 groups")
18+
19+
self.meta = dataset
20+
self.column_name = column_name
21+
22+
groups = dataset[column_name].unique()
23+
self.pairs = [(g1, g2) for i, g1 in enumerate(groups) for g2 in groups[i + 1:]]
24+
self.index_ = [
25+
dataset.index[dataset[column_name] == g1].tolist()
26+
+ dataset.index[dataset[column_name] == g2].tolist()
27+
for g1, g2 in self.pairs
28+
]
29+
self.names = [f"{g1}_vs_{g2}".replace("/", "_") for g1, g2 in self.pairs]
30+
31+
def get_index(self):
32+
index_ = self.index_
33+
return index_
34+
35+
def get_name(self):
36+
names = self.names
37+
return names
38+
39+
def get_meta(self):
40+
meta = self.meta
41+
column_name = self.column_name
42+
return meta[column_name]
43+
44+
def get_column_name(self):
45+
column_name = self.column_name
46+
return column_name
47+
48+
def get_dataset(self):
49+
df = self.meta
50+
index_ = self.index_
51+
list_of_df = []
52+
for i in range(len(index_)):
53+
list_of_df.append(df.loc[index_[i]])
54+
55+
#Create object attribute
56+
self.list_of_df = list_of_df
57+
return list_of_df

0 commit comments

Comments
 (0)