Skip to content

Commit

Permalink
added protein name reformatting for libraries with single, non-list p…
Browse files Browse the repository at this point in the history
…roteins
  • Loading branch information
CCranney committed Nov 24, 2023
1 parent 8bf4fec commit 7fa55aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/zodiaq/loaders/library/libraryLoaderStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,18 @@ def load_zodiaq_library_dict_from_file(
random.seed(0)
self._load_raw_library_object_from_file(libraryFilePath)
zodiaqLibDict = self._format_raw_library_object_into_zodiaq_library_dict()
format_proteins_into_list_format(zodiaqLibDict)
if determine_if_decoys_should_be_generated(zodiaqLibDict) and not isTest:
zodiaqLibDict = add_decoys_to_zodiaq_library(zodiaqLibDict)
return zodiaqLibDict


def format_proteins_into_list_format(zodiaqLibDict):
for key, value in zodiaqLibDict.items():
if value["proteinName"] and not value["proteinName"][:1].isdigit():
value["proteinName"] = f'1/{value["proteinName"]}'


def create_peaks_from_mz_intensity_lists_and_zodiaq_key_id(
mz: list, intensities: list, id: int
) -> list:
Expand Down
25 changes: 22 additions & 3 deletions tests/unit/loaders/library/test_LibraryLoaderStrategy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from zodiaq.loaders.library.libraryLoaderStrategy import (
create_peaks_from_mz_intensity_lists_and_zodiaq_key_id,
remove_low_intensity_peaks_below_max_peak_num,
format_proteins_into_list_format,
)
import pytest

Expand All @@ -26,7 +27,7 @@ def testPeaks():
]


def test__library_loader_strategy_traml__create_peaks_from_mz_intensity_lists_and_zodiaq_key_id(
def test__library_loader_strategy__create_peaks_from_mz_intensity_lists_and_zodiaq_key_id(
testPeaks,
):
numPeaks = 15
Expand All @@ -39,7 +40,7 @@ def test__library_loader_strategy_traml__create_peaks_from_mz_intensity_lists_an
assert peaks == testPeaks


def test__library_loader_strategy_traml__remove_low_intensity_peaks_below_max_peak_num(
def test__library_loader_strategy__remove_low_intensity_peaks_below_max_peak_num(
testPeaks,
):
maxPeakNum = 10
Expand All @@ -61,7 +62,7 @@ def test__library_loader_strategy_traml__remove_low_intensity_peaks_below_max_pe
assert reducedTestPeaks == expectedReducedTestPeaks


def test__library_loader_strategy_traml__remove_low_intensity_peaks_below_max_peak_num__all_peaks_returned_when_length_fewer_than_max_peak_num(
def test__library_loader_strategy__remove_low_intensity_peaks_below_max_peak_num__all_peaks_returned_when_length_fewer_than_max_peak_num(
testPeaks,
):
maxPeakNum = 10
Expand All @@ -81,3 +82,21 @@ def test__library_loader_strategy_traml__remove_low_intensity_peaks_below_max_pe
shortTestPeaks, maxPeakNum
)
assert reducedShortTestPeaks == expectedReducedShortTestPeaks


def test__library_loader_strategy__format_proteins_into_list_format():
zodiaqLibraryDict = {
(100.0, "PEPTIDE"): {
"proteinName": "PROTEIN",
}
}
format_proteins_into_list_format(zodiaqLibraryDict)
assert zodiaqLibraryDict[(100.0, "PEPTIDE")]["proteinName"] == "1/PROTEIN"

zodiaqLibraryDict = {
(200.0, "PEPTIDE"): {
"proteinName": "",
}
}
format_proteins_into_list_format(zodiaqLibraryDict)
assert zodiaqLibraryDict[(200.0, "PEPTIDE")]["proteinName"] == ""

0 comments on commit 7fa55aa

Please sign in to comment.