From deee4160b8275838e3e17261d3626d992a70579b Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Tue, 21 Nov 2023 11:03:18 +0100 Subject: [PATCH] adding predictor structure to algorithm --- imspy/imspy/algorithm/ccs/__init__.py | 0 imspy/imspy/algorithm/ccs/predictors.py | 0 imspy/imspy/algorithm/intensity/__init__.py | 0 imspy/imspy/algorithm/ionization/__init__.py | 0 .../imspy/algorithm/ionization/predictors.py | 0 imspy/imspy/algorithm/pretrained/__init__.py | 0 imspy/imspy/algorithm/rt/__init__.py | 0 imspy/imspy/algorithm/rt/predictors.py | 29 +++++++++++++++++++ 8 files changed, 29 insertions(+) create mode 100644 imspy/imspy/algorithm/ccs/__init__.py create mode 100644 imspy/imspy/algorithm/ccs/predictors.py create mode 100644 imspy/imspy/algorithm/intensity/__init__.py create mode 100644 imspy/imspy/algorithm/ionization/__init__.py create mode 100644 imspy/imspy/algorithm/ionization/predictors.py create mode 100644 imspy/imspy/algorithm/pretrained/__init__.py create mode 100644 imspy/imspy/algorithm/rt/__init__.py create mode 100644 imspy/imspy/algorithm/rt/predictors.py diff --git a/imspy/imspy/algorithm/ccs/__init__.py b/imspy/imspy/algorithm/ccs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/ccs/predictors.py b/imspy/imspy/algorithm/ccs/predictors.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/intensity/__init__.py b/imspy/imspy/algorithm/intensity/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/ionization/__init__.py b/imspy/imspy/algorithm/ionization/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/ionization/predictors.py b/imspy/imspy/algorithm/ionization/predictors.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/pretrained/__init__.py b/imspy/imspy/algorithm/pretrained/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/rt/__init__.py b/imspy/imspy/algorithm/rt/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/imspy/imspy/algorithm/rt/predictors.py b/imspy/imspy/algorithm/rt/predictors.py new file mode 100644 index 00000000..84b3ec63 --- /dev/null +++ b/imspy/imspy/algorithm/rt/predictors.py @@ -0,0 +1,29 @@ +import numpy as np +import tensorflow as tf +import importlib.resources as resources + +""" +def get_model_path(model_name: str) -> str: + return resources.files('ionmob.pretrained_models').joinpath(model_name) + + +def get_gru_predictor(model_name: str = 'GRUPredictor') -> tf.keras.models.Model: + return tf.keras.models.load_model(get_model_path(model_name)) +""" + + +class ProjectToInitialSqrtCCS(tf.keras.layers.Layer): + """ + Simple sqrt regression layer, calculates ccs value as linear mapping from mz, charge -> ccs + """ + + def __init__(self, slopes, intercepts): + super(ProjectToInitialSqrtCCS, self).__init__() + self.slopes = tf.constant([slopes]) + self.intercepts = tf.constant([intercepts]) + + def call(self, inputs, **kwargs): + mz, charge = inputs[0], inputs[1] + # since charge is one-hot encoded, can use it to gate linear prediction by charge state + return tf.expand_dims(tf.reduce_sum((self.slopes * tf.sqrt(mz) + self.intercepts) * tf.squeeze(charge), axis=1), + 1)