sirius-ms / sirius

SIRIUS is a software for discovering a landscape of de-novo identification of metabolites using tandem mass spectrometry. This repository contains the code of the SIRIUS Software (GUI and CLI)
GNU Affero General Public License v3.0
78 stars 18 forks source link

API available to interface sirius from R? #11

Open jorainer opened 3 years ago

jorainer commented 3 years ago

Dear all,

we're currently implementing and (trying to streamline) functionality for MS data analysis in R (the Spectra package is one example of that). On the to-do list are also tools to determine formulas and structural features in spectra - and here it would make more sense to use sirius for that instead of re-implementing everything in R. I was wondering if you have already an API to the web service (REST?) in place that I could play around with? I would e.g. have spectra as an Spectra object in R and e.g. would like to identify the most likely formula based on the isotope pattern.

I've seen the sirius-apis repository, but there seems to be little development lastly.

thanks for any feedback or suggestions

kaibioinfo commented 3 years ago

Hi, the github repository is just a mirror of our lab-internal repository. With each release we merge all changes from our internal repository to github. That's why it seems like there would be little development ;)

Inter-software usage of SIRIUS is definitely possible and I think there are other R-users who are writing interfaces to SIRIUS. You can start SIRIUS as server in background and run function calls via a REST API. I'm currently not sure how much of the API is already implemented, Markus can tell you more about that.

jorainer commented 3 years ago

That sounds great! Is there somewhere a documentation of the REST API? Would also be cool if you could point me to the R-users that are already working on an interface - always better to join efforts than to develop individually...

mfleisch commented 3 years ago

Hey Johannes, happy to hear that you want to use SIRIUS to determine formulas and structural features in the Spectra package.

As Kai already mentioned we are working on a background service mode for SIRIUS that will provide a local REST API that can easily be queried from any programming language.

The rest API is based on an OpenAPI specification, so that we can easily generate client libraries for many languages using swagger-codegen. This has the advantage that the API stays maintainable even for multiple languages and that programmers that build higher level functionality and workflows on top of this API will not have to deal with creating REST URLs by them selves.

It would be great if you could join to implement higher level functionality on top of the swagger-client for the R community.

Unfortunately the API is not finished yet. Currently it just can retrieve data from SIRIUS projects but not compute anything. But we could at least finish the specification very soon which we can then use to generate the full R client even if not all of its functionality is implemented yet.

This repository https://github.com/boecker-lab/Rsirius contains R package for the currently implemented features. We can provide a early version of SIRIUS with the REST functionality within the next days for testing . When running the SIRIUS background mode this will also provide an API endpoint with an interactive API documentation.

The development and code generation of the clients happen in this Repo: https://github.com/boecker-lab/sirius-client-openAPI

Best Markus

mfleisch commented 3 years ago

Regarding other users that are already working on an R interface for SIRIUS, patRoom is also wrapping SIRIUS with R.

jorainer commented 3 years ago

Thanks for the feedback and yes, I would be very interested to test the API and implement R-based functionality around that! Just let me know when you have the first testable version ready.

nirshahaf commented 3 years ago

Hi Johannes,

I am wondering if you had the chance to test the R API in 'https://github.com/boecker-lab/Rsirius '? As a temp workaround in 'R', I convert peak groups in MS1-MS2 into '.ms' files using this simple function:

exportMS = function (spectra,metaData,filePath,fileIdx) { if (!dir.exists (filePath)) { dir.create (filePath) } fileName=paste0 (fileIdx,".ms") if (file.exists (file.path (filePath,fileName))) { file.remove (file.path (filePath,fileName)) } OUT = file (file.path (filePath,fileName),open="a") writeLines (text=paste (">compound",metaData$compound),con=OUT,sep="\n") writeLines (text=paste (">formula",metaData$formula),con=OUT,sep="\n")
writeLines (text=paste (">parentmass",metaData$parentmass),con=OUT,sep="\n") writeLines (text=paste (">ionization",metaData$ionization),con=OUT,sep="\n") writeLines (text=paste (">retentionTimeInSeconds",metaData$RT),con=OUT,sep="\n")
writeLines (text=paste (">instrumentation","Waters QTOF-HRMS"),con=OUT,sep="\n")
writeLines (text="",con=OUT,sep="\n")
writeLines (text=">ms1",con=OUT,sep="\n")
sapply (1:nrow (spectra$ms1),function(i) { writeLines (text=paste (spectra$ms1[i,1],spectra$ms1[i,2]),con=OUT,sep="\n")
}) writeLines (text="",con=OUT,sep="\n")
writeLines (text=">ms2",con=OUT,sep="\n")
sapply (1:nrow (spectra$ms2),function(i) { writeLines (text=paste (spectra$ms2[i,1],spectra$ms2[i,2]),con=OUT,sep="\n")
}) writeLines (text="",con=OUT,sep="\n")
close (OUT) return (file.path (filePath,fileName)) }

and then call Sirius as a system call, e.g.:

_CMD = paste ("sirius -i",[ms_proc_dir],"-o",file.path ("Sirius",basename ([ms_proc_dir])),"--recompute --ignore-formula formula structure --database pubchem")_ system (CMD,intern=FALSE)

BTW, can we perhaps integrate formula decomposition into XCMS (are you still maintaining it?), at the stage right after p.picking? It can help improve accurate grouping/alignment plus downstream analysis. I can help, in case.

jorainer commented 3 years ago

Hi @nirshahaf ! Thanks for the comment! But unfortunately I did not yet have time to test it.

So, if I understand correctly, the R API works by calling the sirius command line on exported txt files?

Regarding xcms integration, yes, that makes sense. But ideally I would like to keep the functions independent of the xcms data structure so that they can be re-used also in other tools.

I hope to find some time soon to dig into this more.

nirshahaf commented 3 years ago

Hi Johannes, yes you got it right. I have further ideas about XCMS integration - let's please continue offline. Bests, Nir.

jorainer commented 3 years ago

Sure - my email is johannes.rainer at eurac.edu