Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast conversion of cov_table dataset #63

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})