Skip to content

Commit

Permalink
Merge pull request #220 from iomega/isort
Browse files Browse the repository at this point in the history
Isort
  • Loading branch information
niekdejonge authored Nov 22, 2023
2 parents b54ec66 + 65b4282 commit 2073d4c
Show file tree
Hide file tree
Showing 35 changed files with 147 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
run: pytest --cov --cov-report term --cov-report xml -m "not integration"
- name: Check style against standards using prospector
run: prospector -o grouped -o pylint:pylint-report.txt
# - name: Check whether import statements are used consistently
# run: isort --check-only --diff .
- name: Check whether import statements are used consistently
run: isort --check-only --diff .
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
10 changes: 6 additions & 4 deletions ms2query/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os


os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
# pylint: disable=wrong-import-position
import argparse
import logging
from .run_ms2query import download_zenodo_files, run_complete_folder, run_ms2query_single_file
from .ms2library import create_library_object_from_one_dir
from .utils import SettingsRunMS2Query
from .__version__ import __version__
from .ms2library import MS2Library
from .ms2library import MS2Library, create_library_object_from_one_dir
from .results_table import ResultsTable
from .run_ms2query import (download_zenodo_files, run_complete_folder,
run_ms2query_single_file)
from .utils import SettingsRunMS2Query


logging.getLogger(__name__).addHandler(logging.NullHandler())
Expand Down
20 changes: 10 additions & 10 deletions ms2query/benchmarking/collect_test_data_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
"""

import os
from typing import List, Tuple, Union
from tqdm import tqdm
import random
import tempfile
from matchms import Spectrum
from ms2query.create_new_library.calculate_tanimoto_scores import calculate_single_tanimoto_score, calculate_highest_tanimoto_score
from ms2query.ms2library import MS2Library
import sqlite3
import tempfile
from typing import List, Tuple, Union
import pandas as pd
from matchms import Spectrum
from matchms.calculate_scores import calculate_scores
from matchms.similarity.CosineGreedy import CosineGreedy
from matchms.similarity.ModifiedCosine import ModifiedCosine
from ms2deepscore import MS2DeepScore
from ms2deepscore.models import SiameseModel
from spec2vec.vector_operations import cosine_similarity_matrix
from matchms.calculate_scores import calculate_scores
from matchms.similarity.ModifiedCosine import ModifiedCosine
from matchms.similarity.CosineGreedy import CosineGreedy

from tqdm import tqdm
from ms2query.create_new_library.calculate_tanimoto_scores import (
calculate_highest_tanimoto_score, calculate_single_tanimoto_score)
from ms2query.ms2library import MS2Library
from ms2query.query_from_sqlite_database import SqliteLibrary
from ms2query.utils import save_json_file

Expand Down
5 changes: 2 additions & 3 deletions ms2query/benchmarking/create_accuracy_vs_recall_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"""
import os
import random
from typing import List, Tuple, Dict
from tqdm import tqdm
from typing import Dict, List, Tuple
import numpy as np
from matplotlib import pyplot as plt

from tqdm import tqdm
from ms2query.utils import load_json_file, load_pickled_file, save_pickled_file


Expand Down
12 changes: 8 additions & 4 deletions ms2query/benchmarking/k_fold_cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import random
from typing import List
from matchms import Spectrum
from ms2query.create_new_library.split_data_for_training import split_spectra_in_random_inchikey_sets, select_spectra_per_unique_inchikey
from ms2query.utils import load_matchms_spectrum_objects_from_file, save_pickled_file
from ms2query.benchmarking.collect_test_data_results import (
generate_exact_matches_test_results, generate_test_results)
from ms2query.clean_and_filter_spectra import \
clean_normalize_and_split_annotated_spectra
from ms2query.create_new_library.split_data_for_training import (
select_spectra_per_unique_inchikey, split_spectra_in_random_inchikey_sets)
from ms2query.create_new_library.train_models import train_all_models
from ms2query.benchmarking.collect_test_data_results import generate_test_results, generate_exact_matches_test_results
from ms2query.clean_and_filter_spectra import clean_normalize_and_split_annotated_spectra
from ms2query.ms2library import create_library_object_from_one_dir
from ms2query.utils import (load_matchms_spectrum_objects_from_file,
save_pickled_file)


def split_and_store_annotated_unannotated(spectrum_file_name,
Expand Down
7 changes: 4 additions & 3 deletions ms2query/benchmarking/visualize_mass_distribution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
from typing import Dict, List, Tuple
from create_accuracy_vs_recall_plot import (
calculate_means_and_standard_deviation, load_results_from_folder)
from matchms import Spectrum
from create_accuracy_vs_recall_plot import load_results_from_folder, \
calculate_means_and_standard_deviation
from ms2query.utils import load_matchms_spectrum_objects_from_file, load_pickled_file
from matplotlib import pyplot as plt
from ms2query.utils import (load_matchms_spectrum_objects_from_file,
load_pickled_file)


def split_results_mass(list_of_test_spectra: List[List[Spectrum]],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Tuple, Dict
from typing import Dict, List, Tuple
import numpy as np
from matplotlib import pyplot as plt

Expand Down
7 changes: 4 additions & 3 deletions ms2query/clean_and_filter_spectra.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import List, Tuple
import matchms.filtering as msfilters
from tqdm import tqdm
from matchms import Spectrum
from matchms.metadata_utils import is_valid_inchi, is_valid_inchikey, is_valid_smiles
from matchms.typing import SpectrumType
from matchms.logging_functions import set_matchms_logger_level
from matchms.metadata_utils import (is_valid_inchi, is_valid_inchikey,
is_valid_smiles)
from matchms.typing import SpectrumType
from matchmsextras.pubchem_lookup import pubchem_metadata_lookup
from spec2vec import SpectrumDocument
from tqdm import tqdm


def clean_metadata(spectrum: Spectrum) -> Spectrum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import urllib
from http.client import InvalidURL
from typing import List, Optional

import pandas as pd
from tqdm import tqdm

Expand Down
7 changes: 3 additions & 4 deletions ms2query/create_new_library/calculate_tanimoto_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,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, jaccard_index
from matchms.similarity.vector_similarity_functions import (
jaccard_index, jaccard_similarity_matrix)
from rdkit import Chem
from tqdm import tqdm

Expand Down
6 changes: 3 additions & 3 deletions ms2query/create_new_library/create_sqlite_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import sqlite3
from typing import Dict, List
import pandas as pd
from matchms import Spectrum
from tqdm import tqdm
import pandas as pd

from ms2query.create_new_library.calculate_tanimoto_scores import calculate_highest_tanimoto_score
from ms2query.create_new_library.calculate_tanimoto_scores import \
calculate_highest_tanimoto_score
from ms2query.utils import return_non_existing_file_name


Expand Down
6 changes: 4 additions & 2 deletions ms2query/create_new_library/library_files_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
from ms2deepscore.models import load_model as load_ms2ds_model
from spec2vec.vector_operations import calc_vector
from tqdm import tqdm
from ms2query.create_new_library.create_sqlite_database import make_sqlfile_wrapper
from ms2query.clean_and_filter_spectra import create_spectrum_documents
from ms2query.create_new_library.add_classifire_classifications import select_compound_classes, convert_to_dataframe
from ms2query.create_new_library.add_classifire_classifications import (
convert_to_dataframe, select_compound_classes)
from ms2query.create_new_library.create_sqlite_database import \
make_sqlfile_wrapper


class LibraryFilesCreator:
Expand Down
4 changes: 2 additions & 2 deletions ms2query/create_new_library/split_data_for_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
new models
"""

from typing import List, Dict
from matchms import Spectrum
import random
from typing import Dict, List
from matchms import Spectrum


def select_unique_inchikeys(spectra: List[Spectrum]) -> List[str]:
Expand Down
12 changes: 8 additions & 4 deletions ms2query/create_new_library/train_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

import os
from spec2vec.model_building import train_new_word2vec_model
from ms2query.create_new_library.train_ms2deepscore import train_ms2deepscore_wrapper
from ms2query.create_new_library.train_ms2query_model import train_ms2query_model, convert_to_onnx_model
from ms2query.create_new_library.library_files_creator import LibraryFilesCreator
from ms2query.clean_and_filter_spectra import (
clean_normalize_and_split_annotated_spectra, create_spectrum_documents)
from ms2query.create_new_library.library_files_creator import \
LibraryFilesCreator
from ms2query.create_new_library.train_ms2deepscore import \
train_ms2deepscore_wrapper
from ms2query.create_new_library.train_ms2query_model import (
convert_to_onnx_model, train_ms2query_model)
from ms2query.utils import load_matchms_spectrum_objects_from_file
from ms2query.clean_and_filter_spectra import create_spectrum_documents, clean_normalize_and_split_annotated_spectra


class SettingsTrainingModels:
Expand Down
10 changes: 6 additions & 4 deletions ms2query/create_new_library/train_ms2deepscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"""

import os
from typing import List, Dict, Optional
from typing import Dict, List, Optional
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 tensorflow.keras.callbacks import ( # pylint: disable=import-error
EarlyStopping, ModelCheckpoint)
from tensorflow.keras.optimizers import Adam # pylint: disable=import-error
from ms2query.create_new_library.split_data_for_training import split_spectra_on_inchikeys
from ms2query.create_new_library.calculate_tanimoto_scores import calculate_tanimoto_scores_unique_inchikey
from ms2query.create_new_library.calculate_tanimoto_scores import \
calculate_tanimoto_scores_unique_inchikey
from ms2query.create_new_library.split_data_for_training import \
split_spectra_on_inchikeys


def train_ms2ds_model(training_spectra,
Expand Down
15 changes: 9 additions & 6 deletions ms2query/create_new_library/train_ms2query_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
import os
from typing import List
import pandas as pd
from matchms import Spectrum
from onnxconverter_common import FloatTensorType
from skl2onnx import convert_sklearn
from tqdm import tqdm
from matchms import Spectrum
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from tqdm import tqdm
from ms2query import MS2Library
from ms2query.create_new_library.calculate_tanimoto_scores import \
calculate_tanimoto_scores_from_smiles
from ms2query.create_new_library.library_files_creator import \
LibraryFilesCreator
from ms2query.create_new_library.split_data_for_training import (
split_spectra_on_inchikeys, split_training_and_validation_spectra)
from ms2query.query_from_sqlite_database import SqliteLibrary
from ms2query.create_new_library.library_files_creator import LibraryFilesCreator
from ms2query.create_new_library.split_data_for_training import split_spectra_on_inchikeys, split_training_and_validation_spectra
from ms2query.create_new_library.calculate_tanimoto_scores import calculate_tanimoto_scores_from_smiles
from ms2query.utils import save_pickled_file, return_non_existing_file_name
from ms2query.utils import return_non_existing_file_name, save_pickled_file


class DataCollectorForTraining():
Expand Down
15 changes: 8 additions & 7 deletions ms2query/ms2library.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import os.path
from typing import Dict, List, Set, Tuple, Union, Optional, Iterator
from typing import Dict, Iterator, List, Optional, Set, Tuple, Union
import numpy as np
import pandas as pd
from gensim.models import Word2Vec
from matchms.Spectrum import Spectrum
from ms2deepscore import MS2DeepScore
from ms2deepscore.models import load_model as load_ms2ds_model
from onnxruntime import InferenceSession
from spec2vec.vector_operations import calc_vector, cosine_similarity_matrix
from tqdm import tqdm
from onnxruntime import InferenceSession
from ms2query.query_from_sqlite_database import SqliteLibrary
from ms2query.results_table import ResultsTable
from ms2query.clean_and_filter_spectra import (clean_metadata,
create_spectrum_documents,
normalize_and_filter_peaks)
from ms2query.utils import (column_names_for_output, load_ms2query_model,
load_pickled_file, SettingsRunMS2Query, predict_onnx_model,
select_files_in_directory, return_non_existing_file_name)
from ms2query.query_from_sqlite_database import SqliteLibrary
from ms2query.results_table import ResultsTable
from ms2query.utils import (SettingsRunMS2Query, column_names_for_output,
load_ms2query_model, load_pickled_file,
predict_onnx_model, return_non_existing_file_name,
select_files_in_directory)


class MS2Library:
Expand Down
1 change: 0 additions & 1 deletion ms2query/query_from_sqlite_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os.path
import sqlite3
from typing import Dict, List, Tuple

import pandas as pd
from ms2query.utils import column_names_for_output

Expand Down
2 changes: 1 addition & 1 deletion ms2query/results_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
from matchms.Spectrum import Spectrum
from ms2query.query_from_sqlite_database import SqliteLibrary
from ms2query.utils import (column_names_for_output)
from ms2query.utils import column_names_for_output


class ResultsTable:
Expand Down
4 changes: 3 additions & 1 deletion ms2query/run_ms2query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from typing import Union
from urllib.request import urlopen, urlretrieve
from ms2query.ms2library import MS2Library
from ms2query.utils import load_matchms_spectrum_objects_from_file, SettingsRunMS2Query, return_non_existing_file_name
from ms2query.utils import (SettingsRunMS2Query,
load_matchms_spectrum_objects_from_file,
return_non_existing_file_name)


def zenodo_dois(ionisation_mode):
Expand Down
6 changes: 3 additions & 3 deletions ms2query/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import os
import sys
import json
from typing import List, Union, Tuple, Optional
from typing import List, Optional, Tuple, Union
import numpy as np
from matchms import importing
from spec2vec.Spec2Vec import Spectrum
from onnxruntime import InferenceSession
from spec2vec.Spec2Vec import Spectrum


if sys.version_info < (3, 8):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from matchms import Spectrum
from matchms.importing.load_from_mgf import load_from_mgf
from ms2query.ms2library import (MS2Library)
from ms2query.ms2library import MS2Library
from ms2query.query_from_sqlite_database import SqliteLibrary


Expand Down
5 changes: 3 additions & 2 deletions tests/test_add_classifier_annotations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from matchms import Spectrum
import pytest
from ms2query.create_new_library.add_classifire_classifications import select_compound_classes
from matchms import Spectrum
from ms2query.create_new_library.add_classifire_classifications import \
select_compound_classes


@pytest.fixture
Expand Down
13 changes: 7 additions & 6 deletions tests/test_calculate_tanimoto_scores.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os

import pandas as pd

from ms2query.clean_and_filter_spectra import normalize_and_filter_peaks_multiple_spectra
from ms2query.create_new_library.calculate_tanimoto_scores import calculate_tanimoto_scores_unique_inchikey, \
calculate_highest_tanimoto_score
from ms2query.utils import load_matchms_spectrum_objects_from_file, load_pickled_file
from ms2query.clean_and_filter_spectra import \
normalize_and_filter_peaks_multiple_spectra
from ms2query.create_new_library.calculate_tanimoto_scores import (
calculate_highest_tanimoto_score,
calculate_tanimoto_scores_unique_inchikey)
from ms2query.utils import (load_matchms_spectrum_objects_from_file,
load_pickled_file)


def test_calculate_tanimoto_scores_unique_inchikey(path_to_general_test_files, hundred_test_spectra):
Expand Down
Loading

0 comments on commit 2073d4c

Please sign in to comment.