Skip to content

Commit

Permalink
isort import linting
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-huber committed Aug 11, 2023
1 parent 533bd6d commit 1997d0e
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 83 deletions.
4 changes: 2 additions & 2 deletions ms2deepscore/MS2DeepScore.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List

import numpy as np
from matchms import Spectrum
from matchms.similarity.BaseSimilarity import BaseSimilarity
from tqdm import tqdm

from .vector_operations import cosine_similarity
from .vector_operations import cosine_similarity_matrix
from .typing import BinnedSpectrumType
from .vector_operations import cosine_similarity, cosine_similarity_matrix


class MS2DeepScore(BaseSimilarity):
Expand Down
6 changes: 3 additions & 3 deletions ms2deepscore/MS2DeepScoreMonteCarlo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import List, Tuple

import numpy as np
from matchms import Spectrum
from matchms.similarity.BaseSimilarity import BaseSimilarity
from tqdm import tqdm

from .vector_operations import cosine_similarity_matrix
from .vector_operations import mean_pooling, median_pooling
from .vector_operations import std_pooling, iqr_pooling
from .typing import BinnedSpectrumType
from .vector_operations import (cosine_similarity_matrix, iqr_pooling,
mean_pooling, median_pooling, std_pooling)


class MS2DeepScoreMonteCarlo(BaseSimilarity):
Expand Down
5 changes: 3 additions & 2 deletions ms2deepscore/MetadataFeatureGenerator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List, Union
from matchms import Metadata
import json
from importlib import import_module
from typing import List, Union

from matchms import Metadata


class MetadataFeatureGenerator:
Expand Down
12 changes: 7 additions & 5 deletions ms2deepscore/SpectrumBinner.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import json
from typing import List, Tuple
from tqdm import tqdm

from matchms.typing import SpectrumType
from tqdm import tqdm

from ms2deepscore.MetadataFeatureGenerator import (MetadataFeatureGenerator,
load_from_json)

from .BinnedSpectrum import BinnedSpectrum
from .spectrum_binning_fixed import (create_peak_list_fixed, set_d_bins_fixed,
unique_peaks_fixed)
from .typing import BinnedSpectrumType
from .spectrum_binning_fixed import create_peak_list_fixed
from .spectrum_binning_fixed import set_d_bins_fixed
from .spectrum_binning_fixed import unique_peaks_fixed
from .utils import create_peak_dict
from ms2deepscore.MetadataFeatureGenerator import MetadataFeatureGenerator, load_from_json


class SpectrumBinner:
Expand Down
2 changes: 1 addition & 1 deletion ms2deepscore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from . import models
from .__version__ import __version__
from .BinnedSpectrum import BinnedSpectrum
from .MS2DeepScore import MS2DeepScore
from .MS2DeepScoreMonteCarlo import MS2DeepScoreMonteCarlo
from .SpectrumBinner import SpectrumBinner


logging.getLogger(__name__).addHandler(logging.NullHandler())

__author__ = "Netherlands eScience Center"
Expand Down
3 changes: 2 additions & 1 deletion ms2deepscore/data_generators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
""" Data generators for training/inference with siamese Keras model.
"""
import warnings
from typing import List, Iterator, NamedTuple, Optional
from typing import Iterator, List, NamedTuple, Optional

import numpy as np
import pandas as pd
from tensorflow.keras.utils import Sequence # pylint: disable=import-error

from ms2deepscore.SpectrumBinner import SpectrumBinner

from .typing import BinnedSpectrumType


Expand Down
4 changes: 3 additions & 1 deletion ms2deepscore/models/SiameseModel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
from typing import Tuple, Union

import h5py
from tensorflow import keras
from tensorflow.keras.layers import BatchNormalization, Dense, Dropout, Input, concatenate # pylint: disable=import-error
from tensorflow.keras.layers import ( # pylint: disable=import-error
BatchNormalization, Dense, Dropout, Input, concatenate)

from ms2deepscore import SpectrumBinner

Expand Down
2 changes: 2 additions & 0 deletions ms2deepscore/models/load_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pathlib import Path
from typing import Union

import h5py
from tensorflow import keras

from ms2deepscore.SpectrumBinner import SpectrumBinner

from .SiameseModel import SiameseModel


Expand Down
3 changes: 2 additions & 1 deletion ms2deepscore/spectrum_binning_fixed.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
""" Functions to create binned vector from spectrum using fixed width bins.
"""
from typing import List

import numpy as np
from tqdm import tqdm
from matchms import Spectrum
from tqdm import tqdm


def create_peak_list_fixed(spectrums, peaks_vocab, d_bins,
Expand Down
2 changes: 1 addition & 1 deletion ms2deepscore/spectrum_pair_selection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numba
import numpy as np
from scipy.sparse import lil_array, coo_array
from matchms.similarity.vector_similarity_functions import jaccard_index
from scipy.sparse import coo_array, lil_array


def jaccard_similarity_matrix_cherrypicking(
Expand Down
6 changes: 3 additions & 3 deletions ms2deepscore/train_new_model/calculate_tanimoto_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from collections import Counter
from typing import List

import numpy as np
import pandas as pd
from matchms import Spectrum
import numpy as np

from matchms.similarity.vector_similarity_functions import jaccard_similarity_matrix
from matchms.similarity.vector_similarity_functions import \
jaccard_similarity_matrix
from rdkit import Chem
from tqdm import tqdm

Expand Down
19 changes: 9 additions & 10 deletions ms2deepscore/train_new_model/train_ms2deepscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@

import os
from os import PathLike
from typing import List, Dict, Optional, Union
from typing import Dict, List, Optional, Union

import numpy as np
import tensorflow as tf
from matplotlib import pyplot as plt
from matchms import Spectrum
from matplotlib import pyplot as plt

from ms2deepscore import SpectrumBinner
from ms2deepscore.data_generators import DataGeneratorAllInchikeys
from ms2deepscore.models import SiameseModel
from ms2deepscore.train_new_model.calculate_tanimoto_matrix import (
calculate_tanimoto_scores_unique_inchikey,
)
from ms2deepscore.utils import (
save_pickled_file,
return_non_existing_file_name,
load_pickled_file,
)
from ms2deepscore.train_new_model.calculate_tanimoto_matrix import \
calculate_tanimoto_scores_unique_inchikey
from ms2deepscore.utils import (load_pickled_file,
return_non_existing_file_name,
save_pickled_file)


def bin_spectra(
Expand Down
6 changes: 4 additions & 2 deletions ms2deepscore/train_new_model/validation_and_test_split.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import random
from typing import List, Tuple

from matchms import Spectrum
import random
from tqdm import tqdm
from ms2deepscore.utils import save_pickled_file, load_pickled_file

from ms2deepscore.utils import load_pickled_file, save_pickled_file


def select_unique_inchikeys(spectra):
Expand Down
6 changes: 4 additions & 2 deletions ms2deepscore/train_new_model/visualize_results.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

import numpy as np
from matplotlib import pyplot as plt
from ms2deepscore.models import load_model
from ms2deepscore.utils import load_pickled_file, save_pickled_file

from ms2deepscore import MS2DeepScore
from ms2deepscore.models import load_model
from ms2deepscore.plotting import create_histograms_plot
from ms2deepscore.utils import load_pickled_file, save_pickled_file


def get_tanimoto_indexes(tanimoto_df, spectra):
Expand Down
1 change: 1 addition & 0 deletions ms2deepscore/typing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional

from .BinnedSpectrum import BinnedSpectrum

BinnedSpectrumType = Optional[BinnedSpectrum]
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python
import os

from setuptools import setup
from setuptools import find_packages
from setuptools import find_packages, setup

here = os.path.abspath(os.path.dirname(__file__))

Expand Down
10 changes: 4 additions & 6 deletions tests/test_MetadataFeatureGenerator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pytest
from matchms import Metadata
from ms2deepscore.MetadataFeatureGenerator import (
MetadataFeatureGenerator,
StandardScaler,
OneHotEncoder,
CategoricalToBinary,
)

from ms2deepscore.MetadataFeatureGenerator import (CategoricalToBinary,
MetadataFeatureGenerator,
OneHotEncoder,
StandardScaler)


@pytest.fixture
Expand Down
5 changes: 4 additions & 1 deletion tests/test_SpectrumBinner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import numpy as np
import pytest
from matchms import Spectrum

from ms2deepscore import SpectrumBinner
from ms2deepscore.MetadataFeatureGenerator import CategoricalToBinary, StandardScaler
from ms2deepscore.MetadataFeatureGenerator import (CategoricalToBinary,
StandardScaler)


def test_SpectrumBinner():
"""Test if default initalization works"""
Expand Down
9 changes: 6 additions & 3 deletions tests/test_data_generators.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import string

import numpy as np
import pandas as pd
import pytest
import string
from matchms import Spectrum

from ms2deepscore import SpectrumBinner
from ms2deepscore.MetadataFeatureGenerator import StandardScaler, CategoricalToBinary
from ms2deepscore.data_generators import (DataGeneratorAllInchikeys,
DataGeneratorAllSpectrums,
_exclude_nans_from_labels,
_validate_labels)
from tests.test_user_worfklow import load_processed_spectrums, get_reference_scores
from ms2deepscore.MetadataFeatureGenerator import (CategoricalToBinary,
StandardScaler)
from tests.test_user_worfklow import (get_reference_scores,
load_processed_spectrums)


def create_dummy_data():
Expand Down
12 changes: 8 additions & 4 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import os
from pathlib import Path
from packaging import version

import numpy as np
import tensorflow as tf
from packaging import version
from tensorflow import keras

if version.parse(tf.__version__) >= version.parse("2.11"):
AdamOptimizer = keras.optimizers.legacy.Adam
else:
AdamOptimizer = keras.optimizers.Adam
from ms2deepscore import SpectrumBinner
from ms2deepscore.data_generators import DataGeneratorAllInchikeys, DataGeneratorAllSpectrums
from ms2deepscore.models import SiameseModel, load_model
from ms2deepscore.data_generators import (DataGeneratorAllInchikeys,
DataGeneratorAllSpectrums)
from ms2deepscore.MetadataFeatureGenerator import StandardScaler
from tests.test_user_worfklow import load_processed_spectrums, get_reference_scores
from ms2deepscore.models import SiameseModel, load_model
from tests.test_user_worfklow import (get_reference_scores,
load_processed_spectrums)

TEST_RESOURCES_PATH = Path(__file__).parent / 'resources'

Expand Down
10 changes: 6 additions & 4 deletions tests/test_models_duplicate_inchikeys.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
from pathlib import Path

from ms2deepscore import SpectrumBinner
from ms2deepscore.data_generators import DataGeneratorAllSpectrums, DataGeneratorAllInchikeys
from tests.test_user_worfklow import load_processed_spectrums, get_reference_scores

import pytest

from ms2deepscore import SpectrumBinner
from ms2deepscore.data_generators import (DataGeneratorAllInchikeys,
DataGeneratorAllSpectrums)
from tests.test_user_worfklow import (get_reference_scores,
load_processed_spectrums)


def test_error_duplicate_inchikeys():
"""Test an expected error when duplicate inchikeys are given to DataGenerator"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_ms2deepscore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

import numpy as np
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/test_ms2deepscoremontecarlo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path

import numpy as np
import pytest

Expand Down
9 changes: 3 additions & 6 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import numpy as np
from ms2deepscore.plotting import (
create_confusion_matrix_plot,
create_histograms_plot,
plot_histograms,
calculate_histograms
)

from ms2deepscore.plotting import (calculate_histograms,
create_confusion_matrix_plot,
create_histograms_plot, plot_histograms)

mock_reference_scores = np.random.random((100, 100))
mock_comparison_scores = np.random.random((100, 100))
Expand Down
9 changes: 5 additions & 4 deletions tests/test_spectrum_binning_fixed.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import numpy as np
import pytest
from matchms import Spectrum
from ms2deepscore.spectrum_binning_fixed import bin_number_array_fixed
from ms2deepscore.spectrum_binning_fixed import create_peak_list_fixed
from ms2deepscore.spectrum_binning_fixed import set_d_bins_fixed
from ms2deepscore.spectrum_binning_fixed import unique_peaks_fixed

from ms2deepscore.spectrum_binning_fixed import (bin_number_array_fixed,
create_peak_list_fixed,
set_d_bins_fixed,
unique_peaks_fixed)


def test_create_peak_list_fixed():
Expand Down
10 changes: 6 additions & 4 deletions tests/test_spectrum_binning_linear.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os

import numpy as np
import pytest
from matchms import Spectrum
from ms2deepscore.spectrum_binning_linear import bin_number_array_linear
from ms2deepscore.spectrum_binning_linear import create_peak_list_linear
from ms2deepscore.spectrum_binning_linear import set_d_bins_linear
from ms2deepscore.spectrum_binning_linear import unique_peaks_linear

from ms2deepscore.spectrum_binning_linear import (bin_number_array_linear,
create_peak_list_linear,
set_d_bins_linear,
unique_peaks_linear)


def test_create_peak_list_linear():
Expand Down
Loading

0 comments on commit 1997d0e

Please sign in to comment.