| olink_normalization_subset | R Documentation |
Normalizes two NPX projects (data frames) using all or a subset of samples.
This function is a wrapper of olink_normalization.
olink_normalization_subset(
project_1_df,
project_2_df,
reference_samples,
project_1_name = "P1",
project_2_name = "P2",
project_ref_name = "P1",
format = FALSE,
project_1_check_log = NULL,
project_2_check_log = NULL
)
project_1_df |
Data frame of the first project (required). |
project_2_df |
Data frame of the second project (required). |
reference_samples |
Named list of 2 arrays containing SampleID of the subset of samples to be used for the calculation of median NPX within each project. The names of the two arrays should be DF1 and DF2 corresponding to projects 1 and 2, respectively. Arrays do not need to be of equal length and the order the samples appear in does not play any role. (required) |
project_1_name |
Name of the first project (default: P1). |
project_2_name |
Name of the second project (default: P2). |
project_ref_name |
Name of the project to be used as reference set. Needs to be one of the project_1_name or project_2_name. It marks the project to which the other project will be adjusted to (default: P1). |
format |
Boolean that controls whether the normalized dataset will be formatted for input to downstream analysis. |
project_1_check_log |
A named list returned by |
project_2_check_log |
A named list returned by |
In subset normalization one of the projects is adjusted to another using a subset of all samples from each. Please note that the subsets of samples are not expected to be replicates of each other or to have the SampleID. Adjustment between the two projects is made using the assay-specific differences in median between the subsets of samples from the two projects. The two data frames are inputs project_1_df and project_2_df, the one being adjusted to is specified in the input project_ref_name and the shared samples are specified in reference_samples.
A special case of subset normalization is to use all samples (except control samples) from each project as a subset.
A "tibble" of NPX data in long format containing normalized NPX values, including adjustment factors and name of project.
#### Subset normalization
# datasets
npx_df1 <- npx_data1 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::select(
-dplyr::all_of("Project")
) |>
dplyr::mutate(
Normalization = "Intensity"
)
npx_df2 <- npx_data2 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::select(
-dplyr::all_of("Project")
) |>
dplyr::mutate(
Normalization = "Intensity"
)
# Find a suitable subset of samples from both projects, but exclude Olink
# controls and samples that fail QC.
df1_samples <- npx_df1 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::group_by(
dplyr::across(
dplyr::all_of("SampleID")
)
) |>
dplyr::filter(
all(.data[["QC_Warning"]] == "Pass")
) |>
dplyr::pull(
.data[["SampleID"]]
) |>
unique() |>
sample(
size = 16L,
replace = FALSE
)
df2_samples <- npx_df2 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::group_by(
dplyr::across(
dplyr::all_of("SampleID")
)
) |>
dplyr::filter(
all(.data[["QC_Warning"]] == "Pass")
) |>
dplyr::pull(
.data[["SampleID"]]
) |>
unique() |>
sample(
size = 16L,
replace = FALSE
)
# create named list
subset_samples_list <- list("DF1" = df1_samples,
"DF2" = df2_samples)
# check npx
df1_check_log <- OlinkAnalyze::check_npx(df = npx_df1)
df2_check_log <- OlinkAnalyze::check_npx(df = npx_df2)
# Normalize
OlinkAnalyze::olink_normalization_subset(
project_1_df = npx_df1,
project_2_df = npx_df2,
reference_samples = subset_samples_list,
project_1_name = "P1",
project_2_name = "P2",
project_ref_name = "P1",
project_1_check_log = df1_check_log,
project_2_check_log = df2_check_log
)
#### Special case of subset normalization using all samples
# datasets
npx_df1 <- npx_data1 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::select(
-dplyr::all_of("Project")
) |>
dplyr::mutate(
Normalization = "Intensity"
)
npx_df2 <- npx_data2 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::select(
-dplyr::all_of("Project")
) |>
dplyr::mutate(
Normalization = "Intensity"
)
# Find a suitable subset of samples from both projects, but exclude Olink
# controls and samples that fail QC.
df1_samples_all <- npx_df1 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::group_by(
dplyr::across(
dplyr::all_of("SampleID")
)
) |>
dplyr::filter(
all(.data[["QC_Warning"]] == "Pass")
) |>
dplyr::pull(
.data[["SampleID"]]
) |>
unique()
df2_samples_all <- npx_df2 |>
dplyr::filter(
!stringr::str_detect(string = .data[["SampleID"]],
pattern = "CONTROL_")
) |>
dplyr::group_by(
dplyr::across(
dplyr::all_of("SampleID")
)
) |>
dplyr::filter(
all(.data[["QC_Warning"]] == "Pass")
) |>
dplyr::pull(
.data[["SampleID"]]
) |>
unique()
# create named list
subset_samples_all_list <- list("DF1" = df1_samples_all,
"DF2" = df2_samples_all)
# check npx
df1_check_log <- OlinkAnalyze::check_npx(df = npx_df1)
df2_check_log <- OlinkAnalyze::check_npx(df = npx_df2)
# Normalize
OlinkAnalyze::olink_normalization_subset(
project_1_df = npx_df1,
project_2_df = npx_df2,
reference_samples = subset_samples_all_list,
project_1_name = "P1",
project_2_name = "P2",
project_ref_name = "P1",
project_1_check_log = df1_check_log,
project_2_check_log = df2_check_log
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.