|
1 | | -# function that converts test data in long format into wide format |
2 | | - |
3 | | -convert.long.vcf.to.wide.vcf <- function(long.vcf) { |
4 | | - long.vcf <- as.data.frame(long.vcf); |
5 | | - fixed.colnames <- c('CHROM', 'POS', 'ID', 'REF', 'ALT'); |
6 | | - fixed.data <- long.vcf[, fixed.colnames]; |
7 | | - fixed.data$variant.id <- paste0(fixed.data$CHROM, ':', fixed.data$POS); |
8 | | - fixed.data <- unique(fixed.data); # remove duplicates |
9 | | - # convert to data.table |
10 | | - fixed.data <- data.table::as.data.table(fixed.data); |
11 | | - #fixed.data$allele.matrix.row.index <- seq_len(nrow(fixed.data)); |
12 | | - |
13 | | - variant.id <- paste0(long.vcf$CHROM, ':', long.vcf$POS); |
14 | | - allele.matrix <- as.matrix(get.variant.by.sample.matrix( |
15 | | - long.data = long.vcf, |
16 | | - row.id.cols = c('CHROM', 'POS'), |
17 | | - value.col = 'gt_GT_alleles' |
18 | | - )); |
19 | | - |
20 | | - # sort allele matrix in order of corresponding fixed data variant id |
21 | | - allele.matrix <- allele.matrix[match(fixed.data$variant.id, rownames(allele.matrix)), ]; |
22 | | - |
23 | | - # save allele matrix row indices in fixed data |
24 | | - fixed.data$allele.matrix.row.index <- seq_len(nrow(allele.matrix)); |
25 | | - |
26 | | - # format output according to import.vcf standards |
27 | | - output <- list( |
28 | | - genotyped.alleles = allele.matrix, |
29 | | - vcf.fixed.fields = fixed.data |
30 | | - ); |
31 | | - |
32 | | - return(output); |
33 | | - |
34 | | - } |
35 | 1 |
|
36 | 2 | initialize.defaults <- function() { |
37 | 3 | phenotype.data <- NULL |
|
0 commit comments