Skip to content

Commit 7a310ea

Browse files
Deploy PR #101 preview [skip ci]
1 parent ed4f1a2 commit 7a310ea

190 files changed

Lines changed: 1109 additions & 1587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pr-101/Parameters/Spectrum.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,10 @@ <h2>Example Usage<a class="headerlink" href="#example-usage" title="Link to this
621621
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum from extracted data. No binning is applied."><img alt="" src="../_images/sphx_glr_plot_spectrum_dia_ms_bokeh_thumb.png" />
622622
<p><a class="reference internal" href="../gallery/ms_bokeh/plot_spectrum_dia_ms_bokeh.html"><span class="doc">Spectrum of Extracted DIA Data ms_bokeh</span></a></p>
623623
<div class="sphx-glr-thumbnail-title">Spectrum of Extracted DIA Data ms_bokeh</div>
624-
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_bokeh_thumb.png" />
624+
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_bokeh_thumb.png" />
625625
<p><a class="reference internal" href="../gallery/ms_bokeh/plot_spectrum_ms_bokeh.html"><span class="doc">Spectrum ms_bokeh</span></a></p>
626626
<div class="sphx-glr-thumbnail-title">Spectrum ms_bokeh</div>
627-
</div><div class="sphx-glr-thumbcontainer" tooltip="Here we use a dummy spectrum example to investigate spectrum binning. "><img alt="" src="../_images/sphx_glr_plot_investigate_spectrum_binning_ms_matplotlib_thumb.png" />
627+
</div><div class="sphx-glr-thumbcontainer" tooltip="Here we use a dummy spectrum example to investigate spectrum binning."><img alt="" src="../_images/sphx_glr_plot_investigate_spectrum_binning_ms_matplotlib_thumb.png" />
628628
<p><a class="reference internal" href="../gallery/ms_matplotlib/plot_investigate_spectrum_binning_ms_matplotlib.html"><span class="doc">Investigate Spctrum Binning ms_matplotlib</span></a></p>
629629
<div class="sphx-glr-thumbnail-title">Investigate Spctrum Binning ms_matplotlib</div>
630630
</div><div class="sphx-glr-thumbcontainer" tooltip="This shows the code required to plot the d-fructose example in the manuscript. The mzML file is from the the Human Metabolome Database (ID: HMDB0000660)"><img alt="" src="../_images/sphx_glr_plot_manuscript_d_fructose_spectrum_prediction_ms_matplotlib_thumb.png" />
@@ -633,13 +633,13 @@ <h2>Example Usage<a class="headerlink" href="#example-usage" title="Link to this
633633
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum from extracted data. No binning is applied."><img alt="" src="../_images/sphx_glr_plot_spectrum_dia_ms_matplotlib_thumb.png" />
634634
<p><a class="reference internal" href="../gallery/ms_matplotlib/plot_spectrum_dia_ms_matplotlib.html"><span class="doc">Spectrum of Extracted DIA Data ms_matplotlib</span></a></p>
635635
<div class="sphx-glr-thumbnail-title">Spectrum of Extracted DIA Data ms_matplotlib</div>
636-
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_matplotlib_thumb.png" />
636+
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_matplotlib_thumb.png" />
637637
<p><a class="reference internal" href="../gallery/ms_matplotlib/plot_spectrum_ms_matplotlib.html"><span class="doc">Spectrum ms_matplotlib</span></a></p>
638638
<div class="sphx-glr-thumbnail-title">Spectrum ms_matplotlib</div>
639639
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum from extracted data. No binning is applied."><img alt="" src="../_images/sphx_glr_plot_spectrum_dia_ms_plotly_thumb.png" />
640640
<p><a class="reference internal" href="../gallery/ms_plotly/plot_spectrum_dia_ms_plotly.html"><span class="doc">Spectrum of Extracted DIA Data ms_plotly</span></a></p>
641641
<div class="sphx-glr-thumbnail-title">Spectrum of Extracted DIA Data ms_plotly</div>
642-
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_plotly_thumb.png" />
642+
</div><div class="sphx-glr-thumbcontainer" tooltip="This example shows a spectrum. We can add the ion_annotation and sequence annotation by specifying these columns."><img alt="" src="../_images/sphx_glr_plot_spectrum_ms_plotly_thumb.png" />
643643
<p><a class="reference internal" href="../gallery/ms_plotly/plot_spectrum_ms_plotly.html"><span class="doc">Spectrum ms_plotly</span></a></p>
644644
<div class="sphx-glr-thumbnail-title">Spectrum ms_plotly</div>
645645
</div></div></section>

pr-101/_downloads/02c3fb5f62267b776b91e2ba90235d76/plot_mobilogram_ms_bokeh.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
This example shows how to use different approaches.
77
"""
88

9+
import os
910
import pandas as pd
10-
import requests
11-
from io import StringIO
11+
from pyopenms_viz.util import download_file
1212

1313
pd.options.plotting.backend = "ms_bokeh"
1414

15-
# download the file for example plotting
16-
url = "https://github.com/OpenMS/pyopenms_viz/releases/download/v0.1.5/ionMobilityTestFeatureDf.tsv"
17-
response = requests.get(url)
18-
response.raise_for_status() # Check for any HTTP errors
19-
df = pd.read_csv(StringIO(response.text), sep="\t")
15+
local_path = "ionMobilityTestFeatureDf.tsv"
16+
url = "https://zenodo.org/records/17904352/files/ionMobilityTestFeatureDf.tsv?download=1"
17+
download_file(url, local_path)
18+
df = pd.read_csv(local_path, sep="\t")
2019

2120
df.plot(
2221
kind="mobilogram",

pr-101/_downloads/055bb6e84f747c63485d2dc9635a2dae/plot_chromatogram_ms_bokeh.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"import pandas as pd\nimport requests\nfrom io import StringIO\n\npd.options.plotting.backend = \"ms_bokeh\"\n\n\n# download the file for example plotting\nurl = \"https://github.com/OpenMS/pyopenms_viz/releases/download/v0.1.5/ionMobilityTestChromatogramDf.tsv\"\nresponse = requests.get(url)\nresponse.raise_for_status() # Check for any HTTP errors\ndf = pd.read_csv(StringIO(response.text), sep=\"\\t\")\n\ndf.plot(\n kind=\"chromatogram\",\n x=\"rt\",\n y=\"int\",\n by=\"Annotation\",\n legend_config=dict(bbox_to_anchor=(1, 0.7)),\n)"
18+
"import pandas as pd\nfrom pyopenms_viz.util import download_file\n\npd.options.plotting.backend = \"ms_bokeh\"\n\nurl = \"https://zenodo.org/records/17904352/files/ionMobilityTestChromatogramDf.tsv?download=1\"\nlocal_path = \"ionMobilityTestChromatogramDf.tsv\"\ndownload_file(url, local_path)\ndf = pd.read_csv(local_path, sep=\"\\t\")\n\ndf.plot(\n kind=\"chromatogram\",\n x=\"rt\",\n y=\"int\",\n by=\"Annotation\",\n legend_config=dict(bbox_to_anchor=(1, 0.7)),\n)"
1919
]
2020
}
2121
],

pr-101/_downloads/09f9dd56f5c8755cebde1b45fc070778/plot_manuscript_d_fructose_spectrum_prediction_ms_matplotlib.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"outputs": [],
3535
"source": [
36-
"import requests\nimport zipfile\nimport io\n\n# URL of the ZIP file\nurl = \"https://github.com/OpenMS/pyopenms_viz/releases/download/manuscript/d_fructose_example.zip\"\n\n# Download the ZIP file\nresponse = requests.get(url)\nresponse.raise_for_status() # Check for request errors\n\n# Unzip the content\nwith zipfile.ZipFile(io.BytesIO(response.content)) as zip_file:\n zip_file.extractall(\"d_fructose_example\") # Extract to a directory\n print(\"Files extracted to 'd_fructose_example'\")"
36+
"from pyopenms_viz.util import download_file, unzip_file\n\n# URL of the ZIP file\nurl = \"https://zenodo.org/records/17904512/files/d_fructose_example.zip?download=1\"\n\n# Download and extract the ZIP file\nzip_filename = \"d_fructose_example.zip\"\ndownload_file(url, zip_filename)\nunzip_file(zip_filename, \".\") # Extract to current directory"
3737
]
3838
},
3939
{
@@ -87,7 +87,7 @@
8787
},
8888
"outputs": [],
8989
"source": [
90-
"import pymzml\n\n# Load the known annotated SMILES and formula into a dataframe\ndata = {\n \"mz\": [45.0, 61.0, 73.0, 75.0, 87.0],\n \"formula\": [\"CHO2\", \"C2H5O2\", \"C2HO3\", \"C2H3O3\", \"C3H3O3\"],\n \"SMILES\": [\"C(=O)O\", \"CC(=O)O\", \"O=CC(=O)O\", \"OCC(=O)O\", \"O=CC(=O)CO\"],\n}\nann_df = pd.DataFrame(data)\n\n# We can use pymzml to load the spectrum data from the mzML file\n\ninput_file = \"./d_fructose_example/d_fructose_example/D-Fructose_lc_msms.mzML\"\n\nrun = pymzml.run.Reader(input_file)\n# Get the first spec\nspec = run.next()\n# Convert to Pandas DataFrame\ndf = pd.DataFrame(spec.centroidedPeaks).rename(columns={0: \"mz\", 1: \"int\"})\ndf[\"rel_int\"] = df[\"int\"] / df[\"int\"].max() * 100\ndf[\"color_peak\"] = \"#1b9e77\"\ni = 1\nfor mz in df[\"mz\"]:\n if np.floor(mz) in ann_df[\"mz\"].values:\n # print(f\"{ann_df[['mz']].isin([mz]).values.flatten()}\")\n df.loc[df.mz == mz, [\"custom_annotation\"]] = ann_df.loc[\n ann_df[[\"mz\"]].isin([mz]).values.flatten(), [\"formula\"]\n ].values[0][0]\n # Apply the formatting function to the 'formula' column\n df.loc[df.mz == mz, [\"custom_annotation\"]] = df.loc[df.mz == mz][\n \"custom_annotation\"\n ].apply(format_formula)\n i += 1\n# replace the NaN values with empty strings in custom_annotation column\ndf[\"custom_annotation\"] = df[\"custom_annotation\"].fillna(\"\")\ndf.head()"
90+
"import pymzml\n\n# Load the known annotated SMILES and formula into a dataframe\ndata = {\n \"mz\": [45.0, 61.0, 73.0, 75.0, 87.0],\n \"formula\": [\"CHO2\", \"C2H5O2\", \"C2HO3\", \"C2H3O3\", \"C3H3O3\"],\n \"SMILES\": [\"C(=O)O\", \"CC(=O)O\", \"O=CC(=O)O\", \"OCC(=O)O\", \"O=CC(=O)CO\"],\n}\nann_df = pd.DataFrame(data)\n\n# We can use pymzml to load the spectrum data from the mzML file\n\ninput_file = \"./d_fructose_example/D-Fructose_lc_msms.mzML\"\n\nrun = pymzml.run.Reader(input_file)\n# Get the first spec\nspec = run.next()\n# Convert to Pandas DataFrame\ndf = pd.DataFrame(spec.centroidedPeaks).rename(columns={0: \"mz\", 1: \"int\"})\ndf[\"rel_int\"] = df[\"int\"] / df[\"int\"].max() * 100\ndf[\"color_peak\"] = \"#1b9e77\"\ni = 1\nfor mz in df[\"mz\"]:\n if np.floor(mz) in ann_df[\"mz\"].values:\n # print(f\"{ann_df[['mz']].isin([mz]).values.flatten()}\")\n df.loc[df.mz == mz, [\"custom_annotation\"]] = ann_df.loc[\n ann_df[[\"mz\"]].isin([mz]).values.flatten(), [\"formula\"]\n ].values[0][0]\n # Apply the formatting function to the 'formula' column\n df.loc[df.mz == mz, [\"custom_annotation\"]] = df.loc[df.mz == mz][\n \"custom_annotation\"\n ].apply(format_formula)\n i += 1\n# replace the NaN values with empty strings in custom_annotation column\ndf[\"custom_annotation\"] = df[\"custom_annotation\"].fillna(\"\")\ndf.head()"
9191
]
9292
},
9393
{
@@ -105,7 +105,7 @@
105105
},
106106
"outputs": [],
107107
"source": [
108-
"pred_df, annotation_df = parse_cfm_data(\n \"./d_fructose_example/d_fructose_example/cfm_prediction/cfm_d_fructose_smile_prediction.txt\",\n \"energy2\",\n)\npred_df[\"rel_int\"] = pred_df[\"int\"] / pred_df[\"int\"].max() * 100\npred_df_long = explode_frag_ids_probabilities(pred_df)\npred_df[\"color_peak\"] = \"#d95f02\"\ni = 1\nfor mz in pred_df[\"mz\"]:\n if np.floor(mz) in ann_df[\"mz\"].values:\n pred_df.loc[pred_df.mz == mz, [\"custom_annotation\"]] = f\"f{i}\"\n i += 1\n\n\n# We also want to create a dataframe with the predictions for each fragment ion with their corresponding probabilities.\npred_ann_df = annotation_df[\n (annotation_df[\"frag_id\"].isin(pred_df_long.frag_id.values.tolist()))\n]\n# Apply the function to the SMILES column to create a new column 'formula'\npred_ann_df[\"formula\"] = pred_ann_df[\"SMILES\"].apply(smiles_to_formula)\npred_ann_df = pred_ann_df = pred_ann_df.loc[\n pred_ann_df[\"mz\"].isin(pred_df.dropna().mz.values.tolist())\n]\npred_ann_df.sort_values(\"mz\", inplace=True)\npred_ann_df = pd.merge(pred_ann_df, pred_df_long, on=[\"frag_id\", \"mz\"], how=\"inner\")\npred_ann_df.sort_values([\"mz\", \"probabilities\"], inplace=True, ascending=[True, False])\n# Apply the formatting function to the 'formula' column\npred_ann_df[\"formatted_formula\"] = pred_ann_df[\"formula\"].apply(format_formula)"
108+
"pred_df, annotation_df = parse_cfm_data(\n \"./d_fructose_example/cfm_prediction/cfm_d_fructose_smile_prediction.txt\",\n \"energy2\",\n)\npred_df[\"rel_int\"] = pred_df[\"int\"] / pred_df[\"int\"].max() * 100\npred_df_long = explode_frag_ids_probabilities(pred_df)\npred_df[\"color_peak\"] = \"#d95f02\"\ni = 1\nfor mz in pred_df[\"mz\"]:\n if np.floor(mz) in ann_df[\"mz\"].values:\n pred_df.loc[pred_df.mz == mz, [\"custom_annotation\"]] = f\"f{i}\"\n i += 1\n\n\n# We also want to create a dataframe with the predictions for each fragment ion with their corresponding probabilities.\npred_ann_df = annotation_df[\n (annotation_df[\"frag_id\"].isin(pred_df_long.frag_id.values.tolist()))\n]\n# Apply the function to the SMILES column to create a new column 'formula'\npred_ann_df[\"formula\"] = pred_ann_df[\"SMILES\"].apply(smiles_to_formula)\npred_ann_df = pred_ann_df = pred_ann_df.loc[\n pred_ann_df[\"mz\"].isin(pred_df.dropna().mz.values.tolist())\n]\npred_ann_df.sort_values(\"mz\", inplace=True)\npred_ann_df = pd.merge(pred_ann_df, pred_df_long, on=[\"frag_id\", \"mz\"], how=\"inner\")\npred_ann_df.sort_values([\"mz\", \"probabilities\"], inplace=True, ascending=[True, False])\n# Apply the formatting function to the 'formula' column\npred_ann_df[\"formatted_formula\"] = pred_ann_df[\"formula\"].apply(format_formula)"
109109
]
110110
},
111111
{

pr-101/_downloads/0f0ff118cf435a491bc3ac61ea475f1f/plot_spyogenes_subplots_ms_plotly.py

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,16 @@
66
"""
77

88
import pandas as pd
9-
import requests
10-
import zipfile
119
import numpy as np
1210
from plotly.subplots import make_subplots
11+
from pyopenms_viz.util import download_file, unzip_file
1312

14-
###### Load/Download Data #######
15-
16-
# URL of the zip file
17-
url = "https://github.com/OpenMS/pyopenms_viz/releases/download/v0.1.3/spyogenes.zip"
1813
zip_filename = "spyogenes.zip"
14+
zip_dir = "spyogenes"
15+
url = "https://zenodo.org/records/17904512/files/spyogenes.zip?download=1"
1916

20-
# Download the zip file
21-
try:
22-
print(f"Downloading {zip_filename}...")
23-
response = requests.get(url)
24-
response.raise_for_status() # Check for any HTTP errors
25-
26-
# Save the zip file to the current directory
27-
with open(zip_filename, "wb") as out:
28-
out.write(response.content)
29-
print(f"Downloaded {zip_filename} successfully.")
30-
except requests.RequestException as e:
31-
print(f"Error downloading zip file: {e}")
32-
except IOError as e:
33-
print(f"Error writing zip file: {e}")
34-
35-
# Unzipping the file
36-
try:
37-
with zipfile.ZipFile(zip_filename, "r") as zip_ref:
38-
# Extract all files to the current directory
39-
zip_ref.extractall()
40-
print("Unzipped files successfully.")
41-
except zipfile.BadZipFile as e:
42-
print(f"Error unzipping file: {e}")
17+
download_file(url, zip_filename)
18+
unzip_file(zip_filename, ".") # Extract to current directory
4319

4420
annotation_bounds = pd.read_csv(
4521
"spyogenes/AADGQTVSGGSILYR3_manual_annotations.tsv", sep="\t"
Binary file not shown.

pr-101/_downloads/1434bf1f6f1744c3b93b14a76d60360b/plot_peakmap_marginals_ms_matplotlib.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"import pandas as pd\nimport requests\nfrom io import StringIO\n\npd.options.plotting.backend = \"ms_matplotlib\"\n\n# download the file for example plotting\nurl = \"https://github.com/OpenMS/pyopenms_viz/releases/download/v0.1.5/ionMobilityTestFeatureDf.tsv\"\nresponse = requests.get(url)\nresponse.raise_for_status() # Check for any HTTP errors\ndf = pd.read_csv(StringIO(response.text), sep=\"\\t\")\n\ndf.plot(\n kind=\"peakmap\",\n x=\"rt\",\n y=\"mz\",\n z=\"int\",\n add_marginals=True,\n aggregate_duplicates=True,\n)"
18+
"import pandas as pd\nfrom pyopenms_viz.util import download_file\n\npd.options.plotting.backend = \"ms_matplotlib\"\n\nurl = \"https://zenodo.org/records/17904352/files/ionMobilityTestFeatureDf.tsv?download=1\"\nlocal_path = \"ionMobilityTestFeatureDf.tsv\"\ndownload_file(url, local_path)\ndf = pd.read_csv(local_path, sep=\"\\t\")\n\ndf.plot(\n kind=\"peakmap\",\n x=\"rt\",\n y=\"mz\",\n z=\"int\",\n add_marginals=True,\n aggregate_duplicates=True,\n)"
1919
]
2020
}
2121
],
Binary file not shown.

0 commit comments

Comments
 (0)