view set_path.py @ 1:90d60c9da21e draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics/blob/master/tools/mzmine/ commit 889d26f1e96edf1f2608ce0dba2d66e8ee60e313
author iuc
date Fri, 10 Nov 2023 14:20:45 +0000
parents
children
line wrap: on
line source

import argparse
import re
import sys
from xml.etree import ElementTree

parser = argparse.ArgumentParser(
    prog="set_path.py", description="update paths in mzmine batch XML"
)
parser.add_argument("--input", help="input XML")
parser.add_argument("--output", help="output XML")
parser.add_argument("--localdb", required=False, help="Local CVS DB for Search")
args = parser.parse_args()

PATHSEP = re.compile(r"[/\\]")
tree = ElementTree.parse(args.input)

for batchstep in tree.findall(".//batchstep"):
    method = batchstep.attrib.get("method")
    for current_file in batchstep.findall(".//current_file"):
        if (
            method
            == "io.github.mzmine.modules.dataprocessing.id_localcsvsearch.LocalCSVDatabaseSearchModule"
        ):
            if args.localdb:
                current_file.text = args.localdb
            else:
                sys.exit("Batch file contains LocalCSVDatabaseSearchModule but no local DB CSV file given")
        else:
            current_file.text = f"./output/{PATHSEP.split(current_file.text)[-1]}"

tree.write(args.output)