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

duplicate code related to msfinder #7

Open
hechth opened this issue Feb 16, 2023 · 0 comments
Open

duplicate code related to msfinder #7

hechth opened this issue Feb 16, 2023 · 0 comments

Comments

@hechth
Copy link
Member

hechth commented Feb 16, 2023

if(is.null(mat.dir)) {
mat.dir = paste0(home.dir, "/spectra/mat")
}
if(is.null(msp.dir)) {
msp.dir = paste0(home.dir, "/spectra/msp")
}
usemat = TRUE
usemsp = TRUE
if(!dir.exists(mat.dir)) {
usemat = FALSE
}
if(!dir.exists(msp.dir)) {
usemsp = FALSE
}
if(!usemsp & !usemat) {
stop("neither of these two directories exist: ", '\n',
" ", mat.dir, '\n',
" ", msp.dir, '\n')
}
if(usemsp & usemat) {
msps<-list.files(msp.dir, recursive = TRUE)
mats<-list.files(mat.dir, recursive = TRUE)
if(length(mats) > length(msps)) {usemsp <- FALSE}
if(length(msps) > length(mats)) {usemat <- FALSE}
if(length(msps) == length(mats)) {
feedback<-readline(prompt="Press 1 for .mat or 2 for .msp to continue")
if(feedback == 1) {usemsp <- FALSE}
if(feedback == 2) {usemat <- FALSE}
}
}
mat.dir <- c(mat.dir, msp.dir)[c(usemat, usemsp)]
do <- ramclustObj$cmpd
### retrieve parameter file from mat directory and parse to save with results.
params <- list.files(mat.dir, pattern = "batchparam", full.names = TRUE)
if(length(params) == 0) {
params <- list.files(mat.dir, pattern = "MSFINDER.INI", full.names = TRUE)
}
if(length(params) > 0) {
mtime <- rep(NA, length(params))
for(i in 1:length(mtime)) {
mtime[i] <- format(file.info(params[i])$mtime, format = '%y%m%d%H%M%S')
}
params <- params[which.max(mtime)]
params <- readLines(params)
breaks <- which(nchar(params)==0)
## structure inference parameters
st <- grep ("Structure finder parameters", params)+1
end <- breaks[which(breaks > st)[1]]-1
if(end <= st) {stop('parsing of parameter file has failed')}
tmp <- strsplit(params[st:end], "=")
nms <- sapply(1:length(tmp), FUN = function(x) {tmp[[x]][1]})
vals <- sapply(1:length(tmp), FUN = function(x) {tmp[[x]][2]})
names(vals) <- nms
ramclustObj$msfinder.structure.parameters <- vals

This code section reading data from MSfinder outputs is duplicated in import.MSFinder.formulas.R

if (is.null(mat.dir)) {
mat.dir = paste0(getwd(), "/spectra/mat")
}
if (is.null(msp.dir)) {
msp.dir = paste0(getwd(), "/spectra/msp")
}
usemat = TRUE
usemsp = TRUE
if (!dir.exists(mat.dir)) {
usemat = FALSE
}
if (!dir.exists(msp.dir)) {
usemsp = FALSE
}
if (!usemsp & !usemat) {
stop("neither of these two directories exist: ", "\n",
" ", mat.dir, "\n", " ", msp.dir, "\n")
}
if (usemsp & usemat) {
msps <- list.files(msp.dir, recursive = TRUE)
mats <- list.files(mat.dir, recursive = TRUE)
if (length(mats) > length(msps)) {
usemsp <- FALSE
}
if (length(msps) > length(mats)) {
usemat <- FALSE
}
if (length(msps) == length(mats)) {
feedback <- readline(prompt = "Press 1 for .mat or 2 for .msp to continue")
if (feedback == 1) {
usemsp <- FALSE
}
if (feedback == 2) {
usemat <- FALSE
}
}
}
mat.dir <- c(mat.dir, msp.dir)[c(usemat, usemsp)]
do <- list.files(mat.dir, pattern = ".fgt", full.names = TRUE)
### retrieve parameter file from mat directory and parse to save with results.
params <- list.files(mat.dir, pattern = "batchparam", full.names = TRUE)
if(length(params) == 0) {
params <- list.files(mat.dir, pattern = "MSFINDER.INI", full.names = TRUE)
}
if(length(params) > 0) {
mtime <- rep(NA, length(params))
for(i in 1:length(mtime)) {
mtime[i] <- format(file.info(params[i])$mtime, format = '%y%m%d%H%M%S')
}
params <- params[which.max(mtime)]
params <- readLines(params)
breaks <- which(nchar(params)==0)
## formula inference parameters
st <- grep ("Formula finder parameters", params)+1
end <- breaks[which(breaks > st)[1]]-1
if(end <= st) {stop('parsing of parameter file has failed')}
tmp <- strsplit(params[st:end], "=")
nms <- sapply(1:length(tmp), FUN = function(x) {tmp[[x]][1]})
vals <- sapply(1:length(tmp), FUN = function(x) {tmp[[x]][2]})
names(vals) <- nms
ramclustObj$msfinder.formula.parameters <- vals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants