Classes
lazy_opls_da
Parameters
dataDataFrame containing the dataset.groupsList of class labels for each data sample.working_dirDirectory path for storing output files.feature_namesNames of features, defaults to None.n_componentsNumber of components for OPLS-DA, defaults to 2.scalingScaling method ('pareto'), defaults to 'pareto'.estimatorModel estimator, defaults to 'opls'.kfoldNumber of folds in cross-validation, defaults to 3.random_stateRandom seed, defaults to 94.auto_ncompAutomatically choose the optimal number of components, defaults to True.permutationConduct permutation tests, defaults to True.VIPCalculate VIP scores, defaults to True.linear_regressionConduct linear regression analysis, defaults to True.Returns
fit Method
Fits the OPLS-DA model to the dataset, generates plots, and saves them to the output directory.
Parameters
marker_colorDictionary mapping groups to colors.custom_colorCustom color grouping.custom_shapeCustom shape grouping.symbol_dictDictionary mapping groups to marker symbols.custom_legend_nameCustom for the legend, defaults to ['Group', 'Sub-group'].marker_labelSpecifies marker labels ('class', 'group', or 'sub-group').marker_sizeSize of markers in plots.marker_opacityOpacity level of markers in plots.individual_ellipseOption to display individual ellipses for each group.Returns
Directory and Project Setup =========================== Creates necessary folders in the working directory based on project needs (e.g., for VIP score plots, permutation scores, etc.). Paths are stored in a dictionary (self.path).
Directories Created
Plotting and Saving Data
1. Score Plot: Generates OPLS-DA score plots for each group. 2. Loading Plot: Generates and saves loading plots. 3. S Plot: Generates and saves S-score plots. 4. VIP Score Plot: Generates VIP score plots and saves VIP scores as CSV if VIP=True. 5. Permutation Test Plot: Conducts permutation tests and saves permutation scores as CSV if permutation=True. 6. Volcano Plot (Linear Regression): Generates volcano plot and saves data if linear_regression=True.
Examples: >>> import pandas as pd >>> import numpy as np >>> import metbit >>> X = pd.DataFrame(np.random.randn(40, 100), columns=[str(i) for i in range(100)]) >>> y = ['Control'] * 20 + ['Disease'] * 20 >>> model = metbit.lazy_opls_da(data=X, groups=y, working_dir='/tmp/opls_output') >>> model.fit()
Methods
__init__(self, data: pd.DataFrame, groups: list, working_dir: str, feature_: list=None, n_components: int=2, scaling: str='pareto', estimator: str='opls', kfold: int=3, random_state: int=94, auto_ncomp: bool=True, permutation: bool=True, n_permutation: int=500, n_jobs: int=4, VIP: bool=True, VIP_threshold: float=1.5, linear_regression: bool=True, FC_threshold: float=1.5, p_val_threshold: float=2)
This function takes in a dataframe and a list of y values and returns the project_name model.
Parameters
datapandas dataframeThe dataframe to be used.
ylistThe list of y values.
n_componentsintThe number of components to use. lazy_opls_da(data, y, n_components).fit()
Examples: >>> import pandas as pd >>> import numpy as np >>> import metbit >>> X = pd.DataFrame(np.random.randn(40, 100), columns=[str(i) for i in range(100)]) >>> y = ['Control'] * 20 + ['Disease'] * 20 >>> model = metbit.lazy_opls_da(data=X, groups=y, working_dir='/tmp/opls_output')
fit(self, marker_color: dict=None, custom_color: list=None, custom_shape: list=None, symbol_dict: dict=None, custom_legend_name=['Group', 'Sub-group'], marker_label=None, marker_size=None, marker_opacity=None, individual_ellipse=False)
Fit the OPLS-DA model to all pairwise group comparisons and save plots and data.
Parameters:
marker_colorDictionary mapping group labels to hex color strings.custom_colorList assigning a color group to each sample.custom_shapeList assigning a shape group to each sample.symbol_dictDictionary mapping group labels to plotly marker symbols.custom_legend_nameLegend header names, defaults to ['Group', 'Sub-group'].marker_labelMarker label source - 'class', 'group', 'sub-group', or 'index'.marker_sizeMarker size in pixels.marker_opacityMarker opacity between 0 and 1.individual_ellipseDraw a confidence ellipse per group, defaults to False.Returns: None
Examples: >>> import pandas as pd >>> import numpy as np >>> import metbit >>> X = pd.DataFrame(np.random.randn(40, 100), columns=[str(i) for i in range(100)]) >>> y = ['Control'] * 20 + ['Disease'] * 20 >>> model = metbit.lazy_opls_da(data=X, groups=y, working_dir='/tmp/opls_output') >>> model.fit(marker_size=20, marker_opacity=0.8)