Skip to content

Commit

Permalink
Add initial support for reading Spectronaut log files
Browse files Browse the repository at this point in the history
  • Loading branch information
csoneson committed Apr 28, 2024
1 parent 5780bce commit c1dd85a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export(readDIANNInfo)
export(readFragPipeInfo)
export(readMaxQuantXML)
export(readProteomeDiscovererInfo)
export(readSpectronautSetup)
export(runDIANNAnalysis)
export(runFragPipeAnalysis)
export(runMaxQuantAnalysis)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Update DIA-NN example data
* Expand input data paths in run*Analysis() functions
* Add support for importing Spectronaut PG pivot files
* Add initial support for reading Spectronaut setup.txt files

# einprot 0.9.3

Expand Down
55 changes: 55 additions & 0 deletions R/readSpectronautSetup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Extract information from Spectronaut setup file
#'
#' Read \code{Spectronaut} setup.txt file and extract information about the
#' run.
#'
#' @param spectronautSetupFile Character scalar, the path to a
#' \code{Spectronaut} setup file. Can be \code{NULL} (in this case, an
#' empty list is returned).
#'
#' @author Charlotte Soneson
#' @export
#'
#' @returns A list with extracted information about the Spectronaut run.
#'
readSpectronautSetup <- function(spectronautSetupFile) {
.assertScalar(x = spectronautSetupFile, type = "character",
allowNULL = TRUE)

if (is.null(spectronautSetupFile)) {
return(list())
} else {
if (!file.exists(spectronautSetupFile)) {
stop(spectronautSetupFile, " doesn't exist.")
}

## Read file and extract settings and setup part
sf <- readLines(spectronautSetupFile)
settings <- sf[seq(which(sf == "[BEGIN-SETTINGS]") + 1,
which(sf == "[END-SETTINGS]") - 1)]
setup <- sf[seq(which(sf == "[BEGIN-SETUP]") + 1,
which(sf == "[END-SETUP]") - 1)]

## Version
sp_version <- grep("^Spectronaut ", sf, value = TRUE)[1]

## Raw files
sp_raw_files <- paste(sub("Run: ", "", grep("^Run: ", setup,
value = TRUE)),
collapse = ", ")

## Protein databases
sp_fasta_files <- unique(sub(".*Original File: ", "",
grep("Original File: ", setup,
value = TRUE)))
sp_fasta_files <- paste(sp_fasta_files, collapse = ", ")

L <- list(
"Spectronaut version" = sp_version,
"Setup file" = spectronautSetupFile,
"Raw files" = sp_raw_files,
"Databases" = sp_fasta_files
)
return(L[!vapply(L, is.null, TRUE)])
}
}
2 changes: 1 addition & 1 deletion R/runSpectronautAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @param outLevel Character string indicating the desired output level.
#' Currently only \code{"pg"} is supported.
#' @param spectronautLogFile Character string pointing to the Spectronaut
#' log file. File paths will be expressed in canonical form (using
#' setup.txt log file. File paths will be expressed in canonical form (using
#' \code{normalizePath()}) before they are processed.
#' @param iColPattern Character scalar defining a regular expression to
#' identify sample columns (only used if \code{spectronautFileType} is
Expand Down
6 changes: 3 additions & 3 deletions inst/extdata/process_basic_template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ if (expType == "MaxQuant") {
"Analysis level" = outLevel), dia)
tb <- dia[names(dia) != "DIA-NN command"]
} else if (expType == "Spectronaut") {
tb <- list("Spectronaut file" = spectronautFile,
"Spectronaut log file" = spectronautLogFile,
"Analysis level" = outLevel)
tb <- readSpectronautSetup(spectronautSetupFile = spectronautLogFile)
tb <- c(list("Spectronaut file" = spectronautFile,
"Analysis level" = outLevel), tb)
} else {
stop("Unknown 'expType'")
}
Expand Down
23 changes: 23 additions & 0 deletions man/readSpectronautSetup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runSpectronautAnalysis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1dd85a

Please sign in to comment.