From 1a76ce3a6e06bcfd30c4827207b25138694e0c35 Mon Sep 17 00:00:00 2001 From: Julian Pollmann Date: Thu, 30 Oct 2025 22:44:54 +0100 Subject: [PATCH 1/4] Update docs with recent filtering --- README.rst | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 3890bbe..a519b12 100644 --- a/README.rst +++ b/README.rst @@ -88,7 +88,7 @@ For more extensive documentation `see our readthedocs = 4.0.0` which should make it faster and more future proof. Model trained with older versions should still be importable without any issues. If you had scripts that used additional gensim code, however, those might occationally need some adaptation, see also the `gensim documentation on how to migrate your code `_. +Since version `0.9.0` Spec2Vec uses `gensim >= 4.4.0` which should make it faster and more future proof. Model trained with older versions should still be importable without any issues. If you had scripts that used additional gensim code, however, those might occationally need some adaptation, see also the `gensim documentation on how to migrate your code `_. Installation @@ -97,14 +97,14 @@ Installation Prerequisites: -- Python 3.7, 3.8, or 3.9 +- Python 3.10, 3.11, 3.12 or 3.13 - Recommended: Anaconda We recommend installing spec2vec from Anaconda Cloud with .. code-block:: console - conda create --name spec2vec python=3.8 + conda create --name spec2vec python=3.13 conda activate spec2vec conda install --channel bioconda --channel conda-forge spec2vec @@ -124,31 +124,24 @@ dataset. .. code-block:: python - import os - import matchms.filtering as msfilters + from matchms import SpectrumProcessor + from matchms.filtering.default_pipelines import DEFAULT_FILTERS from matchms.importing import load_from_mgf from spec2vec import SpectrumDocument from spec2vec.model_building import train_new_word2vec_model - def spectrum_processing(s): - """This is how one would typically design a desired pre- and post- - processing pipeline.""" - s = msfilters.default_filters(s) - s = msfilters.add_parent_mass(s) - s = msfilters.normalize_intensities(s) - s = msfilters.reduce_to_number_of_peaks(s, n_required=10, ratio_desired=0.5, n_max=500) - s = msfilters.select_by_mz(s, mz_from=0, mz_to=1000) - s = msfilters.require_minimum_number_of_peaks(s, n_required=10) - return s - - # Load data from MGF file and apply filters - spectrums = [spectrum_processing(s) for s in load_from_mgf("reference_spectrums.mgf")] - - # Omit spectrums that didn't qualify for analysis - spectrums = [s for s in spectrums if s is not None] + # Load spectra from MGF + spectra = list(load_from_mgf("reference_spectrums.mgf")) + + # Add some default filters. You can add more filters functions like require min. number of peaks + processor = SpectrumProcessor(DEFAULT_FILTERS) + # processor.parse_and_add_filter(("require_minimum_number_of_peaks", {"n_required": 4})) + + # Apply filter pipeline + spectra_cleaned, _ = processor.process_spectra(spectra) # Create spectrum documents - reference_documents = [SpectrumDocument(s, n_decimals=2, loss_mz_from=10.0, loss_mz_to=200.0) for s in spectrums] + reference_documents = [SpectrumDocument(s, n_decimals=2, loss_mz_from=10.0, loss_mz_to=200.0) for s in spectra_cleaned] model_file = "references.model" model = train_new_word2vec_model(reference_documents, iterations=[10, 20, 30], filename=model_file, From 00123abb2bd3514cf5dc01fb8745c7039d3e1784 Mon Sep 17 00:00:00 2001 From: Julian Pollmann Date: Fri, 31 Oct 2025 20:41:51 +0100 Subject: [PATCH 2/4] Update code examples --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index a519b12..0888951 100644 --- a/README.rst +++ b/README.rst @@ -148,7 +148,7 @@ dataset. workers=2, progress_logger=True) Once a word2vec model has been trained, spec2vec allows to calculate the similarities -between mass spectrums based on this model. In cases where the word2vec model was +between mass spectra based on this model. In cases where the word2vec model was trained on data different than the data it is applied for, a number of peaks ("words") might be unknown to the model (if they weren't part of the training dataset). To account for those cases it is important to specify the ``allowed_missing_percentage``, @@ -160,11 +160,11 @@ as in the example below. from matchms import calculate_scores from spec2vec import Spec2Vec - # query_spectrums loaded from files using https://matchms.readthedocs.io/en/latest/api/matchms.importing.load_from_mgf.html - query_spectrums = [spectrum_processing(s) for s in load_from_mgf("query_spectrums.mgf")] + # query_spectra loaded from files using https://matchms.readthedocs.io/en/latest/api/matchms.importing.load_from_mgf.html + query_spectra = [spectrum_processing(s) for s in load_from_mgf("query_spectrums.mgf")] - # Omit spectrums that didn't qualify for analysis - query_spectrums = [s for s in query_spectrums if s is not None] + # Omit spectra that didn't qualify for analysis + query_spectra = [s for s in query_spectrums if s is not None] # Import pre-trained word2vec model (see code example above) model_file = "references.model" @@ -174,8 +174,8 @@ as in the example below. spec2vec_similarity = Spec2Vec(model=model, intensity_weighting_power=0.5, allowed_missing_percentage=5.0) - # Calculate scores on all combinations of reference spectrums and queries - scores = calculate_scores(reference_documents, query_spectrums, spec2vec_similarity) + # Calculate scores on all combinations of reference spectra and queries + scores = calculate_scores(reference_documents, query_spectra, spec2vec_similarity) # Find the highest scores for a query spectrum of interest best_matches = scores.scores_by_query(query_documents[0], sort=True)[:10] From 2c907587d8a180ff9a82fd28cfb699460ff718a4 Mon Sep 17 00:00:00 2001 From: Julian Pollmann Date: Wed, 5 Nov 2025 22:31:18 +0100 Subject: [PATCH 3/4] Update Code examples --- README.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 0888951..fa9e61c 100644 --- a/README.rst +++ b/README.rst @@ -135,14 +135,15 @@ dataset. # Add some default filters. You can add more filters functions like require min. number of peaks processor = SpectrumProcessor(DEFAULT_FILTERS) - # processor.parse_and_add_filter(("require_minimum_number_of_peaks", {"n_required": 4})) # Apply filter pipeline spectra_cleaned, _ = processor.process_spectra(spectra) + spectra_cleaned = [s for s in spectra_cleaned if s is not None] # Create spectrum documents - reference_documents = [SpectrumDocument(s, n_decimals=2, loss_mz_from=10.0, loss_mz_to=200.0) for s in spectra_cleaned] + reference_documents = [SpectrumDocument(s, n_decimals=2) for s in spectra_cleaned] + # Train your reference model model_file = "references.model" model = train_new_word2vec_model(reference_documents, iterations=[10, 20, 30], filename=model_file, workers=2, progress_logger=True) @@ -161,10 +162,11 @@ as in the example below. from spec2vec import Spec2Vec # query_spectra loaded from files using https://matchms.readthedocs.io/en/latest/api/matchms.importing.load_from_mgf.html - query_spectra = [spectrum_processing(s) for s in load_from_mgf("query_spectrums.mgf")] + query_spectra = list(load_from_mgf("query_spectrums.mgf")) + query_spectra_cleaned, _ = processor.process_spectra(query_spectra) # Omit spectra that didn't qualify for analysis - query_spectra = [s for s in query_spectrums if s is not None] + query_spectra_cleaned = [s for s in query_spectra_cleaned if s is not None] # Import pre-trained word2vec model (see code example above) model_file = "references.model" @@ -175,10 +177,10 @@ as in the example below. allowed_missing_percentage=5.0) # Calculate scores on all combinations of reference spectra and queries - scores = calculate_scores(reference_documents, query_spectra, spec2vec_similarity) + scores = calculate_scores(reference_documents, query_spectra_cleaned, spec2vec_similarity) # Find the highest scores for a query spectrum of interest - best_matches = scores.scores_by_query(query_documents[0], sort=True)[:10] + best_matches = scores.scores_by_query(query_spectra_cleaned[0], sort=True)[:10] # Return highest scores print([x[1] for x in best_matches]) From a685347b9f51ce3b4ec5a54d2905574a47778540 Mon Sep 17 00:00:00 2001 From: Julian Pollmann Date: Thu, 6 Nov 2025 10:42:43 +0100 Subject: [PATCH 4/4] Update CI (Remove SonarQube, Testing Python Version matrix) --- .github/workflows/CI_build.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI_build.yml b/.github/workflows/CI_build.yml index 85f7379..b6b08ef 100644 --- a/.github/workflows/CI_build.yml +++ b/.github/workflows/CI_build.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.13" - name: Python info run: | which python @@ -38,12 +38,12 @@ jobs: - name: Check whether import statements are used consistently shell: bash -l {0} run: poetry run isort --check-only --diff --conda-env spec2vec-dev . - - name: SonarQube Scan - if: github.repository == 'iomega/spec2vec' - uses: SonarSource/sonarqube-scan-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# - name: SonarQube Scan +# if: github.repository == 'iomega/spec2vec' +# uses: SonarSource/sonarqube-scan-action@master +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} build_pypi: name: Pypi and documentation build / python-${{ matrix.python-version }} / ${{ matrix.os }} @@ -53,10 +53,10 @@ jobs: fail-fast: false matrix: os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] - python-version: ['3.10'] + python-version: ['3.10', '3.11', '3.12', '3.13'] exclude: # already tested in first_check job - - python-version: "3.10" + - python-version: "3.13" os: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -123,7 +123,7 @@ jobs: activate-environment: spec2vec-build auto-update-conda: true environment-file: conda/environment-build.yml - python-version: "3.10" + python-version: "3.13" - name: Show conda config shell: bash -l {0} run: |