| Title: | Mass-Spectra Prediction Using the FIORA Model |
|---|---|
| Description: | Provides a wrapper for the python module 'FIORA' as well as a 'shiny'-App to facilitate data processing and visualization. 'FIORA' allows to predict Mass-Spectra based on the SMILES code of chemical compounds. It is described in the Nature Communications article by Nowatzky (2025) <doi:10.1038/s41467-025-57422-4>. |
| Authors: | Jan Lisec [aut, cre] |
| Maintainer: | Jan Lisec <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.16 |
| Built: | 2026-05-14 09:29:26 UTC |
| Source: | https://github.com/janlisec/fiora |
This function will check and perform the installation of three components in the following order: reticulate, miniconda and fiora. It will ensure that a working conda environment 'fiora' is available. This is a prerequisite for both, run_app and run_script.
install_fiora(conda_name = "fiora")install_fiora(conda_name = "fiora")
conda_name |
The name of the conda environment where fiora shall be installed to. |
A list providing the current OS and path information on the current python executable and the fiora script.
## Not run: # this will install packages and software on your machine install_fiora() ## End(Not run)## Not run: # this will install packages and software on your machine install_fiora() ## End(Not run)
This is a wrapper around function 'InterpretMSSpectrum::PlotSpec()' allowing to add chemical structures of MS^2 fragments to the plot.
plot_spec(s, show_neutral_losses = TRUE, smiles_size = 0.3, ...)plot_spec(s, show_neutral_losses = TRUE, smiles_size = 0.3, ...)
s |
A valid spectrum as predicted by fiora. |
show_neutral_losses |
Connect main peaks by gray lines and annotate the respective sum formula of the neutral loss. |
smiles_size |
Overlay SMILES (if present in columns of s) in plot. |
... |
Passed on to 'InterpretMSSpectrum::PlotSpec()'. |
See examples and documentation of 'InterpretMSSpectrum::PlotSpec()'.
Creates an annotated plot of a mass spectrum and returns the spectrum invisibly.
[InterpretMSSpectrum::PlotSpec()]
fl <- system.file("extdata/annotated_output.mgf", package = "fioRa") tmp <- fioRa::read_fiora(fl = fl) s <- tmp[[3]][["spec"]] plot_spec(s = s) plot_spec(s = s, show_neutral_losses = FALSE) plot_spec(s = s, masslab = 0.05, xlim=c(150, 200))fl <- system.file("extdata/annotated_output.mgf", package = "fioRa") tmp <- fioRa::read_fiora(fl = fl) s <- tmp[[3]][["spec"]] plot_spec(s = s) plot_spec(s = s, show_neutral_losses = FALSE) plot_spec(s = s, masslab = 0.05, xlim=c(150, 200))
Allows to import a 'FIORA' output file (msp like format) to a list like format or simplified to a data frame or Spectra object.
read_fiora(fl, fmt = c("list", "df", "Spectra"), check = TRUE, scale = 0)read_fiora(fl, fmt = c("list", "df", "Spectra"), check = TRUE, scale = 0)
fl |
file. |
fmt |
A named list object is returned if not specified otherwise. Set 'fmt=df' to simplify the return value to a data frame. Use 'fmt=Spectra' to convert to a [Spectra::Spectra()] object. |
check |
Perform some sanity checks on a 'FIORA' result file, i.e. avoiding invalid adducts defining [M-3H] where only one or two H atoms are contained in the formula. |
scale |
Allows to scale spectra upon import. For scale=0 (default) no modification is applied. Otherwise the maximum intensity peak is set to the specified value. Values of 999 (for NIST), 1 or 100 would be common choices. |
A result list of length = n_compounds containing metadata fields as sub-lists and the predicted MS^2 spectrum as sub-list 'spec'. You can set parameter ‘fmt' to ’df' in which case each compound list will be coerced to a data frame row (spectra will be encoded as 'mz1:int1 mz2:int2 ...' and information regarding SMILES, adduct or formula per peak will be lost).
[Spectra::Spectra()]
fl <- system.file("extdata/annotated_output.mgf", package = "fioRa") # read as data.frame (return a simplified version) str(fioRa::read_fiora(fl = fl, fmt = "df")) # read as a list (standard case) fioRa::read_fiora(fl = fl) # read as Spectra object (requires Spectra-package) if (requireNamespace("Spectra", quietly = TRUE)) { fioRa::read_fiora(fl = fl, fmt = "Spectra") }fl <- system.file("extdata/annotated_output.mgf", package = "fioRa") # read as data.frame (return a simplified version) str(fioRa::read_fiora(fl = fl, fmt = "df")) # read as a list (standard case) fioRa::read_fiora(fl = fl) # read as Spectra object (requires Spectra-package) if (requireNamespace("Spectra", quietly = TRUE)) { fioRa::read_fiora(fl = fl, fmt = "Spectra") }
Will open a Shiny App in the local browser.
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
onStart |
A function that will be called before the app is actually run.
This is only needed for |
options |
Named options that should be passed to the |
enableBookmarking |
Can be one of |
uiPattern |
A regular expression that will be applied to each |
... |
arguments to pass to golem_opts. See '?golem::get_golem_options' for more details. |
A shinyApp object. Will open a Shiny App in the local browser.
A wrapper around the python script 'fiora-predict' using the fiora open source model to generate a MS^2 spectra for a compound with known SMILES code.
run_script( x = data.frame(Name = "Example_0", SMILES = "CC1=CC(=O)OC2=CC(OS(O)(=O)=O)=CC=C12", Precursor_type = "[M-H]-", CE = 17, Instrument_type = "HCD"), min_prob = 0.001, annotation = FALSE, fiora_script = NULL, fmt = c("list", "df", "Spectra", "file_only"), file_out = NULL, verbose = TRUE )run_script( x = data.frame(Name = "Example_0", SMILES = "CC1=CC(=O)OC2=CC(OS(O)(=O)=O)=CC=C12", Precursor_type = "[M-H]-", CE = 17, Instrument_type = "HCD"), min_prob = 0.001, annotation = FALSE, fiora_script = NULL, fmt = c("list", "df", "Spectra", "file_only"), file_out = NULL, verbose = TRUE )
x |
A data frame containing columns Name (compound names), SMILES (SMILES code of the compounds, Precursor_type (currently "[M-H]-" or "[M+H]+"), CE (Collision energy) and Instrument_type (i.e. HCD). |
min_prob |
Minimum peak probability to be recorded in the spectrum. |
annotation |
Return SMILES for fragments if TRUE. |
fiora_script |
Path to python script fiora-predict. |
fmt |
Set fmt to 'df' to simplify the return value to a data frame (named list otherwise). You may also use 'file_only' to omit output to the console if you specify a valid path in 'file_out'. |
file_out |
Specify a path to a file to store the FIORA result permanently. |
verbose |
Set to FALSE to omit messages. |
This wrapper will generate a fiora ready input file (csv-format) based on the user parameters which is stored as a temp file. It will ensure that the current version of the fiora package is installed in a respective python environment. It will use 'system2()' to run the python script 'fiora-predict' and import its result back into R using function 'read_fiora()'. You can try different installed version of 'fiora' by providing the path the the script explicitly.
A list with the fiora results for the specified compound(s).
## Not run: # !!! running this example will install the python module `fiora` td <- fioRa::test_data x <- setNames(data.frame( t(sapply(td[2:11], function(x) { strsplit(x, ",")[[1]] }))), strsplit(td[1], ",")[[1]] ) foo <- run_script(x = x) foo[[1]][["spec"]] # modify parameters run_script(x = x[1,,drop=FALSE], min_prob = 0.05) # you may also return a Spectra object run_script(x = x[1,,drop=FALSE], min_prob = 0.05, annotation = TRUE, fmt = "Spectra") # use a different fiora environment/model s_pth <- "c:/Users/jlisec/AppData/Local/r-miniconda/envs/fiora-0.1.0/Scripts/fiora-predict" # this setup will be used internally fioRa:::find_fiora_predict_paths(default_path = dirname(s_pth), script_name = basename(s_pth)) # run the script foo2 <- run_script(x = x, fiora_script = s_pth) foo2[[1]][["spec"]] for (i in 1:length(foo)) { cat("\n") print(names(foo)[i])#' print(foo[[i]][["spec"]]) print(foo2[[i]][["spec"]]) } ## End(Not run)## Not run: # !!! running this example will install the python module `fiora` td <- fioRa::test_data x <- setNames(data.frame( t(sapply(td[2:11], function(x) { strsplit(x, ",")[[1]] }))), strsplit(td[1], ",")[[1]] ) foo <- run_script(x = x) foo[[1]][["spec"]] # modify parameters run_script(x = x[1,,drop=FALSE], min_prob = 0.05) # you may also return a Spectra object run_script(x = x[1,,drop=FALSE], min_prob = 0.05, annotation = TRUE, fmt = "Spectra") # use a different fiora environment/model s_pth <- "c:/Users/jlisec/AppData/Local/r-miniconda/envs/fiora-0.1.0/Scripts/fiora-predict" # this setup will be used internally fioRa:::find_fiora_predict_paths(default_path = dirname(s_pth), script_name = basename(s_pth)) # run the script foo2 <- run_script(x = x, fiora_script = s_pth) foo2[[1]][["spec"]] for (i in 1:length(foo)) { cat("\n") print(names(foo)[i])#' print(foo[[i]][["spec"]]) print(foo2[[i]][["spec"]]) } ## End(Not run)
The example set of test compounds provided with FIORA.
data(test_data)data(test_data)
A character vector of length = 12 containing the readLines equivalent of a fiora input file in csv format, with header, 10 example compounds, defined via their SMILES, and an empty final line (or vector element respectively).
https://github.com/BAMeScience/fiora/blob/main/examples/example_input.csv