Skip to content

Commit 2f53db1

Browse files
committed
add function to get peptides by deuteration type
1 parent e0c58dd commit 2f53db1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hdxms_datasets/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import numpy as np
99

10+
from hdxms_datasets.models import DeuterationType, Peptides
11+
1012

1113
def diff_sequence(a: str, b: str) -> float:
1214
return difflib.SequenceMatcher(None, a, b).ratio()
@@ -184,3 +186,13 @@ def peptide_redundancy(
184186
redundancy[i0:i1] += 1
185187

186188
return r_number, redundancy
189+
190+
191+
def get_peptides_by_type(peptides: list[Peptides], deuteration_type: DeuterationType) -> Peptides:
192+
"""Get peptides of a specific deuteration type."""
193+
matching_peptides = [p for p in peptides if p.deuteration_type == deuteration_type]
194+
if not matching_peptides:
195+
raise ValueError(f"No peptides found with deuteration type: {deuteration_type}")
196+
if len(matching_peptides) > 1:
197+
raise ValueError(f"Multiple peptides found with deuteration type: {deuteration_type}")
198+
return matching_peptides[0]

0 commit comments

Comments
 (0)