Skip to content

Commit 76f71e2

Browse files
authored
Merge pull request #2 from CompOmics/pretrained_model_choose
Black improvements
2 parents 9e26b39 + c45ea3b commit 76f71e2

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

ideeplc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""iDeepLC: A deep Learning-based retention time predictor for unseen modified peptides with a novel encoding system"""
22

3-
__version__ = "1.2.1"
3+
__version__ = "1.3.0"

tests/test_CLI.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import unittest
33
from ideeplc.__main__ import _argument_parser
44

5+
56
class TestCLI(unittest.TestCase):
67
def test_argument_parser(self):
78
"""Test the CLI argument parser."""
@@ -13,5 +14,6 @@ def test_argument_parser(self):
1314
self.assertTrue(args.save, "Save argument should be True")
1415
self.assertTrue(args.calibrate, "Calibrate argument should be True")
1516

17+
1618
if __name__ == "__main__":
17-
unittest.main()
19+
unittest.main()

tests/test_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ideeplc.config import get_config
22

3+
34
def test_get_config():
45
"""Test the get_config function to ensure it returns a valid configuration."""
56
config = get_config(epoch=5) # Adjust epoch for testing purposes
@@ -8,4 +9,5 @@ def test_get_config():
89
assert config["epochs"] == 5, "Epoch in config should match the input value"
910
assert "learning_rate" in config, "'learning_rate' should be in config"
1011

11-
test_get_config()
12+
13+
test_get_config()

tests/test_data_initialize.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22
import pandas as pd
33
from ideeplc.data_initialize import data_initialize
44

5+
56
def test_data_initialize():
67
"""Test the data_initialize function."""
7-
test_csv_path = "ideeplc/example_input/Hela_deeprt.csv" # Path to a sample test CSV file
8+
test_csv_path = (
9+
"ideeplc/example_input/Hela_deeprt.csv" # Path to a sample test CSV file
10+
)
811
matrix_input, x_shape = data_initialize(csv_path=test_csv_path)
912

1013
df_3 = pd.DataFrame(matrix_input[3][0])
11-
expected = pd.DataFrame({
12-
1: [1.286264, 0.209934, 12.0, 23.0, 2.0, 5.0],
13-
2: [-1.076330, -2.715786, 6.0, 11.0, 7.0, 2.0],
14-
3: [-1.435417, 1.267611, 14.0, 16.0, 4.0, 2.0],
15-
4: [-1.280370, -2.870834, 6.0, 10.0, 4.0, 2.0]
16-
}, index=[0, 1, 2, 3, 4, 5])
14+
expected = pd.DataFrame(
15+
{
16+
1: [1.286264, 0.209934, 12.0, 23.0, 2.0, 5.0],
17+
2: [-1.076330, -2.715786, 6.0, 11.0, 7.0, 2.0],
18+
3: [-1.435417, 1.267611, 14.0, 16.0, 4.0, 2.0],
19+
4: [-1.280370, -2.870834, 6.0, 10.0, 4.0, 2.0],
20+
},
21+
index=[0, 1, 2, 3, 4, 5],
22+
)
1723

1824
pd.testing.assert_frame_equal(df_3.iloc[:6, 1:5], expected, check_dtype=False)
1925
assert matrix_input is not None, "Matrix input should not be None"
2026
assert isinstance(x_shape, tuple), "x_shape should be a tuple"
2127
assert x_shape == (1, 41, 62), "Expected shape of x is (1, 41, 62)"
22-

tests/test_model_save_path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def test_get_model_save_path():
88
pretrained_model, model_dir = get_model_save_path()
99
assert isinstance(pretrained_model, Path), "Model path should be a Path object"
1010
assert isinstance(model_dir, Path), "Model directory should be a Path object"
11-
assert pretrained_model.name == "pretrained_model.pth", "Model name should be 'pretrained_model.pth'"
12-
13-
11+
assert (
12+
pretrained_model.name == "pretrained_model.pth"
13+
), "Model name should be 'pretrained_model.pth'"

tests/test_prediction_calibration.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@
77
from ideeplc.config import get_config
88
from ideeplc.ideeplc_core import get_model_save_path
99

10+
1011
def test_predict():
1112
"""Test the predict function."""
1213
# Mock data and model
1314
config = get_config()
1415
pretrained_model, model_dir = get_model_save_path()
1516

16-
test_csv_path = "ideeplc/example_input/Hela_deeprt.csv" # Path to a sample test CSV file
17+
test_csv_path = (
18+
"ideeplc/example_input/Hela_deeprt.csv" # Path to a sample test CSV file
19+
)
1720
matrix_input, x_shape = data_initialize(csv_path=test_csv_path)
18-
dataloader = DataLoader(matrix_input, batch_size=config["batch_size"], shuffle=False)
21+
dataloader = DataLoader(
22+
matrix_input, batch_size=config["batch_size"], shuffle=False
23+
)
1924
model = MyNet(x_shape=x_shape, config=config)
2025
device = torch.device("cpu")
21-
model.load_state_dict(torch.load(pretrained_model, map_location=device), strict=False)
26+
model.load_state_dict(
27+
torch.load(pretrained_model, map_location=device), strict=False
28+
)
2229
loss_fn = torch.nn.L1Loss()
2330

24-
2531
pred_loss, pred_cor, pred_results, ground_truth = predict(
2632
model=model,
2733
dataloader_input=dataloader,
2834
loss_fn=loss_fn,
2935
device=device,
3036
calibrate=False,
3137
input_file=test_csv_path,
32-
save_results=False
38+
save_results=False,
3339
)
3440
assert pred_loss is not None, "Prediction loss should not be None"
3541
assert pred_results is not None, "Prediction results should not be None"
@@ -43,9 +49,10 @@ def test_predict():
4349
device=device,
4450
calibrate=True,
4551
input_file=test_csv_path,
46-
save_results=False
52+
save_results=False,
4753
)
4854

4955
assert pred_loss < 200, "Calibrated prediction loss should be less than 200"
50-
assert pred_cor > 0.95, "Calibrated prediction correlation should be greater than 0.95"
51-
56+
assert (
57+
pred_cor > 0.95
58+
), "Calibrated prediction correlation should be greater than 0.95"

0 commit comments

Comments
 (0)