Skip to content

Commit

Permalink
Merge pull request #16 from MannLabs/synchro_integration
Browse files Browse the repository at this point in the history
Synchro integration
  • Loading branch information
PatriciaSkowronek authored Dec 19, 2023
2 parents 063d8e4 + 969b361 commit d2c9781
Show file tree
Hide file tree
Showing 34 changed files with 99,889 additions and 2,689 deletions.
1,410 changes: 1,410 additions & 0 deletions nbs/20231129_diaPASEF_method _generation.ipynb

Large diffs are not rendered by default.

1,925 changes: 1,925 additions & 0 deletions nbs/20231201_synchroPASEF_method_generation.ipynb

Large diffs are not rendered by default.

4,279 changes: 4,279 additions & 0 deletions nbs/20231207_synchroPASEF_quadrupole_isolation.ipynb

Large diffs are not rendered by default.

937 changes: 0 additions & 937 deletions nbs/py_diAID_tutorial_v2.ipynb

This file was deleted.

12 changes: 3 additions & 9 deletions pydiaid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@


__project__ = "pydiaid"
__version__ = "0.0.19"
__version__ = "0.0.1"
__license__ = "Apache"
__description__ = "An open-source Python package of the AlphaPept ecosystem"
__author__ = "Patricia Skowronek, Sander Willems, Eugenia Voytik"
__author__ = "Mann Labs"
__author_email__ = "opensource@alphapept.com"
__github__ = "https://github.com/MannLabs/pydiaid"
__keywords__ = [
"bioinformatics",
"software",
"AlphaPept ecosystem",
"ms",
"mass spectrometry",
"bruker",
"timsTOF",
"proteomics",
"bioinformatics",
"diaPASEF",
]
__python_version__ = ">=3.8,<3.10"
__classifiers__ = [
Expand All @@ -40,6 +33,7 @@
]
__urls__ = {
"Mann Labs at MPIB": "https://www.biochem.mpg.de/mann",
"Mann Labs at CPR": "https://www.cpr.ku.dk/research/proteomics/mann/",
"GitHub": __github__,
# "ReadTheDocs": None,
# "PyPi": None,
Expand Down
315 changes: 1 addition & 314 deletions pydiaid/cli.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
#!python


# external
import click

# local
import pydiaid
from pydiaid import loader
from pydiaid import main
from pydiaid import method_optimizer

# for data manipulation
import pandas as pd

# for saving input data as json:
import json

# for creating new folders:
import os

BASE_PATH = os.path.dirname(__file__)
LIB_PATH = os.path.join(BASE_PATH, "lib")
DEFAULT_FILE = os.path.join(
LIB_PATH,
"default_parameters.json"
)


@click.group(
Expand All @@ -47,298 +29,3 @@ def run(ctx, **kwargs):
def gui():
import pydiaid.gui
pydiaid.gui.run()


@run.command("optimize", help="Optimize a dia-PASEF method.")
@click.option(
"parameter_file_name",
"-p",
help=f"Parameter file (check out {DEFAULT_FILE} for an example)",
default=DEFAULT_FILE,
required=True,
)
def optimize_window_scheme(parameter_file_name):
print(f"Using parameter file {parameter_file_name}")
with open(parameter_file_name, "r") as infile:
method_conf = json.load(infile)
run_all(method_conf)


@run.command("create", help="Create a specific dia-PASEF method.")
@click.option(
"parameter_file_name",
"-p",
help=f"Parameter file (check out {DEFAULT_FILE} for an example)",
default=DEFAULT_FILE,
required=True,
)
def create_diaPASEF_method(parameter_file_name,):
print(f"Using parameter file {parameter_file_name}")
with open(parameter_file_name, "r") as infile:
method_conf = json.load(infile)
library_plus_create_methods(method_conf)


@run.command("evaluate", help="Evaluate a dia-PASEF method.")
@click.option(
"parameter_file_name",
"-p",
help=f"Parameter file (check out {DEFAULT_FILE} for an example)",
default=DEFAULT_FILE,
required=True,
)
def evaluate_diaPASEF_method(parameter_file_name,):
print(f"Using parameter file {parameter_file_name}")
with open(parameter_file_name, "r") as infile:
method_conf = json.load(infile)
library_plus_evaluate_method(method_conf)


@run.command("charge", help="Evaluate a dia-PASEF method for multiply charged precursors.")
@click.option(
"parameter_file_name",
"-p",
help=f"Parameter file (check out {DEFAULT_FILE} for an example)",
default=DEFAULT_FILE,
required=True,
)
def evaluate_multiple_charged_prec(parameter_file_name,):
print(f"Using parameter file {parameter_file_name}")
with open(parameter_file_name, "r") as infile:
method_conf = json.load(infile)
multiple_charged_prec(method_conf)


def run_all(
method_conf: dict,
) -> None:
"""This function carries out all sub-functions step by step: creating a
folder for the output information, loading of the proteomics library,
calculation of the kernel density estimation for the density plots,
Bayesian optimization of dia-PASEF method parameters by trying multiple scan
area coordinates using a Gaussian process, writing all input and output
information in json or csv files, creating final dia-PASEF method, plotting
dia-PASEF windows on top of a kernel density estimation of precursors and
calculating method evaluation information.
Parameters:
method_conf (dict): this dictionary contains all input parameters for all
sub-functions.
"""

method_parameters = method_conf["method_parameters"]
optimizer_parameters = method_conf["optimizer"]
save_at = method_conf["input"]["save_at"]

folder_paths = [
save_at,
save_at+'/optimization_plots',
save_at+'/input_library',
save_at+'/final_method'
]
main.create_folder(folder_paths)

# save input parameters as json file for reusing
out_file = open(save_at+"/input_parameters.json", "w")
json.dump(method_conf, out_file, indent=4)
out_file.close()

xi, yi, zi, library = main.library_information(
method_conf,
save_at
)

main.precursor_within_scan_area(
library,
method_parameters,
save_at
)

dim = method_optimizer.optimization(
library,
method_parameters,
xi,
yi,
zi,
method_conf,
optimizer_parameters
)

df_parameters_final = main.create_final_method(
library,
method_parameters,
dim,
method_conf
)

main.final_method_information(
df_parameters_final,
xi,
yi,
zi,
method_conf,
save_at, library,
method_parameters,
dim
)


def library_plus_evaluate_method(
method_conf: dict
) -> None:
"""This function carries out all sub-functions required for method
evaluation: creating a folder for the output information, loading of the
proteomics library, loading of the acquisition scheme, calculation of the
kernel density estimation for the density plots, writing all input and
output information in json or csv files, plotting of the diaPASEF windows
on top of a kernel density estimation of precursors, and calculating method
evaluation information.
Parameters:
method_conf (dict): this dictionary contains all input parameters for all
sub-functions.
"""

method_parameters = method_conf["method_parameters"]
save_at = method_conf["input"]["save_at"]

folder_paths = [
save_at,
save_at+'/input_library',
save_at+'/final_method'
]
main.create_folder(folder_paths)

# save input parameters as json file for reusing
out_file = open(save_at+"/input_parameters.json", "w")
json.dump(method_conf, out_file, indent=4)
out_file.close()

df_parameters_final = pd.read_csv(
method_conf["input"]["diaPASEF_method_only_used_for_evaluate"],
skiprows=4,
names=["MS Type", "Cycle Id", "Start IM", "End IM", "Start Mass", "End Mass", "CE"]
)

xi, yi, zi, library = main.library_information(
method_conf,
save_at
)

main.final_method_information(
df_parameters_final,
xi,
yi,
zi,
method_conf,
save_at,
library,
method_parameters,
None
)

print("Method evaluated")


def library_plus_create_methods(
method_conf: dict
) -> None:
"""This function carries out all sub-functions required to generate a
dia-PASEF method with specific scan area coordinates (A1, A2, B1, B2):
creating a folder for the output information, loading of the proteomics
library, writing all input and output information in json or csv files,
creating the dia-PASEF method.
Parameters:
method_conf (dict): this dictionary contains all input parameters for all
sub-functions.
"""

method_parameters = method_conf["method_parameters"]
save_at = method_conf["input"]["save_at"]
dim = method_parameters["scan_area_A1_A2_B1_B2_only_used_for_create"]

folder_paths = [
save_at,
save_at+'/final_method'
]
main.create_folder(folder_paths)

# save input parameters as json file for reusing
out_file = open(save_at+"/input_parameters.json", "w")
json.dump(method_conf, out_file, indent=4)
out_file.close()

library = loader.load_library(
method_conf["input"]["library_name"],
method_conf["input"]["analysis_software"],
method_conf["input"]["PTM"]
)

main.precursor_within_scan_area(
library,
method_parameters,
save_at
)

main.create_final_method(
library,
method_parameters,
dim,
method_conf
)

print("Method created")


def multiple_charged_prec(
method_conf: dict
) -> None:
"""This function carries out all sub-functions required for method
evaluation of precursor with multiple charge states: creating a folder for
the output information, loading of the proteomics library, loading of the
acquisition scheme, calculation of the kernel density estimation for the
density plots depending on the charge state, writing all input information
in a json file, plotting of the diaPASEF windows on top of a kernel density
estimation and calculating of method evaluation information.
Parameters:
method_conf (dict): this dictionary contains all input parameters for all
sub-functions.
"""

save_at = method_conf["input"]["save_at"]

folder_paths = [
save_at,
save_at+'/evaluation_multiple_charged_prec'
]
main.create_folder(folder_paths)

# save input parameters as json file for reusing
out_file = open(save_at+"/input_parameters.json", "w")
json.dump(method_conf, out_file, indent=4)
out_file.close()

df_parameters_final = pd.read_csv(
method_conf["input"]["diaPASEF_method_only_used_for_evaluate"],
skiprows=4,
names=["MS Type", "Cycle Id", "Start IM", "End IM", "Start Mass", "End Mass", "CE"]
)

library = loader.load_library(
method_conf["input"]["library_name"],
method_conf["input"]["analysis_software"],
method_conf["input"]["PTM"]
)

main.evaluate_for_multiple_charged_prec(
method_conf,
save_at,
library,
df_parameters_final
)
Loading

0 comments on commit d2c9781

Please sign in to comment.