Mercurial > repos > recetox > ms2deepscore_training
comparison ms2deepscore_training.xml @ 0:0a0529822d91 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/ms2deepscore commit 4bd610e0cbbcbed51a6bfb880179777fc8034fd6
| author | recetox |
|---|---|
| date | Mon, 02 Sep 2024 12:12:30 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:0a0529822d91 |
|---|---|
| 1 <tool id="ms2deepscore_training" name="MS2DeepScore Model Training" version="@TOOL_VERSION@+galaxy0"> | |
| 2 <description>Compute similarity scores using a pre-trained MS2DeepScore model</description> | |
| 3 <macros> | |
| 4 <import>macros.xml</import> | |
| 5 </macros> | |
| 6 <expand macro="creator"/> | |
| 7 <expand macro="edam" /> | |
| 8 | |
| 9 <requirements> | |
| 10 <requirement type="package" version="@TOOL_VERSION@">ms2deepscore</requirement> | |
| 11 <requirement type="package" version="@ONNX_VERSION@">onnx</requirement> | |
| 12 </requirements> | |
| 13 | |
| 14 <command detect_errors="exit_code"><![CDATA[ | |
| 15 mkdir processing; | |
| 16 cp $spectra processing/input."$spectra.ext"; | |
| 17 python3 ${python_wrapper} | |
| 18 ]]></command> | |
| 19 <configfiles> | |
| 20 <configfile name="python_wrapper"> | |
| 21 import onnx | |
| 22 import os | |
| 23 import torch | |
| 24 from ms2deepscore.models import load_model | |
| 25 from ms2deepscore.SettingsMS2Deepscore import SettingsMS2Deepscore | |
| 26 from ms2deepscore.wrapper_functions.training_wrapper_functions import train_ms2deepscore_wrapper, StoreTrainingData | |
| 27 | |
| 28 @json_load@ | |
| 29 | |
| 30 settings = SettingsMS2Deepscore(**model_params) | |
| 31 file = "processing/input.$spectra.ext" | |
| 32 directory = train_ms2deepscore_wrapper(file, settings, $validation_split_fraction) | |
| 33 | |
| 34 expected_file_names = StoreTrainingData(file) | |
| 35 pt_model_path = os.path.join(expected_file_names.trained_models_folder, directory, settings.model_file_name) | |
| 36 | |
| 37 model = load_model(pt_model_path) | |
| 38 model.eval() | |
| 39 | |
| 40 batch_size = 1 | |
| 41 number_of_bins = settings.number_of_bins() | |
| 42 additional_inputs = len(settings.additional_metadata) | |
| 43 | |
| 44 # Create dummy inputs | |
| 45 spectra_tensors_1 = torch.randn(batch_size, number_of_bins) | |
| 46 spectra_tensors_2 = torch.randn(batch_size, number_of_bins) | |
| 47 metadata_1 = torch.randn(batch_size, additional_inputs) | |
| 48 metadata_2 = torch.randn(batch_size, additional_inputs) | |
| 49 | |
| 50 # Export the model to ONNX | |
| 51 torch.onnx.export( | |
| 52 model, | |
| 53 (spectra_tensors_1, spectra_tensors_2, metadata_1, metadata_2), | |
| 54 "$onnx_trained_model", | |
| 55 verbose=True | |
| 56 ) | |
| 57 | |
| 58 </configfile> | |
| 59 </configfiles> | |
| 60 | |
| 61 <inputs> | |
| 62 <expand macro="training_param" /> | |
| 63 </inputs> | |
| 64 | |
| 65 <outputs> | |
| 66 <data label="Trained model" name="onnx_trained_model" format="onnx"/> | |
| 67 </outputs> | |
| 68 | |
| 69 <tests> | |
| 70 <test expect_num_outputs="1"> | |
| 71 <param name="spectra" value="clean_spectra.mgf" ftype="mgf"/> | |
| 72 <param name="model_param" value="Model_Parameter_JSON.json" ftype="json" /> | |
| 73 <param name="validation_split_fraction" value="5"/> | |
| 74 <output name="onnx_trained_model" value="Trained_model.onnx" ftype="onnx" compare="sim_size"/> | |
| 75 </test> | |
| 76 </tests> | |
| 77 | |
| 78 <help> | |
| 79 <![CDATA[ | |
| 80 Info | |
| 81 ==== | |
| 82 This tool trains a MS2DeepScore model using the provided training data and model configuration. | |
| 83 The trained model is then exported using ONNX. | |
| 84 | |
| 85 About | |
| 86 ===== | |
| 87 @HELP@ | |
| 88 ]]> | |
| 89 </help> | |
| 90 <expand macro="citations"/> | |
| 91 </tool> |
