diff --git a/pymochi/data.py b/pymochi/data.py index d064a31..bad2218 100644 --- a/pymochi/data.py +++ b/pymochi/data.py @@ -966,9 +966,11 @@ def one_hot_encode_interactions( all_features_flat = list(itertools.chain(*list(all_features.values()))) #Check if all interaction features exist (i.e. with mutation order>1) - if len([i for i in features if (i not in all_features_flat) and (len(i.split('_'))>1)]) != 0: - print("Error: Invalid feature names.") - raise ValueError + invalid_features = [i for i in features if (i not in all_features_flat) and (len(i.split('_'))>1)] + if len(invalid_features) != 0: + # print("Error: Invalid feature names.") + print("Warning: Invalid feature names: "+",".join(invalid_features)) + # raise ValueError #Select interactions int_list = [] @@ -1059,9 +1061,11 @@ def filter_features( :returns: filtered DataFrame. """ #Check if all features exist - if len([i for i in features if i not in input_df.columns]) != 0: - print("Error: Invalid feature names.") - raise ValueError + invalid_features = [i for i in features if i not in input_df.columns] + if len(invalid_features) != 0: + # print("Error: Invalid feature names.") + print("Warning: Invalid feature names: "+",".join(invalid_features)) + # raise ValueError #Filter features features_order = [i for i in input_df.columns if i in features] return input_df.loc[:,features_order] diff --git a/pymochi/tests/test_pymochi.py b/pymochi/tests/test_pymochi.py index 2f6d745..52c5117 100644 --- a/pymochi/tests/test_pymochi.py +++ b/pymochi/tests/test_pymochi.py @@ -95,23 +95,23 @@ def test_MochiData_invalid_features_argument_trait_names(capsys): captured = capsys.readouterr() assert captured.out == "Error: One or more invalid trait names in 'features' argument.\n" and e_info -def test_MochiData_invalid_features_argument_features(capsys): - """Test MochiData initialization with invalid features argument features""" - model_design = pd.read_csv(Path(__file__).parent.parent / "data/model_design.txt", sep = "\t", index_col = False) - model_design['file'] = [ - str(Path(__file__).parent.parent / "data/fitness_abundance.txt"), - str(Path(__file__).parent.parent / "data/fitness_binding.txt")] - #Create a problematic features dict - features = { - 'Folding': ["WT"], - 'Binding': ["WT", "Hello World!"]} - with pytest.raises(ValueError) as e_info: - MochiData( - model_design = model_design, - features = features) - captured = capsys.readouterr() - print(captured.out) - assert captured.out.split("\n")[-2] == "Error: Invalid feature names." and e_info +# def test_MochiData_invalid_features_argument_features(capsys): +# """Test MochiData initialization with invalid features argument features""" +# model_design = pd.read_csv(Path(__file__).parent.parent / "data/model_design.txt", sep = "\t", index_col = False) +# model_design['file'] = [ +# str(Path(__file__).parent.parent / "data/fitness_abundance.txt"), +# str(Path(__file__).parent.parent / "data/fitness_binding.txt")] +# #Create a problematic features dict +# features = { +# 'Folding': ["WT"], +# 'Binding': ["WT", "Hello World!"]} +# with pytest.raises(ValueError) as e_info: +# MochiData( +# model_design = model_design, +# features = features) +# captured = capsys.readouterr() +# print(captured.out) +# assert captured.out.split("\n")[-2] == "Warning: Invalid feature names: Hello World!" and e_info def test_MochiData_invalid_features_argument_missingWT(capsys): """Test MochiData initialization with invalid features argument missing WT"""