Skip to content

Commit

Permalink
Merge pull request #88 from iomega/matchms_0_18
Browse files Browse the repository at this point in the history
Move to matchms >=0.18.0
  • Loading branch information
florian-huber authored Jan 9, 2023
2 parents b1edf87 + 248c4c0 commit b7fdd00
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 19 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.8.0] - 2022-01-06

### Changed

- Minor changes to make tests pass with new matchms versions (>=0.18.0). Should nearly always be backwards compatible though.
- Now dependency requirement is set to `matchms>=0.14.0`

## [0.7.0] - 2022-10-01

### Added
Expand Down Expand Up @@ -135,7 +142,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fossa configuration
- Flowchart

[Unreleased]: https://github.com/iomega/spec2vec/compare/0.7.0...HEAD
[Unreleased]: https://github.com/iomega/spec2vec/compare/0.8.0...HEAD
[0.8.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0
[0.7.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0
[0.6.0]: https://github.com/iomega/spec2vec/compare/0.5.0...0.6.0
[0.5.0]: https://github.com/iomega/spec2vec/compare/0.4.0...0.5.0
Expand Down
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "spec2vec" %}
{% set version = "0.7.0" %}
{% set version = "0.8.0" %}

package:
name: {{ name|lower }}
Expand Down Expand Up @@ -37,7 +37,7 @@ requirements:
- setuptools
run:
- gensim >=4.2.0
- matchms >=0.6.0
- matchms >=0.14.0
- numba >=0.51
- numpy
- pip
Expand Down
26 changes: 14 additions & 12 deletions integration-tests/test_user_workflow_spec2vec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import gensim
import pytest
import numpy as np
from matchms import calculate_scores
from matchms.filtering import (add_losses, add_parent_mass, default_filters,
normalize_intensities,
Expand Down Expand Up @@ -68,16 +68,18 @@ def apply_my_filters(s):
actual_top10 = sorted_by_score[:10]

expected_top10 = [
(documents[19], documents[25], pytest.approx(0.9999121928249473, rel=1e-9)),
(documents[20], documents[25], pytest.approx(0.9998846890269892, rel=1e-9)),
(documents[20], documents[45], pytest.approx(0.9998756073673759, rel=1e-9)),
(documents[25], documents[45], pytest.approx(0.9998750427994474, rel=1e-9)),
(documents[19], documents[27], pytest.approx(0.9998722768460854, rel=1e-9)),
(documents[22], documents[27], pytest.approx(0.9998633023352553, rel=1e-9)),
(documents[18], documents[27], pytest.approx(0.9998616961532616, rel=1e-9)),
(documents[19], documents[45], pytest.approx(0.9998528723697396, rel=1e-9)),
(documents[14], documents[71], pytest.approx(0.9998404364805897, rel=1e-9)),
(documents[20], documents[27], pytest.approx(0.9998336807761137, rel=1e-9))
(documents[19], documents[25], 0.9999121928249473),
(documents[20], documents[25], 0.9998846890269892),
(documents[20], documents[45], 0.9998756073673759),
(documents[25], documents[45], 0.9998750427994474),
(documents[19], documents[27], 0.9998722768460854),
(documents[22], documents[27], 0.9998633023352553),
(documents[18], documents[27], 0.9998616961532616),
(documents[19], documents[45], 0.9998528723697396),
(documents[14], documents[71], 0.9998404364805897),
(documents[20], documents[27], 0.9998336807761137)
]

assert actual_top10 == expected_top10, "Expected different top 10 table."
assert [x[0] for x in actual_top10] == [x[0] for x in expected_top10]
assert [x[1] for x in actual_top10] == [x[1] for x in expected_top10]
assert np.allclose([x[2][0] for x in actual_top10], [x[2] for x in expected_top10]), "Expected different top 10 table."
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.0
current_version = 0.8.0

[bumpversion:file:conda/meta.yaml]
search = set version = "{current_version}"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
python_requires='>=3.7',
install_requires=[
"gensim >=4.2.0",
"matchms <0.18.0",
"matchms >=0.14.0",
"numba >=0.51",
"numpy",
"scipy",
Expand Down
5 changes: 5 additions & 0 deletions spec2vec/Spec2Vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def pair(self, reference: Union[SpectrumDocument, Spectrum],

def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]],
queries: Union[List[SpectrumDocument], List[Spectrum]],
array_type: str = "numpy",
is_symmetric: bool = False) -> np.ndarray:
"""Calculate the spec2vec similarities between all references and queries.
Expand All @@ -143,6 +144,10 @@ def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]],
Reference spectrums or spectrum documents.
queries:
Query spectrums or spectrum documents.
array_type
Specify the output array type. Can be "numpy" or "sparse".
Currently, only "numpy" is supported and will return a numpy array.
Future versions will include "sparse" as option to return a COO-sparse array.
is_symmetric:
Set to True if references == queries to speed up calculation about 2x.
Uses the fact that in this case score[i, j] = score[j, i]. Default is False.
Expand Down
2 changes: 1 addition & 1 deletion spec2vec/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '0.8.0'
5 changes: 4 additions & 1 deletion spec2vec/serialization/model_importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def build(self) -> KeyedVectors:

def from_dict(self, dictionary: dict):
expected_keys = {"vector_size", "__numpys", "__scipys", "__ignoreds", "__recursive_saveloads",
"index_to_key", "norms", "key_to_index", "next_index", "__weights_format"}
"index_to_key", "norms", "key_to_index", "__weights_format"}
if dictionary.keys() == expected_keys:
self.__dict__ = dictionary
elif expected_keys.symmetric_difference(dictionary.keys()) == {"next_index"}: # backward compatibility
dictionary.pop("next_index")
self.__dict__ = dictionary
else:
raise ValueError("The keys of model's dictionary representation do not match the expected keys.")
return self
Expand Down

0 comments on commit b7fdd00

Please sign in to comment.