Skip to content

Commit

Permalink
Merge pull request #15 from hgb-bin-proteomics/develop
Browse files Browse the repository at this point in the history
v1.2.2
  • Loading branch information
michabirklbauer authored Jul 22, 2024
2 parents 9c65d3a + 137a3c6 commit 54a16d9
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 64 deletions.
9 changes: 5 additions & 4 deletions create_spectral_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# [email protected]

# version tracking
__version = "1.2.1"
__date = "2024-07-18"
__version = "1.2.2"
__date = "2024-07-21"

# REQUIREMENTS
# pip install pandas
Expand Down Expand Up @@ -310,6 +310,7 @@ def get_positions_in_protein(row: pd.Series) -> Dict[str, int]:
return {"A": pep_pos_A + xl_pos_A, "B": pep_pos_B + xl_pos_B}

##### DECOY GENERATION #####
# decoy generation implemented as described by Zhang et al. here: https://doi.org/10.1021/acs.jproteome.7b00614

def generate_decoy_csm(row: pd.Series, crosslinker: str = CROSSLINKER) -> pd.Series:
"""
Expand Down Expand Up @@ -722,7 +723,7 @@ def main(spectra_file: Union[List[str], List[BinaryIO]] = SPECTRA_FILE,
iRT_m: float = iRT_PARAMS["iRT_m"],
iRT_t: float = iRT_PARAMS["iRT_t"],
is_streamlit: bool = False,
save_output: bool = True) -> pd.DataFrame:
save_output: bool = True) -> Dict[str, pd.DataFrame]:

if is_streamlit:
print("INFO: Creating spectral library with input files:\nSpectra: " +
Expand Down Expand Up @@ -991,7 +992,7 @@ def main(spectra_file: Union[List[str], List[BinaryIO]] = SPECTRA_FILE,
print("SUCCESS: Decoy Spectral library created with filename:")
print(".".join(csms_file.split(".")[:-1]) + "_spectralLibraryDECOY.csv")

return spectral_library
return {"TargetLib": spectral_library, "DecoyLib": spectral_library_decoy}

##### SCRIPT #####

Expand Down
151 changes: 91 additions & 60 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,108 @@
# https://github.com/michabirklbauer/
# [email protected]

# check output shape
# check output shape target
def test1_spectral_library_exporter():

from create_spectral_library import main

sl = main()
sl = sl["TargetLib"]

assert sl.shape[0] == 12 and sl.shape[1] == 27

# check values
# check values target
def test2_spectral_library_exporter():

from create_spectral_library import main

sl = main()
sl = sl["TargetLib"]

value_tests = True

if str(sl.loc[0, "FragmentCharge"]) != "1":
value_tests = False
if str(sl.loc[0, "FragmentType"]) != "y":
value_tests = False
if str(sl.loc[0, "FragmentNumber"]) != "1":
value_tests = False
if str(sl.loc[0, "FragmentPepId"]) != "0":
value_tests = False
if str(sl.loc[0, "CLContainingFragment"]) != "False":
value_tests = False

if str(sl.loc[1, "FragmentCharge"]) != "1":
value_tests = False
if str(sl.loc[1, "FragmentType"]) != "b":
value_tests = False
if str(sl.loc[1, "FragmentNumber"]) != "2":
value_tests = False
if str(sl.loc[1, "FragmentPepId"]) != "0":
value_tests = False
if str(sl.loc[1, "CLContainingFragment"]) != "True":
value_tests = False

if str(sl.loc[2, "FragmentCharge"]) != "1":
value_tests = False
if str(sl.loc[2, "FragmentType"]) != "b":
value_tests = False
if str(sl.loc[2, "FragmentNumber"]) != "2":
value_tests = False
if str(sl.loc[2, "FragmentPepId"]) != "0":
value_tests = False
if str(sl.loc[2, "CLContainingFragment"]) != "True":
value_tests = False

if str(sl.loc[3, "FragmentCharge"]) != "1":
value_tests = False
if str(sl.loc[3, "FragmentType"]) != "y":
value_tests = False
if str(sl.loc[3, "FragmentNumber"]) != "3":
value_tests = False
if str(sl.loc[3, "FragmentPepId"]) != "0":
value_tests = False
if str(sl.loc[3, "CLContainingFragment"]) != "False":
value_tests = False

if str(sl.loc[11, "FragmentCharge"]) != "1":
value_tests = False
if str(sl.loc[11, "FragmentType"]) != "y":
value_tests = False
if str(sl.loc[11, "FragmentNumber"]) != "5":
value_tests = False
if str(sl.loc[11, "FragmentPepId"]) != "1":
value_tests = False
if str(sl.loc[11, "CLContainingFragment"]) != "False":
value_tests = False

assert value_tests
assert str(sl.loc[0, "ModifiedPeptide"]) == "KQQGHR_KQQGHR"
assert str(sl.loc[0, "FragmentCharge"]) == "1"
assert str(sl.loc[0, "FragmentType"]) == "y"
assert str(sl.loc[0, "FragmentNumber"]) == "1"
assert str(sl.loc[0, "FragmentPepId"]) == "0"
assert str(sl.loc[0, "CLContainingFragment"]) == "False"

assert str(sl.loc[1, "ModifiedPeptide"]) == "KQQGHR_KQQGHR"
assert str(sl.loc[1, "FragmentCharge"]) == "1"
assert str(sl.loc[1, "FragmentType"]) == "b"
assert str(sl.loc[1, "FragmentNumber"]) == "2"
assert str(sl.loc[1, "FragmentPepId"]) == "0"
assert str(sl.loc[1, "CLContainingFragment"]) == "True"

assert str(sl.loc[2, "ModifiedPeptide"]) == "KQQGHR_KQQGHR"
assert str(sl.loc[2, "FragmentCharge"]) == "1"
assert str(sl.loc[2, "FragmentType"]) == "b"
assert str(sl.loc[2, "FragmentNumber"]) == "2"
assert str(sl.loc[2, "FragmentPepId"]) == "0"
assert str(sl.loc[2, "CLContainingFragment"]) == "True"

assert str(sl.loc[3, "ModifiedPeptide"]) == "KQQGHR_KQQGHR"
assert str(sl.loc[3, "FragmentCharge"]) == "1"
assert str(sl.loc[3, "FragmentType"]) == "y"
assert str(sl.loc[3, "FragmentNumber"]) == "3"
assert str(sl.loc[3, "FragmentPepId"]) == "0"
assert str(sl.loc[3, "CLContainingFragment"]) == "False"

assert str(sl.loc[11, "ModifiedPeptide"]) == "KQQGHR_KQQGHR"
assert str(sl.loc[11, "FragmentCharge"]) == "1"
assert str(sl.loc[11, "FragmentType"]) == "y"
assert str(sl.loc[11, "FragmentNumber"]) == "5"
assert str(sl.loc[11, "FragmentPepId"]) == "1"
assert str(sl.loc[11, "CLContainingFragment"]) == "False"

# check output shape decoy
def test3_spectral_library_exporter():

from create_spectral_library import main

sl = main()
sl = sl["DecoyLib"]

assert sl.shape[0] == 22 and sl.shape[1] == 27

# check values decoy
def test4_spectral_library_exporter():

from create_spectral_library import main

sl = main()
sl = sl["DecoyLib"]

assert str(sl.loc[0, "ModifiedPeptide"]) == "HGQQKR_HGQQKR"
assert str(sl.loc[0, "FragmentCharge"]) == "1"
assert str(sl.loc[0, "FragmentType"]) == "y"
assert str(sl.loc[0, "FragmentNumber"]) == "1"
assert str(sl.loc[0, "FragmentPepId"]) == "0"
assert str(sl.loc[0, "CLContainingFragment"]) == "False"

assert str(sl.loc[1, "ModifiedPeptide"]) == "HGQQKR_HGQQKR"
assert str(sl.loc[1, "FragmentCharge"]) == "1"
assert str(sl.loc[1, "FragmentType"]) == "b"
assert str(sl.loc[1, "FragmentNumber"]) == "2"
assert str(sl.loc[1, "FragmentPepId"]) == "0"
assert str(sl.loc[1, "CLContainingFragment"]) == "False"

assert str(sl.loc[2, "ModifiedPeptide"]) == "HGQQKR_HGQQKR"
assert str(sl.loc[2, "FragmentCharge"]) == "1"
assert str(sl.loc[2, "FragmentType"]) == "y"
assert str(sl.loc[2, "FragmentNumber"]) == "3"
assert str(sl.loc[2, "FragmentPepId"]) == "0"
assert str(sl.loc[2, "CLContainingFragment"]) == "True"

assert str(sl.loc[3, "ModifiedPeptide"]) == "HGQQKR_HGQQKR"
assert str(sl.loc[3, "FragmentCharge"]) == "1"
assert str(sl.loc[3, "FragmentType"]) == "y"
assert str(sl.loc[3, "FragmentNumber"]) == "3"
assert str(sl.loc[3, "FragmentPepId"]) == "0"
assert str(sl.loc[3, "CLContainingFragment"]) == "True"

assert str(sl.loc[21, "ModifiedPeptide"]) == "HGQQKR_HGQQKR"
assert str(sl.loc[21, "FragmentCharge"]) == "1"
assert str(sl.loc[21, "FragmentType"]) == "y"
assert str(sl.loc[21, "FragmentNumber"]) == "5"
assert str(sl.loc[21, "FragmentPepId"]) == "1"
assert str(sl.loc[21, "CLContainingFragment"]) == "True"

0 comments on commit 54a16d9

Please sign in to comment.