Skip to content

Commit

Permalink
adding MS1 only spectra
Browse files Browse the repository at this point in the history
  • Loading branch information
Adafede committed Aug 11, 2023
1 parent f6dab69 commit 42d61ea
Showing 1 changed file with 68 additions and 55 deletions.
123 changes: 68 additions & 55 deletions R/create_edges_spectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,69 +49,82 @@ create_edges_spectra <- function(

log_debug("Loading spectra...")
spectra <- input |>
import_spectra() |>
## TODO make it a param
sanitize_spectra(cutoff = qutoff, deeper = TRUE) |>
Spectra::addProcessing(remove_above_precursor(),
spectraVariables = c("precursorMz")
) |>
Spectra::addProcessing(normalize_peaks()) |>
Spectra::applyProcessing()
import_spectra()
if (length(spectra) > 0) {
spectra <- spectra |>
## TODO make it a param
sanitize_spectra(cutoff = qutoff, deeper = TRUE) |>
Spectra::addProcessing(remove_above_precursor(),
spectraVariables = c("precursorMz")
) |>
Spectra::addProcessing(normalize_peaks()) |>
Spectra::applyProcessing()

log_debug("Performing spectral comparison")
log_debug(
"As we do not limit the precursors delta,
log_debug("Performing spectral comparison")
log_debug(
"As we do not limit the precursors delta,
expect a (relatively) long processing time."
)
log_debug("Take yourself a break, you deserve it.")
nspecz <- length(spectra)
precz <- spectra$precursorMz
fragz <- spectra@backend@peaksData

edges <-
pbapply::pblapply(
X = 1:(nspecz - 1),
FUN = create_edges,
frags = fragz,
precs = precz,
nspecs = nspecz,
ms2_tolerance = dalton,
ppm_tolerance = ppm,
threshold = threshold
) |>
dplyr::bind_rows()

edges <- edges |>
tidytable::select(
!!as.name(name_source) := "feature_id",
!!as.name(name_target) := "target_id",
tidytable::everything()
)
log_debug("Take yourself a break, you deserve it.")
nspecz <- length(spectra)
precz <- spectra$precursorMz
fragz <- spectra@backend@peaksData

## TODO find a way to have consistency in spectrum IDs
idz <- spectra@backend@spectraData$acquisitionNum
edges <- edges |>
dplyr::mutate(
name_source = idz[name_source],
name_target = idz[name_target]
)
edges <-
pbapply::pblapply(
X = 1:(nspecz - 1),
FUN = create_edges,
frags = fragz,
precs = precz,
nspecs = nspecz,
ms2_tolerance = dalton,
ppm_tolerance = ppm,
threshold = threshold
) |>
dplyr::bind_rows()

edges <- edges |>
tidytable::select(tidytable::any_of(
c(
name_source,
name_target,
"score",
"reverse_score",
"presence_ratio",
"count_peaks_matched"
edges <- edges |>
tidytable::select(
!!as.name(name_source) := "feature_id",
!!as.name(name_target) := "target_id",
tidytable::everything()
)
))

edges <- edges |>
dplyr::filter(
score >= threshold
## TODO find a way to have consistency in spectrum IDs
idz <- spectra@backend@spectraData$acquisitionNum
edges <- edges |>
dplyr::mutate(
name_source = idz[name_source],
name_target = idz[name_target]
)

edges <- edges |>
tidytable::select(tidytable::any_of(
c(
name_source,
name_target,
"score",
"reverse_score",
"presence_ratio",
"count_peaks_matched"
)
))

edges <- edges |>
dplyr::filter(
score >= threshold
)
} else {
log_debug("No spectra were found, returning an empty dataframe instead")
edges <- tidytable::tidytable(
!!as.name(name_source) := NA,
!!as.name(name_target) := NA,
"score" = NA,
"reverse_score" = NA,
"presence_ratio" = NA,
"count_peaks_matched" = NA
)
}

export_params(step = "create_edges_spectra")
export_output(x = edges, file = output[[1]])
Expand Down

0 comments on commit 42d61ea

Please sign in to comment.