-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoftware_comparison.py
183 lines (171 loc) · 8.36 KB
/
Software_comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import pandas as pd
import os
import time
import glob
import Benchmarking_paper_only.FDR as FDR
import TPP_reusable.Confident_PTMs as Confident_PTMs
import TPP_reusable.Unique_PTMs as Unique_PTMs
import Benchmarking_paper_only.extract_scan as extract_scan
import TPP_reusable.convert_xml_sax as convert_xml_sax
import TPP_reusable.Comparison as Comparison
import TPP_reusable.Post_analysis as Post_analysis
import TPP_reusable.pAla as pAla
import sys
from params_software import *
start_time = time.time()
Ascore_cutoff = 0
sub = "FDR_" + str(FDR_cutoff) + "_PTM_score_" + str(Ascore_cutoff)
decoy_list=[]
for wd, software in zip(w, s):
try:
os.chdir(wd)
except OSError:
print("Can't find results directory, please check location: ")
print(wd)
if "PEAKS" in software:
input = "DB search psm.csv"
results_file = "DB search psm_edit.csv"
# extract scan from peaks output
if os.path.isfile(results_file):
print("Scan already found")
else:
extract_scan.scan(search_files_location, input, results_file, wd)
print("Scan found")
search_software="PEAKS"
elif "TPP" in software:
# Run pepXML converter - if csv not in dir
results_file = "interact.ptm.pep.csv"
if os.path.isfile(results_file):
print("XML converted file exists")
else:
xml = glob.glob("*.ptm.pep.xml")
try:
print("Converting XML file")
convert_xml_sax.convert(xml[0])
print("XML converted")
except ValueError:
raise ValueError("Please provide TPP '.ptm.pep.xml' results file")
search_software = "TPP"
elif "MaxQuant" in software:
results_file = "evidence.txt"
if not os.path.isfile(results_file):
print("Please provide location for 'evidence.txt' MaxQuant results file")
search_software = "MaxQuant"
elif "PD" in software:
text_file = glob.glob("*PSMs.txt")
if len(text_file) != 1:
raise ValueError('should be only one txt file in the PD directory')
results_file = text_file[0]
search_software = "PD"
# calculate FDR
if not os.path.exists(sub):
os.mkdir(sub)
FDR_output = sub + "/FDR_output.csv"
if "pL" in software or "pL" in wd or "pLeu" in wd:
search="STYL"
decoy="pLeu"
elif "pG" in software or "pG" in wd or "pGly" in wd:
search="STYG"
decoy="pGly"
elif "pD" in software or "pD" in wd or "pAsp" in wd:
search="STYD"
decoy="pAsp"
elif "pE" in software or "pE" in wd or "pGlu" in wd:
search="STYE"
decoy="pGlu"
elif "pP" in software or "pP" in wd or "pPro" in wd:
search="STYP"
decoy="pPro"
else:
search="STYA"
decoy="pAla"
decoy_list.append(decoy)
FDR.calculateFDR(results_file, search_software, FDR_output, PXD, wd, search)
print("FDR done")
print("--- %s seconds ---" % (time.time() - start_time))
# filter for FDR (and A-score) cutoff
confident_PTM_output = sub + "/PTM_confident.csv"
Confident_PTMs.confident(FDR_output, database, FDR_cutoff, Ascore_cutoff, confident_PTM_output)
print("Confident PTMs done")
print("--- %s seconds ---" % (time.time() - start_time))
# Collapse for best scoring for each peptide, protein site, mass shift on protein or no collapse
unique_peptide = sub + "/Peptide_confident_PTM_unique.csv"
unique_site = sub + "/Site_confident_PTM_unique.csv"
unique_mass = sub + "/Peptide_mass_confident_PTM_unique.csv"
non_collapse = sub + "/All_confident_PTM_no_collapse.csv"
#If synthetic dataset, use alternative analysis (include pool etc.)
if PXD=="PXD007058":
sys.exit("Use Synthetics Analysis Pipeline")
else:
Unique_PTMs.unique(confident_PTM_output, unique_peptide, unique_site, unique_mass, non_collapse)
print("Unique PTMs done")
print(FDR_cutoff, software, "--- %s seconds ---" % (time.time() - start_time))
# Compare spectrum between different searches
files = []
for i in w:
files.append(i + "/"+ sub + "/PTM_confident.csv")
Comparison.comparison(p, sub, files, s)
print("Spectrum Comparison Done --- %s seconds ---" % (time.time() - start_time))
file_input_list = ["All_confident_PTM_no_collapse.csv"]
files = []
for i in w:
files.append(i + "/" + sub + "/")
software_list_edit = ""
for i in s:
software_list_edit += i + "_"
os.chdir(p)
if not os.path.exists("Comparisons"):
os.mkdir("Comparisons")
# load in list of hits where spectrum comparisons gave match between all searches
spectrum_match_list = []
spectrum = p + "\Spectrum_Comparisons/" + software_list_edit[
:-1] + "/" + sub + "_spectrum_comparison_" + software_list_edit[
:-1] + ".csv"
df = pd.read_csv(spectrum, dtype=str)
for i in range(len(df)):
if df.loc[i, 'Match'] == "TRUE":
spectrum_match_list.append(df.loc[i, 'Spectrum'])
print("Starting FLR calculations --- %s seconds ---" % (time.time() - start_time))
#Post analysis - FLR calulations and plots
files = []
for i in w:
for f in file_input_list:
files.append(i + "/" + sub + "/" + f)
for file in files:
Post_analysis.site_input = Post_analysis.site_based(file)
Post_analysis.site_all_input=Post_analysis.site_based_all(file)
output = file.replace(".csv", "_Site-based.csv")
Post_analysis.spectrum_comparison(output, spectrum_match_list)
final_file_list = []
final_file_list_collapsed = []
final_file_list_filtered =[]
final_file_list_PTM=[]
for i,decoy in zip(w,decoy_list):
Post_analysis.model_FLR(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match.csv")
Post_analysis.model_FLR_new(i + "/" + sub + "/" + "All_confident_PTM_no_collapse_Site-based_spectrum_match.csv")
Post_analysis.model_FLR_filter(i + "/" + sub + "/" + "All_confident_PTM_no_collapse_Site-based_spectrum_match.csv")
pAla.calulate_decoy_FLR(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR.csv",decoy)
pAla.calulate_decoy_FLR(i + "/" + sub + "/" + "All_confident_PTM_no_collapse_Site-based_spectrum_match_new_FLR_collapse.csv", decoy)
pAla.calulate_decoy_FLR(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR_filtered.csv",decoy)
final_file_list.append(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR_"+decoy+".csv")
final_file_list_collapsed.append(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_new_FLR_collapse_"+decoy+".csv")
final_file_list_filtered.append(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR_filtered_"+decoy+".csv")
Post_analysis.PTM_sort_FLR(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match.csv")
pAla.calulate_decoy_FLR(i + "/" + sub + "/" + "All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR_PTM_sort.csv",decoy)
final_file_list_PTM.append(i+"/"+sub+"/"+"All_confident_PTM_no_collapse_Site-based_spectrum_match_FLR_PTM_sort_"+decoy+".csv")
Post_analysis.plot_FLR_comparisons(sub, final_file_list, s, p)
Post_analysis.plot_FLR_comparisons(sub, final_file_list_collapsed, s, p)
Post_analysis.plot_FLR_comparisons_PTM_prob(sub,final_file_list_PTM,s,p)
Post_analysis.plot_FLR_comparisons(sub,final_file_list_filtered,s,p)
final_file_list = []
final_file_list_collapse=[]
for i,decoy in zip(w,decoy_list):
Post_analysis.model_FLR(i+"/"+sub+"/"+"Site_confident_PTM_unique.csv")
Post_analysis.model_FLR_new(i+"/"+sub+"/"+"Site_confident_PTM_unique.csv")
pAla.calulate_decoy_FLR(i+"/"+sub+"/"+"Site_confident_PTM_unique_FLR.csv",decoy)
pAla.calulate_decoy_FLR(i+"/"+sub+"/"+"Site_confident_PTM_unique_new_FLR_collapse.csv",decoy)
final_file_list.append(i+"/"+sub+"/"+"Site_confident_PTM_unique_FLR_"+decoy+".csv")
final_file_list_collapse.append(i + "/" + sub + "/" + "Site_confident_PTM_unique_new_FLR_collapse_" + decoy + ".csv")
Post_analysis.plot_FLR_comparisons(sub, final_file_list, s, p)
Post_analysis.plot_FLR_comparisons(sub, final_file_list_collapse, s, p)
print("FLR calculations done --- %s seconds ---" % (time.time() - start_time))