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

fixed Cmin bug #58

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed Cmin bug
WBS-TW committed Mar 4, 2025
commit e85cf86f652c9cc1ac1ad8a4eefeba150f9c555e
20 changes: 14 additions & 6 deletions R/CPions.R
Original file line number Diff line number Diff line change
@@ -59,6 +59,8 @@ ui <- shiny::navbarPage(
width = NULL,
size = NULL),
shiny::numericInput("threshold", "Isotope rel ab threshold (5-99%)", value = 5, min = 0, max = 99),
shiny::textAreaInput("ISRS_input", "Optional: add ion formula for IS/RS",
placeholder = "Enter one formula per line (e.g., )", height = "150px"),
shiny::actionButton("go1", "Submit", width = "100%"),
width = 3),
shiny::mainPanel(
@@ -98,7 +100,7 @@ ui <- shiny::navbarPage(
width = NULL,
size = NULL),
selectInput("TP_adv", "Transformation product?",
choices = c("None", "-Cl+OH", "-2Cl+2OH", "+OH", "+2OH", "+SO4"),
choices = c("None", "-Cl+OH", "-2Cl+2OH", "+OH", "+2OH", "-2H+O", "+SO4H"),
selected = "None",
multiple = TRUE,
selectize = TRUE,
@@ -181,6 +183,7 @@ server = function(input, output, session) {
Brmin <- shiny::eventReactive(input$go1, {as.integer(input$Brmin)})
Brmax <- shiny::eventReactive(input$go1, {as.integer(input$Brmax)})
threshold <- shiny::eventReactive(input$go1, {as.integer(input$threshold)})
ISRS_input <- shiny::eventReactive(input$go1, {as.character(input$ISRS_input)})


# ADVANCED
@@ -189,7 +192,7 @@ server = function(input, output, session) {
selectedCharge_adv <- shiny::eventReactive(input$go_adv, {as.character((input$Charge_adv))})
selectedTP_adv <- shiny::eventReactive(input$go_adv, {as.character((input$TP_adv))})

C_adv <- shiny::eventReactive(input$go_adv, {as.integer(input$Cmin:input$Cmax_adv)})
C_adv <- shiny::eventReactive(input$go_adv, {as.integer(input$Cmin_adv:input$Cmax_adv)})
Cl_adv <- shiny::eventReactive(input$go_adv, {as.integer(input$Clmin:input$Clmax_adv)})
Clmin_adv <- shiny::eventReactive(input$go_adv, {as.integer(input$Clmin_adv)})
Clmax_adv <- shiny::eventReactive(input$go_adv, {as.integer(input$Clmax_adv)})
@@ -224,6 +227,11 @@ server = function(input, output, session) {
}
CP_allions <- dplyr::full_join(CP_allions, input)
}

# Add the ISRS if they exist
# ISRS <- unlist(str_split(ISRS_input(), "\n"))
# browser()

return(CP_allions)
})

@@ -359,7 +367,7 @@ server = function(input, output, session) {
hoverinfo = "text",
hovertext = paste("Molecule_Formula:", CP_allions_compl2$Molecule_Formula,
'<br>',
"Adduct/Fragment ion:", CP_allions_compl2$Adduct,
"Adduct/Fragment ion:", CP_allions_compl2$Adduct_Annotation,
'<br>',
"Ion Formula:", CP_allions_compl2$Adduct_Formula,
'<br>',
@@ -383,7 +391,7 @@ server = function(input, output, session) {
hoverinfo = "text",
hovertext = paste("Molecule_Formula:", CP_allions_compl2$Molecule_Formula,
'<br>',
"Adduct/Fragment ion:", CP_allions_compl2$Adduct,
"Adduct/Fragment ion:", CP_allions_compl2$Adduct_Annotation,
'<br>',
"Ion Formula:", CP_allions_compl2$Adduct_Formula,
'<br>',
@@ -411,7 +419,7 @@ server = function(input, output, session) {
hoverinfo = "text",
hovertext = paste("Molecule_Formula:", CP_allions_compl2$Molecule_Formula,
'<br>',
"Adduct/Fragment ion:", CP_allions_compl2$Adduct,
"Adduct/Fragment ion:", CP_allions_compl2$Adduct_Annotation,
'<br>',
"Ion Formula:", CP_allions_compl2$Adduct_Formula,
'<br>',
@@ -438,7 +446,7 @@ server = function(input, output, session) {
hoverinfo = "text",
hovertext = paste("Molecule_Formula:", CP_allions_compl2$Molecule_Formula,
'<br>',
"Adduct/Fragment ion:", CP_allions_compl2$Adduct,
"Adduct/Fragment ion:", CP_allions_compl2$Adduct_Annotation,
'<br>',
"Ion Formula:", CP_allions_compl2$Adduct_Formula,
'<br>',
14 changes: 7 additions & 7 deletions R/instructions_CPquant.md
Original file line number Diff line number Diff line change
@@ -10,19 +10,19 @@ In CPquant, the deconvolution is performed using the nnls package (https://cran.


## Input file
The input excel file should be from the Skyline results table. It must include the following column with the names:
The input excel file should be exported from the Skyline results table. It should include the following column with the names:
`Replicate Name`: sample name
`Sample Type`: the following characters can be used, _Unknown_ (which is the sample to be quantified), _Blank_ (field blanks and procedural blanks are not distinguished), _Standard_ (standard used for quantification), _Quality Control_ (standard/sample used to determine the recovery).
`Molecule List`
`Molecule`: homologue group.
`Molecule List`: compounds used internal standards are denoted `IS`, recovery standards as `RS`.
`Molecule`: PCA homologue group.
`Area`: integrated area from Skyline.
`Mass Error PPM`: might be exported from Skyline but currently not used by CPquant.
`Isotope Label Type`
`Chromatogram Precursor M/Z`
`Isotope Label Type`: Quan or Qual.
`Chromatogram Precursor M/Z`: might be exported from Skyline but currently not used by CPquant.
`Analyte Concentration`: For standards only. This is the standard concentrations/amounts. This column could be in concentration or weight/amount unit depending on the user input. It will affect the final quantification unit.
`Batch Name`: For standards only (leave blank for Unknown). This will determine which standards that belongs to a calibration series as well as which carbon chain groups to quantify with the standard.
The naming of the Batch Name should be: CarbonGroups_StandardName. An underscore is a separator for the carbon chain group and standard name.
Example A: C10-C13_StandardA. This standard will then be used to quantify carbon chains C10, C12, C13. This belongs to the StandardA which can be at different Analyte Concentration for the same calibration series.
Example A: C10-C13_StandardA. This standard will then be used to quantify carbon chains C10, C12, C13 (the hyphen specify the range of carbon chains). This belongs to the StandardA which can be at different Analyte Concentration for the same calibration series.
Example B: C14_52%Cl. This standard will only quantify C14 carbon chains. It specifies 52% chlorine content (although this information is not needed for quantification).


@@ -49,7 +49,7 @@ __Proceed__: pressing this button will quantify the samples based on the deconvo
### Quantification process
The process starts by creating calibration curves for each carbon chain group for each standard mixture.
The Batch Name in the excel file determines which carbon chain group to be included for each standard mixture. A linear regression will be fitted and the slope is used as the response factor (RF).
If the R-squared of the fit for a homologue group for a standard series (calibration curve) is below the user input threshold (modified in the first tab), then the homologue group in that standard is not considered for subsequent quantification.
If the R-squared of the goodnes of fit for a homologue group for a standard series (calibration curve) is below the user input threshold (modified in the first tab), then the homologue group in that standard is not considered for subsequent quantification.



27 changes: 17 additions & 10 deletions R/utils_CPions.R
Original file line number Diff line number Diff line change
@@ -249,13 +249,14 @@ generateInput_Envipat_advanced <- function(data = data, Compounds = Compounds, A
dplyr::mutate(O = dplyr::case_when(
TP == "+OH" ~ 1,
TP == "+2OH" ~ 2,
TP == "+SO4" ~ 4,
TP == "+SO4H" ~ 4,
TP == "-Cl+OH" ~ 1,
TP == "-2Cl+2OH" ~ 2,
TP == "-2H+O" ~ 1,
.default = 0
)) |>
dplyr::mutate(S = dplyr::case_when(
TP == "+SO4" ~ 1,
TP == "+SO4H" ~ 1,
.default = 0)) |>
dplyr::mutate(Adduct_Formula = create_formula(C, H, Cl, Br, S, O))|>
dplyr::rowwise() |>
@@ -552,12 +553,13 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
dplyr::filter(C >= Cl) |> # filter so Cl dont exceed C atoms
dplyr::filter(Cl <= Clmax) |> # limit chlorine atoms.
dplyr::mutate(H = dplyr::case_when(# add H atoms
TP == "None" ~ 2*C+2-Cl,
TP == "None" ~ 2*C+2-Cl, #PCA general formula 2*C+2-Cl
TP == "+OH" ~ 2*C+2-Cl,
TP == "+2OH" ~ 2*C+2-Cl,
TP == "-Cl+OH" ~ 2*C+2-Cl+1,
TP == "-2Cl+2OH" ~ 2*C+2-Cl+2,
TP == "+SO4" ~ 2*C+2-Cl-1)) |>
TP == "-2H+O" ~ 2*C-Cl,
TP == "+SO4H" ~ 2*C+2-Cl)) |>
dplyr::mutate(Cl = dplyr::case_when(
TP == "-Cl+OH" ~ Cl-1,
TP == "-2Cl+2OH" ~ Cl-2,
@@ -569,7 +571,8 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
TP == "+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O2"),
TP == "-Cl+OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O"),
TP == "-2Cl+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O2"),
TP == "+SO4" ~ paste0("C", C, "H", H, "Cl", Cl, "SO4")))
TP == "-2H+O" ~ paste0("C", C, "H", H, "Cl", Cl,"O"),
TP == "+SO4H" ~ paste0("C", C, "H", H, "Cl", Cl, "SO4")))

} else if (Compounds == "PCO") {
data <- crossing(C, Cl) |>
@@ -581,7 +584,8 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
TP == "+2OH" ~ 2*C-Cl,
TP == "-Cl+OH" ~ 2*C-Cl+1,
TP == "-2Cl+2OH" ~ 2*C-Cl+2,
TP == "+SO4" ~ 2*C-Cl-1)) |>
TP == "-2H+O" ~ 2*C-Cl-2,
TP == "+SO4H" ~ 2*C-Cl)) |>
dplyr::mutate(Cl = dplyr::case_when(
TP == "-Cl+OH" ~ Cl-1,
TP == "-2Cl+2OH" ~ Cl-2,
@@ -593,7 +597,8 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
TP == "+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O2"),
TP == "-Cl+OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O"),
TP == "-2Cl+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "O2"),
TP == "+SO4" ~ paste0("C", C, "H", H, "Cl", Cl, "SO4")))
TP == "-2H+O" ~ paste0("C", C, "H", H, "Cl", Cl,"O"),
TP == "+SO4H" ~ paste0("C", C, "H", H, "Cl", Cl, "SO4")))

} else if (Compounds == "BCA") {
data <- tidyr::crossing(C, Cl, Br) |> #get combinations of C, Cl, Br
@@ -607,14 +612,16 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
TP == "+2OH" ~ 2*C+2-Cl-Br,
TP == "-Cl+OH" ~ 2*C+2-Cl-Br+1,
TP == "-2Cl+2OH" ~ 2*C+2-Cl-Br+2,
TP == "+SO4" ~ 2*C+2-Cl-Br-1)) |>
TP == "-2H+O" ~ 2*C-Cl-Br,
TP == "+SO4H" ~ 2*C+2-Cl-Br)) |>
dplyr::mutate(Molecule_Formula = dplyr::case_when( #DOUBLE CHECK THE FORMULA IS CORRECT!!!!!
TP == "None" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br),
TP == "+OH" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "O"),
TP == "+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "O2"),
TP == "-Cl+OH" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "O"),
TP == "-2Cl+2OH" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "O2"),
TP == "+SO4" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "SO4")))
TP == "-2H+O" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "O"),
TP == "+SO4H" ~ paste0("C", C, "H", H, "Cl", Cl, "Br", Br, "SO4")))


}
@@ -719,7 +726,7 @@ getAdduct_advanced <- function(Compounds, Adduct_Ion, TP, Charge, C, Cl, Clmax,
########################################################################
########################################################################


# from envipat
isotopes <- structure(list(element = c("H", "H", "He", "He", "Li", "Li",
"Be", "B", "B", "C", "C", "N", "N", "O", "O", "O", "F", "Ne",
"Ne", "Ne", "Na", "Mg", "Mg", "Mg", "Al", "Si", "Si", "Si", "P",