feat: netmix2 - #225
Conversation
| output_vertices.rename(output_file) | ||
|
|
||
| @staticmethod | ||
| def parse_output(raw_pathway_file, standardized_pathway_file): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Is there something bad about getting the induced subgraph that makes netmix2/RWR not work well with ML post processing?
|
This PR doesn't have the pydantic style. Reminder to update this PR. |
| run1: | ||
| n: 1 | ||
|
|
||
| - name: "netmix2" |
There was a problem hiding this comment.
can we add some defaults here?
|
getting this error when I try to run this locally: |
akniyetnurbol
left a comment
There was a problem hiding this comment.
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.
| 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') |
There was a problem hiding this comment.
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')
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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)
| 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): |
There was a problem hiding this comment.
Check for no input cases in this function
|
|
||
| import pytest | ||
|
|
||
| import spras.config as config |
There was a problem hiding this comment.
import spras.config.config as config since init_from_file lives in spras/config/config.py
import spras.config.config as config
| class TestNetMix2: | ||
| def test_nm2_required(self): | ||
| OUT_FILE.unlink(missing_ok=True) | ||
| NetMix2.run( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Should add packaging for patsy with a consistent version
packaging==24.0
|
|
||
| def test_nm2_missing(self): | ||
| with pytest.raises(ValueError): | ||
| NetMix2.run( |
There was a problem hiding this comment.
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
)
|
|
||
| @staticmethod | ||
| def run(inputs, output_file, args, container_settings=None): | ||
| gurobi_path = gurobi() |
There was a problem hiding this comment.
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
|
Proposed edits look good, we'll check with @tristan-f-r to see whether you should do a PR to |
|
@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. |
|
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 |
|
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. |
# Conflicts: # spras/runner.py
Netmix2 conflict resolved
Closes #157. We need a SPRAS gurobi server license. Once this is integrated, this lays the ground for #105.