Skip to content

Commit

Permalink
Run black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ErBarb committed Aug 4, 2024
1 parent 744f307 commit 4a707c5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def test_available_grpc():


def test_inference():
lib_test_inference(MODEL_NAME, SERVER_GRPC)
lib_test_inference(MODEL_NAME, SERVER_GRPC)
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def test_available_grpc():


def test_inference():
lib_test_inference(MODEL_NAME, SERVER_GRPC)
lib_test_inference(MODEL_NAME, SERVER_GRPC)
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
"Y": 20,
}

TERMINAL_ALPHABET = {"[]-": 30, "-[]": 31} # unmodified n terminus # unmodified c terminus
TERMINAL_ALPHABET = {
"[]-": 30,
"-[]": 31,
} # unmodified n terminus # unmodified c terminus

ALPHABET_MODS = {
"M[UNIMOD:35]": 21,
Expand Down Expand Up @@ -233,7 +236,14 @@
"REVERSE",
]
META_DATA_COLUMNS = SHARED_DATA_COLUMNS + META_DATA_ONLY_COLUMNS
MZML_ONLY_DATA_COLUMNS = ["INTENSITIES", "MZ", "MZ_RANGE", "RETENTION_TIME", "MASS_ANALYZER", "FRAGMENTATION"]
MZML_ONLY_DATA_COLUMNS = [
"INTENSITIES",
"MZ",
"MZ_RANGE",
"RETENTION_TIME",
"MASS_ANALYZER",
"FRAGMENTATION",
]
MZML_DATA_COLUMNS = SHARED_DATA_COLUMNS + MZML_ONLY_DATA_COLUMNS

TMT_MODS = {
Expand Down Expand Up @@ -275,7 +285,9 @@

IONS = ["y", "b"] # limited to single character unicode string when array is created
CHARGES = [1, 2, 3] # limited to uint8 (0-255) when array is created
POSITIONS = [x for x in range(1, 30)] # fragment numbers 1-29 -- limited to uint8 (0-255) when array is created
POSITIONS = [
x for x in range(1, 30)
] # fragment numbers 1-29 -- limited to uint8 (0-255) when array is created

ANNOTATION_FRAGMENT_TYPE = []
ANNOTATION_FRAGMENT_CHARGE = []
Expand All @@ -287,7 +299,11 @@
ANNOTATION_FRAGMENT_CHARGE.append(charge)
ANNOTATION_FRAGMENT_NUMBER.append(pos)

ANNOTATION = [ANNOTATION_FRAGMENT_TYPE, ANNOTATION_FRAGMENT_CHARGE, ANNOTATION_FRAGMENT_NUMBER]
ANNOTATION = [
ANNOTATION_FRAGMENT_TYPE,
ANNOTATION_FRAGMENT_CHARGE,
ANNOTATION_FRAGMENT_NUMBER,
]


########################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ def execute(self, requests):
peptide_in_1 = [x[0].decode("utf-8") for x in peptide_in_1]
peptide_in_2 = [x[0].decode("utf-8") for x in peptide_in_2]

peptide_2_sequence = [
s.replace("[UNIMOD:1898]", "") for s in peptide_in_2
]
peptide_2_sequence = [s.replace("[UNIMOD:1898]", "") for s in peptide_in_2]
peptide_in_2_mass = [compute_peptide_mass(s) for s in peptide_2_sequence]

crosslinker_position = [find_crosslinker_position(x) for x in peptide_in_1]
Expand All @@ -177,10 +175,15 @@ def execute(self, requests):
mask = create_masking(precursor_charges_in, peptide_length)
masked_peaks = apply_masking(peaks_in, mask)

fragmentmz = [initialize_peaks(seq, chg, mass, pos) for seq, chg, mass, pos in zip(peptide_in_1, charge, peptide_in_2_mass, crosslinker_position)]
fragmentmz = [
initialize_peaks(seq, chg, mass, pos)
for seq, chg, mass, pos in zip(
peptide_in_1, charge, peptide_in_2_mass, crosslinker_position
)
]
fragmentmz = np.array(fragmentmz)
fragmentmz = fragmentmz.astype("float32")

fragmentmz[np.isnan(masked_peaks)] = -1
masked_peaks[np.isnan(masked_peaks)] = -1

Expand Down
38 changes: 26 additions & 12 deletions models/Prosit/XL_Prosit_NMS2_Helper_annotation/1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@
import re



def find_crosslinker_position(peptide_sequence: str):
peptide_sequence = re.sub(r"\[UNIMOD:(?!1898).*?\]", "", peptide_sequence)
crosslinker_position = re.search(r"K(?=\[UNIMOD:1898\])", peptide_sequence)
crosslinker_position = crosslinker_position.start() + 1
return crosslinker_position


def gen_annotation_linear_pep(unmod_seq: str, precursor_charge: int):
peptide_length = len(unmod_seq)
ions = ["y", "b"]
positions = [x for x in range(1, 30)] # Generate positions 1 through 29
annotation = []
max_charge = 3 # Always consider three charges

for pos in positions:
for ion in ions:
for charge in range(1, max_charge + 1):
if charge > precursor_charge or pos >= peptide_length:
annotation.append(None) # Append None for invalid charges and positions beyond the sequence length
annotation.append(
None
) # Append None for invalid charges and positions beyond the sequence length
else:
annotation.append(f"{ion}{pos}+{charge}")

return annotation


def gen_annotation_xl(annotation, unmod_seq: str, crosslinker_position: int):
peptide_length = len(unmod_seq)

Expand All @@ -39,21 +42,24 @@ def gen_annotation_xl(annotation, unmod_seq: str, crosslinker_position: int):
index = annotation.index(b_ion)
annotation[index] = f"b_xl{i}+{charge}"

# Correcting y-ion annotation to move backward from the end
# Correcting y-ion annotation to move backward from the end
for i in range(peptide_length, 1, -1):
for charge in ["1", "2", "3"]:
y_ion = f"y{i}+{charge}"
if y_ion in annotation:
index = annotation.index(y_ion)

# Only annotate with '_xl' if within the crosslinker adjusted position
if i >= peptide_length - crosslinker_position + 1:
annotation[index] = f"y_xl{i}+{charge}"
else:
annotation[index] = y_ion # this line could be omitted if y_ions need no re-assignment
annotation[index] = (
y_ion # this line could be omitted if y_ions need no re-assignment
)

return np.array(annotation).astype(np.object_)


class TritonPythonModel:
def initialize(self, args):
self.model_config = json.loads(args["model_config"])
Expand All @@ -67,20 +73,28 @@ def execute(self, requests):
annotation = np.empty((0, 174))

for request in requests:
batchsize = pb_utils.get_input_tensor_by_name(request, "precursor_charges").as_numpy().shape[0]
precursor_charges = pb_utils.get_input_tensor_by_name(request, "precursor_charges").as_numpy()
batchsize = (
pb_utils.get_input_tensor_by_name(request, "precursor_charges")
.as_numpy()
.shape[0]
)
precursor_charges = pb_utils.get_input_tensor_by_name(
request, "precursor_charges"
).as_numpy()

peptide_sequences_1 = pb_utils.get_input_tensor_by_name(
request, "peptide_sequences_1"
).as_numpy()

for i in range(batchsize):
regular_sequence = peptide_sequences_1[i][0].decode("utf-8")
crosslinker_position = find_crosslinker_position(regular_sequence)
precursor_charge = int(precursor_charges[i][0])
unmod_seq = re.sub(r"\[.*?\]", "", regular_sequence)
annotation_lin = gen_annotation_linear_pep(unmod_seq, precursor_charge)
annotation_i = gen_annotation_xl(annotation_lin, unmod_seq, crosslinker_position)
annotation_i = gen_annotation_xl(
annotation_lin, unmod_seq, crosslinker_position
)
annotation = np.vstack((annotation, annotation_i))

t = pb_utils.Tensor("annotation", annotation)
Expand All @@ -89,4 +103,4 @@ def execute(self, requests):
return responses

def finalize(self):
pass
pass

0 comments on commit 4a707c5

Please sign in to comment.