Skip to content

Commit

Permalink
add tests for xi
Browse files Browse the repository at this point in the history
  • Loading branch information
michabirklbauer committed Dec 6, 2024
1 parent 0701029 commit 1bedb47
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/python-app-xi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# Reference workflow provided by (c) GitHub
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: msannika_spectral_library_xi

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Copy scripts and data to "/tests"
run: |
rm -f config.py
cp data/config_xi.py .
mv config_xi.py config.py
cp create_spectral_library.py tests
cp config.py tests
cp data/XLpeplib_Beveridge_QEx-HFX_DSS_R1.mgf .
cp data/example_CSM_xiFDR2.2.1.csv .
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest tests/tests-xi.py
239 changes: 239 additions & 0 deletions tests/tests-xi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
#!/usr/bin/env python3

# MS ANNIKA SPECTRAL LIBRARY EXPORTER - TESTS XI
# 2023 (c) Micha Johannes Birklbauer
# https://github.com/michabirklbauer/
# micha.birklbauer@gmail.com

# check converted csm file
def test1_converter():

import pandas as pd
from create_spectral_library import main
from config import CSMS_FILE as CSMS_FILE

sl = main()
csms = pd.read_csv(CSMS_FILE + ".converted.csv")

assert csms.shape[0] == 2
assert csms.shape[1] == 17

assert str(csms.loc[0, "Sequence A"]) == "KIECFDSVEISGVEDR"
assert str(csms.loc[0, "Modifications A"]) == "C4(Carbamidomethyl);K1(BS3)"
assert str(csms.loc[0, "Sequence B"]) == "KIECFDSVEISGVEDR"
assert str(csms.loc[0, "Modifications B"]) == "C4(Carbamidomethyl);K1(BS3)"
assert str(csms.loc[0, "First Scan"]) == "19140"
assert str(csms.loc[0, "Spectrum File"]) == "XLpeplib_Beveridge_QEx-HFX_DSS_R1.mgf"
assert str(csms.loc[0, "A in protein"]) == "574"
assert str(csms.loc[0, "B in protein"]) == "574"
assert str(csms.loc[0, "Crosslinker Position A"]) == "1"
assert str(csms.loc[0, "Crosslinker Position B"]) == "1"
assert str(csms.loc[0, "Accession A"]) == "Cas9"
assert str(csms.loc[0, "Accession B"]) == "Cas9"
assert str(csms.loc[0, "Charge"]) == "4"
assert str(int(csms.loc[0, "m/z [Da]"])) == "976"
assert str(csms.loc[0, "Crosslink Strategy"]) == "xi"
assert str(int(csms.loc[0, "RT [min]"])) == "85"
assert str(int(csms.loc[0, "Compensation Voltage"])) == "0"

assert str(csms.loc[1, "Sequence A"]) == "MIAKSEQEIGK"
assert str(csms.loc[1, "Modifications A"]) == "K4(BS3)"
assert str(csms.loc[1, "Sequence B"]) == "DFQFYKVR"
assert str(csms.loc[1, "Modifications B"]) == "K6(BS3)"
assert str(csms.loc[1, "First Scan"]) == "15867"
assert str(csms.loc[1, "Spectrum File"]) == "XLpeplib_Beveridge_QEx-HFX_DSS_R1.mgf"
assert str(csms.loc[1, "A in protein"]) == "1024"
assert str(csms.loc[1, "B in protein"]) == "972"
assert str(csms.loc[1, "Crosslinker Position A"]) == "4"
assert str(csms.loc[1, "Crosslinker Position B"]) == "6"
assert str(csms.loc[1, "Accession A"]) == "Cas9"
assert str(csms.loc[1, "Accession B"]) == "Cas9"
assert str(csms.loc[1, "Charge"]) == "3"
assert str(int(csms.loc[1, "m/z [Da]"])) == "825"
assert str(csms.loc[1, "Crosslink Strategy"]) == "xi"
assert str(int(csms.loc[1, "RT [min]"])) == "72"
assert str(int(csms.loc[1, "Compensation Voltage"])) == "0"

# check output shape target
def test1_spectral_library_exporter():

from create_spectral_library import main

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

assert sl.shape[0] == 55 and sl.shape[1] == 30

# check values target
def test2_spectral_library_exporter():

from create_spectral_library import main

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

assert str(sl.loc[0, "ModifiedPeptide"]) == "KIEC[Carbamidomethyl]FDSVEISGVEDR_KIEC[Carbamidomethyl]FDSVEISGVEDR"
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[0, "IsDecoy"]) == "False"
assert str(sl.loc[0, "DecoyType"]) == "TT"

assert str(sl.loc[54, "ModifiedPeptide"]) == "MIAKSEQEIGK_DFQFYKVR"
assert str(sl.loc[54, "FragmentCharge"]) == "1"
assert str(sl.loc[54, "FragmentType"]) == "b"
assert str(sl.loc[54, "FragmentNumber"]) == "5"
assert str(sl.loc[54, "FragmentPepId"]) == "1"
assert str(sl.loc[54, "CLContainingFragment"]) == "False"
assert str(sl.loc[54, "IsDecoy"]) == "False"
assert str(sl.loc[54, "DecoyType"]) == "TT"

# check output shape decoy dd
def test3_spectral_library_exporter():

from create_spectral_library import main

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

assert sl.shape[0] == 54 and sl.shape[1] == 30

# check values decoy dd
def test4_spectral_library_exporter():

from create_spectral_library import main

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

assert str(sl.loc[0, "ModifiedPeptide"]) == "DEVGSIEVSDFC[Carbamidomethyl]EIKR_DEVGSIEVSDFC[Carbamidomethyl]EIKR"
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[0, "IsDecoy"]) == "True"
assert str(sl.loc[0, "DecoyType"]) == "DD"

assert str(sl.loc[53, "ModifiedPeptide"]) == "GIEQESKAIMK_VKYFQFDR"
assert str(sl.loc[53, "FragmentCharge"]) == "1"
assert str(sl.loc[53, "FragmentType"]) == "b"
assert str(sl.loc[53, "FragmentNumber"]) == "5"
assert str(sl.loc[53, "FragmentPepId"]) == "1"
assert str(sl.loc[53, "CLContainingFragment"]) == "True"
assert str(sl.loc[53, "IsDecoy"]) == "True"
assert str(sl.loc[53, "DecoyType"]) == "DD"

# check output shape decoy dt
def test5_spectral_library_exporter():

from create_spectral_library import main

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

assert sl.shape[0] == 54 and sl.shape[1] == 30

# check values decoy dt
def test6_spectral_library_exporter():

from create_spectral_library import main

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

assert str(sl.loc[0, "ModifiedPeptide"]) == "DEVGSIEVSDFC[Carbamidomethyl]EIKR_KIEC[Carbamidomethyl]FDSVEISGVEDR"
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[0, "IsDecoy"]) == "True"
assert str(sl.loc[0, "DecoyType"]) == "DT"

assert str(sl.loc[53, "ModifiedPeptide"]) == "GIEQESKAIMK_DFQFYKVR"
assert str(sl.loc[53, "FragmentCharge"]) == "1"
assert str(sl.loc[53, "FragmentType"]) == "b"
assert str(sl.loc[53, "FragmentNumber"]) == "5"
assert str(sl.loc[53, "FragmentPepId"]) == "1"
assert str(sl.loc[53, "CLContainingFragment"]) == "False"
assert str(sl.loc[53, "IsDecoy"]) == "True"
assert str(sl.loc[53, "DecoyType"]) == "DT"

# check output shape decoy td
def test7_spectral_library_exporter():

from create_spectral_library import main

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

assert sl.shape[0] == 55 and sl.shape[1] == 30

# check values decoy td
def test8_spectral_library_exporter():

from create_spectral_library import main

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

assert str(sl.loc[0, "ModifiedPeptide"]) == "KIEC[Carbamidomethyl]FDSVEISGVEDR_DEVGSIEVSDFC[Carbamidomethyl]EIKR"
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[0, "IsDecoy"]) == "True"
assert str(sl.loc[0, "DecoyType"]) == "TD"

assert str(sl.loc[54, "ModifiedPeptide"]) == "MIAKSEQEIGK_VKYFQFDR"
assert str(sl.loc[54, "FragmentCharge"]) == "1"
assert str(sl.loc[54, "FragmentType"]) == "b"
assert str(sl.loc[54, "FragmentNumber"]) == "5"
assert str(sl.loc[54, "FragmentPepId"]) == "1"
assert str(sl.loc[54, "CLContainingFragment"]) == "True"
assert str(sl.loc[54, "IsDecoy"]) == "True"
assert str(sl.loc[54, "DecoyType"]) == "TD"

# check output shape full
def test9_spectral_library_exporter():

from create_spectral_library import main

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

assert sl.shape[0] == 218 and sl.shape[1] == 30
assert sl["DecoyType"].value_counts()["TT"] == 55
assert sl["DecoyType"].value_counts()["TD"] == 55
assert sl["DecoyType"].value_counts()["DD"] == 54
assert sl["DecoyType"].value_counts()["DT"] == 54

# check values full
def test10_spectral_library_exporter():

from create_spectral_library import main

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

assert str(sl.loc[0, "ModifiedPeptide"]) == "KIEC[Carbamidomethyl]FDSVEISGVEDR_KIEC[Carbamidomethyl]FDSVEISGVEDR"
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[0, "IsDecoy"]) == "False"
assert str(sl.loc[0, "DecoyType"]) == "TT"

assert str(sl.loc[217, "ModifiedPeptide"]) == "MIAKSEQEIGK_VKYFQFDR"
assert str(sl.loc[217, "FragmentCharge"]) == "1"
assert str(sl.loc[217, "FragmentType"]) == "b"
assert str(sl.loc[217, "FragmentNumber"]) == "5"
assert str(sl.loc[217, "FragmentPepId"]) == "1"
assert str(sl.loc[217, "CLContainingFragment"]) == "True"
assert str(sl.loc[217, "IsDecoy"]) == "True"
assert str(sl.loc[217, "DecoyType"]) == "TD"

0 comments on commit 1bedb47

Please sign in to comment.