Mercurial > repos > galaxyp > pyteomics_mztab2tsv
changeset 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 | |
files | mztab2tsv.xml mztab_reader.py |
diffstat | 2 files changed, 9 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/mztab2tsv.xml Fri Jan 15 15:58:54 2021 +0000 +++ b/mztab2tsv.xml Fri Jan 15 21:10:59 2021 +0000 @@ -60,13 +60,13 @@ <assert_contents><has_text text="accession"/></assert_contents> </output> <output name="out_pep" ftype="tabular"> - <assert_contents><has_text text=""""/></assert_contents> + <assert_contents><has_n_lines n="0"/></assert_contents> </output> <output name="out_psm" ftype="tabular"> <assert_contents><has_text text="PSM_ID"/></assert_contents> </output> <output name="out_sml" ftype="tabular"> - <assert_contents><has_text text=""""/></assert_contents> + <assert_contents><has_n_lines n="0"/></assert_contents> </output> </test> <test expect_num_outputs="4">
--- a/mztab_reader.py Fri Jan 15 15:58:54 2021 +0000 +++ b/mztab_reader.py Fri Jan 15 21:10:59 2021 +0000 @@ -9,43 +9,17 @@ def read_mztab(input_path, output_path): """ - Read mztab file + Read and process mztab file """ mztab = MzTab(input_path) - if mztab.variant == 'P': - return read_mztab_p(mztab, output_path) - elif mztab.variant == 'M': - return read_mztab_m(mztab, output_path) - - -def read_mztab_p(mztab, output_path): - """ - Processing mztab "P" - """ mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index') mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t") - prt = mztab.protein_table - prt.to_csv(os.path.join(output_path, "prt.tsv"), sep="\t") - pep = mztab.peptide_table - pep.to_csv(os.path.join(output_path, "pep.tsv"), sep="\t") - psm = mztab.spectrum_match_table - psm.to_csv(os.path.join(output_path, "psm.tsv"), sep="\t") - sml = mztab.small_molecule_table - sml.to_csv(os.path.join(output_path, "sml.tsv"), sep="\t") - - -def read_mztab_m(mztab, output_path): - """ - Processing mztab "M" - """ - mtd = pd.DataFrame.from_dict(mztab.metadata, orient='index') - mtd.to_csv(os.path.join(output_path, "mtd.tsv"), sep="\t") - sml = mztab.small_molecule_table - sml.to_csv(os.path.join(output_path, "sml.tsv"), sep="\t") - smf = mztab.small_molecule_feature_table - smf.to_csv(os.path.join(output_path, "smf.tsv"), sep="\t") - sme = mztab.small_molecule_evidence_table - sme.to_csv(os.path.join(output_path, "sme.tsv"), sep="\t") + for name, tab in mztab: + if not tab.empty: + tab.to_csv(os.path.join(output_path, f"{name.lower()}.tsv"), sep="\t") + else: + with open(os.path.join(output_path, f"{name.lower()}.tsv"), "w"): + pass if __name__ == "__main__":