-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement most of spectrum_output for v4.0.0
- Loading branch information
Showing
5 changed files
with
661 additions
and
703 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
from ms2pip.spectrum import Spectrum | ||
|
||
try: | ||
import matplotlib.pyplot as plt | ||
import spectrum_utils.plot as sup | ||
|
||
_can_plot = True | ||
except ImportError: | ||
_can_plot = False | ||
|
||
|
||
def spectrum_to_png(spectrum: Spectrum, filepath: Union[str, Path]): | ||
"""Plot a single spectrum and write to a PNG file.""" | ||
if not _can_plot: | ||
raise ImportError("Matplotlib and spectrum_utils are required to plot spectra.") | ||
ax = plt.gca() | ||
ax.set_title("MS²PIP prediction for " + str(spectrum.peptidoform)) | ||
sup.spectrum(spectrum.to_spectrum_utils(), ax=ax) | ||
plt.savefig(Path(filepath).with_suffix(".png")) | ||
plt.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.