AGENT SKILL

lasso-logistics-analysis

Use when building a binary classification model from an expression matrix or other omics feature matrix with LASSO logistic regression, cross-validation, and coefficient path visualization. NOT for: multiclass classification, survival/Cox models, or ordinary linear regression.

License 许可
MIT
最近更新
2026-10-12
Stars
★ 2
Forks
0

01 前言 Front Matter

name
lasso-logistics-analysis
license
MIT
description
Use when building a binary classification model from an expression matrix or other omics feature matrix with LASSO logistic regression, cross-validation, and coefficient path visualization. NOT for: multiclass classification, survival/Cox models, or ordinary linear regression.
skill-author
AIPOCH

02 资源文件 19

03 SKILL.md 正文

LASSO Logistic Regression Analysis

When to Read External Files

Situation File to Read Purpose
Need algorithm details references/algorithm.md LASSO objective function, cross-validation, and interpretation
Need to run analysis scripts/main.R Execute: Rscript scripts/main.R --input_file ... --group_file ...
Encounter errors references/troubleshooting.md Common errors and solutions
Need CLI examples references/cli-guide.md Detailed CLI usage examples
Need test data tests/data/ Sample input files for testing
Need workflow implementation details scripts/run_analysis.R Inspect orchestration, outputs, and file-writing behavior
Need input-validation or error-handling details scripts/utils.R, scripts/io.R Inspect validation, parsing, logging, and standardized safeguards

Usage

Rscript scripts/main.R \
  --input_file ./expression_matrix.csv \
  --group_file ./groups.csv \
  --case_group case \
  --control_group control \
  --output_dir ./output/ \
  --nfolds 10 \
  --timeout_seconds 1800 \
  --seed 42

Arguments

Short Long Type Default Description
-i --input_file character required Expression matrix file (features as rows, samples as columns)
-g --group_file character required Group file with sample and group columns
-c --case_group character required Case class label encoded as 1
-t --control_group character required Control class label encoded as 0
-f --feature character NULL Optional feature list file or comma-separated feature names
-n --nfolds integer 10 Cross-validation folds: 3, 5, 7, 10
--cv_title character "" Optional title for the cross-validation plot
--path_title character "" Optional title for the coefficient path plot
--timeout_seconds integer 1800 Maximum elapsed runtime in seconds
-o --output_dir character ./output/ Output directory
-s --seed integer 42 Random seed for reproducibility

Input Format

Expression Matrix (input_file)

Features as rows, samples as columns, CSV or TSV format with feature IDs in the first column.

,Sample01,Sample02,Sample03
TSPAN6,1.8479,1.8318,3.8276
TNMD,0.0349,0.0533,1.3889

Group File (group_file)

CSV or TSV with sample IDs and binary-group labels.

sample,group
Sample01,case
Sample02,control
Sample03,case

Optional Feature File (feature)

One feature per line, or pass a comma-separated feature list directly on the CLI.

TNMD
DPM1
SCYL3

Output Files

File Description
coefficient.csv All coefficients at lambda.min
feature_matrix.csv Sample-level matrix with original group labels and binary event column
selected_features.txt Non-zero features at lambda.min excluding the intercept, when available
missing_features.txt Requested features not found in the matrix, when applicable
lasso_lambda_binary_plot.pdf Cross-validation curve
lasso_var_binary_plot.pdf Coefficient path plot
session_info.txt R session and package version info

Workflow

Step 1: Validate Input

WHEN checking validation rules or parsing behavior, READ: scripts/utils.R and scripts/io.R

  • Check file existence
  • Read expression matrix and group file
  • Verify samples match between files
  • Ensure both classes are present with at least 2 samples per class

Step 2: Prepare Modeling Matrix

WHEN checking class encoding or feature filtering behavior, READ: scripts/modeling.R

  • Encode case_group as 1 and control_group as 0
  • Optionally restrict to a user-supplied feature panel
  • Transpose expression data to sample-by-feature format

Step 3: Fit LASSO Logistic Regression

WHEN understanding the statistical method or lambda selection, READ: references/algorithm.md

  • Train a binomial glmnet model with alpha = 1
  • Run cv.glmnet to select the optimal lambda
  • Extract coefficients at lambda.min

Step 4: Save Results and Visualizations

WHEN checking output generation or plot behavior, READ: scripts/run_analysis.R and scripts/plotting.R

  • Save flat output files directly into output_dir
  • Generate cross-validation and coefficient path PDF plots
  • Leave plot titles empty by default unless the user provides custom titles

Methods

LASSO Logistic Regression

The model minimizes binomial deviance with an L1 penalty, shrinking weak coefficients to zero and performing embedded feature selection.

Cross-Validation

cv.glmnet evaluates candidate lambda values across nfolds folds and reports lambda.min and lambda.1se.


Examples

Basic Usage

Rscript scripts/main.R \
  -i ./expression_matrix.csv \
  -g ./groups.csv \
  -c case \
  -t control \
  -o ./output

Use a Feature Panel

Rscript scripts/main.R \
  -i ./expression_matrix.csv \
  -g ./groups.csv \
  -c case \
  -t control \
  -f ./genes.txt \
  -o ./output

Custom Folds and Seed

Rscript scripts/main.R \
  -i ./expression_matrix.csv \
  -g ./groups.csv \
  -c case \
  -t control \
  -n 5 \
  --timeout_seconds 900 \
  -s 123 \
  -o ./output

Custom Plot Titles

Rscript scripts/main.R \
  -i ./expression_matrix.csv \
  -g ./groups.csv \
  -c case \
  -t control \
  --cv_title "LASSO Cross-Validation" \
  --path_title "LASSO Coefficient Paths" \
  --timeout_seconds 1200 \
  -o ./output

Error Handling

Common Errors

Error Cause Solution
SKILL_FILE_NOT_FOUND Input file does not exist Check file path
SKILL_EMPTY_FILE An input file exists but contains no data Verify the file is not empty
SKILL_PARSE_ERROR The input file cannot be parsed as CSV or TSV Check delimiters, headers, and encoding
SKILL_FILE_WRITE_ERROR The output directory cannot be created or written Check output path and permissions
SKILL_EMPTY_DATA The loaded table has no usable rows or columns Verify that the input file contains valid data
SKILL_MISSING_COLUMNS The group file does not provide the required columns Provide sample and group columns
SKILL_INVALID_TYPE A parameter or data field has the wrong type Ensure numeric fields are numeric and strings are valid
SKILL_SAMPLE_MISMATCH Sample IDs differ between matrix and group file Make names match exactly
SKILL_INVALID_GROUP Case/control labels not found in group file Check --case_group and --control_group
SKILL_INVALID_DATA Too few classes, samples, or valid features Review input structure and feature list
SKILL_INVALID_PARAMETER Unsupported nfolds or empty parameter Use documented argument values
SKILL_DEPENDENCY_MISSING Required R package not installed Install missing CRAN package
SKILL_TIMEOUT Analysis exceeded the configured time limit Reduce feature count or increase --timeout_seconds
SKILL_MEMORY_ERROR The runtime environment cannot allocate enough memory Reduce matrix size or available workload
SKILL_RUNTIME_ERROR An unexpected runtime error occurred Review the exact console error and retry

IF error persists, READ: references/troubleshooting.md


Testing

Test with Sample Data

# Check help
Rscript scripts/main.R --help

# Run with sample data
Rscript scripts/main.R \
  -i tests/data/expression_matrix.csv \
  -g tests/data/groups.csv \
  -c case \
  -t control \
  -f tests/data/genes.csv \
  --timeout_seconds 1800 \
  -o tests/output

Validation Commands

# Check coefficient output
ls -la tests/output/coefficient.csv

# Check plots exist
ls -la tests/output/lasso_lambda_binary_plot.pdf
ls -la tests/output/lasso_var_binary_plot.pdf

Implementation Checklist

  • [x] CLI parsing with optparse
  • [x] set.seed() for reproducibility
  • [x] requireNamespace() dependency checks
  • [x] Session info recording
  • [x] Timeout control with --timeout_seconds
  • [x] Temp file cleanup
  • [x] File reading instructions in SKILL.md
  • [x] Modular script structure (<150 lines per file)
  • [x] Test data provided
  • [x] Error handling with SKILL_* codes
  • [x] Scripts in scripts/ directory
  • [x] References in references/ directory

Last updated: 2026-04-17 | Version: 1.0.0

04 同仓库更多 Skills

mrsonord2240
mrsonord2240/openscience-specialists

bio-workflows-metabolomics-pipeline

Orchestrates the untargeted LC-MS metabolomics pipeline end-to-end (xcms 4.x feature extraction, QC/drift/normalization, confidence-stratified annotation, permutation-validated statistics, background-aware pathway mapping), naming what each stage decides and where it silently fails. Use when running a full LC-MS metabolomics study from raw mzML to enriched pathways and needing the honest handoffs between stages. Each stage defers to its component skill for parameters and traps; for stable-isotope flux (a separate branch, not this untargeted flow) see metabolomics/isotope-tracing.

★ 2
mrsonord2240
mrsonord2240/openscience-specialists

bio-metabolomics-xcms-preprocessing

Programmatic untargeted LC-MS feature extraction in R with the modern xcms 4.x MsExperiment/XcmsExperiment API, taking raw mzML to a feature table via CentWave peak detection, retention-time alignment, peak-density correspondence, gap-filling, CAMERA redundancy collapse, and built-in QC feature filtering. Use when converting centroided LC-MS runs into a features-by-samples matrix and deciding centWave/grouping/alignment parameters. For drift correction and QC/CV filtering execution see metabolomics/normalization-qc; for metabolite identification see metabolomics/metabolite-annotation; for the MS-DIAL GUI alternative with MS2Dec deconvolution see metabolomics/msdial-preprocessing; for downstream statistics see metabolomics/statistical-analysis.

★ 2
mrsonord2240
mrsonord2240/openscience-specialists

bio-metabolomics-statistical-analysis

Decision-grade statistical analysis for metabolomics intensity tables. Covers transformation and scaling (Pareto vs unit-variance as a hidden hypothesis), unsupervised structure (PCA/HCA for QC), permutation-validated PLS-DA/OPLS-DA (R2 vs Q2, double CV, VIP as heuristic), univariate testing (Welch/Mann-Whitney/ANOVA/LMM with covariate adjustment), and dependence-aware multiple testing. Use when testing which metabolites differ, building or validating a discriminant model, choosing a scaling, or correcting many correlated tests. For sample-wise normalization/drift correction see metabolomics/normalization-qc; for ML classifiers and selection-inside-CV leakage see machine-learning/biomarker-discovery and machine-learning/model-validation; for pathway interpretation see metabolomics/pathway-mapping; for design/power/multiplicity regime see experimental-design/multiple-testing.

★ 2
mrsonord2240
mrsonord2240/openscience-specialists

bio-metabolomics-pathway-mapping

Maps metabolomics results to biological pathways via over-representation (ORA), metabolite-set enrichment (MSEA/QEA), mummichog/PSEA on raw m/z peaks, and network-diffusion enrichment (FELLA), with correct background-set construction and honest interpretive ceilings. Use when interpreting differential metabolites or an untargeted LC-MS feature table in pathway context, choosing ORA vs MSEA vs mummichog vs topology, or setting the reference/background set. For annotation confidence levels feeding ORA see metabolomics/metabolite-annotation; for gene-set concepts see pathway-analysis/go-enrichment and pathway-analysis/gsea; for joint gene+metabolite pathways see multi-omics-integration/mofa-integration.

★ 2
mrsonord2240
mrsonord2240/openscience-specialists

bio-metabolomics-normalization-qc

Designs QC, corrects signal drift, removes batch effects, filters features, normalizes samples, and imputes missing values for untargeted LC-MS/GC-MS metabolomics, framing each step as a measurement model that can create or erase biological signal. Use when processing a peak/feature table before statistical analysis, choosing a drift-correction or sample-normalization method, deciding QC RSD vs D-ratio filtering, or handling left-censored missing values. The feature table is produced by metabolomics/xcms-preprocessing or metabolomics/msdial-preprocessing; transformation/scaling for modeling defers to metabolomics/statistical-analysis; cross-study design issues link to experimental-design/batch-design.

★ 2
mrsonord2240
mrsonord2240/openscience-specialists

bio-metabolomics-msdial-preprocessing

Runs the MS-DIAL preprocessing workflow (peak picking, MS2Dec spectral deconvolution, alignment, gap-filling) and imports the alignment-result table into R or Python with honest filtering. Use when preprocessing LC-MS DDA/DIA (SWATH) or GC-MS raw data with MS-DIAL, deciding MS-DIAL vs XCMS, configuring the MSDIALCUI console run, or parsing an MS-DIAL export into a clean feature matrix. For programmatic R peak detection and the feature-table-as-artifact framing see metabolomics/xcms-preprocessing; for lipid annotation mode see metabolomics/lipidomics; for MSI-level confidence honesty see metabolomics/metabolite-annotation; for drift correction and QC see metabolomics/normalization-qc.

★ 2