Picking n-th spectra from a mgf file #103
-
Hello, I would like to read a I can read the file perfectly fine, and I can easily print every n-th spectra by indexing like this: For example, taking every tenth spectra, doing something along these lines:
Or by using In other words, something like this:
Any help is much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
file = mgf.read(filePath)
nSpectra = len(file)
for i in range(nSpectra):
if i % 10 == 0:
mgf.write([file[i]], outputFile) Or file = mgf.read(filePath)
nSpectra = len(file)
mgf.write((file[i] for i in range(nSpectra) if i % 10), outputFile) The first solves the problem by calling |
Beta Was this translation helpful? Give feedback.
mgf.write
takes anIterable
over spectra, not a single spectrum as its first argument. Without seeing an error message, I have to guess this is the problem you've encountered. You can rewrite this two ways to make it work:Or
The first solves the problem by calling
write
and passing a list of spectra of length 1 for every spectrum you want to write.The second solves the problem by converting your for-loop to a generator expression and passing…