Skip to content

Commit

Permalink
removed param
Browse files Browse the repository at this point in the history
  • Loading branch information
hechth committed Nov 6, 2024
1 parent a03fdfa commit 699633f
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 6 deletions.
112 changes: 112 additions & 0 deletions tools/matchms/matchms_export_skyline_transition_list.ipynb
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
}
7 changes: 1 addition & 6 deletions tools/matchms/matchms_export_skyline_transition_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ from matchms.exporting.metadata_export import get_metadata_as_array
name_key = 'compound_name'
cols_to_include = [name_key, 'mz', 'intensity']

if "$harmonize_metadata" == "False":
matchms.Metadata.set_key_replacements({})

#if $metadata_cols != 'None':
cols_to_include += '$metadata_cols'.split(',')
#end if

spectra = list(load_from_${input_file.ext}("${input_file}", $harmonize_metadata))
spectra = list(load_from_${input_file.ext}("${input_file}", True))

spectra_dict = {}
for spectrum in spectra:
Expand All @@ -51,8 +48,6 @@ spectra_metadata_df.to_csv("${output_file}", sep='\t', index=False)

<inputs>
<param label="Spectra file" name="input_file" type="data" format="msp,mgf" help="Mass spectral library file."/>
<param label="Harmonize metadata" name="harmonize_metadata" type="boolean" truevalue="True" falsevalue="False" hidden="True"
checked="true" help="Apply harmonization process on the metadata keys (e.g. parse numeric values, derive precursor mass)."/>
<param name="metadata_cols" type="select" label="Metadata to include" help="Select the metadata attributes to include in the output file." multiple="true">
<option value="retention_index">Retention Index</option>
<option value="precursor_mz">Precursor m/z</option>
Expand Down

0 comments on commit 699633f

Please sign in to comment.