Skip to content
8 changes: 3 additions & 5 deletions docs/contributing/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,9 @@ image using the ``Dockerfile`` that was completed in Step 2.

Modify generate inputs:

1. Include a key-value pair in the algo_exp_file dictionary that links
the specific algorithm to its expected network file.
2. Obtain the expected network file from the workflow, manually confirm
it is correct, and save it to ``test/generate-inputs/expected``. Name
it as ``{algorithm_name}-{network_file_name}-expected.txt``.
1. Obtain the expected network and nodes file from the workflow,
manually confirm it is correct, and save it to ``test/generate-inputs/expected``.
Name it as ``{algorithm_name}-{network_file_name}-expected.txt``.

Modify parse outputs:

Expand Down
7 changes: 4 additions & 3 deletions spras/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ def __init__(self, dataset_params: DatasetSchema):
f"Edge file {interactome_loc} must have three or four columns but found {num_cols}"
)

node_set = set(self.interactome.Interactor1.unique())
node_set = node_set.union(set(self.interactome.Interactor2.unique()))
# We get uniqueness afterwards to make `load_files_from_dict` have a well-defined node ordering,
# since algorithms may depend on the order of nodes passed.
nodes = list(pd.concat([self.interactome.Interactor1, self.interactome.Interactor2]).unique())

# Load generic node tables
self.node_table = pd.DataFrame(node_set, columns=[self.NODE_ID])
self.node_table = pd.DataFrame(nodes, columns=[self.NODE_ID])
for node_file in node_data_files:
single_node_table = pd.read_table(os.path.join(data_loc, node_file))
# If we have only 1 column, assume this is an indicator variable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Node Node type
test_A source
C target
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENSG0test_A
ENSG0C
1 change: 1 addition & 0 deletions test/generate-inputs/expected/meo/meo-sources-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test꧁SEP꧂A
1 change: 1 addition & 0 deletions test/generate-inputs/expected/meo/meo-targets-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name prize
test_A 2.0
C 5.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name prize
test_A 2.0
C 5.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Node Node type
test_A source
C target
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
2 changes: 2 additions & 0 deletions test/generate-inputs/expected/rwr/rwr-nodes-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_A
C
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
56 changes: 20 additions & 36 deletions test/generate-inputs/test_generate_inputs.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
import filecmp
import os
import shutil
from pathlib import Path

from spras import runner
from spras.config.config import Config
from spras.runner import algorithms, get_required_inputs, merge_input, prepare_inputs

OUTDIR = "test/generate-inputs/output/"
EXPDIR = "test/generate-inputs/expected/"

algo_exp_file = {
'mincostflow': 'edges',
'meo': 'edges',
'omicsintegrator1': 'edges',
'omicsintegrator2': 'edges',
'diamond': 'network',
'domino': 'network',
'pathlinker': 'network',
'allpairs': 'network',
'bowtiebuilder': 'edges',
'strwr': 'network',
'rwr': 'network',
'responsenet': 'edges'
}

OUTDIR = Path("test", "generate-inputs", "output")
EXPDIR = Path("test", "generate-inputs", "expected")

class TestGenerateInputs:
@classmethod
def setup_class(cls):
"""
Create the expected output directory
"""
Path(OUTDIR).mkdir(parents=True, exist_ok=True)
if OUTDIR.exists():
shutil.rmtree(OUTDIR)
OUTDIR.mkdir(parents=True, exist_ok=True)

def test_prepare_inputs_networks(self):
config_loc = Path("test", "generate-inputs", "inputs", "test_config.yaml")

config = Config.from_file(config_loc)
test_file = Path("test", "generate-inputs", "output", "test_pickled_dataset.pkl")

assert len(config.datasets) == 1
test_dataset = list(config.datasets.values())[0]
runner.merge_input(test_dataset, test_file)

for algo in algo_exp_file.keys():
inputs = runner.get_required_inputs(algo)
filename_map = {input_str: os.path.join("test", "generate-inputs", "output", f"{algo}-{input_str}.txt")
for input_str in inputs}
runner.prepare_inputs(algo, test_file, filename_map)
exp_file_name = algo_exp_file[algo]
assert filecmp.cmp(OUTDIR + f"{algo}-{exp_file_name}.txt", EXPDIR + f"{algo}-{exp_file_name}-expected.txt",
shallow=False)

for file in filename_map.values():
assert Path(file).exists()
test_dataset = next((ds for ds in config.datasets.values() if ds.label == "test_data"), None)
assert test_dataset is not None
merge_input(test_dataset, test_file)

for algo in algorithms.keys():
inputs = get_required_inputs(algo)
(OUTDIR / algo).mkdir(exist_ok=True)
filename_map = {input_str: str(OUTDIR / algo / f"{algo}-{input_str}.txt") for input_str in inputs}
prepare_inputs(algo, test_file, filename_map)
required_inputs = algorithms[algo].required_inputs
for exp_file_name in required_inputs:
assert filecmp.cmp(OUTDIR / algo / f"{algo}-{exp_file_name}.txt", EXPDIR / algo / f"{algo}-{exp_file_name}-expected.txt",
shallow=False), f"{algo} for {exp_file_name}.txt does not match up!"
Loading