From 243a1d6ab3b31a2766a65fd435799bb458650f29 Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Wed, 22 Nov 2023 10:59:54 +0100 Subject: [PATCH 1/2] isort --- ms2query/__init__.py | 10 ++++++---- .../benchmarking/collect_test_data_results.py | 20 +++++++++---------- .../create_accuracy_vs_recall_plot.py | 5 ++--- .../benchmarking/k_fold_cross_validation.py | 12 +++++++---- .../visualize_mass_distribution.py | 7 ++++--- .../visualize_tanimoto_score_distribution.py | 2 +- ms2query/clean_and_filter_spectra.py | 7 ++++--- .../add_classifire_classifications.py | 1 - .../calculate_tanimoto_scores.py | 7 +++---- .../create_sqlite_database.py | 6 +++--- .../library_files_creator.py | 6 ++++-- .../split_data_for_training.py | 4 ++-- ms2query/create_new_library/train_models.py | 12 +++++++---- .../create_new_library/train_ms2deepscore.py | 10 ++++++---- .../train_ms2query_model.py | 15 ++++++++------ ms2query/ms2library.py | 15 +++++++------- ms2query/query_from_sqlite_database.py | 1 - ms2query/results_table.py | 2 +- ms2query/run_ms2query.py | 4 +++- ms2query/utils.py | 6 +++--- tests/conftest.py | 2 +- tests/test_add_classifier_annotations.py | 5 +++-- tests/test_calculate_tanimoto_scores.py | 13 ++++++------ tests/test_clean_and_filter_spectra.py | 13 ++++++------ tests/test_collect_test_data_results.py | 19 ++++++++---------- tests/test_library_files_creator.py | 5 +++-- tests/test_ms2library.py | 6 +++--- tests/test_run_ms2query.py | 10 ++++++---- tests/test_split_data_for_training.py | 5 +++-- tests/test_sqlite.py | 11 ++++++---- tests/test_train_models.py | 2 +- tests/test_train_ms2deepscore.py | 6 ++++-- tests/test_train_ms2query_model.py | 17 ++++++++-------- tests/test_utils.py | 1 - 34 files changed, 145 insertions(+), 122 deletions(-) diff --git a/ms2query/__init__.py b/ms2query/__init__.py index 5be87e5c..46c08ec3 100644 --- a/ms2query/__init__.py +++ b/ms2query/__init__.py @@ -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()) diff --git a/ms2query/benchmarking/collect_test_data_results.py b/ms2query/benchmarking/collect_test_data_results.py index 5c328172..8115c488 100644 --- a/ms2query/benchmarking/collect_test_data_results.py +++ b/ms2query/benchmarking/collect_test_data_results.py @@ -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 diff --git a/ms2query/benchmarking/create_accuracy_vs_recall_plot.py b/ms2query/benchmarking/create_accuracy_vs_recall_plot.py index e98fd522..f18d6390 100644 --- a/ms2query/benchmarking/create_accuracy_vs_recall_plot.py +++ b/ms2query/benchmarking/create_accuracy_vs_recall_plot.py @@ -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 diff --git a/ms2query/benchmarking/k_fold_cross_validation.py b/ms2query/benchmarking/k_fold_cross_validation.py index fa5bdae4..c0138626 100644 --- a/ms2query/benchmarking/k_fold_cross_validation.py +++ b/ms2query/benchmarking/k_fold_cross_validation.py @@ -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, diff --git a/ms2query/benchmarking/visualize_mass_distribution.py b/ms2query/benchmarking/visualize_mass_distribution.py index d2f8dc96..183bc7a6 100644 --- a/ms2query/benchmarking/visualize_mass_distribution.py +++ b/ms2query/benchmarking/visualize_mass_distribution.py @@ -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]], diff --git a/ms2query/benchmarking/visualize_tanimoto_score_distribution.py b/ms2query/benchmarking/visualize_tanimoto_score_distribution.py index 91c2100a..5e06934c 100644 --- a/ms2query/benchmarking/visualize_tanimoto_score_distribution.py +++ b/ms2query/benchmarking/visualize_tanimoto_score_distribution.py @@ -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 diff --git a/ms2query/clean_and_filter_spectra.py b/ms2query/clean_and_filter_spectra.py index c02a3856..68736324 100644 --- a/ms2query/clean_and_filter_spectra.py +++ b/ms2query/clean_and_filter_spectra.py @@ -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: diff --git a/ms2query/create_new_library/add_classifire_classifications.py b/ms2query/create_new_library/add_classifire_classifications.py index 26ab3a6a..e28f3ef8 100644 --- a/ms2query/create_new_library/add_classifire_classifications.py +++ b/ms2query/create_new_library/add_classifire_classifications.py @@ -2,7 +2,6 @@ import urllib from http.client import InvalidURL from typing import List, Optional - import pandas as pd from tqdm import tqdm diff --git a/ms2query/create_new_library/calculate_tanimoto_scores.py b/ms2query/create_new_library/calculate_tanimoto_scores.py index 38ed59c6..80ca3f2a 100644 --- a/ms2query/create_new_library/calculate_tanimoto_scores.py +++ b/ms2query/create_new_library/calculate_tanimoto_scores.py @@ -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 diff --git a/ms2query/create_new_library/create_sqlite_database.py b/ms2query/create_new_library/create_sqlite_database.py index 1f3d309a..722a6b3e 100644 --- a/ms2query/create_new_library/create_sqlite_database.py +++ b/ms2query/create_new_library/create_sqlite_database.py @@ -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 diff --git a/ms2query/create_new_library/library_files_creator.py b/ms2query/create_new_library/library_files_creator.py index 0604ee61..4285b067 100644 --- a/ms2query/create_new_library/library_files_creator.py +++ b/ms2query/create_new_library/library_files_creator.py @@ -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: diff --git a/ms2query/create_new_library/split_data_for_training.py b/ms2query/create_new_library/split_data_for_training.py index d9f311d0..8acb1e1a 100644 --- a/ms2query/create_new_library/split_data_for_training.py +++ b/ms2query/create_new_library/split_data_for_training.py @@ -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]: diff --git a/ms2query/create_new_library/train_models.py b/ms2query/create_new_library/train_models.py index fb3e012e..aaf99426 100644 --- a/ms2query/create_new_library/train_models.py +++ b/ms2query/create_new_library/train_models.py @@ -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: diff --git a/ms2query/create_new_library/train_ms2deepscore.py b/ms2query/create_new_library/train_ms2deepscore.py index e279e760..d61348c7 100644 --- a/ms2query/create_new_library/train_ms2deepscore.py +++ b/ms2query/create_new_library/train_ms2deepscore.py @@ -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, diff --git a/ms2query/create_new_library/train_ms2query_model.py b/ms2query/create_new_library/train_ms2query_model.py index 5500a282..1162fc69 100644 --- a/ms2query/create_new_library/train_ms2query_model.py +++ b/ms2query/create_new_library/train_ms2query_model.py @@ -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(): diff --git a/ms2query/ms2library.py b/ms2query/ms2library.py index 677690ba..38a58c99 100644 --- a/ms2query/ms2library.py +++ b/ms2query/ms2library.py @@ -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: diff --git a/ms2query/query_from_sqlite_database.py b/ms2query/query_from_sqlite_database.py index 23f19ed8..83a6773d 100644 --- a/ms2query/query_from_sqlite_database.py +++ b/ms2query/query_from_sqlite_database.py @@ -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 diff --git a/ms2query/results_table.py b/ms2query/results_table.py index fd4a9da2..c3d3b156 100644 --- a/ms2query/results_table.py +++ b/ms2query/results_table.py @@ -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: diff --git a/ms2query/run_ms2query.py b/ms2query/run_ms2query.py index 27a1129c..015169ce 100644 --- a/ms2query/run_ms2query.py +++ b/ms2query/run_ms2query.py @@ -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): diff --git a/ms2query/utils.py b/ms2query/utils.py index ebe07e95..b92bee45 100644 --- a/ms2query/utils.py +++ b/ms2query/utils.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index bfaadd5e..9dc6c965 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_add_classifier_annotations.py b/tests/test_add_classifier_annotations.py index 39e23f4c..f6852cdf 100644 --- a/tests/test_add_classifier_annotations.py +++ b/tests/test_add_classifier_annotations.py @@ -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 diff --git a/tests/test_calculate_tanimoto_scores.py b/tests/test_calculate_tanimoto_scores.py index f0cbdab8..6c5a3d70 100644 --- a/tests/test_calculate_tanimoto_scores.py +++ b/tests/test_calculate_tanimoto_scores.py @@ -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): diff --git a/tests/test_clean_and_filter_spectra.py b/tests/test_clean_and_filter_spectra.py index 09f01535..05caee6a 100644 --- a/tests/test_clean_and_filter_spectra.py +++ b/tests/test_clean_and_filter_spectra.py @@ -3,13 +3,12 @@ import numpy as np from matchms import Spectrum from spec2vec import SpectrumDocument -from ms2query.clean_and_filter_spectra import (create_spectrum_documents, - normalize_and_filter_peaks_multiple_spectra, - normalize_and_filter_peaks, - remove_wrong_ion_modes, - harmonize_annotation, - split_annotated_spectra, - clean_normalize_and_split_annotated_spectra) +from ms2query.clean_and_filter_spectra import ( + clean_normalize_and_split_annotated_spectra, create_spectrum_documents, + harmonize_annotation, normalize_and_filter_peaks, + normalize_and_filter_peaks_multiple_spectra, remove_wrong_ion_modes, + split_annotated_spectra) + if sys.version_info < (3, 8): import pickle5 as pickle diff --git a/tests/test_collect_test_data_results.py b/tests/test_collect_test_data_results.py index 7c96758b..dafce8dc 100644 --- a/tests/test_collect_test_data_results.py +++ b/tests/test_collect_test_data_results.py @@ -1,18 +1,15 @@ import os +import numpy as np import pandas as pd import pytest -import numpy as np from matchms import Spectrum -from ms2query.benchmarking.collect_test_data_results import (generate_test_results_ms2query, - get_all_ms2ds_scores, - select_highest_ms2ds_in_mass_range, - get_modified_cosine_score_results, - get_cosines_score_results, - create_optimal_results, - create_random_results, - generate_test_results) - -from ms2query.utils import load_matchms_spectrum_objects_from_file, load_json_file +from ms2query.benchmarking.collect_test_data_results import ( + create_optimal_results, create_random_results, generate_test_results, + generate_test_results_ms2query, get_all_ms2ds_scores, + get_cosines_score_results, get_modified_cosine_score_results, + select_highest_ms2ds_in_mass_range) +from ms2query.utils import (load_json_file, + load_matchms_spectrum_objects_from_file) @pytest.fixture diff --git a/tests/test_library_files_creator.py b/tests/test_library_files_creator.py index 0f0a7652..89864bed 100644 --- a/tests/test_library_files_creator.py +++ b/tests/test_library_files_creator.py @@ -1,10 +1,11 @@ import os import pandas as pd import pytest -from ms2query.create_new_library.library_files_creator import LibraryFilesCreator +from ms2query.clean_and_filter_spectra import normalize_and_filter_peaks +from ms2query.create_new_library.library_files_creator import \ + LibraryFilesCreator from ms2query.utils import (load_matchms_spectrum_objects_from_file, load_pickled_file) -from ms2query.clean_and_filter_spectra import normalize_and_filter_peaks def test_give_already_used_file_name(tmp_path, path_to_general_test_files, hundred_test_spectra): diff --git a/tests/test_ms2library.py b/tests/test_ms2library.py index 0854d380..a82fe672 100644 --- a/tests/test_ms2library.py +++ b/tests/test_ms2library.py @@ -4,9 +4,9 @@ import pandas as pd import pytest from pandas.testing import assert_series_equal -from ms2query.ms2library import (MS2Library, - create_library_object_from_one_dir) -from ms2query.utils import load_pickled_file, SettingsRunMS2Query, column_names_for_output +from ms2query.ms2library import MS2Library, create_library_object_from_one_dir +from ms2query.utils import (SettingsRunMS2Query, column_names_for_output, + load_pickled_file) from tests.test_utils import check_correct_results_csv_file diff --git a/tests/test_run_ms2query.py b/tests/test_run_ms2query.py index ee1694c7..3110bb4d 100644 --- a/tests/test_run_ms2query.py +++ b/tests/test_run_ms2query.py @@ -1,14 +1,16 @@ import os import sys - import pandas as pd - -from ms2query.ms2library import create_library_object_from_one_dir, select_files_for_ms2query -from ms2query.run_ms2query import download_zenodo_files, run_complete_folder, zenodo_dois, available_zenodo_files +from ms2query.ms2library import (create_library_object_from_one_dir, + select_files_for_ms2query) +from ms2query.run_ms2query import (available_zenodo_files, + download_zenodo_files, run_complete_folder, + zenodo_dois) from ms2query.utils import SettingsRunMS2Query from tests.test_ms2library import MS2Library from tests.test_utils import check_correct_results_csv_file + if sys.version_info < (3, 8): import pickle5 as pickle else: diff --git a/tests/test_split_data_for_training.py b/tests/test_split_data_for_training.py index 001ba1b0..e4b5712e 100644 --- a/tests/test_split_data_for_training.py +++ b/tests/test_split_data_for_training.py @@ -1,7 +1,8 @@ import os +from ms2query.create_new_library.split_data_for_training import ( + select_unique_inchikeys, split_spectra_in_random_inchikey_sets, + split_spectra_on_inchikeys) from ms2query.utils import load_matchms_spectrum_objects_from_file -from ms2query.create_new_library.split_data_for_training import split_spectra_on_inchikeys, \ - split_spectra_in_random_inchikey_sets, select_unique_inchikeys def test_split_spectra_on_inchikeys(path_to_general_test_files, hundred_test_spectra): diff --git a/tests/test_sqlite.py b/tests/test_sqlite.py index 82dde516..27f42a7f 100644 --- a/tests/test_sqlite.py +++ b/tests/test_sqlite.py @@ -9,10 +9,13 @@ import sqlite3 import numpy as np import pandas as pd -from ms2query.create_new_library.create_sqlite_database import make_sqlfile_wrapper -from ms2query.clean_and_filter_spectra import normalize_and_filter_peaks_multiple_spectra -from ms2query.utils import load_pickled_file, column_names_for_output -from ms2query.create_new_library.add_classifire_classifications import convert_to_dataframe +from ms2query.clean_and_filter_spectra import \ + normalize_and_filter_peaks_multiple_spectra +from ms2query.create_new_library.add_classifire_classifications import \ + convert_to_dataframe +from ms2query.create_new_library.create_sqlite_database import \ + make_sqlfile_wrapper +from ms2query.utils import column_names_for_output, load_pickled_file def check_sqlite_files_are_equal(new_sqlite_file_name, reference_sqlite_file, check_metadata=True): diff --git a/tests/test_train_models.py b/tests/test_train_models.py index d4503735..1d5efe72 100644 --- a/tests/test_train_models.py +++ b/tests/test_train_models.py @@ -1,7 +1,7 @@ import os import pytest from ms2query.create_new_library.train_models import clean_and_train_models -from ms2query.ms2library import create_library_object_from_one_dir, MS2Library +from ms2query.ms2library import MS2Library, create_library_object_from_one_dir @pytest.mark.integration diff --git a/tests/test_train_ms2deepscore.py b/tests/test_train_ms2deepscore.py index 963f2c97..b3384e4c 100644 --- a/tests/test_train_ms2deepscore.py +++ b/tests/test_train_ms2deepscore.py @@ -1,8 +1,10 @@ import os from ms2deepscore.models import SiameseModel -from ms2deepscore.models.load_model import load_model as load_ms2deepscore_model +from ms2deepscore.models.load_model import \ + load_model as load_ms2deepscore_model from ms2query.create_new_library.train_ms2deepscore import train_ms2ds_model -from ms2query.utils import load_matchms_spectrum_objects_from_file, load_pickled_file +from ms2query.utils import (load_matchms_spectrum_objects_from_file, + load_pickled_file) def test_train_ms2ds_model(path_to_general_test_files, tmp_path, hundred_test_spectra): diff --git a/tests/test_train_ms2query_model.py b/tests/test_train_ms2query_model.py index b0efe5ec..3da39fb0 100644 --- a/tests/test_train_ms2query_model.py +++ b/tests/test_train_ms2query_model.py @@ -1,17 +1,16 @@ import os - -import numpy as np -import pytest import sys +import numpy as np import pandas as pd -from ms2query.create_new_library.train_ms2query_model import \ - DataCollectorForTraining, calculate_tanimoto_scores_with_library, train_random_forest, train_ms2query_model, \ - convert_to_onnx_model -from ms2query.utils import load_pickled_file, load_matchms_spectrum_objects_from_file, load_ms2query_model, \ - predict_onnx_model +import pytest from onnxruntime import InferenceSession -from ms2query.utils import predict_onnx_model +from ms2query.create_new_library.train_ms2query_model import ( + DataCollectorForTraining, calculate_tanimoto_scores_with_library, + convert_to_onnx_model, train_ms2query_model, train_random_forest) from ms2query.ms2library import MS2Library +from ms2query.utils import (load_matchms_spectrum_objects_from_file, + load_ms2query_model, load_pickled_file, + predict_onnx_model) if sys.version_info < (3, 8): diff --git a/tests/test_utils.py b/tests/test_utils.py index 4cf9778c..3d205143 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,6 @@ import os from io import StringIO from typing import List - import pandas as pd import pytest from matchms import Spectrum From 65b4282aea416a394bfc80a651b053abcc102c7f Mon Sep 17 00:00:00 2001 From: niekdejonge Date: Wed, 22 Nov 2023 11:00:36 +0100 Subject: [PATCH 2/2] Added isort back to checks and run isort --- .github/workflows/CI_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI_build.yml b/.github/workflows/CI_build.yml index b6a1d1ed..c9a06cdb 100644 --- a/.github/workflows/CI_build.yml +++ b/.github/workflows/CI_build.yml @@ -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: