-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
tools/matchms/matchms_export_skyline_transition_list.ipynb
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,112 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from matchms.importing import load_from_msp\n", | ||
"from matchms.exporting.metadata_export import get_metadata_as_array\n", | ||
"\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spectra_file = \"test-data/filtering/reduce_to_top_n_peaks.msp\"\n", | ||
"name_key = 'compound_name'\n", | ||
"cols_to_include = [name_key, 'retention_index', 'mz', 'intensity']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 40, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"2024-11-06 14:26:01,189:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.\n", | ||
"2024-11-06 14:26:01,190:WARNING:matchms:add_retention:None can't be converted to float.\n", | ||
"2024-11-06 14:26:01,191:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.\n", | ||
"2024-11-06 14:26:01,192:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.\n", | ||
"2024-11-06 14:26:01,193:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.\n", | ||
"2024-11-06 14:26:01,194:WARNING:matchms:add_precursor_mz:No precursor_mz found in metadata.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"spectra = list(load_from_msp(spectra_file))\n", | ||
"spectra_dict = {}\n", | ||
"for spectrum in spectra:\n", | ||
" spectra_dict[spectrum.get(name_key)] = spectrum" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 41, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spectra_metadata, cols = get_metadata_as_array(spectra)\n", | ||
"spectra_metadata_df = pd.DataFrame(spectra_metadata)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 42, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spectra_metadata_df['peaks'] = spectra_metadata_df[name_key].transform(lambda x: spectra_dict[x].peaks)\n", | ||
"spectra_metadata_df['mz'] = spectra_metadata_df['peaks'].transform(lambda x: x.mz)\n", | ||
"spectra_metadata_df['intensity'] = spectra_metadata_df['peaks'].transform(lambda x: x.intensities)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 43, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spectra_metadata_df = spectra_metadata_df.explode(['mz', 'intensity']).reset_index(drop=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 45, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"result = spectra_metadata_df[cols_to_include].rename(columns={'compound_name': 'precursor name', 'retention_index': 'retention index'})" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "matchms", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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