Skip to content

Commit 95ca902

Browse files
authored
Merge pull request #9 from compomics/fix-no-write-output
Fix write_output=False bug
2 parents c5a1a81 + 5400864 commit 95ca902

File tree

2 files changed

+81
-77
lines changed

2 files changed

+81
-77
lines changed

im2deep/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""IM2Deep: Deep learning framework for peptide collisional cross section prediction."""
22

3-
__version__ = "1.0.1"
3+
__version__ = "1.0.2"

im2deep/im2deep.py

Lines changed: 80 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -71,83 +71,87 @@ def predict_ccs(
7171
use_charge_state,
7272
)
7373

74-
if write_output:
75-
LOGGER.info("Writing output file...")
76-
output_file = open(output_file, "w")
74+
if ion_mobility:
7775
if not multi:
78-
if not ion_mobility:
79-
output_file.write("modified_seq,charge,predicted CCS\n")
80-
for peptidoform, charge, CCS in zip(
81-
psm_list_pred_df["peptidoform"],
82-
psm_list_pred_df["charge"],
83-
psm_list_pred_df["predicted_ccs"],
84-
):
85-
output_file.write(f"{peptidoform},{charge},{CCS}\n")
86-
output_file.close()
87-
else:
88-
LOGGER.info("Converting CCS to IM values...")
89-
psm_list_pred_df["predicted_im"] = ccs2im(
90-
psm_list_pred_df["predicted_ccs"],
91-
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
92-
psm_list_pred_df["charge"],
93-
)
94-
LOGGER.info("Writing output file...")
95-
output_file = open(output_file, "w")
96-
output_file.write("modified_seq,charge,predicted IM\n")
97-
for peptidoform, charge, IM in zip(
98-
psm_list_pred_df["peptidoform"],
99-
psm_list_pred_df["charge"],
100-
psm_list_pred_df["predicted_im"],
101-
):
102-
output_file.write(f"{peptidoform},{charge},{IM}\n")
103-
output_file.close()
76+
psm_list_pred_df["predicted_im"] = ccs2im(
77+
psm_list_pred_df["predicted_ccs"],
78+
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
79+
psm_list_pred_df["charge"],
80+
)
81+
if write_output:
82+
LOGGER.info("Writing output file for ion mobility prediction...")
83+
with open(output_file, "w") as f:
84+
f.write("modified_seq,charge,predicted IM\n")
85+
for peptidoform, charge, IM in zip(
86+
psm_list_pred_df["peptidoform"],
87+
psm_list_pred_df["charge"],
88+
psm_list_pred_df["predicted_im"],
89+
):
90+
f.write(f"{peptidoform},{charge},{IM}\n")
91+
LOGGER.info("IM2Deep finished!")
92+
return psm_list_pred_df["predicted_im"]
10493
else:
105-
if not ion_mobility:
106-
output_file.write(
107-
"modified_seq,charge,predicted CCS single,predicted CCS multi 1,predicted CCS multi 2\n"
108-
)
109-
for peptidoform, charge, CCS_single, CCS_multi_1, CCS_multi_2 in zip(
110-
psm_list_pred_df["peptidoform"],
111-
psm_list_pred_df["charge"],
112-
psm_list_pred_df["predicted_ccs"],
113-
pred_df["predicted_ccs_multi_1"],
114-
pred_df["predicted_ccs_multi_2"],
115-
):
116-
output_file.write(
117-
f"{peptidoform},{charge},{CCS_single},{CCS_multi_1},{CCS_multi_2}\n"
94+
psm_list_pred_df["predicted_im"] = ccs2im(
95+
psm_list_pred_df["predicted_ccs"],
96+
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
97+
psm_list_pred_df["charge"],
98+
)
99+
psm_list_pred_df["predicted_im_multi_1"] = ccs2im(
100+
pred_df["predicted_ccs_multi_1"],
101+
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
102+
psm_list_pred_df["charge"],
103+
)
104+
psm_list_pred_df["predicted_im_multi_2"] = ccs2im(
105+
pred_df["predicted_ccs_multi_2"],
106+
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
107+
psm_list_pred_df["charge"],
108+
)
109+
if write_output:
110+
LOGGER.info("Writing output file for multi-ion mobility prediction...")
111+
with open(output_file, "w") as f:
112+
f.write(
113+
"modified_seq,charge,predicted IM single,predicted IM multi 1,predicted IM multi 2\n"
118114
)
119-
else:
120-
LOGGER.info("Converting CCS to IM values...")
121-
psm_list_pred_df["predicted_im_multi_1"] = ccs2im(
122-
pred_df["predicted_ccs_multi_1"],
123-
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
124-
psm_list_pred_df["charge"],
125-
)
126-
psm_list_pred_df["predicted_im_multi_2"] = ccs2im(
127-
pred_df["predicted_ccs_multi_2"],
128-
psm_list_pred_df["peptidoform"].apply(lambda x: x.theoretical_mz),
129-
psm_list_pred_df["charge"],
130-
)
131-
LOGGER.info("Writing output file...")
132-
output_file = open(output_file, "w")
133-
output_file.write(
134-
"modified_seq,charge,predicted IM single,predicted IM multi 1,predicted IM multi 2\n"
135-
)
136-
for peptidoform, charge, IM_single, IM_multi_1, IM_multi_2 in zip(
137-
psm_list_pred_df["peptidoform"],
138-
psm_list_pred_df["charge"],
139-
psm_list_pred_df["predicted_im"],
140-
psm_list_pred_df["predicted_im_multi_1"],
141-
psm_list_pred_df["predicted_im_multi_2"],
142-
):
143-
output_file.write(
144-
f"{peptidoform},{charge},{IM_single},{IM_multi_1},{IM_multi_2}\n"
145-
)
146-
output_file.close()
147-
148-
LOGGER.info("IM2Deep finished!")
149-
150-
if not ion_mobility:
151-
return psm_list_pred_df["predicted_ccs"]
115+
for peptidoform, charge, IM_single, IM_multi_1, IM_multi_2 in zip(
116+
psm_list_pred_df["peptidoform"],
117+
psm_list_pred_df["charge"],
118+
psm_list_pred_df["predicted_im"],
119+
psm_list_pred_df["predicted_im_multi_1"],
120+
psm_list_pred_df["predicted_im_multi_2"],
121+
):
122+
f.write(f"{peptidoform},{charge},{IM_single},{IM_multi_1},{IM_multi_2}\n")
123+
LOGGER.info("IM2Deep finished!")
124+
return psm_list_pred_df["predicted_im"]
152125
else:
153-
return psm_list_pred_df["predicted_im"]
126+
if not multi:
127+
if write_output:
128+
LOGGER.info("Writing output file for CCS prediction...")
129+
with open(output_file, "w") as f:
130+
f.write("modified_seq,charge,predicted CCS\n")
131+
for peptidoform, charge, CCS in zip(
132+
psm_list_pred_df["peptidoform"],
133+
psm_list_pred_df["charge"],
134+
psm_list_pred_df["predicted_ccs"],
135+
):
136+
f.write(f"{peptidoform},{charge},{CCS}\n")
137+
LOGGER.info("IM2Deep finished!")
138+
return psm_list_pred_df["predicted_ccs"]
139+
else:
140+
if write_output:
141+
LOGGER.info("Writing output file for multi-CCS prediction...")
142+
with open(output_file, "w") as f:
143+
f.write(
144+
"modified_seq,charge,predicted CCS single,predicted CCS multi 1,predicted CCS multi 2\n"
145+
)
146+
for peptidoform, charge, CCS_single, CCS_multi_1, CCS_multi_2 in zip(
147+
psm_list_pred_df["peptidoform"],
148+
psm_list_pred_df["charge"],
149+
psm_list_pred_df["predicted_ccs"],
150+
pred_df["predicted_ccs_multi_1"],
151+
pred_df["predicted_ccs_multi_2"],
152+
):
153+
f.write(
154+
f"{peptidoform},{charge},{CCS_single},{CCS_multi_1},{CCS_multi_2}\n"
155+
)
156+
LOGGER.info("IM2Deep finished!")
157+
return psm_list_pred_df["predicted_ccs"]

0 commit comments

Comments
 (0)