Skip to content

Commit

Permalink
Resolved merge conflicts against main
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoffmann committed Nov 2, 2023
2 parents cadf03f + 1079e3b commit 397d945
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
15 changes: 8 additions & 7 deletions streamlit_app/library_spectra_validation/library_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from matchms.importing import load_spectra
from matchms.filtering.SpectrumProcessor import SpectrumProcessor
from library_spectra_validation.filters import PRIMARY_FILTERS
from library_spectra_validation.validation_pipeline import Modification, SpectrumRepairer, SpectrumValidator
from filters import PRIMARY_FILTERS
from validation_pipeline import METADATA_FIELDS_OF_INTEREST, Modification, SpectrumRepairer, SpectrumValidator
import pandas as pd

class LibraryHandler:
"""Stores the 3 different types of spectra. Correct, repaired, wrong.
Expand Down Expand Up @@ -69,8 +70,10 @@ def return_user_validation_info(self, spectrum_id):

modifications = self.modifications[spectrum_id]
failed_requirements = self.failed_requirements[spectrum_id]

return modifications, failed_requirements, self.spectra[spectrum_id]
metadata = pd.DataFrame(self.spectra[spectrum_id].metadata, index=["Value"])
metadata = metadata.T
metadata = metadata.loc[metadata.index.isin(METADATA_FIELDS_OF_INTEREST)]
return modifications, failed_requirements, metadata

def approve_repair(self, spectrum_id, field_name):
"""Accepts every modification done to a field_name"""
Expand Down Expand Up @@ -157,7 +160,5 @@ def user_rerun_repair(self, spectrum_id, rerun: bool):
if rerun: #todo do we even need it??
self.modifications[spectrum_id] = self.spectrum_repairer.process_spectrum_store_modifications(self.spectra[spectrum_id])
self.failed_requirements[spectrum_id] = self.spectrum_validator.process_spectrum_store_failed_filters(self.spectra[spectrum_id])





Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ def test_user_metadata_change():
spectrum_id = 0
library_handler.user_metadata_change(spectrum_id=spectrum_id, field_name="smiles", user_input="CCC")
assert library_handler.spectra[spectrum_id].get("smiles") == "CCC"


def test_return_():
library_handler = LibraryHandler("./examples/test_case_correct.mgf")
spectrum_id = 0
modifications, failed_requirements, metadata = library_handler.return_user_validation_info(spectrum_id=spectrum_id)
# todo add checks that tests that the expected output is given.
print(metadata)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

logger = logging.getLogger("matchms")

METADATA_FIELDS_OF_INTEREST = ["parent_mass", "precursor_mz", "adduct", "smiles",
"compound_name", "inchi", "inchikey", "charge", "ionmode"]

class Modification:
def __init__(self, metadata_field, before, after, logging_message, validated_by_user):
Expand All @@ -34,9 +36,7 @@ def __init__(self, metadata_field, logging_message):
def find_modifications(spectrum_old, spectrum_new, logging_message: str):
"""Checks which modifications have been made in a filter step"""
modifications = []
metadata_fields_to_check = ["parent_mass", "precursor_mz", "adduct", "smiles",
"compound_name", "inchi", "inchikey", "charge", "ionmode"]
for metadata_field in metadata_fields_to_check:
for metadata_field in METADATA_FIELDS_OF_INTEREST:
if spectrum_old.get(metadata_field) != spectrum_new.get(metadata_field):
modifications.append(
Modification(metadata_field=metadata_field,
Expand Down

0 comments on commit 397d945

Please sign in to comment.