Skip to content

feat: netmix2 - #225

Open
tristan-f-r wants to merge 35 commits into
Reed-CompBio:mainfrom
tristan-f-r:netmix2
Open

feat: netmix2#225
tristan-f-r wants to merge 35 commits into
Reed-CompBio:mainfrom
tristan-f-r:netmix2

Conversation

@tristan-f-r

@tristan-f-r tristan-f-r commented May 23, 2025

Copy link
Copy Markdown
Collaborator

Closes #157. We need a SPRAS gurobi server license. Once this is integrated, this lays the ground for #105.

Comment thread config/config.yaml Outdated
@tristan-f-r tristan-f-r changed the title feat: begin netmix2 feat: netmix2 May 23, 2025
@tristan-f-r tristan-f-r mentioned this pull request May 23, 2025
Comment thread config/config.yaml
Comment thread spras/netmix2.py
Comment thread spras/netmix2.py Outdated
Comment thread spras/netmix2.py Outdated
output_vertices.rename(output_file)

@staticmethod
def parse_output(raw_pathway_file, standardized_pathway_file):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Netmix2 will not work with the ML post processing and possibly some of the other post processing. I'm not sure how to fix this at the moment, but this is something that will need to be considered.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is there something bad about getting the induced subgraph that makes netmix2/RWR not work well with ML post processing?

Comment thread test/parse-outputs/test_parse_outputs.py
Comment thread test/generate-inputs/test_generate_inputs.py
Comment thread spras/netmix2.py
Comment thread test/NetMix2/test_nm2.py
@tristan-f-r tristan-f-r added the algorithm Pathway reconstruction algorithm to add to SPRAS label May 29, 2025
@tristan-f-r
tristan-f-r marked this pull request as ready for review July 7, 2025 23:12
@github-actions github-actions Bot added the merge-conflict This PR has merge conflicts. label Oct 3, 2025
@tristan-f-r tristan-f-r added the awaiting-author Author of the PR needs to fix something from a review / etc. label Jan 23, 2026
@github-actions github-actions Bot added merge-conflict This PR has merge conflicts. and removed merge-conflict This PR has merge conflicts. labels Mar 16, 2026
@ntalluri

Copy link
Copy Markdown
Collaborator

This PR doesn't have the pydantic style. Reminder to update this PR.

@github-actions github-actions Bot removed the merge-conflict This PR has merge conflicts. label Apr 28, 2026
Comment thread config/config.yaml
run1:
n: 1

- name: "netmix2"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we add some defaults here?

@ntalluri

Copy link
Copy Markdown
Collaborator

getting this error when I try to run this locally:

ImportError in file "/Users/nehatalluri/Desktop/research/spras/Snakefile", line 2:
cannot import name 'algorithms' from partially initialized module 'spras.runner' (most likely due to a circular import) (/Users/nehatalluri/Desktop/research/spras/spras/runner.py)
  File "/Users/nehatalluri/Desktop/research/spras/Snakefile", line 2, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/runner.py", line 11, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/netmix2.py", line 13, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/secrets.py", line 9, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/config/config.py", line 27, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/config/schema.py", line 17, in <module>
  File "/Users/nehatalluri/Desktop/research/spras/spras/config/algorithms.py", line 20, in <module>

@github-actions github-actions Bot added the merge-conflict This PR has merge conflicts. label Jun 6, 2026

@akniyetnurbol akniyetnurbol 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.

Comments describe the changes made to get NetMix2 running locally through SPRAS and the tests passing. Also, includes a note on how the Gurobi license is configured in config.yaml and accessed via secrets.py.

Comment thread spras/netmix2.py Outdated
node_df = data.get_node_columns(['prize'])
else:
raise ValueError("Node prizes are required for NetMix2.")
node_df.to_csv(filename_map['scores'], index=False, columns=['prize', 'NODEID'], header=False, sep='\t')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The order of the column should be changed, so it's node then prize, but also raw SPRAS prizes are random weights and can't be used as p-values, so np.exp(-prize) is needed to convert them to valid numbers from 0 to 1 as required by locfdr

import numpy as np
node_df['pval'] = np.exp(-node_df['prize'])
node_df.to_csv(filename_map['scores'], index=False, columns=['NODEID', 'pval'], header=False, sep='\t')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we might want to add np.exp(-prize) as its own function in the same place we have the -log(p-val) function - that would keep these consistent since they transform scores into p-values and vice versa.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, this doesn't exactly transform scores into p-values because there's no statistical test here - it's just converting them to numbers between 0 and 1 where lower is better.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does Netmix require the values to be between 0 - 1 or is this a statistical test that the Netmix2 paper used to convert their data?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

By my understanding, it's less of a statistical choice and more of a hard requirement in the code based on how NetMix2 processes inputs. It converts scores to z-scores using norm.ppf, which only works for values in (0, 1], so the input just needs to be a number in that range where lower is better.

Comment thread spras/netmix2.py Outdated
bind_path, scores_file = prepare_volume(inputs["scores"], work_dir, container_settings)
volumes.append(bind_path)

bind_path, license_file = prepare_volume(inputs["gurobi_path"], work_dir, container_settings)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the gurobi path is not in the inputs dict, so it causes an error when run() is used. Could use the gurobi_path variable from line 52

bind_path, scores_file = prepare_volume(gurobi_path, work_dir, container_settings)

Comment thread spras/netmix2.py
edges_df.to_csv(filename_map['network'], index=False, sep='\t', columns=['Interactor1', 'Interactor2'], header=False)

@staticmethod
def run(inputs, output_file, args, container_settings=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Check for no input cases in this function

Comment thread test/NetMix2/test_nm2.py Outdated

import pytest

import spras.config as config

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

import spras.config.config as config since init_from_file lives in spras/config/config.py

import spras.config.config as config

Comment thread test/NetMix2/test_nm2.py
class TestNetMix2:
def test_nm2_required(self):
OUT_FILE.unlink(missing_ok=True)
NetMix2.run(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inputs must be a dict, not keyword args (consistent with other SPRAS wrappers)
Also, if the container is set to None, then prepare_volume raises an error, so container_settings should be passed explicitly

NetMix2.run(
{"network": TEST_DIR / 'input' / 'network-basic.txt',
"scores": TEST_DIR / 'input' / 'scores-basic.txt'},
output_file=OUT_FILE,
args=NetMix2Params(num_edges=1),
container_settings=config.config.container_settings
)

pandas==1.1.5
statsmodels==0.12.2
gurobipy==9.5.2
networkx==2.5.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should add packaging for patsy with a consistent version

packaging==24.0

Comment thread test/NetMix2/test_nm2.py

def test_nm2_missing(self):
with pytest.raises(ValueError):
NetMix2.run(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TypeError because args was missing

NetMix2.run(
{"network": TEST_DIR / 'input' / 'network-basic.txt'},
output_file=OUT_FILE,
args=NetMix2Params(),
container_settings=config.config.container_settings #config.container_settings
)

Comment thread spras/netmix2.py

@staticmethod
def run(inputs, output_file, args, container_settings=None):
gurobi_path = gurobi()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

gurobi() function in spras/secrets.py is used to get the Gurobi license path, which is read from secrets.gurobi in config.yaml

When the user downloads the gurobi.lic file, they need to update the directory in config.yaml under "secrets:"
OR
Place it at the location already indicated

@annaritz

annaritz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Proposed edits look good, we'll check with @tristan-f-r to see whether you should do a PR to tristan-f-r-:netmix2 to get the changes in.

@ntalluri

ntalluri commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

@akniyetnurbol I saw your email about the pval - prize prize - pval conversion. Would you be able to explain why in SPRAS we would need this conversion for Netmix2? In my opinion pval - prize conversions would happen before putting data into SPRAS.

@akniyetnurbol

Copy link
Copy Markdown

@akniyetnurbol I saw your email about the pval - prize prize - pval conversion. Would you be able to explain why in SPRAS we would need this conversion for Netmix2? In my opinion pval - prize conversions would happen before putting data into SPRAS.

@ntalluri Yeah, when I was running snakemake there was an error because NetMix2 explicitly expects p-values as input (per its readme and paper), but spras stores node data as prizes using -log10(p-value). So by the time data enters spras it's already been converted from p-values to prizes. The generate_inputs wrapper converts back using 10^(-prize), which recovers the original p-value. I put it in the wrapper so the user doesn't have to handle this themselves just to keep things consistent with other algorithms in spras.

@annaritz

Copy link
Copy Markdown
Contributor

I think we are nearly ready to review this PR, after @akniyetnurbol's changes. I added the gurobi license to this repo as a secret.

There seems to be two unresolved conflicts in spras/runner.py related to how algorithms are loaded - @akniyetnurbol or @tristan-f-r can you resolve those? The remaining tests will trigger once the conflict is resolved.

@annaritz

Copy link
Copy Markdown
Contributor

In talking with @akniyetnurbol, it seems like we might need to set a GitHub Environment for the gurobi license to work. Will wait to see if the tests fail before adding that.

@github-actions github-actions Bot removed the merge-conflict This PR has merge conflicts. label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

algorithm Pathway reconstruction algorithm to add to SPRAS awaiting-author Author of the PR needs to fix something from a review / etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetMix2

4 participants