Skip to content
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
2 changes: 1 addition & 1 deletion autopeptideml/apml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .reps import RepEngineBase, PLMs, CLMs, FPs


__version__ = '2.0.4'
__version__ = '2.0.6'


class AutoPeptideML:
Expand Down
19 changes: 10 additions & 9 deletions autopeptideml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,18 @@ def predict(result_dir: str, features_path: str,
if n_jobs == -1:
n_jobs = cpu_count()

if not osp.isfile(metadata_path):
raise RuntimeError("No metadata file was found. Check you're using the correct AutoPeptideML version.",
"Try: pip install autopeptideml<=2.0.1",
"Alternatively, check that the result_dir path is properly formatted.")
if osp.isfile(metadata_path):
metadata = yaml.safe_load(open(metadata_path))
print(f"Using model created on {metadata['start-time']} with AutoPeptideML v.{metadata['autopeptideml-version']}")

# raise RuntimeError("No metadata file was found. Check you're using the correct AutoPeptideML version.",
# "Try: pip install autopeptideml<=2.0.1",
# "Alternatively, check that the result_dir path is properly formatted.")
if not osp.isdir(ensemble_path):
raise RuntimeError("No ensemble path was found in result_dir. Check you're using the correct AutoPeptideML version.",
"Try: pip install autopeptideml<=2.0.1",
"Alternatively, check that the result_dir path is properly formatted.")

metadata = yaml.safe_load(open(metadata_path))
print(f"Using model created on {metadata['start-time']} with AutoPeptideML v.{metadata['autopeptideml-version']}")
ensemble = VotingEnsemble.load(ensemble_path)
df = read_data(features_path)
if feature_field is None:
Expand Down Expand Up @@ -281,9 +282,10 @@ def predict(result_dir: str, features_path: str,
verbose=True)
x = {}
for rep in ensemble.reps:
if rep in x:
continue
if rep in PLMs:
from .reps.lms import RepEngineLM

repengine = RepEngineLM(rep)
repengine.move_to_device(device)
x[rep] = repengine.compute_reps(
Expand All @@ -292,7 +294,6 @@ def predict(result_dir: str, features_path: str,

elif rep in CLMs:
from .reps.lms import RepEngineLM

repengine = RepEngineLM(rep)
repengine.move_to_device(device)
x[rep] = repengine.compute_reps(
Expand All @@ -310,7 +311,7 @@ def predict(result_dir: str, features_path: str,

try:
preds, std = ensemble.predict_proba(x)
preds = preds[:, 1]
# preds = preds
except AttributeError:
preds, std = ensemble.predict(x)
if 'pipe-seq' in df:
Expand Down
17 changes: 13 additions & 4 deletions autopeptideml/train/architectures.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def predict(self, x: np.ndarray):
:return: Predicted values from the ONNX model.
:rtype: np.ndarray
"""
input_dict = {"float_input": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
try:
input_dict = {"float_input": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
except ValueError:
input_dict = {"X": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
return preds[0]

def predict_proba(self, x: np.ndarray):
Expand All @@ -62,8 +66,12 @@ def predict_proba(self, x: np.ndarray):
:return: Array of predicted probabilities for the positive class (shape: [n_samples]).
:rtype: np.ndarray
"""
input_dict = {"float_input": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
try:
input_dict = {"float_input": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
except ValueError:
input_dict = {"X": x.astype(np.float32)}
preds = self.session.run(None, input_dict)
return np.array([i[1] for i in preds[1]])


Expand Down Expand Up @@ -230,6 +238,7 @@ def load(self, path) -> "VotingEnsemble":
raise RuntimeError(f"File: {filepath} in path: {path} is not ONNX model.")
models.append(OnnxModel(filepath))
reps.append(osp.basename(filepath).split("_")[1].split('.')[0])
reps = [r if r != 'class' else 'esm2-8m' for r in reps]
return VotingEnsemble(models, reps)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ def get_files_in_dir(path: Path, base: Path) -> list:
name='autopeptideml',
packages=find_packages(exclude=['examples']),
url='https://ibm.github.io/AutoPeptideML/',
version='2.0.5',
version='2.0.6',
zip_safe=False,
)