Skip to content

Commit

Permalink
Add tests for invalid 4th edge column
Browse files Browse the repository at this point in the history
  • Loading branch information
agitter committed Dec 3, 2023
1 parent 7bc9e3e commit d918c00
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion spras/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Methods and intermediate state for loading data and putting it into pandas tables for use by pathway reconstruction algorithms.
"""


class Dataset:

NODE_ID = "NODEID"
Expand Down Expand Up @@ -88,8 +89,11 @@ def load_files_from_dict(self, dataset_dict):
"Direction",
]

# Make directionality column case insensitive
self.interactome["Direction"] = self.interactome["Direction"].str.upper()
if not self.interactome["Direction"].isin(["U", "D"]).all():
raise ValueError(f"The Direction column for {self.label} contains values other than U and D")
raise ValueError(f"The Direction column for {self.label} edge file {interactome_loc} contains values "
f"other than U and D")

else:
raise ValueError(
Expand Down
6 changes: 6 additions & 0 deletions test/interactome/input/test-network-invalid-value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A B 0.5 U
B C 0.5 D
C B 0.5 D
A D 0.5 U
C D 0.5 ?
D C 0.5 D
6 changes: 6 additions & 0 deletions test/interactome/input/test-network-missing-value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A B 0.5 U
B C 0.5 D
C B 0.5
A D 0.5 U
C D 0.5 D
D C 0.5 D
26 changes: 26 additions & 0 deletions test/interactome/test_interactome.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pathlib import Path

import pandas as pd
import pytest

from spras.dataset import Dataset
from spras.interactome import (
add_constant,
add_directionality_constant,
Expand Down Expand Up @@ -86,3 +88,27 @@ def test_reinsert_col_dir(self):
df.to_csv(OUT_DIR + "/output_reinsert_direction_col_dir.txt", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR + "/reinsert_dir.txt", sep='\t', header=None, names=expected_columns)
assert df.equals(expected_df)

def test_invalid_value(self):
"""
Test error is thrown when fourth column of edge file has an invalid value (not D or U)
"""
with pytest.raises(ValueError):
dataset_info = {'label': 'test',
'edge_files': ['test-network-invalid-value.txt'],
'node_files': None, # Will raise error before loading node table
'data_dir': IN_DIR
}
Dataset(dataset_info)

def test_missing_value(self):
"""
Test error is thrown when fourth column of edge file is missing
"""
with pytest.raises(ValueError):
dataset_info = {'label': 'test',
'edge_files': ['test-network-missing-value.txt'],
'node_files': None, # Will raise error before loading node table
'data_dir': IN_DIR
}
Dataset(dataset_info)

0 comments on commit d918c00

Please sign in to comment.