annotate mztab_reader.py @ 1:a475c1906e0b draft default tip

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
author galaxyp
date Fri, 15 Jan 2021 21:10:59 +0000
parents 84e4b5d4b7ad
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
1 #!/usr/bin/env python
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
2
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
3 import argparse
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
4 import os
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
5
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
6 import pandas as pd
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
7 from pyteomics.mztab import MzTab
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
8
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
9
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
10 def read_mztab(input_path, output_path):
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
11 """
1
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
12 Read and process mztab file
0
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
13 """
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
14 mztab = MzTab(input_path)
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
15 mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index')
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
16 mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t")
1
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
17 for name, tab in mztab:
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
18 if not tab.empty:
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
19 tab.to_csv(os.path.join(output_path, f"{name.lower()}.tsv"), sep="\t")
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
20 else:
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
21 with open(os.path.join(output_path, f"{name.lower()}.tsv"), "w"):
a475c1906e0b "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 58fe8232b7f4659b37e8725197d63e81efae0683"
galaxyp
parents: 0
diff changeset
22 pass
0
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
23
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
24
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
25 if __name__ == "__main__":
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
26 # Create the parser
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
27 my_parser = argparse.ArgumentParser(description='List of paths')
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
28 # Add the arguments
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
29 my_parser.add_argument('--path_in',
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
30 metavar='path',
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
31 type=str,
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
32 required=True,
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
33 help='the path of input .mztab file')
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
34 my_parser.add_argument('--path_out',
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
35 metavar='path',
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
36 type=str,
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
37 default=os.getcwd(),
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
38 help='the path of folder for output .tsv file')
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
39
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
40 # Execute parse_args()
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
41 args = my_parser.parse_args()
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
42
84e4b5d4b7ad "planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/pyteomics commit 49b21b01937067ffc7cf088e615d68177644640b"
galaxyp
parents:
diff changeset
43 read_mztab(args.path_in, args.path_out)