Create a new synthetic sample in a qseaSet by mixing reads from three existing samples according to user-specified proportions. Useful for simple mixture simulations; currently intended for internal use.

mixThreeQsetSamples(
  qseaSet,
  sample1,
  sample2,
  sample3,
  nReadsTotal,
  proportion1,
  proportion2,
  newName = NULL,
  groupName = NULL,
  onlyNew = FALSE,
  renormalise = TRUE
)

Arguments

qseaSet

qseaSet. The input object containing the three source samples.

sample1,

sample2, sample3 character(1). Sample names to mix (must exist in qseaSet).

nReadsTotal

integer(1). Total number of reads to simulate in the mixed sample. Must be >= 0.

proportion1

numeric(1). Proportion taken from sample1. Must be in [0, 1]. Default: none (must be supplied).

proportion2

numeric(1). Proportion taken from sample2. Must be in [0, 1]. Default: none (must be supplied).

The proportion from sample3 is computed as 1 - proportion1 - proportion2. The sum proportion1 + proportion2 must be strictly less than 1 (so that sample3 gets a non-negative share).

newName

character(1) or NULL. Name for the new synthetic sample. Default: NULL (auto-generated, e.g., "Mix3_<s1>_<s2>_<s3>_<p1>_<p2>").

groupName

character(1) or NULL. Group name recorded in the sampleTable for the new sample. Default: NULL (uses newName).

onlyNew

logical(1). If TRUE, return only the synthetic mixture. If FALSE, append it to the original qseaSet. Default: FALSE.

renormalise

logical(1). Whether to run addNormalisation() on the result. For batching multiple mixtures, consider FALSE and normalise once at the end. Default: TRUE.

Value

A qseaSet containing the new synthetic sample:

  • If onlyNew = TRUE, a qseaSet with one (mixed) sample.

  • If onlyNew = FALSE, the input qseaSet plus the mixed sample. The sampleTable, counts, and dependent slots are updated consistently.

Details

Note that if the qseaSet windows have been filtered prior to using this, the fraction of fragments present in the current qseaSet is calculated, such that the total number of reads would have been approximately nReadsTotal. E.g. if there are 50% of the total fragments in the windows present in the current samples, 0.5*nReadsTotal fragments will be sampled.

  • Validates that sample1, sample2, sample3 exist; nReadsTotal >= 0; proportion1, proportion2 in [0, 1]; and proportion1 + proportion2 < 1.

  • The mixing strategy follows the package implementation (proportional allocation / sampling); use renormalise = TRUE if downstream steps rely on offsets/enrichment being recomputed.

See also

mixSamples() (two-sample mixture), addNormalisation()

Other sample-simulation: mixSamples()

Examples

if (FALSE) { # \dontrun{
data(exampleTumourNormal, package = "mesa")

# Mix three samples 50/30/20 into ~100k total fragments; append to the
# qseaSet
exampleTumourNormal %>%
    mesa:::mixThreeQsetSamples("Colon1_T", "Colon1_N", "Lung1_T",
        nReadsTotal = 100000,
        proportion1 = 0.5, proportion2 = 0.3,
        newName = "Mix_Colon1_T_0.5_Colon1_N_0.3_Lung1_T_0.2",
        renormalise = FALSE
    ) %>%
    # Only a few reads are included in this small subset of windows (78):
    getCountTable() %>%
    pull(Mix_Colon1_T_0.5_Colon1_N_0.3_Lung1_T_0.2) %>%
    sum()


# Mix three samples and return only the synthetic sample, with an explicit
# name and group.
exampleTumourNormal %>%
    mesa:::mixThreeQsetSamples("Colon1_T", "Colon1_N", "Lung1_T",
        nReadsTotal = 50000,
        proportion1 = 0.1, proportion2 = 0.2,
        newName = "Mix_Colon1_T_0.1_Colon1_N_0.2_Lung1_T_0.7",
        groupName = "Synthetic",
        onlyNew = TRUE,
        renormalise = FALSE
    ) %>%
    # Only a few reads are included in this small subset of windows (29):
    getCountTable() %>%
    dplyr::pull(Mix_Colon1_T_0.1_Colon1_N_0.2_Lung1_T_0.7) %>%
    sum()
} # }