ms2pip.spectrum_output

Write spectrum files from MS2PIP predictions.

exception ms2pip.spectrum_output.InvalidWriteModeError[source]

Bases: ValueError

class ms2pip.spectrum_output.SpectrumOutput(results, output_filename='ms2pip_predictions', write_mode='wt+', return_stringbuffer=False, is_log_space=True)[source]

Bases: object

Write MS2PIP predictions to various output formats.

Parameters:
  • results (List['ProcessingResult']) – List of ProcessingResult objects

  • output_filename (str, optional) – path and name for output files, will be suffexed with _predictions and the relevant file extension (default: ms2pip_predictions)

  • write_mode (str, optional) – write mode to use: “wt+” to append to start a new file, “at” to append to an existing file (default: “wt+”)

  • return_stringbuffer (bool, optional) – If True, files are written to a StringIO object, which the write function returns. If False, files are written to a file on disk.

  • is_log_space (bool, optional) – Set to true if predicted intensities in all_preds are in log-space. In that case, intensities will first be transformed to “normal”-space.

Example

>>> so = ms2pip.spectrum_tools.spectrum_output.SpectrumOutput(
        results
    )
>>> so.write_msp()
>>> so.write_spectronaut()
write_results(output_formats)[source]

Write MS2PIP predictions in output formats defined by output_formats.

Parameters:

output_formats (List[str]) –

Return type:

Dict[str, Any]

write_msp(file_object)[source]

Construct MSP string and write to file_object.

write_mgf(file_object)[source]

Construct MGF string and write to file_object

write_spectronaut(file_obj)[source]

Construct spectronaut DataFrame and write to file_object.

write_bibliospec()[source]

Write MS2PIP predictions to BiblioSpec/Skyline SSL and MS2 spectral library files.

write_dlib()[source]

Write MS2PIP predictions to a DLIB SQLite file.

get_normalized_predictions(normalization_method='tic')[source]

Return normalized copy of predictions.

write_csv()[source]

Write MS2PIP predictions to CSV.

ms2pip.spectrum_output.write_single_spectrum_csv(spectrum, filepath)[source]

Write a single spectrum to a CSV file.

ms2pip.spectrum_output.write_single_spectrum_png(spectrum, filepath)[source]

Plot a single spectrum and write to a PNG file.