Mercurial > repos > recetox > msp_merge
comparison msp_merge.py @ 0:d19767887ccb draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msp_merge commit 51ff658aecc8738ef57af512229cd155763082d1
| author | recetox |
|---|---|
| date | Thu, 19 May 2022 12:03:55 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d19767887ccb |
|---|---|
| 1 import argparse | |
| 2 from itertools import chain | |
| 3 from typing import List | |
| 4 | |
| 5 from matchms import Spectrum | |
| 6 from matchms.exporting import save_as_msp | |
| 7 from matchms.importing import load_from_msp | |
| 8 | |
| 9 | |
| 10 def read_spectra(filenames: str) -> List[Spectrum]: | |
| 11 """Read spectra from files. | |
| 12 | |
| 13 Args: | |
| 14 filenames (str): Paths to MSP files from which to load each spectrum. | |
| 15 | |
| 16 Returns: | |
| 17 List[Spectrum]: Spectra stored in the file. | |
| 18 """ | |
| 19 spectra = list(chain(*[load_from_msp(file) for file in filenames])) | |
| 20 return spectra | |
| 21 | |
| 22 | |
| 23 listarg = argparse.ArgumentParser() | |
| 24 listarg.add_argument('--filenames', nargs='+', type=str) | |
| 25 listarg.add_argument('--outfilename', type=str) | |
| 26 args = listarg.parse_args() | |
| 27 | |
| 28 if __name__ == "__main__": | |
| 29 spectra = read_spectra(args.filenames) | |
| 30 save_as_msp(spectra, args.outfilename) |
