Skip to content

Add --LR_model and --demo options to gene_vec_model.py#4

Open
chronicgiardia wants to merge 2 commits into
chenhcs:mainfrom
chronicgiardia:feature/lr-model-demo-args
Open

Add --LR_model and --demo options to gene_vec_model.py#4
chronicgiardia wants to merge 2 commits into
chenhcs:mainfrom
chronicgiardia:feature/lr-model-demo-args

Conversation

@chronicgiardia

Copy link
Copy Markdown

Summary

Adds two optional CLI arguments to src/gene_vec_model.py and documents them:

  • --LR_model <dir>: after training gene embeddings, trains (or loads, if already present) a logistic regression model that predicts whether a pair of genes is associated, using the element-wise product of the two genes' embeddings as features. Persisted as gene_pair_lr.pkl in the directory. Requires scikit-learn.
  • --demo <dir>: exports a copy of the learned embeddings into the demo directory (into its data/ subdirectory when present) so the demo scripts can consume freshly trained embeddings.

To make this testable, the training pipeline was refactored into a main() guarded by if __name__ == '__main__', and the new logic was extracted into small helpers (build_pair_features, train_or_load_lr_model, export_embeddings_for_demo). CLI behavior is unchanged.

Tests

Adds src/test_gene_vec_model.py (stdlib unittest, no pytest required) covering argument parsing, feature construction, LR model save/load (including load-without-retrain), and demo export. Run with:

cd src && python3 -m unittest test_gene_vec_model -v

All 11 tests pass.

Conversation: https://app.warp.dev/conversation/2180fe28-77cf-4cc1-9147-26b5fd7a2e6a

Refactor gene_vec_model.py to expose the embedding pipeline via main()
and add helpers for the new CLI arguments:
- --LR_model: train (or load) a logistic regression model over gene-pair
  embedding features and persist it as gene_pair_lr.pkl in the directory.
- --demo: export a copy of the learned embeddings into the demo directory.

Add a unittest suite covering argument parsing, feature construction, LR
model save/load, and demo export. Document both arguments in the README.

Co-Authored-By: Oz <oz-agent@warp.dev>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the src/gene_vec_model.py training script with two optional CLI flags to (1) train/load a downstream logistic regression model on learned gene embeddings and (2) export trained embeddings into a demo directory, and adds unit tests and README documentation for these behaviors.

Changes:

  • Added --LR_model <dir> and helper logic to train or load a persisted gene-pair logistic regression model.
  • Added --demo <dir> and helper logic to export the embeddings CSV into the demo directory (preferring demo/data/ when present).
  • Refactored the script to a main() entrypoint guarded by if __name__ == '__main__' and introduced unittest coverage for the new helpers/CLI parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/gene_vec_model.py Adds new CLI args, extracts helper functions, and wraps training flow into a main() entrypoint; optionally trains/loads LR and exports embeddings.
src/test_gene_vec_model.py Adds unittest coverage for argument parsing, feature construction, LR save/load behavior, and demo export (skips LR tests if sklearn missing).
README.md Documents the new --LR_model and --demo options and their outputs/behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gene_vec_model.py
Comment on lines +66 to +67
from sklearn.linear_model import LogisticRegression

Mirrors the argument-parsing style used by graphify's args-demo command:
explicit per-flag cursor loop supporting both --flag value and
--flag=value forms, manual --help/-h output, and error+exit(1) on
unrecognized arguments. Returns a SimpleNamespace so main() usage
(args.datatype, args.LR_model, etc.) is unchanged.

All 11 existing tests in test_gene_vec_model.py pass unmodified.

Co-Authored-By: Oz <oz-agent@warp.dev>
@chronicgiardia

Copy link
Copy Markdown
Author

Updated: replaced the argparse-based parser in src/gene_vec_model.py with a manual sys.argv scanner (explicit per-flag cursor loop supporting both --flag value and --flag=value forms, manual --help, and error+exit(1) on unrecognized arguments). Behavior and the args.* attribute interface are unchanged; all 11 existing tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants