0

I'm trying to write a program that can analyse Mass Spectrometry .mzml files for my Chemistry project at university. I'm new to programming. I have some code that allows the user to browse a file, but the code only prints the file path.

import Tkinter
import tkFileDialog

def main():

    Tkinter.Tk().withdraw()
    in_path = tkFileDialog.askopenfilename(filetypes=[("mzml file","*.mzML")])
    print in_path


if __name__ == "__main__":
    main()

How would I change it so that the file chosen is imported into the code and is able to be read so that I can take information from it (Mass spectra, chromatograms and the like)?

filepath is the file-browser file. I want to import the file into something like this using PyOpenMS package:

import pyopenms
from pyopenms import *
import numpy as np
import filepath

filepath.main()

exp = pyopenms.MSExperiment()
pyopenms.MzMLFile().load('**in_path**', exp)

I know that trying to load in_path is wrong, but I'm not sure what to put!

martineau
  • 119,623
  • 25
  • 170
  • 301
  • All `askopenfilename()` does is return a filename (string) which you're storing in `in_path`. To use it will depending how `pyopenms` works. This should be in the module's documentation somewhere. One thing you will need to do is change the `main()` function to `return in_path` so the script that actually does the importing will be able to use it as needed, – martineau Feb 02 '20 at 21:10
  • Change `print in_path` to `return in_path` and `.load(filepath.main(), ...` – stovfl Feb 02 '20 at 22:37

0 Answers0