Skip to content

Commit

Permalink
Merge pull request #177 from iomega/implement_onnx
Browse files Browse the repository at this point in the history
Define zenodo doi
  • Loading branch information
niekdejonge committed Mar 21, 2023
2 parents 69755b7 + 58aaf96 commit 12ece85
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.1]
- Define the newest zenodo DOI in one location.

## [0.7.0]
- Store random forest model in Onnx format

Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ ms2query --library .\folder_to_store_the_library --download --ionmode positive
```

Alternatively all model files can be manually downloaded from
https://zenodo.org/record/6997924#.YvuonS5BxPY for positive mode and
https://zenodo.org/record/7107654#.Yy3BeKRBxPY for negative mode.
https://zenodo.org/record/7753249#.ZBmO_sLMJPY for positive mode and
https://zenodo.org/record/7753267#.ZBmPYsLMJPY for negative mode.

#### Preprocessing mass spectra
MS2Query is run on all MS2 spectra in a spectrum file.
Expand Down Expand Up @@ -136,11 +136,8 @@ ms2query_library_files_directory = "./ms2query_library_files"
ms2_spectra_directory =
ion_mode = # Fill in "positive" or "negative" to indicate for which ion mode you would like to download the library

zenodo_DOIs = {"positive": 7753249,
"negative": 7753267}

# Downloads pretrained models and files for MS2Query (>2GB download)
download_zenodo_files(zenodo_DOIs[ion_mode],
download_zenodo_files(ion_mode,
ms2query_library_files_directory)

# Create a MS2Library object
Expand Down
4 changes: 1 addition & 3 deletions ms2query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def command_line():
additional_metadata_columns=additional_columns)
if args.download:
assert ion_mode is not None, "Ion mode should be specified by adding --ion_mode"
zenodo_DOIs = {"positive": 7753249,
"negative": 7753267}
download_zenodo_files(zenodo_DOIs[ion_mode],
download_zenodo_files(ion_mode,
ms2query_library_files_directory)

if ms2_spectra_location is not None:
Expand Down
2 changes: 1 addition & 1 deletion ms2query/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '0.7.1'
13 changes: 11 additions & 2 deletions ms2query/run_ms2query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
from ms2query.utils import load_matchms_spectrum_objects_from_file, SettingsRunMS2Query, return_non_existing_file_name


def download_zenodo_files(zenodo_doi: int,
dir_to_store_files:str):
def zenodo_dois(ionisation_mode):
"Returns the most up to date DOI for Zenodo"
zenodo_DOIs = {"positive": 7753249,
"negative": 7753267}
assert ionisation_mode in zenodo_DOIs, "Expected 'positive' or 'negative' as input"
return zenodo_DOIs[ionisation_mode]


def download_zenodo_files(ionisation_mode: str,
dir_to_store_files: str):
"""Downloads files from Zenodo
Args:
Expand All @@ -20,6 +28,7 @@ def download_zenodo_files(zenodo_doi: int,
"""
if not os.path.exists(dir_to_store_files):
os.mkdir(dir_to_store_files)
zenodo_doi = zenodo_dois(ionisation_mode)
file_names_metadata_url = "https://zenodo.org/api/records/" + str(zenodo_doi)
with urlopen(file_names_metadata_url) as zenodo_metadata_file:
file_names_metadata_json: dict = json.loads(zenodo_metadata_file.read())
Expand Down
16 changes: 2 additions & 14 deletions tests/test_run_ms2query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,13 @@ def test_download_default_models(tmp_path):
"""Tests downloading small files from zenodo
The files are a total of 20 MB from https://zenodo.org/record/7108049#.Yy2nPKRBxPY"""
dir_to_store_test_files = os.path.join(tmp_path, "positive_model")
download_zenodo_files(7108049, dir_to_store_test_files)
assert os.path.exists(dir_to_store_test_files)
assert os.path.exists(os.path.join(dir_to_store_test_files,
"GNPS_15_12_2021_neg_test_250_inchikeys.pickle"))
assert os.path.exists(os.path.join(dir_to_store_test_files,
"GNPS_15_12_2021_neg_test_3000_spectra.pickle"))
assert os.path.exists(os.path.join(dir_to_store_test_files,
"GNPS_15_12_2021_pos_test_250_inchikeys.pickle"))
assert os.path.exists(os.path.join(dir_to_store_test_files,
"GNPS_15_12_2021_pos_test_3000_spectra.pickle"))

run_test = False # Run test is set to false, since downloading takes too long for default testing
if run_test:
dir_to_store_positive_files = os.path.join(tmp_path, "positive_model")
dir_to_store_negative_files = os.path.join(tmp_path, "negative_model")

download_zenodo_files(6997924, dir_to_store_positive_files)
download_zenodo_files(7107654, dir_to_store_negative_files)
download_zenodo_files("positive", dir_to_store_positive_files)
download_zenodo_files("negative", dir_to_store_negative_files)
assert os.path.exists(dir_to_store_positive_files)
assert os.path.exists(dir_to_store_negative_files)
pos_ms2library = create_library_object_from_one_dir(dir_to_store_positive_files)
Expand Down

0 comments on commit 12ece85

Please sign in to comment.