Skip to content
Discussion options

You must be logged in to vote

You could do almost exactly what you have there, just wrap each individual spectrum in a list or tuple:

with mgf.MGF(input_mgf_fp) as reader:
    for spectrum in reader:
        params = spectrum.get('params')
        if params['feature_id'] in feature_ids:
            mgf.write([spectrum], output_fp)

The first parameter of mgf.write is an iterable of spectra, so in order to match its expectations, we need to wrap single spectrum dict objects in something that satisfies the expectation that next(iter(obj)) -> dict. This happens to work because mgf.write doesn't close the output stream and doesn't automatically append a file header unless you tell it to.

Another option is to use a generato…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ekopylova
Comment options

Answer selected by levitsky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants