Skip to content

Commit

Permalink
fast conversion of cov_table dataset (#63)
Browse files Browse the repository at this point in the history
* fast conversion of cov_table dataset

* fast conversion of cov_table dataset in EXOMEDEPTHCOV and CODEXCOV packages
  • Loading branch information
wkusmirek authored and mwiewior committed Dec 15, 2017
1 parent c2f23f6 commit c0bf3f5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
12 changes: 6 additions & 6 deletions R/CODEXCOV/R/functions_CODEXCOV.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
12 changes: 6 additions & 6 deletions R/EXOMEDEPTHCOV/R/functions_EXOMEDEPTHCOV.R
Original file line number Diff line number Diff line change
@@ -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))
}

Expand Down
12 changes: 6 additions & 6 deletions R/TARGET.QC/R/functions_TARGET.QC.R
Original file line number Diff line number Diff line change
@@ -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))
}

Expand Down
11 changes: 4 additions & 7 deletions R/TARGET.QC/R/run_TARGET.QC.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),]
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/tests/test_TARGET.QC_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit c0bf3f5

Please sign in to comment.