comparison 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
comparison
equal deleted inserted replaced
0:84e4b5d4b7ad 1:a475c1906e0b
7 from pyteomics.mztab import MzTab 7 from pyteomics.mztab import MzTab
8 8
9 9
10 def read_mztab(input_path, output_path): 10 def read_mztab(input_path, output_path):
11 """ 11 """
12 Read mztab file 12 Read and process mztab file
13 """ 13 """
14 mztab = MzTab(input_path) 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') 15 mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index')
26 mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t") 16 mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t")
27 prt = mztab.protein_table 17 for name, tab in mztab:
28 prt.to_csv(os.path.join(output_path, "prt.tsv"), sep="\t") 18 if not tab.empty:
29 pep = mztab.peptide_table 19 tab.to_csv(os.path.join(output_path, f"{name.lower()}.tsv"), sep="\t")
30 pep.to_csv(os.path.join(output_path, "pep.tsv"), sep="\t") 20 else:
31 psm = mztab.spectrum_match_table 21 with open(os.path.join(output_path, f"{name.lower()}.tsv"), "w"):
32 psm.to_csv(os.path.join(output_path, "psm.tsv"), sep="\t") 22 pass
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 23
50 24
51 if __name__ == "__main__": 25 if __name__ == "__main__":
52 # Create the parser 26 # Create the parser
53 my_parser = argparse.ArgumentParser(description='List of paths') 27 my_parser = argparse.ArgumentParser(description='List of paths')