Skip to content

Commit

Permalink
Merge pull request #19 from rformassspectrometry/phili
Browse files Browse the repository at this point in the history
quick fixes for import from MetaboLights
  • Loading branch information
jorainer authored Sep 24, 2024
2 parents fc5efd4 + c00fb47 commit 413ff51
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions R/MsExperiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ setMethod("readMsObject",
## merging
ord <- match(assay_data$`Sample Name`, sample_info$`Sample Name`)
merged_data <- cbind(assay_data, sample_info[ord, ])
names(merged_data) <- gsub(" ", "_", names(merged_data))
if (keepProtocol || keepOntology || simplify)
merged_data <- .clean_merged(x = merged_data,
keepProtocol = keepProtocol,
Expand All @@ -274,35 +273,29 @@ setMethod("readMsObject",
filePattern = param@filePattern)

## sample to spectra link
fl <- object@spectra@backend@spectraData[
1, "derived_spectral_data_file"]
nme <- colnames(merged_data)[which(merged_data[1, ] == fl)]
fl <- object@spectra@backend@spectraData[1, "derived_spectral_data_file"]
idx <- which(merged_data[1, ,drop = TRUE] == fl)
nme <- colnames(merged_data)[idx]
merged_data <- merged_data[grepl(param@filePattern,
merged_data[, nme]), ]
nme <- gsub(" ", "_", nme) #use concatenate instead ?
object@sampleData <- DataFrame(merged_data, check.names = FALSE)
l <- paste0("sampleData.", nme,
" = spectra.derived_spectral_data_file")
object <- MsExperiment::linkSampleData(object, with = l)
nme <- gsub(" ", "_", nme)
colnames(merged_data)[idx] <- nme
object@sampleData <- DataFrame(merged_data, check.names = FALSE,
row.names = NULL)
object <- MsExperiment::linkSampleData(object,
with = paste0("sampleData.",
nme,
"= spectra.derived_spectral_data_file"))
validObject(object)
object
})


#####HELPERS

#' function that takes the extra parameters and clean the metadata if asked by
#' Function that takes the extra parameters and clean the metadata if asked by
#' the user.
#'
#' Note: the subsetting of the merged data is done here, which WILL rename the
#' duplicated columns. I could fix that by first transforming the data.frame into
#' a list but I am not sure that it is useful.. The user might do some
#' subsetting too later and then the same thing will happen. Might as well have
#' it from the beginning.
#'
#' Note2: I would move that function later, keeping it her for review to help
#' clarity
#'
#' @noRd
.clean_merged <- function(x, keepProtocol, keepOntology, simplify) {
# remove ontology
Expand Down

0 comments on commit 413ff51

Please sign in to comment.