Computes log2 ratios of observed and reference values and calculates a weight for each observation based on bin length and repeat fraction.

compute_weighted_log2_ratios(
  data,
  observed_col = "observed",
  reference_col = "reference",
  bin_length_col = "bin_length",
  repeat_fraction_col = "repeat_fraction"
)

Arguments

data

A data.frame containing the observed, reference, bin length, and repeat fraction columns.

observed_col

Character. Name of the column with observed values.

reference_col

Character. Name of the column with reference values.

bin_length_col

Character. Name of the column indicating bin length.

repeat_fraction_col

Character. Name of the column with repeat fraction values.

Value

The input data augmented with two new columns: log2_ratio and weight.

Details

The log2 ratio is computed as log2(observed / reference). The weight is calculated as the product of the ratio of bin length over the median bin length and (1 - repeat_fraction).

Examples

df <- data.frame(observed = c(10, 20, 30),
                 reference = c(8, 18, 33),
                 bin_length = c(100, 120, 110),
                 repeat_fraction = c(0.1, 0.2, 0.15))
result <- compute_weighted_log2_ratios(df, "observed", "reference", "bin_length", "repeat_fraction")
print(result)
#>   observed reference bin_length repeat_fraction log2_ratio    weight
#> 1       10         8        100            0.10  0.3219281 0.8181818
#> 2       20        18        120            0.20  0.1520031 0.8727273
#> 3       30        33        110            0.15 -0.1375035 0.8500000