diff --git a/R/CODEXCOV/R/functions_CODEXCOV.R b/R/CODEXCOV/R/functions_CODEXCOV.R index 1a4a12d..3f7522c 100644 --- a/R/CODEXCOV/R/functions_CODEXCOV.R +++ b/R/CODEXCOV/R/functions_CODEXCOV.R @@ -10,14 +10,14 @@ library(CODEX) #' @examples #' coverageObj1 coverageObj1 <- function(cov_table, sampname, targets_for_chr, chr){ - Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = length(sampname)) + Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = 0) + for(sample in sampname) { + cov_targets_for_sample <- cov_table[cov_table[,"sample_name"] == sample,] + cov_targets_for_sample <- cov_targets_for_sample[with(cov_targets_for_sample, order(target_id)), ] + Y <- cbind(Y, cov_targets_for_sample[,"read_count"]) + } colnames(Y) <- sampname rownames(Y) <- targets_for_chr[,"target_id"] - cov_targets_for_chr <- cov_table[cov_table[,"chr"] == chr,] - for(i in 1:nrow(cov_targets_for_chr)) { - cov_row <- cov_targets_for_chr[i,] - Y[toString(cov_row[,"target_id"]),toString(cov_row[,"sample_name"])] = as.integer(cov_row[,"read_count"]) - } return(list(Y=Y)) } diff --git a/R/EXOMEDEPTHCOV/R/functions_EXOMEDEPTHCOV.R b/R/EXOMEDEPTHCOV/R/functions_EXOMEDEPTHCOV.R index c596a67..2b38d6b 100644 --- a/R/EXOMEDEPTHCOV/R/functions_EXOMEDEPTHCOV.R +++ b/R/EXOMEDEPTHCOV/R/functions_EXOMEDEPTHCOV.R @@ -1,14 +1,14 @@ library(ExomeDepth) coverageObj1 <- function(cov_table, sampname, targets_for_chr, chr){ - Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = length(sampname)) + Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = 0) + for(sample in sampname) { + cov_targets_for_sample <- cov_table[cov_table[,"sample_name"] == sample,] + cov_targets_for_sample <- cov_targets_for_sample[with(cov_targets_for_sample, order(target_id)), ] + Y <- cbind(Y, cov_targets_for_sample[,"read_count"]) + } colnames(Y) <- sampname rownames(Y) <- targets_for_chr[,"target_id"] - cov_targets_for_chr <- cov_table[cov_table[,"chr"] == chr,] - for(i in 1:nrow(cov_targets_for_chr)) { - cov_row <- cov_targets_for_chr[i,] - Y[toString(cov_row[,"target_id"]),toString(cov_row[,"sample_name"])] = as.integer(cov_row[,"read_count"]) - } return(list(Y=Y)) } diff --git a/R/TARGET.QC/R/functions_TARGET.QC.R b/R/TARGET.QC/R/functions_TARGET.QC.R index 2c017eb..63f2278 100644 --- a/R/TARGET.QC/R/functions_TARGET.QC.R +++ b/R/TARGET.QC/R/functions_TARGET.QC.R @@ -1,14 +1,14 @@ library(CODEX) coverageObj1 <- function(cov_table, sampname, targets_for_chr, chr){ - Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = length(sampname)) + Y <- matrix(data=as.integer(0), nrow = nrow(targets_for_chr), ncol = 0) + for(sample in sampname) { + cov_targets_for_sample <- cov_table[cov_table[,"sample_name"] == sample,] + cov_targets_for_sample <- cov_targets_for_sample[with(cov_targets_for_sample, order(target_id)), ] + Y <- cbind(Y, cov_targets_for_sample[,"read_count"]) + } colnames(Y) <- sampname rownames(Y) <- targets_for_chr[,"target_id"] - cov_targets_for_chr <- cov_table[cov_table[,"chr"] == chr,] - for(i in 1:nrow(cov_targets_for_chr)) { - cov_row <- cov_targets_for_chr[i,] - Y[toString(cov_row[,"target_id"]),toString(cov_row[,"sample_name"])] = as.integer(cov_row[,"read_count"]) - } return(list(Y=Y)) } diff --git a/R/TARGET.QC/R/run_TARGET.QC.R b/R/TARGET.QC/R/run_TARGET.QC.R index 843563c..23eed55 100644 --- a/R/TARGET.QC/R/run_TARGET.QC.R +++ b/R/TARGET.QC/R/run_TARGET.QC.R @@ -16,7 +16,6 @@ run_TARGET.QC <- function(mapp_thresh, #K_from <- 1 #K_to <- 9 #lmax <- 200 - sampname <- unique(cov_table[,"sample_name"]) targets <- cov_table[,c("target_id", "chr", "pos_min", "pos_max")] targets <- targets[!duplicated(targets[,"target_id"]),] @@ -32,7 +31,6 @@ run_TARGET.QC <- function(mapp_thresh, next() } Y <- coverageObj1(cov_table, sampname, targets_for_chr, chr)$Y - gcmapp1_result <- gcmapp1(chr, ref) gc <- gcmapp1_result$gc mapp <- gcmapp1_result$mapp @@ -43,11 +41,10 @@ run_TARGET.QC <- function(mapp_thresh, Y_qc <- qcObj1_result$Y_qc sampname_qc <- qcObj1_result$sampname_qc ref_qc <- qcObj1_result$ref_qc - for(i in 1:nrow(Y_qc)) { - for (j in 1:ncol(Y_qc)) { - new_cov_table_qc_row <- c(colnames(Y_qc)[j], rownames(Y_qc)[i], chr, start(ref_qc)[i], end(ref_qc)[i], Y_qc[i,j]) - cov_table_qc <- rbind(cov_table_qc, new_cov_table_qc_row) - } + colnames(Y_qc) <- sampname_qc + for(sample in colnames(Y_qc)) { + new_cov_table_qc_rows <- cbind(sample, rownames(Y_qc), chr, start(ref_qc), end(ref_qc), Y_qc[,sample]) + cov_table_qc <- rbind(cov_table_qc, new_cov_table_qc_rows) } } cov_table_qc <- as.data.frame(cov_table_qc) diff --git a/R/tests/test_TARGET.QC_wrapper.R b/R/tests/test_TARGET.QC_wrapper.R index 980602d..3864ed0 100644 --- a/R/tests/test_TARGET.QC_wrapper.R +++ b/R/tests/test_TARGET.QC_wrapper.R @@ -77,5 +77,5 @@ test_that("basic test for run_wrapper_TARGET.QC function",{ gc_thresh_to, cov_table) expect_equal(ncol(cov_table), 6) - expect_equal(nrow(cov_table), 18) + expect_equal(nrow(cov_table), 24) })