Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit b961d4e

Browse files
Merge pull request #30 from hgb-bin-proteomics/develop
add exporter for xiFDR >= 2.2.1
2 parents 608247f + 972069f commit b961d4e

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ Results can then be exported by selecting `File > Export > To Microsoft Excel…
6060
Files needed:
6161
- result.xlsx - MS Annika CSM result file (unvalidated) exported to .xlsx
6262
```
63+
# for xiFDR version < 2.2.1
6364
python xiFdrExporter_msannika.py result.xlsx
65+
# for xiFDR version >= 2.2.1
66+
python xiFdr2.2.1Exporter_msannika.py result.xlsx
6467
```
6568
- **Exporting to [pyXlinkViewer (pyMOL)](https://github.com/BobSchiffrin/PyXlinkViewer)**
6669
Files needed:
@@ -188,7 +191,7 @@ optional arguments:
188191
--version show program's version number and exit
189192
```
190193

191-
Example usage:
194+
Example usage (xiFDR version < 2.2.1):
192195

193196
```
194197
python xiFdrExporter_msannika.py XLpeplib_Beveridge_QEx-HFX_DSS_R1.xlsx
@@ -200,6 +203,18 @@ Or using the Windows binary:
200203
xiFdrExporter_msannika.exe XLpeplib_Beveridge_QEx-HFX_DSS_R1.xlsx
201204
```
202205

206+
Example usage (xiFDR version 2.2.1 or later):
207+
208+
```
209+
python xiFdr2.2.1Exporter_msannika.py XLpeplib_Beveridge_QEx-HFX_DSS_R1.xlsx
210+
```
211+
212+
Or using the Windows binary:
213+
214+
```
215+
xiFdr2.2.1Exporter_msannika.exe XLpeplib_Beveridge_QEx-HFX_DSS_R1.xlsx
216+
```
217+
203218
## Export to [PyXlinkViewer for pyMOL](https://github.com/BobSchiffrin/PyXlinkViewer)
204219

205220
A schematic workflow of the implementation can be seen in [*this figure*](img/workflow_pyMOLexporter.png).
34 MB
Binary file not shown.

xiFdr2.2.1Exporter_msannika.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python3
2+
3+
# Exporter of MS Annika CSM Results to xiFDR 2.2.1 input format
4+
# 2024 (c) Micha Johannes Birklbauer
5+
# https://github.com/michabirklbauer/
6+
# micha.birklbauer@gmail.com
7+
8+
import argparse
9+
import pandas as pd
10+
11+
__version = "1.0.2"
12+
__date = "202405017"
13+
14+
"""
15+
DESCRIPTION:
16+
A script to export MS Annika CSM results (.xlsx) to a xiFDR input file (.csv).
17+
This version only works for xiFDR 2.2.1 and later!
18+
CSMs should be unfiltered, therefore include decoys and not be validated for any
19+
FDR.
20+
USAGE:
21+
xiFdr2.2.1Exporter_msannika.py f [f]
22+
[-o OUTPUT]
23+
[-h]
24+
[--version]
25+
positional arguments:
26+
f Crosslink-Spectrum-Matches (CSMs) exported from
27+
MS Annika in Microsoft Excel (.xlsx) format.
28+
optional arguments:
29+
-o OUTPUT, --output OUTPUT
30+
Prefix of the output file.
31+
-h, --help show this help message and exit
32+
--version show program's version number and exit
33+
"""
34+
35+
# Exporter class with constructor that takes one MS Annika CSM result file as
36+
# input. CSMs should not be in any way filtered and exported to Microsoft Excel
37+
# .xlsx format from Proteome Discoverer.
38+
class MSAnnika_Exporter:
39+
40+
def __init__(self, input_file: str):
41+
self.input_file = input_file
42+
43+
# static method to generate pandas dataframe of xiFDR export without class
44+
# instance. Takes the file name of the CSM file as input.
45+
@staticmethod
46+
def generate_df(input_file: str) -> pd.DataFrame:
47+
48+
df = pd.read_excel(input_file)
49+
df.rename(columns = {"Spectrum File": "run",
50+
"First Scan": "scan",
51+
"Sequence A": "peptide1",
52+
"Sequence B": "peptide2",
53+
"Crosslinker Position A": "peptide link 1",
54+
"Crosslinker Position B": "peptide link 2",
55+
"Charge": "precursor charge",
56+
"Combined Score": "score",
57+
"Score Alpha": "peptide1 score",
58+
"Score Beta": "peptide2 score",
59+
"Accession A": "accession1",
60+
"Accession B": "accession2",
61+
"A in protein": "peptide position 1",
62+
"B in protein": "peptide position 2"},
63+
inplace = True,
64+
errors = "raise")
65+
df["is decoy 1"] = df["Alpha T/D"].apply(lambda x: "false" if "t" in str(x).lower() else "true")
66+
df["is decoy 2"] = df["Beta T/D"].apply(lambda x: "false" if "t" in str(x).lower() else "true")
67+
df["peptide position 1"] = df["peptide position 1"].apply(lambda x: ";".join([str(int(y) + 1) for y in str(x).split(";")]))
68+
df["peptide position 2"] = df["peptide position 2"].apply(lambda x: ";".join([str(int(y) + 1) for y in str(x).split(";")]))
69+
70+
return df
71+
72+
# classmethod implementation of the static generate_df
73+
def __generate_csv_df(self) -> pd.DataFrame:
74+
return self.generate_df(self.input_file)
75+
76+
# export function, takes one argument "output_file" which sets the prefix
77+
# of generated output file
78+
def export(self, output_file: str = None) -> pd.DataFrame:
79+
csv = self.__generate_csv_df()
80+
81+
if output_file is None:
82+
output_file = ".".join(self.input_file.split(".")[:-1])
83+
84+
csv.to_csv(output_file + "_xiFDR.csv", index = False)
85+
86+
return csv
87+
88+
# initialize exporter and export xiFDR csv file
89+
def main() -> None:
90+
parser = argparse.ArgumentParser()
91+
parser.add_argument(metavar = "f",
92+
dest = "file",
93+
help = "Name/Path of the MS Annika CSM result file (in .xlsx format) to process.",
94+
type = str,
95+
nargs = 1)
96+
parser.add_argument("-o", "--output",
97+
dest = "output",
98+
default = None,
99+
help = "Prefix of the output file.",
100+
type = str)
101+
parser.add_argument("--version",
102+
action = "version",
103+
version = __version)
104+
args = parser.parse_args()
105+
106+
exporter = MSAnnika_Exporter(args.file[0])
107+
108+
exporter.export(args.output)
109+
110+
if __name__ == "__main__":
111+
main()

0 commit comments

Comments
 (0)