Skip to content

Commit

Permalink
2023-06-04
Browse files Browse the repository at this point in the history
Codes optimization in matching experimental and theoretical features.
  • Loading branch information
qzhang503 committed Jun 4, 2023
1 parent b2bcd7d commit af4608e
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 103 deletions.
36 changes: 12 additions & 24 deletions R/ion_ladder.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ bions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -174,8 +173,7 @@ yions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass, aam[length(aam):1L])
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -196,8 +194,7 @@ bstarions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 17.026549, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -219,8 +216,7 @@ b0ions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 18.010565, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand Down Expand Up @@ -248,8 +244,7 @@ ystarions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 17.026549, aam[length(aam):1L])
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -269,8 +264,7 @@ y0ions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 18.010565, aam[length(aam):1L])
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -290,8 +284,7 @@ cions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass + 17.026549, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -311,8 +304,7 @@ zions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 17.026549, aam[length(aam):1L])
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -332,8 +324,7 @@ aions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 27.9949146, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -354,8 +345,7 @@ astarions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 45.0214636, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -376,8 +366,7 @@ a0ions <- function (aam, tmass, digits = 4L)
ions <- c(tmass - 46.0054796, aam)
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand All @@ -398,8 +387,7 @@ xions_base <- function (aam, tmass, digits = 4L)
ions <- c(tmass + 25.9792646, aam[length(aam):1L])
ions <- cumsum(ions)
ions <- ions[-1]

round(ions, digits = digits)
# round(ions, digits = digits)
}


Expand Down
8 changes: 2 additions & 6 deletions R/ms2frames.R
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,6 @@ find_ms2_bypep <- function (theos = NULL, expts = NULL, ex = NULL, d = NULL,
ppm_ms2 = 10L, min_ms2mass = 115L, minn_ms2 = 6L,
index_mgf_ms2 = FALSE)
{
##############################################################################
# `theos`
# the same pep_seq at different applicable ivmods and NLs
#
Expand Down Expand Up @@ -1067,8 +1066,7 @@ find_ms2_bypep <- function (theos = NULL, expts = NULL, ex = NULL, d = NULL,
# (i) %in% and %fin% only shows the first match for duplicated entries thi:
# match(1:4, c(1, 2, 2, 5))
# (so no worry about thi duplication)
##############################################################################


nullout <- list(theo = NULL, expt = NULL, ith = NULL, iex = NULL, m = NULL)
len <- length(theos)

Expand Down Expand Up @@ -1267,7 +1265,7 @@ search_mgf <- function (expt_mass_ms1 = NULL, expt_moverz_ms2 = NULL,
if (!by_modules)
pep_mod_groups <- pep_mod_groups[oks2]

ans <- mapply(
mapply(
function (x, y, g) {
attr(x, "theo_ms1") <- y
attr(x, "pep_mod_group") <- g
Expand Down Expand Up @@ -1320,8 +1318,6 @@ search_mgf <- function (expt_mass_ms1 = NULL, expt_moverz_ms2 = NULL,
# 4 790. 790.
# 5 868. 868.
# 6 1297. 1297.

invisible(ans)
}


Expand Down
23 changes: 14 additions & 9 deletions R/msmsmatches.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@
#' 1} or \code{0}.
#' @param maxn_vmods_sitescombi_per_pep A non-negative integer; the maximum
#' number of combinatorial variable modifications per peptide sequence (per
#' module). The combinations include the ways of neutral losses and
#' modification labels. For instance, at \code{maxn_vnl_per_seq = 2}, the ways
#' of allowed position permutation will be 32. Similarly, at
#' \code{maxn_vnl_per_seq = 2} and, for example, the permutation of labels
#' \code{Acetyl (K)} and \code{TMT (K)} (let's say three ways), the ways of
#' position permutation will be limited to \code{64/2/3}.
#' module). The ways include the permutations in neutral losses and
#' modifications (e.g., \code{Acetyl (K) and TMT (K)}).
#' @param min_len A positive integer; the minimum length of peptide sequences
#' for considerations. Shorter peptides will be excluded. The default is 7.
#' @param max_len A positive integer; the maximum length of peptide sequences
Expand Down Expand Up @@ -1534,7 +1530,7 @@ matchMS <- function (out_path = "~/mzion/outs",
df <- dplyr::mutate(df, pep_expect = 10^((pep_score_co - pep_score)/10) * target_fdr)
df[["pep_score_co"]] <- NULL
df$pep_delta <- df$pep_exp_mr - df$pep_calc_mr

nms <- names(df)
df <- dplyr::bind_cols(
df[grepl("^prot_", nms)],
Expand All @@ -1552,10 +1548,14 @@ matchMS <- function (out_path = "~/mzion/outs",
rows_tmt <- grepl("TMT", df[["pep_fmod"]]) | grepl("TMT", df[["pep_vmod"]])
df[!rows_tmt, cols_tmt] <- NA_real_
rm(list = c("cols_tmt", "rows_tmt"))

readr::write_tsv(df, file.path(out_path, "psmC.txt"))

local({
df$pep_exp_mr <- round(df$pep_exp_mr, digits = 4L)
df$pep_calc_mr <- round(df$pep_calc_mr, digits = 4L)
df$pep_delta <- round(df$pep_delta, digits = 4L)
df$pep_expect <- format(df$pep_expect, digits = 3L)
readr::write_tsv(df, file.path(out_path, "psmC.txt"))

session_info <- sessionInfo()
save(session_info, file = file.path(out_path, "Calls", "mzion.rda"))
})
Expand Down Expand Up @@ -1920,6 +1920,11 @@ post_psmC2Q <- function (df, dfC, tier = NULL)
df[!grepl("^prot_|^pep_|^psm_", names(df))],
)

df$pep_exp_mr <- round(df$pep_exp_mr, digits = 4L)
df$pep_calc_mr <- round(df$pep_calc_mr, digits = 4L)
df$pep_delta <- round(df$pep_delta, digits = 4L)
df$pep_expect <- format(df$pep_expect, digits = 3L)

df <- dplyr::select(df, -which(names(df) %in% c("prot_n_psm", "prot_n_pep")))
}

Expand Down
11 changes: 7 additions & 4 deletions R/scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,10 @@ add_primatches <- function (file = NULL, tempdir = NULL, add_ms2theos = FALSE,
{
df <- qs::qread(file.path(tempdir, file))

if (!add_ms2moverzs) df[["pep_ms2_moverzs"]] <- NA_character_
if (!add_ms2ints) df[["pep_ms2_ints"]] <- NA_character_

df <- dplyr::mutate(df,
pep_ms2_moverzs = NA_character_,
pep_ms2_ints = NA_character_,
pep_ms2_theos = NA_character_,
pep_ms2_theos2 = NA_character_,

Expand Down Expand Up @@ -1231,8 +1232,8 @@ add_primatches <- function (file = NULL, tempdir = NULL, add_ms2theos = FALSE,

if (add_ms2theos) df$pep_ms2_theos <- collapse_vecs(lapply(pris, `[[`, "theo"))
if (add_ms2theos2) df$pep_ms2_theos2 <- collapse_vecs(lapply(secs, `[[`, "theo"))
if (add_ms2moverzs) df$pep_ms2_moverzs <- collapse_vecs(df$ms2_moverz)
if (add_ms2ints) df$pep_ms2_ints <- collapse_vecs(df$ms2_int)
if (add_ms2moverzs) df$pep_ms2_moverzs <- collapse_vecs(df$pep_ms2_moverzs)
if (add_ms2ints) df$pep_ms2_ints <- collapse_vecs(df$pep_ms2_ints)

qs::qsave(df, file.path(tempdir, gsub("^prescores", "ms2info", file)),
preset = "fast")
Expand All @@ -1248,6 +1249,8 @@ add_primatches <- function (file = NULL, tempdir = NULL, add_ms2theos = FALSE,
#' @param sep A separator.
collapse_vecs <- function (vecs, nm = "theo", sep = ";")
{
vecs <- lapply(vecs, round, digits = 4L)

ans <- lapply(vecs, function (v)
.Internal(paste0(list(v), collapse = sep, recycle0 = FALSE))
)
Expand Down
8 changes: 2 additions & 6 deletions man/calc_pepscores.Rd

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

8 changes: 2 additions & 6 deletions man/calib_mgf.Rd

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

8 changes: 2 additions & 6 deletions man/frames_adv.Rd

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

8 changes: 2 additions & 6 deletions man/gen_ms2ions_base.Rd

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

8 changes: 2 additions & 6 deletions man/hms2match.Rd

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

8 changes: 2 additions & 6 deletions man/matchMS.Rd

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

8 changes: 2 additions & 6 deletions man/mframes_adv.Rd

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

8 changes: 2 additions & 6 deletions man/ms2match.Rd

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

8 changes: 2 additions & 6 deletions man/ms2match_all.Rd

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

8 changes: 2 additions & 6 deletions man/ms2match_one.Rd

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

0 comments on commit af4608e

Please sign in to comment.