Skip to contents

This function takes sequencing results in wide format and converts them into a long format data frame. It extracts sample names from column names, processes each sample separately, and then binds them together. Finally, it renames and reorders columns to match the desired output format.

Usage

seq_to_long(seq_results)

Arguments

seq_results

A data frame containing sequencing results in wide format.

Value

A data frame in long format with columns "chr", "from", "to", "ref", "alt", "NV", "DP", "VAF", and "sample_name".

Examples

# Example data frame in wide format
seq_results <- data.frame(chr = c("chr1", "chr2"),
                          chr_pos = c(100, 200),
                          ref = c("A", "C"),
                          alt = c("T", "G"),
                          causes = c("SBS5", "SBS1"),
                          classes = c("germinal", "passneger"),
                          Sample.A.occurrences = c(10, 90),
                          Sample.A.coverage = c(100, 100),
                          Sample.A.VAF = c(0.1, 0.9),
                          normal_sample.occurrences = c(45, 52),
                          normal_sample.coverage = c(100, 100),
                          normal_sample.VAF = c(0.45, 0.52))
seq_results
#>    chr chr_pos ref alt causes   classes Sample.A.occurrences Sample.A.coverage
#> 1 chr1     100   A   T   SBS5  germinal                   10               100
#> 2 chr2     200   C   G   SBS1 passneger                   90               100
#>   Sample.A.VAF normal_sample.occurrences normal_sample.coverage
#> 1          0.1                        45                    100
#> 2          0.9                        52                    100
#>   normal_sample.VAF
#> 1              0.45
#> 2              0.52

# Convert to long format
seq_to_long(seq_results)
#>    chr from ref alt causes   classes NV  DP  VAF   sample_name  to
#> 1 chr1  100   A   T   SBS5  germinal 10 100 0.10      Sample.A 100
#> 2 chr2  200   C   G   SBS1 passneger 90 100 0.90      Sample.A 200
#> 3 chr1  100   A   T   SBS5  germinal 45 100 0.45 normal_sample 100
#> 4 chr2  200   C   G   SBS1 passneger 52 100 0.52 normal_sample 200