iomega / ms2query

MS2Query - machine learning assisted library querying of MS/MS spectra
Apache License 2.0
36 stars 9 forks source link

module 'matchms.filtering' has no attribute 'add_losses' #244

Closed jweinb closed 1 month ago

jweinb commented 1 month ago

I followed the tutorial and stuck in this step.

create_spectrum_documents([query_spectrum])[0]

File "C:\Users\CBL-IDX\miniforge3\envs\ms2query\lib\site-packages\ms2query\clean_and_filter_spectra.py", line 49, in create_spectrum_documents spectrum = msfilters.add_losses(spectrum, AttributeError: module 'matchms.filtering' has no attribute 'add_losses'

I think the matchms version is off. Please advise what to do next. Should I manually change the matchms version to 0.13.0 since it was mentioned in the issue, but now it is updated to 0.27.0?

jweinb commented 1 month ago

If I installed the 0.13.0 matchms, I have the following bug: from matchms import Metadata ImportError: cannot import name 'Metadata' from 'matchms' (C:\Users\CBL-IDX\miniforge3\envs\ms2query\lib\site-packages\matchms__init__.py)

My computer is Windows. I followed exactly what was listed in the website. Few months ago, our lab member could use MS2Query, but now I cannot use it, which may be related to recent MS2Query updates.

florian-huber commented 1 month ago

There were recent changes to MS2Query, and -even more so- to matchms. The most recent MS2Query versions will no longer work with older matchms. So first try to update ms2query and matchms

pip install --upgrade matchms ms2query

Let us know if this fixes the issue or not.

florian-huber commented 1 month ago

Unfortunately, we cannot work on this for the coming weeks. I expect that mid- or end of august @niekdejonge or I will get to it.

nici7 commented 1 month ago

I've just installed ms2query today, and had the same error. I did try pip install --upgrade matchms ms2query, but I still get AttributeError: module 'matchms.filtering' has no attribute 'add_losses'

Thanks for looking into this!

justinjjvanderhooft commented 1 month ago

Thanks for letting us know that you tried several things - and sorry to hear it got frustrating. MS2Query is scientific software and we will do our best to maintain it, and we are dependent on people like yourself to let us know if things work out as intended or not. We have taken note of your experience and once the team is all back from their summer breaks, we will address the above and come with a fix. Thanks for your patience over the summer weeks.

jweinb commented 1 month ago

Thanks! I included my approach as a feedback:

Ms2query version 0.3.2

conda create --name ms2query python=3.8 conda activate ms2query

pip install ms2query==0.3.2

pip install numpy==1.22

pip install scikit-learn==0.24.2 from ms2query.run_ms2query import download_default_models, default_library_file_base_names, run_complete_folder from ms2query.ms2library import create_library_object_from_one_dir

Set the location where all your downloaded model files are stored

ms2query_library_files_directory = "D:\MS2query\MS2query_library\old_positive_negative"

Define the folder in which your query spectra are stored.

Accepted formats are: "mzML", "json", "mgf", "msp", "mzxml", "usi" or a pickled matchms object.

ms2_spectra_directory = "D:\MS2query\MS2data\CHDWB_hilicpos"

Downloads pretrained models and files for MS2Query (>10GB download) manually and save it to the folder (here, it is "D:\ MS2query\MS2query_library\old_positive_negative")

Run library search and analog search on your files.

run_complete_folder(ms2library, ms2_spectra_directory)

wjcranda commented 1 month ago

Hello all,

I can run Ms2Query v1.5.0 with latest models from Zenodo. I have only tested running queries from .mgf files in both positive and negative ion mode.

numpy: 1.24.0 matchms: 0.26.4 ms2query: 1.5.0 gensim: 4.3.2 scipy: 1.10.1

niekdejonge commented 1 month ago

@jweinb Thanks for the clear issue. It is an issue due to the updated version of matchms to 0.27.0. We made add_losses deprecated here, but we did not realize MS2Query still relied on it. The solution given by William Crandall is a quick fix (setting matchms to 0.26.4). I will implement a permanent solution as well. Let us know if that doesn't fix the issue for you.

niekdejonge commented 1 month ago

Should be fixed for ms2query 1.5.1. Feel free to re-open or open a new issue, if there remains any issues for you @jweinb