Skip to content

Commit bccf012

Browse files
committed
Add public config file
1 parent 54d8fc8 commit bccf012

1 file changed

Lines changed: 64 additions & 36 deletions

File tree

PepGM/App.py

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
from PySimpleGUI import Col, FolderBrowse, FileBrowse, Slider, InputText, Text, Combo, Radio, Frame, Input, Button
42
import os
53
import subprocess
@@ -19,12 +17,41 @@
1917

2018

2119
def build_frames(experiment, sample, host, host_scientific, ref_database, path_sample, path_parameter,
22-
path_data, path_database, peptide_shaker, search_gui, alpha, beta, prior, psm_fdr, peptide_fdr,
23-
protein_fdr, n_taxa, mail, key):
24-
# CONFIG FRAME
20+
path_data, path_database, path_peptide_shaker, path_search_gui, alpha, beta, prior, psm_fdr,
21+
peptide_fdr, protein_fdr, n_taxa, mail, key):
22+
"""
23+
Create PySimpleGUI frames.
24+
Parameters
25+
----------
26+
experiment : str, given name for your experiment that will create a subfolder in /results.
27+
sample : str, given name for your sample
28+
host : str, host name
29+
host_scientific : str, scientific (latin) host name
30+
ref_database : str, reference database name
31+
path_sample : str, path to sample spectra files
32+
path_parameter : str, path to your parameter file
33+
path_data : str, path to folder that contains sample
34+
path_database : str, path to folder that contains database
35+
path_peptide_shaker : str, path to PeptideShaker binary
36+
path_search_gui : str, path to SearchGUI binary
37+
alpha : lst, list of alpha candidates for grid search
38+
beta : lst, list of beta candidates for grid search
39+
prior : lst, list of prior probability candidates for grid search
40+
peptide_fdr : str, peptide false discovery rate
41+
protein_fdr : str, protein false discovery rate
42+
n_taxa : int, upper limit of taxa to display in the results plot
43+
mail : str, mail credentials for logging into NCBI
44+
key : str, key for logging into NCBI
45+
46+
Returns
47+
-
48+
-------
49+
50+
"""
51+
# config frame
2552
config_frame = Col([[Text("API mail", size=(12, 1)), InputText(key="APImail", default_text=mail, text_color="grey"),
2653
Text('API key', size=(12, 1)), InputText(key="APIkey", default_text=key, text_color="grey")]])
27-
# RUN FRAME
54+
# run frame
2855
run_frame = Col([
2956
[InputText(key="ExperimentName", default_text=experiment, expand_x=True, enable_events=True)],
3057
[Text("Sample", size=(12, 1)),
@@ -37,7 +64,8 @@ def build_frames(experiment, sample, host, host_scientific, ref_database, path_s
3764
Input(key="ScientificHostName", default_text=host_scientific, expand_x=True)],
3865
[Radio('Filter spectra', default=False, key="FilterSpectra", group_id=1),
3966
Radio('Add host and crap databases', default=True, key="AddHostandCrapToDB", group_id=1)]])
40-
# INPUT FRAMES
67+
68+
# input frame
4169
input_file_frame = Col([
4270
[Text("Sample spectra", size=(20, 1)), InputText(key="SamplePath", default_text=path_sample, size=(90, 1)),
4371
FileBrowse()],
@@ -49,13 +77,14 @@ def build_frames(experiment, sample, host, host_scientific, ref_database, path_s
4977
[Text("Database", size=(20, 1)), Input(key="DatabaseDir", default_text=path_database, size=(90, 1)),
5078
FolderBrowse()],
5179
[Text("Peptide Shaker", size=(20, 1)),
52-
Input(key="PeptideShaker", default_text=peptide_shaker, size=(90, 1)), FolderBrowse()],
53-
[Text("Search GUI", size=(20, 1)), Input(key="SearchGUI", default_text=search_gui, size=(90, 1)),
80+
Input(key="PeptideShaker", default_text=path_peptide_shaker, size=(90, 1)), FolderBrowse()],
81+
[Text("Search GUI", size=(20, 1)), Input(key="SearchGUI", default_text=path_search_gui, size=(90, 1)),
5482
FolderBrowse()],
5583
[Text("Resources", size=(20, 1)), Input(key="ResourcesDir", default_text="resources/", size=(90, 1))],
5684
[Text("Results", size=(20, 1)), Input(key="ResultsDir", default_text="results/", size=(90, 1))],
5785
[Text("TaxID mapping", size=(20, 1)), Input(key="TaxidMapping", default_text="taxidMapping/", size=(90, 1))]])
58-
# PEPGM FRAME
86+
87+
# pepgm frame
5988
gridsearch_frame = Col([[Text("Alpha", size=(12, 2)), InputText(default_text=alpha, key="Alpha")],
6089
[Text("Beta", size=(12, 2)), Input(default_text=beta, key="Beta")],
6190
[Text("Prior", size=(12, 2)), Input(default_text=prior, key="prior")]])
@@ -76,18 +105,19 @@ def build_frames(experiment, sample, host, host_scientific, ref_database, path_s
76105
[Frame("FDR calculation", [[fdr_frame]], expand_x=True, expand_y=True)]], expand_x=True,
77106
expand_y=True)
78107

79-
return config_frame, run_frame, input_file_frame, input_dir_frame, pepgm_frame, \
80-
searchgui_frame
108+
return config_frame, run_frame, input_file_frame, input_dir_frame, pepgm_frame, searchgui_frame
81109

82110

83111
def setup_layout(experiment="", sample="", host="", host_scientific="", ref_database="", path_sample="",
84112
path_parameter="", path_data="", path_database="", peptide_shaker="", search_gui="",
85113
alpha=[0.01, 0.05, 0.1, 0.2, 0.4, 0.6], beta=[0.01, 0.05, 0.1, 0.2, 0.4, 0.5, 0.7],
86114
prior=[0.1, 0.3, 0.5], psm_fdr=1, peptide_fdr=1, protein_fdr=1, n_taxa=15, key="", mail=""):
115+
87116
config_frame, run_frame, input_file_frame, input_dir_frame, pepgm_frame, searchgui_frame = build_frames(
88117
experiment, sample, host, host_scientific, ref_database, path_sample, path_parameter, path_data, path_database,
89118
peptide_shaker, search_gui, list(alpha), list(beta), list(prior), psm_fdr, peptide_fdr, protein_fdr, n_taxa,
90119
key, mail)
120+
91121
scaffold = [[Frame("Configuration details", [[config_frame]], expand_x=True)],
92122
[Frame("Run details", [[run_frame]], tooltip="Run configuration", expand_x=True)],
93123
[Frame("Input paths", [[input_file_frame], [input_dir_frame]], expand_x=True)],
@@ -102,9 +132,16 @@ def setup_layout(experiment="", sample="", host="", host_scientific="", ref_data
102132

103133
def parse_config(configurations, path_config):
104134
"""
105-
Write configuration from GUI into config file.
106-
:param configurations: list, configuration as retrieved from GUI
107-
:param path_config: str, path to config file
135+
Parse configurations into output file in yaml syntax.
136+
Parameters
137+
----------
138+
configurations : lst, list of configuration parameters that are read from the GUI
139+
path_config : str, path to configuration file
140+
141+
Returns
142+
-
143+
-------
144+
108145
"""
109146
with open(path_config, "w") as config_file_out:
110147
# iterate over all dictionary keys and entries
@@ -142,18 +179,18 @@ def parse_config(configurations, path_config):
142179
config_file_out.write("%s: '%s'\n" % (param, value))
143180

144181

145-
def main():
182+
if __name__ == '__main__':
146183
sg.theme("SystemDefaultForReal")
147-
# wd = os.path.dirname(os.path.realpath(workflow.snakefile))
148184
# get config file path
149185
config_file = Path(os.path.normpath(os.path.join(os.path.dirname(__file__), '../config/config.yaml')))
150186

151187
if not config_file.exists():
188+
# use empty layout
152189
scaffold = setup_layout()
153190
else:
154191
# load previous configurations
155192
prev_configs = yaml.load(config_file.read_text(), Loader=SafeLoader)
156-
# do not display single quotes
193+
# do not save single quotes
157194
prev_configs["ScientificHostName"] = prev_configs["ScientificHostName"].replace("'", "")
158195
# auto fill input from config file
159196
scaffold = setup_layout(prev_configs["ExperimentName"], prev_configs["SampleName"], prev_configs["HostName"],
@@ -174,34 +211,25 @@ def main():
174211
input_key_list = [key for key, value in window.key_dict.items()]
175212
# run button
176213
if event == 'Run':
177-
cores = int(values["core_number"])
178-
179-
# print("Your snakemake command: ")
180-
# run_command(snakemake_cmd)
181-
snakemake_cmd = 'cd ..; snakemake --use-conda --conda-frontend conda --cores 30'
182-
# subprocess.Popen([f'{snakemake_cmd}'], shell=True)
183-
# subprocess.Popen(snakemake_cmd, shell=True)
214+
snakemake_cmd = f'cd ..; snakemake --use-conda --conda-frontend conda --cores {int(values["core_number"])}'
184215
subprocess.Popen([f'{snakemake_cmd}'], shell=True)
185-
# dry run button
216+
186217
if event == 'Dry run':
187218
snakemake_cmd = f"cd ..; snakemake -np"
188-
run_command(cmd=snakemake_cmd, window=window)
189-
# update config file
219+
subprocess.Popen([f'{snakemake_cmd}'], shell=True)
220+
190221
if event == "Write":
191-
print("Write configs successfull.")
222+
print("Write configs successfully.")
223+
# filter configurations
192224
configs = {key: val for key, val in values.items() if key in config_keys}
193225
parse_config(configs, config_file)
194-
# help pages are on GitHub
226+
195227
if event == 'Help':
196228
print("You will be redirected to the GitHub help pages.")
197229
webbrowser.open("https://github.com/BAMeScience/PepGM/blob/master/readme.md")
198-
# exit
230+
199231
if event == 'Exit':
200232
break
201-
# close window event (X)
233+
202234
if event == sg.WINDOW_CLOSED:
203235
break
204-
205-
206-
if __name__ == "__main__":
207-
main()

0 commit comments

Comments
 (0)