Skip to content

Commit

Permalink
added generate inputs test, cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Sep 19, 2023
1 parent 713279a commit 1198c9a
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/analysis/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def summarize_networks(file_paths: Iterable[Path], node_table: pd.DataFrame) ->
def degree(g):
return dict(g.degree)


# TODO: redo .run code to work on mixed graphs
# stats is just a list of functions to apply to the graph.
# They should take as input a networkx graph or digraph but may have any output.
# stats = [degree, nx.clustering, nx.betweenness_centrality]
Expand Down
10 changes: 0 additions & 10 deletions src/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,10 @@ def load_files_from_dict(self, dataset_dict):
data_loc = dataset_dict["data_dir"]

# Load everything as pandas tables
print("about to create self.interactome")
print(data_loc)
print(interactome_loc)

with open(os.path.join(data_loc, interactome_loc), "r") as f:
for _i in range(9): # first 5 lines
print(f.readline())

self.interactome = pd.read_table(
os.path.join(data_loc, interactome_loc), sep="\t", header=None
)
print(self.interactome)
num_cols = self.interactome.shape[1]
print(num_cols)
if num_cols == 3:

self.interactome.columns = ["Interactor1", "Interactor2", "Weight"]
Expand Down
1 change: 0 additions & 1 deletion src/domino.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def parse_output(raw_pathway_file, standardized_pathway_file):
edges_df['target'] = edges_df['target'].apply(post_domino_id_transform)
edges_df = readd_direction_col_undirected(edges_df)

print(edges_df)
edges_df.to_csv(standardized_pathway_file, sep='\t', header=False, index=False)


Expand Down
3 changes: 3 additions & 0 deletions test/PrepareInputs/expected/ap-network-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Interactor1 Interactor2 Weight
A B 0.98
B C 0.77
3 changes: 3 additions & 0 deletions test/PrepareInputs/expected/d-network-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID_interactor_A ppi ID_interactor_B
ENSG0A ppi ENSG0B
ENSG0B ppi ENSG0C
4 changes: 4 additions & 0 deletions test/PrepareInputs/expected/mcf-edges-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A B 0.98
B C 0.77
B A 0.98
C B 0.77
2 changes: 2 additions & 0 deletions test/PrepareInputs/expected/meo-edges-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A (pp) B 0.98
B (pp) C 0.77
3 changes: 3 additions & 0 deletions test/PrepareInputs/expected/oi1-network-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
protein1 protein2 weight directionality
A B 0.98 U
B C 0.77 U
3 changes: 3 additions & 0 deletions test/PrepareInputs/expected/oi2-network-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
protein1 protein2 cost
A B 0.52
B C 0.73
5 changes: 5 additions & 0 deletions test/PrepareInputs/expected/pl-network-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Interactor1 Interactor2 Weight
A B 0.98
B C 0.77
B A 0.98
C B 0.77
73 changes: 73 additions & 0 deletions test/PrepareInputs/test_prepare_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import filecmp
import os
import shutil
from pathlib import Path

import yaml

from src import runner

OUTDIR = "test/PrepareInputs/output/"
EXPDIR = "test/PrepareInputs/expected/"
class TestPrepareInputs:
def setup_class(cls):
"""
Create the expected output directory
"""
Path(OUTDIR).mkdir(parents=True, exist_ok=True)

def test_prepare_inputs(self):
config_loc = os.path.join("config", "config.yaml")

with open(config_loc) as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)
test_file = "test/PrepareInputs/output/test_pickled_dataset.pkl"

for dataset in config["datasets"]:
runner.merge_input(dataset, test_file)

# Test PathLinker
filename_map = {"nodetypes": os.path.join("test","PrepareInputs", "output", "pl-nodetypes.txt"),
"network": os.path.join("test","PrepareInputs", "output", "pl-network.txt")}
runner.prepare_inputs("pathlinker", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'pl-network.txt', EXPDIR + 'pl-network-expected.txt')

# Test OmicsIntegrator1
filename_map = {"prizes": os.path.join("test","PrepareInputs", "output", "oi1-prizes.txt"),
"edges": os.path.join("test","PrepareInputs", "output", "oi1-network.txt")}
runner.prepare_inputs("omicsintegrator1", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'oi1-network.txt', EXPDIR + 'oi1-network-expected.txt')

# Test OmicsIntegrator2
filename_map = {"prizes": os.path.join("test","PrepareInputs", "output", "oi2-prizes.txt"),
"edges": os.path.join("test","PrepareInputs", "output", "oi2-network.txt")}
runner.prepare_inputs("omicsintegrator2", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'oi2-network.txt', EXPDIR + 'oi2-network-expected.txt')

# Test MEO
filename_map = {"sources": os.path.join("test","PrepareInputs", "output", "meo-sources.txt"),
"targets": os.path.join("test","PrepareInputs", "output", "meo-targets.txt"),
"edges": os.path.join("test","PrepareInputs", "output", "meo-edges.txt")}
runner.prepare_inputs("meo", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'meo-edges.txt', EXPDIR + 'meo-edges-expected.txt')

# Test MCF
filename_map = {"sources": os.path.join("test","PrepareInputs", "output", "mcf-sources.txt"),
"targets": os.path.join("test","PrepareInputs", "output", "mcf-targets.txt"),
"edges": os.path.join("test","PrepareInputs", "output", "mcf-edges.txt")}
runner.prepare_inputs("mincostflow", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'mcf-edges.txt', EXPDIR + 'mcf-edges-expected.txt')

# Test AllPairs
filename_map = {"nodetypes": os.path.join("test","PrepareInputs", "output", "ap-nodetypes.txt"),
"network": os.path.join("test","PrepareInputs", "output", "ap-network.txt")}
runner.prepare_inputs("allpairs", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'ap-network.txt', EXPDIR + 'ap-network-expected.txt')

# Test Domino
filename_map = {"network": os.path.join("test","PrepareInputs", "output", "d-network.txt"),
"active_genes": os.path.join("test","PrepareInputs", "output", "d-active_genes.txt")}
runner.prepare_inputs("domino", test_file, filename_map)
assert filecmp.cmp(OUTDIR +'d-network.txt', EXPDIR + 'd-network-expected.txt')

break # only run dataset 0
40 changes: 0 additions & 40 deletions test/test_prepare_inputs.py

This file was deleted.

0 comments on commit 1198c9a

Please sign in to comment.