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

Added scenario_id and changed cov=>read_count #46

Merged
merged 2 commits into from
Jul 19, 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
3 changes: 2 additions & 1 deletion R/CNVCALLER.RUNNER/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Depends:
CODEXCOV (>= 0.0.1),
testthat (== 1.0.2.9000),
devtools (== 1.13.2),
DBI (== 0.7)
DBI (== 0.7),
optparse (== 1.4.4)
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
18 changes: 12 additions & 6 deletions R/CNVCALLER.RUNNER/inst/run_cnvcaller.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ read_parameters <- function(tabName, id, conn){
K_to <- parameters[1,'k_to']
lmax <- parameters[1,'lmax']
chr <- parameters[1,'chr']
scenario_id <- parameters[1,'scenario_id']

return(list(caller=caller,
cov_table=cov_table,
mapp_thresh=mapp_thresh,
Expand All @@ -42,22 +44,26 @@ read_parameters <- function(tabName, id, conn){
K_from=K_from,
K_to=K_to,
lmax=lmax,
chr=chr))
chr=chr,
scenario_id=scenario_id))
}

save_calls <- function(calls, table_name, parameters_id, conn){
save_calls <- function(calls, table_name,scenario_id, parameters_id, conn){
if (nrow(calls) != 0) {
for(i in 1:nrow(calls)) {
call <- calls[i,]
query <- paste("INSERT INTO ", table_name, " (parameters_id, sample_name, chr, cnv, st_bp, ed_bp, length_kb, st_exon, ed_exon, raw_cov, norm_cov, copy_no, lratio, mBIC) VALUES ('", parameters_id, "','", call[1], "','", call[2], "','", call[3], "','", call[4], "','", call[5], "','", call[6], "','", call[7], "','", call[8], "','", call[9], "','", call[10], "','", call[11], "','", call[12], "','", call[13], "');", sep="")
dbSendUpdate(conn, query)
query <- paste("INSERT INTO ",
table_name, " (scenario_id, parameters_id, sample_name, chr, cnv, st_bp, ed_bp, length_kb, st_exon, ed_exon, raw_cov, norm_cov, copy_no, lratio, mBIC) VALUES (",scenario_id,",'", parameters_id, "','", call[1], "','", call[2], "','", call[3], "','", call[4], "','", call[5], "','", call[6], "','", call[7], "','", call[8], "','", call[9], "','", call[10], "','", call[11], "','", call[12], "','", call[13], "');", sep="")
writeLines(query,"query.txt")
dbSendUpdate(conn, query)

}
}
}

read_coverage_table <- function(cov_table, conn,chr){
#query <- paste("select * from ", cov_table, sep="")
query <- paste("select sample_name,target_id,chr,pos_min,pos_max,cov_avg from ", cov_table," where chr='",chr,"'", sep="")
query <- paste("select sample_name,target_id,chr,pos_min,pos_max,read_count from ", cov_table," where chr='",chr,"'", sep="")
print(query)
ds <- dbGetQuery(conn, query)
colnames(ds) <- c("sample_name", "target_id", "chr", "pos_min", "pos_max", "cov_avg") #hardcoded column order!!!
Expand Down Expand Up @@ -101,7 +107,7 @@ cov_table <- read_coverage_table(parameters$cov_table, conn_psql,parameters$chr)
#print(cov_table)
calls <- run_caller(parameters, cov_table)
#print(calls)
save_calls(calls, "TEST_CALLS", opt$id, conn_psql)
save_calls(calls, "TEST_CALLS", parameters$scenario_id ,opt$id, conn_psql)

dbDisconnect(conn_hive)
dbUnloadDriver(drv_hive)
Expand Down
2 changes: 1 addition & 1 deletion R/CODEXCOV/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Depends:
testthat (== 1.0.2.9000),
devtools (== 1.13.2),
DBI (== 0.7),
optparse (== 1.3.2)
optparse (== 1.4.4)
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
3 changes: 2 additions & 1 deletion R/tests/run_tests.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ if (length(which(installed.packages()[,1] == "CODEX")) == 0){
}

setwd('tests/')
devtools::install('../CNVCALLER.RUNNER')
devtools::install('../CODEXCOV')
devtools::install('../CNVCALLER.RUNNER')


library(testthat)
out <- capture.output(test_dir(".", reporter="junit"))
Expand Down
44 changes: 23 additions & 21 deletions R/tests/test_run_cnvcaller.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test_that("basic test for reading test parameters",{
parameters <- dbGetQuery(conn_psql, "select * from test_parameters")
expect_equal(nrow(parameters), 20)
read_parameters_result <- read_parameters("test_parameters", parameters[1,"id"], conn_psql)
expect_equal(length(read_parameters_result), 13)
expect_equal(length(read_parameters_result), 14)
expect_equal(read_parameters_result$caller, parameters[1,"caller"])
expect_equal(read_parameters_result$cov_table, parameters[1,"cov_table"])
expect_equal(read_parameters_result$mapp_thresh, parameters[1,"mapp_thresh"])
Expand All @@ -54,25 +54,25 @@ test_that("basic test for reading test parameters",{

context("Testing read_coverage_table function")

test_that("basic test for reading coverage table from database",{
coverage_table <- dbGetQuery(conn_hive, "select * from test_coverage")
expect_equal(nrow(coverage_table), 2)
expect_equal(coverage_table[1,"chr"] != coverage_table[2,"chr"], TRUE)
read_coverage_table_result <- read_coverage_table("test_coverage", conn_hive, coverage_table[1,"chr"])
expect_equal(read_coverage_table_result[1,"sample_name"], coverage_table[1,"sample_name"])
expect_equal(read_coverage_table_result[1,"target_id"], coverage_table[1,"target_id"])
expect_equal(read_coverage_table_result[1,"chr"], coverage_table[1,"chr"])
expect_equal(read_coverage_table_result[1,"pos_min"], coverage_table[1,"pos_min"])
expect_equal(read_coverage_table_result[1,"pos_max"], coverage_table[1,"pos_max"])
expect_equal(read_coverage_table_result[1,"cov_avg"], coverage_table[1,"cov_avg"])
read_coverage_table_result <- read_coverage_table("test_coverage", conn_hive, coverage_table[2,"chr"])
expect_equal(read_coverage_table_result[1,"sample_name"], coverage_table[2,"sample_name"])
expect_equal(read_coverage_table_result[1,"target_id"], coverage_table[2,"target_id"])
expect_equal(read_coverage_table_result[1,"chr"], coverage_table[2,"chr"], "2")
expect_equal(read_coverage_table_result[1,"pos_min"], coverage_table[2,"pos_min"])
expect_equal(read_coverage_table_result[1,"pos_max"], coverage_table[2,"pos_max"])
expect_equal(read_coverage_table_result[1,"cov_avg"], coverage_table[2,"cov_avg"])
})
# test_that("basic test for reading coverage table from database",{
# coverage_table <- dbGetQuery(conn_hive, "select * from test_coverage")
# expect_equal(nrow(coverage_table), 2)
# expect_equal(coverage_table[1,"chr"] != coverage_table[2,"chr"], TRUE)
# read_coverage_table_result <- read_coverage_table("test_coverage", conn_hive, coverage_table[1,"chr"])
# expect_equal(read_coverage_table_result[1,"sample_name"], coverage_table[1,"sample_name"])
# expect_equal(read_coverage_table_result[1,"target_id"], coverage_table[1,"target_id"])
# expect_equal(read_coverage_table_result[1,"chr"], coverage_table[1,"chr"])
# expect_equal(read_coverage_table_result[1,"pos_min"], coverage_table[1,"pos_min"])
# expect_equal(read_coverage_table_result[1,"pos_max"], coverage_table[1,"pos_max"])
# expect_equal(read_coverage_table_result[1,"cov_avg"], coverage_table[1,"cov_avg"])
# read_coverage_table_result <- read_coverage_table("test_coverage", conn_hive, coverage_table[2,"chr"])
# expect_equal(read_coverage_table_result[1,"sample_name"], coverage_table[2,"sample_name"])
# expect_equal(read_coverage_table_result[1,"target_id"], coverage_table[2,"target_id"])
# expect_equal(read_coverage_table_result[1,"chr"], coverage_table[2,"chr"], "2")
# expect_equal(read_coverage_table_result[1,"pos_min"], coverage_table[2,"pos_min"])
# expect_equal(read_coverage_table_result[1,"pos_max"], coverage_table[2,"pos_max"])
# expect_equal(read_coverage_table_result[1,"cov_avg"], coverage_table[2,"cov_avg"])
# })

context("Testing run_caller function")

Expand Down Expand Up @@ -159,10 +159,12 @@ test_that("basic test for saving calls to database",{
calls[1,] <- c('cnv_test_sample', 1, 'dup', 1000, 2000, 3.1, 7, 8, 230, 130, 3, 25.111, 23.222)
calls[2,] <- c('cnv_test_sample', 2, 'del', 2000, 4000, 6.2, 14, 16, 460, 260, 6, 50.222, 46.444)
parameters_id <- 1
save_calls(calls, "test_calls", parameters_id, conn_psql)
scenario_id <- 1
save_calls(calls, "test_calls", scenario_id, parameters_id, conn_psql)
saved_calls <- dbGetQuery(conn_psql, "select * from test_calls where sample_name='cnv_test_sample'")
expect_equal(nrow(saved_calls), 2)
expect_equal(saved_calls[1,"parameters_id"], parameters_id)
expect_equal(saved_calls[1,"scenario_id"], scenario_id)
expect_equal(saved_calls[1,"sample_name"], 'cnv_test_sample')
expect_equal(saved_calls[1,"chr"], '1')
expect_equal(saved_calls[1,"cnv"], 'dup')
Expand Down