Add Logistic PCA (LPCA) analysis - #500
Conversation
Adds an analysis.lpca config block (include, k, m, cv, transpose) with a matching LpcaAnalysis schema, an lpca_analysis Snakemake rule restricted to algorithms with multiple parameter combinations, and an LPCA analysis module that builds the binary edge-by-run matrix via summarize_networks and runs the logisticPCA container through run_container_and_log. m is fixed by default; cross-validation and matrix transposition are opt-in.
Adds docker-wrappers/lpca with a pinned rocker/r-base Dockerfile that installs logisticPCA and its ggplot2 dependencies, the run_lpca.R and run_cv.R scripts under /app, and a README documenting the config options, script contracts, and how to build and publish reedcompbio/lpca:v1.
agitter
left a comment
There was a problem hiding this comment.
Note that this will close #271 when merged.
I pushed the image to DockerHub: https://hub.docker.com/r/reedcompbio/lpca
We should add this to our Docker image building test: https://github.com/Reed-CompBio/spras/blob/main/.github/workflows/build-containers.yml
This comment should be modified to note the alternative LPCA
Line 159 in 07707bf
I didn't comment on every detail yet, but in general there are some small things we can to do make this more like the existing PCA.
agitter
left a comment
There was a problem hiding this comment.
Additional comments because I accidentally submitted the first batch before finishing.
| # Initialize a Docker client using environment variables | ||
| try: | ||
| client = docker.from_env() | ||
| client = docker.from_env(timeout=600) |
There was a problem hiding this comment.
Is this still needed? Was it a workaround for the memory issues?
This modifies Docker but not Singularity.
There was a problem hiding this comment.
The 600s timeout is still needed. Large matrices (e.g. RWR with ~20k edges) can take several minutes even with partial_decomp=TRUE. Singularity is unaffected.
| OUT_DIR.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| @skip_if_no_lpca_image | ||
| def test_lpca_output_exists(self): |
There was a problem hiding this comment.
A stronger test would be that the expected output is created when we use known inputs. These are okay first steps, but if there is time we would add the stronger test.
There is some degeneracy with these existing pathways though that cause the PCA tests to fail at random. It may be okay here because we don't do KDE testing.
Will we need to account for sign non-identifiability in LPCA?
| ml.hac_horizontal(summary_df, output.hac_image_horizontal, output.hac_clusters_horizontal, **hac_params) | ||
| ml.pca(summary_df, output.pca_image, output.pca_variance, output.pca_coordinates, **pca_params) | ||
|
|
||
| rule lpca_analysis: |
There was a problem hiding this comment.
Should this be a new rule or a conditional extension of ml_analysis and ml_analysis_aggregate_algo?
There was a problem hiding this comment.
Kept it as a separate rule to avoid touching existing ml_analysis logic. Happy to refactor it as a conditional extension and add cross-algorithm support if that's the preferred direction before merge.
…o LPCA, Snakefile cleanup
Summary
Adds Logistic PCA (LPCA) as a new SPRAS analysis method. LPCA is the binary-data counterpart to the existing PCA analysis. It is designed for binary matrices (0/1) like the edge-by-run matrix built from pathway reconstruction outputs, whereas standard PCA assumes continuous data.
Changes
New config block
analysis.lpcawith five options:include: enable/disable LPCA (defaultfalse)k: number of principal components (default2)m: logisticPCA tuning parameter, used whencvisfalse(default6)cv: iftrue, determine m by cross-validation; iffalse, use fixed m (defaultfalse)transpose: iffalse, run LPCA on edges x runs matrix (one embedding per edge);if
true, run on runs x edges matrix (one embedding per pathway run,mirrors the classic PCA analysis) (default
false)New Snakemake rule
lpca_analysis{algorithm}-lpca-scores.csv,{algorithm}-lpca.png,{algorithm}-lpca-coordinates.txtNew module
spras/analysis/lpca.pysummarize_networksrun_container_and_logNew Docker wrapper
docker-wrappers/lpca/rocker/r-base:4.4.2Dockerfile installinglogisticPCAandggplot2run_lpca.R: runs LPCA and saves scores + deviance explainedrun_cv.R: cross-validation to find optimal mUnit tests
test/analysis/test_lpca.pyDocker timeout
containers.pyto handle larger binary matricesTesting locally
Build the image and run the pipeline:
Enable
analysis.lpca.include: truein your config and run as usual.Tested end-to-end with OmicsIntegrator2 (216 combos) and MincostFlow (14 combos).
Before / at merge
The image must be published to
reedcompbio/lpca:v1on Docker Hub by a maintainer:cc @agitter @ntalluri