Mercurial > repos > galaxyp > pyteomics_mztab2tsv
comparison mztab_reader.py @ 0:84e4b5d4b7ad draft
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
author | galaxyp |
---|---|
date | Fri, 15 Jan 2021 15:58:54 +0000 |
parents | |
children | a475c1906e0b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:84e4b5d4b7ad |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import argparse | |
4 import os | |
5 | |
6 import pandas as pd | |
7 from pyteomics.mztab import MzTab | |
8 | |
9 | |
10 def read_mztab(input_path, output_path): | |
11 """ | |
12 Read mztab file | |
13 """ | |
14 mztab = MzTab(input_path) | |
15 if mztab.variant == 'P': | |
16 return read_mztab_p(mztab, output_path) | |
17 elif mztab.variant == 'M': | |
18 return read_mztab_m(mztab, output_path) | |
19 | |
20 | |
21 def read_mztab_p(mztab, output_path): | |
22 """ | |
23 Processing mztab "P" | |
24 """ | |
25 mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index') | |
26 mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t") | |
27 prt = mztab.protein_table | |
28 prt.to_csv(os.path.join(output_path, "prt.tsv"), sep="\t") | |
29 pep = mztab.peptide_table | |
30 pep.to_csv(os.path.join(output_path, "pep.tsv"), sep="\t") | |
31 psm = mztab.spectrum_match_table | |
32 psm.to_csv(os.path.join(output_path, "psm.tsv"), sep="\t") | |
33 sml = mztab.small_molecule_table | |
34 sml.to_csv(os.path.join(output_path, "sml.tsv"), sep="\t") | |
35 | |
36 | |
37 def read_mztab_m(mztab, output_path): | |
38 """ | |
39 Processing mztab "M" | |
40 """ | |
41 mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index') | |
42 mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t") | |
43 sml = mztab.small_molecule_table | |
44 sml.to_csv(os.path.join(output_path, "sml.tsv"), sep="\t") | |
45 smf = mztab.small_molecule_feature_table | |
46 smf.to_csv(os.path.join(output_path, "smf.tsv"), sep="\t") | |
47 sme = mztab.small_molecule_evidence_table | |
48 sme.to_csv(os.path.join(output_path, "sme.tsv"), sep="\t") | |
49 | |
50 | |
51 if __name__ == "__main__": | |
52 # Create the parser | |
53 my_parser = argparse.ArgumentParser(description='List of paths') | |
54 # Add the arguments | |
55 my_parser.add_argument('--path_in', | |
56 metavar='path', | |
57 type=str, | |
58 required=True, | |
59 help='the path of input .mztab file') | |
60 my_parser.add_argument('--path_out', | |
61 metavar='path', | |
62 type=str, | |
63 default=os.getcwd(), | |
64 help='the path of folder for output .tsv file') | |
65 | |
66 # Execute parse_args() | |
67 args = my_parser.parse_args() | |
68 | |
69 read_mztab(args.path_in, args.path_out) |