-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from RECETOX/hechth/issue8
Add matchms with 0 scores into the output sctructure
- Loading branch information
Showing
8 changed files
with
247,935 additions
and
303,850 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 73, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"from matchms.importing import load_from_msp\n", | ||
"from matchms.logging_functions import set_matchms_logger_level\n", | ||
"import itertools\n", | ||
"\n", | ||
"set_matchms_logger_level(\"ERROR\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 74, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"predicted_spectra = list(load_from_msp(\"../data/filtered/simulated_matchms_filter_1%I_all_peaks.msp\"))\n", | ||
"predicted_spectra_metadata= pd.DataFrame.from_dict([x.metadata for x in predicted_spectra])\n", | ||
"predicted_spectra_metadata.rename(columns={'compound_name': 'query'}, inplace=True)\n", | ||
"predicted_spectra_names = predicted_spectra_metadata['query'].to_list()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 75, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"experimental_spectra = list(load_from_msp(\"../data/experimental/RECETOX_GC-EI_MS_20201028.msp\"))\n", | ||
"experimental_spectra_metadata= pd.DataFrame.from_dict([x.metadata for x in experimental_spectra])\n", | ||
"experimental_spectra_metadata.rename(columns={'compound_name': 'reference'}, inplace=True)\n", | ||
"experimental_spectra_names = experimental_spectra_metadata['reference'].to_list()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 76, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"all_combinations = set(itertools.product(predicted_spectra_names, experimental_spectra_names))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 77, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"matches = pd.read_csv(\"../data/output_matching/matchms/matchms_tol_0.01_1%I_top5.tsv\", sep=\"\\t\")\n", | ||
"matches.set_index(['query', 'reference'], inplace=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 78, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"existing_rows = set(matches.index.to_list())\n", | ||
"rows_to_add = list(all_combinations - existing_rows)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 79, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"all_zeros = pd.DataFrame(0, index=rows_to_add, columns=matches.columns)\n", | ||
"merged = pd.concat([matches, all_zeros]).reset_index(names=['query', 'reference'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 80, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"merged.to_csv(\"../data/output_matching/matchms/matchms_tol_0.01_1%I_top5_with_0s.tsv\", sep=\"\\t\", index=False)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.10.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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.