Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API available to interface sirius from R? #11

Open
jorainer opened this issue Oct 23, 2020 · 9 comments
Open

API available to interface sirius from R? #11

jorainer opened this issue Oct 23, 2020 · 9 comments

Comments

@jorainer
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Collaborator

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 mfleisch mentioned this issue Oct 28, 2020
@mfleisch
Copy link
Collaborator

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

@jorainer
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link

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

@jorainer
Copy link
Author

jorainer commented Feb 1, 2021

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

mfleisch pushed a commit that referenced this issue Mar 8, 2024
Resolve "Transform GUI to Nightsky API"

Closes #81, #123, #87, #84, #83, #60, #44, #42, #27, #16, #13, and #11

See merge request bright-giant/sirius/sirius-frontend!26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants