Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dataset Label Checking #169

Merged
merged 8 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ algorithms:
# Assume that if a dataset label does not change, the lists of associated input files do not change
datasets:
-
# Labels can only contain letters, numbers, or underscores
label: data0
node_files: ["node-prizes.txt", "sources.txt", "targets.txt"]
# DataLoader.py can currently only load a single edge file, which is the primary network
Expand Down
2 changes: 1 addition & 1 deletion config/egfr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ datasets:
data_dir: input
edge_files:
- phosphosite-irefindex13.0-uniprot.txt
label: tps-egfr
label: tps_egfr
node_files:
- tps-egfr-prizes.txt
other_files: []
Expand Down
6 changes: 6 additions & 0 deletions spras/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import copy as copy
import itertools as it
import os
import re

import numpy as np
import yaml
Expand Down Expand Up @@ -140,6 +141,11 @@ def process_config(self, raw_config):
# Convert to dicts to simplify the yaml logging
self.datasets = {dataset["label"]: dict(dataset) for dataset in raw_config["datasets"]}

for key in self.datasets:
pattern = r'^\w+$'
ntalluri marked this conversation as resolved.
Show resolved Hide resolved
if not bool(re.match(pattern, key)):
raise ValueError(f"Dataset label \'{key}\' contains invalid values. Dataset labels can only contain letters, numbers, or underscores.")

# Code snipped from Snakefile that may be useful for assigning default labels
# dataset_labels = [dataset.get('label', f'dataset{index}') for index, dataset in enumerate(datasets)]
# Maps from the dataset label to the dataset list index
Expand Down
17 changes: 17 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ def test_config_container_registry(self):
test_config["container_registry"]["owner"] = ""
config.init_global(test_config)
assert (config.config.container_prefix == config.DEFAULT_CONTAINER_PREFIX)

def test_error_dataset_label(self):
test_config = get_test_config()
error_test_dicts = [{"label":"test$"}, {"label":"@test'"}, {"label":"[test]"}, {"label":"test-test"}, {"label":"✉"}]

for test_dict in error_test_dicts:
test_config["datasets"]= [test_dict]
with pytest.raises(ValueError): #raises error if any chars other than letters, numbers, or underscores are in dataset label
config.init_global(test_config)

def test_correct_dataset_label(self):
test_config = get_test_config()
correct_test_dicts = [{"label":"test"}, {"label":"123"}, {"label":"test123"}, {"label":"123test"}, {"label":"_"}, {"label":"test_test"}, {"label":"_test"}, {"label":"test_"}]

for test_dict in correct_test_dicts:
test_config["datasets"]= [test_dict]
config.init_global(test_config) # no error should be raised
Loading