Skip to content
Snippets Groups Projects
Commit 3af1cc56 authored by ermueller's avatar ermueller
Browse files

RMassBank now fully functional

parent f8e6b12b
No related branches found
No related tags found
No related merge requests found
......@@ -383,6 +383,7 @@ gatherData <- function(id)
{
# Split the "InChiKey=" part off the key
inchikey_split <- strsplit(inchikey, "=", fixed=TRUE)[[1]][[2]]
print(inchikey_split)
# Actually retrieve data from CTS (see the webaccess scripts)
infos <- getCtsRecord(inchikey_split)
# Check if the name was found. If yes, OK. Otherwise, search again using
......@@ -451,7 +452,7 @@ gatherData <- function(id)
# Eliminate duplicate names from our list of 3
names <- as.list(unique(c(topNameN, storedName, iupacName)))
names <- as.list(unique(c(dbname, storedName, iupacName)))
# Start to fill the MassBank record.
......@@ -477,6 +478,7 @@ gatherData <- function(id)
mbdata[["COMMENT"]][["ID"]] = id
# here compound info starts
mbdata[['CH$NAME']] <- names
print(mbdata[['CH$NAME']])
# Currently we use a fixed value for Compound Class, since there is no useful
# convention of what should go there and what shouldn't, and the field is not used
# in search queries.
......@@ -503,7 +505,7 @@ gatherData <- function(id)
mbdata[['AC$INSTRUMENT']] <- getOption("RMassBank")$annotations$instrument
mbdata[['AC$INSTRUMENT_TYPE']] <- getOption("RMassBank")$annotations$instrument_type
print(mbdata)
print(mbdata)
return(mbdata)
} # function gather.mbdata
......
......@@ -105,7 +105,7 @@ msmsWorkflow <- function(w, mode="pH", steps=c(1:8), confirmMode = FALSE, newRec
if(readMethod == "xcms"){
splitfn <- strsplit(w@files,'_')
cpdIDs <- sapply(splitfn, function(splitted){as.numeric(return(splitted[2]))})
cpdIDs <- sapply(splitfn, function(splitted){as.numeric(return(splitted[length(splitted)-1]))})
files <- list()
wfiles <- vector()
for(i in 1:length(unique(cpdIDs))) {
......@@ -175,7 +175,7 @@ msmsWorkflow <- function(w, mode="pH", steps=c(1:8), confirmMode = FALSE, newRec
if(3 %in% steps)
{
message("msmsWorkflow: Step 3. Aggregate all spectra")
w@aggregatedSpecs <- aggregateSpectra(w@analyzedSpecs)
w@aggregatedSpecs <- aggregateSpectra(w@analyzedSpecs, addIncomplete=TRUE)
}
# Step 4: recalibrate all m/z values in raw spectra
if(4 %in% steps)
......
......@@ -223,7 +223,7 @@ findMsMsHR.direct <- function(msRaw, cpdID, mode = "pH", confirmMode = 0, useRtL
#' psp <- findMsMsHRperxcms.direct(fileList,2184)
#' }
#' @export
findMsMsHRperxcms.direct <- function(fileName, cpdID, mode="pH", findPeaksArgs, plots = FALSE) {
findMsMsHRperxcms.direct <- function(fileName, cpdID, mode="pH", findPeaksArgs = NULL, plots = FALSE) {
require(CAMERA)
require(xcms)
......@@ -244,7 +244,7 @@ findMsMsHRperxcms.direct <- function(fileName, cpdID, mode="pH", findPeaksArgs,
## MSMS
##
xrmsms <- xcmsRaw(fileName, includeMSn=TRUE)
print("File read")
## Where is the wanted isolation ?
precursorrange <- range(which(xrmsms@msnPrecursorMz == parentMass)) ## TODO: add ppm one day
......@@ -259,6 +259,7 @@ findMsMsHRperxcms.direct <- function(fileName, cpdID, mode="pH", findPeaksArgs,
anmsms <- list()
psp <- list()
spectra <- list()
whichmissing <- vector()
for(i in 1:length(xrs)){
peaks(xsmsms[[i]]) <- do.call(findPeaks,c(findPeaksArgs, object = xrs[[i]]))
......@@ -283,7 +284,14 @@ findMsMsHRperxcms.direct <- function(fileName, cpdID, mode="pH", findPeaksArgs,
if((plots == TRUE) && (length(psp[[i]]) > 0)){
plotPsSpectrum(anmsms[[i]], psp[[i]], log=TRUE, mzrange=c(0, findMz(cpdID)[[3]]), maxlabel=10)
}
if(length(psp[[i]]) != 0){
spectra[[i]] <- getpspectra(anmsms[[i]], psp[[i]])
} else {whichmissing <- c(whichmissing,i)}
}
if(length(spectra) != 0){
for(i in whichmissing){
spectra[[i]] <- matrix(0,2,7)
}
}
return(spectra)
}
......@@ -413,7 +421,7 @@ toRMB <- function(msmsXCMSspecs = NA, cpdID = NA, mode="pH", MS1spec = NA){
header[12] <- max(spec[,1])
header[13] <- 1
header[14] <- findMz(cpdID)[[3]]
header[15] <- -1 ##Will be changed for different charges
header[15] <- 1 ##Will be changed for different charges
header[16] <- 0 ##There sadly isnt any precursor intensity to find in the msms-scans. Workaround? msmsXCMS@files[1]
header[17:20] <- 0 ##Will be changed if merge is wanted
return(header)
......
......@@ -138,26 +138,26 @@ getCtsRecord <- function(key, from = "inchikey",
to = c("cas","hmdb","kegg","sid","chebi","inchi","lipidmap","smiles","cid",
"inchikey","mass","formula","iupac","names"))
{
require(devtools)
#require(devtools)
require(RJSONIO)
#install_github(repo = "CTSgetR", username = "dgrapov")
require(CTSgetR)
#require(CTSgetR)
# checks
if(from %in% c("", "None", "Unknown", "Not available"))
return(NA)
if(from %in% c("", "None", "Unknown", "Not available")){
return(NA)}
ChemSpID<-CTSgetR(key,from="InChIKey",to="ChemSpider",parallel=FALSE)
CTS.options<-CTS.options()[2:10]
CTS.options # see options
id<-ChemSpID
childrenProc<-sapply(1:length(CTS.options), function(i)
{
cat(CTS.options[i],"\n")
CTSgetR(id=id,to=CTS.options[i],from="ChemSpider")
})
print(childrenProc)
#ChemSpID<-CTSgetR(key,from="InChIKey",to="ChemSpider",parallel=FALSE)
#CTS.options<-CTS.options()[2:10]
#CTS.options # see options
#id<-ChemSpID
#childrenProc<-sapply(1:length(CTS.options), function(i)
#{
# cat(CTS.options[i],"\n")
# CTSgetR(id=id,to=CTS.options[i],from="ChemSpider")
#})
#print(childrenProc)
require(RJSON)
#require(RJSON)
urlInchi <- paste("http://cts.fiehnlab.ucdavis.edu/service/compound/", key, sep='')
JSONstring <- getURL(urlInchi)
Content <- fromJSON(JSONstring, method = "C", unexpected.escape = "error" )
......@@ -195,10 +195,10 @@ getCtsRecord <- function(key, from = "inchikey",
#}
# Check and fix CAS (eliminate the 12-34-5CHEBI and NIKKAJI stuff)
if(!is.null(childrenProc$CAS))
{
childrenProc$CAS <- childrenProc$CAS[which(grepl("^[-0-9]+$", childrenProc$CAS))]
}
#if(!is.null(childrenProc$CAS))
#{
#childrenProc$CAS <- childrenProc$CAS[which(grepl("^[-0-9]+$", childrenProc$CAS))]
#}
print(Content)
return(Content)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment