Skip to contents

This function takes a dataframe of BSA data, a list of grouping conditions, and a list of sample columns, and returns a dataframe in which the data has been grouped according to the specified conditions. It performs several operations including grouping, summarizing, uniting, and arranging.

Usage

collapse_bsa_data(df_with_meta, grouping_conditions, sample_columns)

Arguments

df_with_meta

A dataframe that contains BSA data.

grouping_conditions

A vector of column names that specifies the grouping conditions.

sample_columns

A vector of column names that specifies the sample columns.

Value

A dataframe in which the data has been grouped, summarized, united, and arranged according to the specified conditions and columns.

Examples

df_with_meta <- data.frame(
  A = rep(c("group1", "group2"), each = 5),
  CHR = rep("CHR1", 10),
  POS = rep(c(1,5,10,20,30), times=2),
  REF_Allele = rep('A', 10),
  ALT1 = rep('G', 10),
  RealDepth = runif(10, 1, 10),
  Depth = runif(10, 1, 10),
  Reference = runif(10, 1, 10),
  Alternative1 = runif(10, 1, 10)
)
grouping_conditions <- c('CHR','POS','REF_Allele','ALT1')
sample_columns <- c("RealDepth", "Depth", "Reference", "Alternative1")

collapse_bsa_data(df_with_meta, grouping_conditions, sample_columns)
#> # A tibble: 5 × 9
#>   CHR     POS REF_Allele ALT1  sample     RealDepth Depth Reference Alternative1
#>   <chr> <dbl> <chr>      <chr> <chr>          <dbl> <dbl>     <dbl>        <dbl>
#> 1 CHR1      1 A          G     6.9242927…      6.92 11.6      11.3          6.17
#> 2 CHR1      5 A          G     13.988993…     14.0   7.21      8.57        10.4 
#> 3 CHR1     10 A          G     10.014753…     10.0   2.88     13.4         13.2 
#> 4 CHR1     20 A          G     10.010813…     10.0   8.38     10.0          9.35
#> 5 CHR1     30 A          G     9.0192885…      9.02 14.4      17.0          8.26