Skip to content

Commit

Permalink
REFERENCE.SAMPLE.SET.SELECTOR package (#64)
Browse files Browse the repository at this point in the history
* init REFERENCE.SAMPLE.SET.SELECTOR package

* function for selecting reference sample set from CANOES cnv caller

* function for selecting reference sample set from ExomeDepth cnv caller

* select reference set sdded to EXOMEDEPTHCOV package

* bugfix and add fields to parameters sql model
  • Loading branch information
wkusmirek authored and mwiewior committed Dec 19, 2017
1 parent c0bf3f5 commit a1dfe05
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 63 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pipeline {
steps {
echo 'Building R package....'
sh "cd R && R CMD build TARGET.QC/ && curl -v --user ${NEXUS_USER}:${NEXUS_PASS} --upload-file TARGET.QC_0.0.1.tar.gz http://zsibio.ii.pw.edu.pl/nexus/repository/r-zsibio/src/contrib/TARGET.QC_0.0.1.tar.gz"
sh "cd R && R CMD build REFERENCE.SAMPLE.SET.SELECTOR/ && curl -v --user ${NEXUS_USER}:${NEXUS_PASS} --upload-file REFERENCE.SAMPLE.SET.SELECTOR_0.0.1.tar.gz http://zsibio.ii.pw.edu.pl/nexus/repository/r-zsibio/src/contrib/REFERENCE.SAMPLE.SET.SELECTOR_0.0.1.tar.gz"
sh "cd R && R CMD build CODEXCOV/ && curl -v --user ${NEXUS_USER}:${NEXUS_PASS} --upload-file CODEXCOV_0.0.1.tar.gz http://zsibio.ii.pw.edu.pl/nexus/repository/r-zsibio/src/contrib/CODEXCOV_0.0.1.tar.gz"
sh "cd R && R CMD build EXOMEDEPTHCOV/ && curl -v --user ${NEXUS_USER}:${NEXUS_PASS} --upload-file EXOMEDEPTHCOV_0.0.1.tar.gz http://zsibio.ii.pw.edu.pl/nexus/repository/r-zsibio/src/contrib/EXOMEDEPTHCOV_0.0.1.tar.gz"
sh "cd R && R CMD build CNVCALLER.RUNNER/ && curl -v --user ${NEXUS_USER}:${NEXUS_PASS} --upload-file CNVCALLER.RUNNER_0.0.1.tar.gz http://zsibio.ii.pw.edu.pl/nexus/repository/r-zsibio/src/contrib/CNVCALLER.RUNNER_0.0.1.tar.gz"
Expand Down
18 changes: 5 additions & 13 deletions R/CNVCALLER.RUNNER/R/CODEXCOV_wrapper.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
library('CODEXCOV')

#' Function Description
#'
#' Function description.
#' @param K_from
#' @param K_to
#' @param lmax
#' @param cov_table
#' @keywords
#' @export
#' @examples
#' run_wrapper_CODEXCOV
run_wrapper_CODEXCOV <- function(K_from,
K_to,
lmax,
reference_set_select_method,
num_of_samples_in_reference_set,
cov_table){
calls <- run_CODEXCOV(strtoi(K_from),
strtoi(K_to),
strtoi(lmax),
cov_table
)
reference_set_select_method,
strtoi(num_of_samples_in_reference_set),
cov_table)
calls
}
9 changes: 6 additions & 3 deletions R/CNVCALLER.RUNNER/R/EXOMEDEPTHCOV_wrapper.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
library('EXOMEDEPTHCOV')

run_wrapper_EXOMEDEPTHCOV <- function(cov_table){
calls <- run_EXOMEDEPTHCOV(cov_table
)
run_wrapper_EXOMEDEPTHCOV <- function(reference_set_select_method,
num_of_samples_in_reference_set,
cov_table){
calls <- run_EXOMEDEPTHCOV(reference_set_select_method,
num_of_samples_in_reference_set,
cov_table)
calls
}
11 changes: 9 additions & 2 deletions R/CNVCALLER.RUNNER/inst/run_cnvcaller.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ read_parameters <- function(tabName, id, conn){
K_to <- parameters[1,'k_to']
lmax <- parameters[1,'lmax']
chr <- parameters[1,'chr']
reference_set_select_method <- parameters[1,'reference_set_select_method']
num_of_samples_in_reference_set <- parameters[1,'num_of_samples_in_reference_set']
scenario_id <- parameters[1,'scenario_id']

return(list(caller=caller,
Expand All @@ -48,6 +50,8 @@ read_parameters <- function(tabName, id, conn){
K_to=K_to,
lmax=lmax,
chr=chr,
reference_set_select_method=reference_set_select_method,
num_of_samples_in_reference_set=num_of_samples_in_reference_set,
scenario_id=scenario_id))
}

Expand Down Expand Up @@ -106,12 +110,15 @@ run_caller <- function(parameters, cov_table){
calls <- run_wrapper_CODEXCOV(parameters$K_from,
parameters$K_to,
parameters$lmax,
parameters$reference_set_select_method,
parameters$num_of_samples_in_reference_set,
cov_table
)
calls
} else if (parameters$caller == "exomedepth"){
calls <- run_wrapper_EXOMEDEPTHCOV(cov_table
)
calls <- run_wrapper_EXOMEDEPTHCOV(parameters$reference_set_select_method,
parameters$num_of_samples_in_reference_set,
cov_table)
calls
} else if(parameters$caller == "xhmm") {
}
Expand Down
3 changes: 2 additions & 1 deletion R/CODEXCOV/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Depends:
devtools (>= 1.13.2),
DBI (== 0.7),
optparse (== 1.4.4),
CODEX (>= 1.8.0)
CODEX (>= 1.8.0),
REFERENCE.SAMPLE.SET.SELECTOR (>= 0.0.1)
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
2 changes: 2 additions & 0 deletions R/CODEXCOV/R/run_CODEXCOV.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
run_CODEXCOV <- function(K_from,
K_to,
lmax,
reference_set_select_method,
num_of_samples_in_reference_set,
cov_table){

sampname <- unique(cov_table[,"sample_name"])
Expand Down
3 changes: 2 additions & 1 deletion R/EXOMEDEPTHCOV/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Depends:
DBI (== 0.7),
optparse (== 1.4.4),
IRanges (>= 2.0.0),
ExomeDepth (>= 1.1.10)
ExomeDepth (>= 1.1.10),
REFERENCE.SAMPLE.SET.SELECTOR (>= 0.0.1)
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
17 changes: 10 additions & 7 deletions R/EXOMEDEPTHCOV/R/run_EXOMEDEPTHCOV.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
library(ExomeDepth)
library(methods)

run_EXOMEDEPTHCOV <- function(cov_table){

run_EXOMEDEPTHCOV <- function(reference_set_select_method,
num_of_samples_in_reference_set,
cov_table){

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 @@ -26,13 +28,14 @@ run_EXOMEDEPTHCOV <- function(cov_table){
for (i in 1:nrow(Y)) {
target_length <- c(target_length, width(ref[i]))
}
reference_set <- select.reference.set (test.counts = Y[,actual_sample_id],
reference.counts = Y[,-actual_sample_id],
bin.length = target_length,
n.bins.reduced = 10000)
reference_samples <- run_REFERENCE.SAMPLE.SET.SELECTOR(actual_sample,
Y,
reference_set_select_method,
num_of_samples_in_reference_set,
target_length)

## ----construct.ref-------------------------------------------------------
my.matrix <- as.matrix(Y[,reference_set$reference.choice])
my.matrix <- as.matrix(Y[,reference_samples])
my.reference.selected <- apply(X = my.matrix,
MAR = 1,
FUN = sum)
Expand Down
16 changes: 16 additions & 0 deletions R/REFERENCE.SAMPLE.SET.SELECTOR/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Package: REFERENCE.SAMPLE.SET.SELECTOR
Title: Package For Selecting Reference Sample Set
Version: 0.0.1
Authors@R: c(
person("Tomasz", "Gambin", email = "[email protected]", role = c("aut", "cre")),
person("Marek", "Wiewiórka", email = "[email protected]", role = c("aut")),
person("Wiktor", "Kuśmirek", email = "[email protected]", role = c("aut")))
Description: An implementation of the package with multiple function
for selecting reference sample set.
Depends:
R (>= 3.2.3),
ExomeDepth (>= 1.1.10)
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1.9000
2 changes: 2 additions & 0 deletions R/REFERENCE.SAMPLE.SET.SELECTOR/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: fake comment so roxygen2 overwrites silently.
exportPattern("^[^\\.]")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library(ExomeDepth)

canoes_method <- function(investigated_sample, Y, num_refs){
if (num_refs == 0) {
num_refs <- 30 # in CANOES application num_refs is default set to 30
}
samples <- colnames(Y)
cov <- cor(Y[, samples], Y[, samples])
reference_samples <- setdiff(samples, investigated_sample)
covariances <- cov[investigated_sample, reference_samples]
reference_samples <- names(sort(covariances,
decreasing=T)[1:min(num_refs, length(covariances))])
return(list(reference_samples=reference_samples))
}

exomedepth_method <- function(investigated_sample, Y, num_refs, target_length){
samples <- colnames(Y)
reference_samples <- setdiff(samples, investigated_sample)
reference_set <- select.reference.set(test.counts = Y[,investigated_sample],
reference.counts = Y[,reference_samples],
bin.length = target_length,
n.bins.reduced = 10000)
if (num_refs == 0) {
reference_samples <- reference_set$reference.choice
} else {
reference <- reference_set$summary.stats[1:num_refs,'ref.samples']
reference_samples <- c()
for (s in reference)
reference_samples <- c(reference_samples, c(s))
}
return(list(reference_samples=reference_samples))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
run_REFERENCE.SAMPLE.SET.SELECTOR <- function(investigated_sample,
Y,
select_method,
num_refs,
target_length){
if(select_method == "canoes") {
reference_samples <- canoes_method(investigated_sample, Y, num_refs)$reference_samples
} else if(select_method == "codex") {
#reference_samples <- codex_method(investigated_sample, Y, num_refs)$reference_samples
} else if(select_method == "exomedepth") {
reference_samples <- exomedepth_method(investigated_sample, Y, num_refs, target_length)$reference_samples
} else if(select_method == "clamms") {
#reference_samples <- clamms_method(investigated_sample, Y, num_refs)$reference_samples
}
reference_samples
}
2 changes: 2 additions & 0 deletions R/tests/run_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ if (length(which(installed.packages()[,1] == "CODEX")) == 0){
if (length(which(installed.packages()[,1] == "ExomeDepth")) == 0){install.packages("ExomeDepth",repos="https://cloud.r-project.org/")}

if (length(which(installed.packages()[,1] == "TARGET.QC")) > 0){remove.packages("TARGET.QC")}
if (length(which(installed.packages()[,1] == "REFERENCE.SAMPLE.SET.SELECTOR")) > 0){remove.packages("REFERENCE.SAMPLE.SET.SELECTOR")}
if (length(which(installed.packages()[,1] == "CODEXCOV")) > 0){remove.packages("CODEXCOV")}
if (length(which(installed.packages()[,1] == "EXOMEDEPTHCOV")) > 0){remove.packages("EXOMEDEPTHCOV")}
if (length(which(installed.packages()[,1] == "CNVCALLER.RUNNER")) > 0){remove.packages("CNVCALLER.RUNNER")}
if (length(which(installed.packages()[,1] == "CNVCALLER.EVALUATOR")) > 0){remove.packages("CNVCALLER.EVALUATOR")}

setwd('tests/')
devtools::install('../TARGET.QC')
devtools::install('../REFERENCE.SAMPLE.SET.SELECTOR')
devtools::install('../CODEXCOV')
devtools::install('../EXOMEDEPTHCOV')
devtools::install('../CNVCALLER.RUNNER')
Expand Down
4 changes: 4 additions & 0 deletions R/tests/test_CODEXCOV_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test_that("basic test for run_wrapper_CODEXCOV function, without calls",{
K_from <- "1"
K_to <- "3"
lmax <- "200"
reference_set_select_method <- "codex"
num_of_samples_in_reference_set <- "0"
cov_table <- as.data.frame(matrix(data=c("NA12044",6,"2",17211,173310,151.636363636364,
"NA11829",4,"2",16712,167190,100,
"NA07051",7,"2",30275,304310,155.929936305732,
Expand Down Expand Up @@ -67,6 +69,8 @@ test_that("basic test for run_wrapper_CODEXCOV function, without calls",{
calls <- run_wrapper_CODEXCOV(K_from,
K_to,
lmax,
reference_set_select_method,
num_of_samples_in_reference_set,
cov_table)
expect_equal(length(calls), 0)
})
Expand Down
6 changes: 5 additions & 1 deletion R/tests/test_EXOMEDEPTHCOV_wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ library(CNVCALLER.RUNNER)
context("Testing run_wrapper_EXOMEDEPTHCOV function")

test_that("basic test for run_wrapper_EXOMEDEPTHCOV function, without calls",{
reference_set_select_method <- "exomedepth"
num_of_samples_in_reference_set <- "0"
cov_table <- as.data.frame(matrix(data=c("NA12044",6,"2",17211,173310,151.636363636364,
"NA11829",4,"2",16712,167190,100,
"NA07051",7,"2",30275,304310,155.929936305732,
Expand Down Expand Up @@ -61,7 +63,9 @@ test_that("basic test for run_wrapper_EXOMEDEPTHCOV function, without calls",{
cov_table[,"pos_min"] <- as.integer(as.character(cov_table[,"pos_min"]))
cov_table[,"pos_max"] <- as.integer(as.character(cov_table[,"pos_max"]))
cov_table[,"read_count"] <- as.numeric(as.character(cov_table[,"read_count"]))
calls <- run_wrapper_EXOMEDEPTHCOV(cov_table)
calls <- run_wrapper_EXOMEDEPTHCOV(reference_set_select_method,
num_of_samples_in_reference_set,
cov_table)
expect_equal(length(calls), 0)
})

111 changes: 111 additions & 0 deletions R/tests/test_functions_REFERENCE_SAMPLE_SET_SELECTOR.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
library(testthat)
library(REFERENCE.SAMPLE.SET.SELECTOR)

context("Testing canoes_method function")

test_that("basic test for canoes_method function with num_refs equal to 5",{
investigated_sample <- "sample_1"
num_refs <- 5
Y = matrix(as.integer(c(52, 53, 54, 56, 70, 147, 58, 51,
25, 22, 39, 31, 27, 217, 17, 27,
57, 61, 66, 65, 64, 177, 67, 59,
101, 100, 90, 85, 98, 182, 92, 103,
149, 154, 140, 160, 165, 213, 149, 162,
95, 90, 90, 98, 88, 262, 93, 103,
50, 55, 45, 52, 59, 135, 65, 55,
79, 57, 63, 90, 71, 216, 69, 66)), nrow=8, ncol=8, byrow = TRUE)
colnames(Y) <- c("sample_1", "sample_2", "sample_3", "sample_4", "sample_5", "sample_6", "sample_7", "sample_8")
reference_samples <- canoes_method(investigated_sample,
Y,
num_refs)
expect_equal(length(reference_samples), 1)
expect_equal(length(reference_samples$reference_samples), num_refs)
expect_equal(reference_samples$reference_samples[1], 'sample_8')
expect_equal(reference_samples$reference_samples[2], 'sample_4')
expect_equal(reference_samples$reference_samples[3], 'sample_2')
expect_equal(reference_samples$reference_samples[4], 'sample_3')
expect_equal(reference_samples$reference_samples[5], 'sample_7')
})

test_that("basic test for canoes_method function with num_refs equal to 0",{
investigated_sample <- "sample_1"
num_refs <- 0
Y = matrix(as.integer(c(52, 53, 54, 56, 70, 147, 58, 51,
25, 22, 39, 31, 27, 217, 17, 27,
57, 61, 66, 65, 64, 177, 67, 59,
101, 100, 90, 85, 98, 182, 92, 103,
149, 154, 140, 160, 165, 213, 149, 162,
95, 90, 90, 98, 88, 262, 93, 103,
50, 55, 45, 52, 59, 135, 65, 55,
79, 57, 63, 90, 71, 216, 69, 66)), nrow=8, ncol=8, byrow = TRUE)
colnames(Y) <- c("sample_1", "sample_2", "sample_3", "sample_4", "sample_5", "sample_6", "sample_7", "sample_8")
reference_samples <- canoes_method(investigated_sample,
Y,
num_refs)
expect_equal(length(reference_samples), 1)
expect_equal(length(reference_samples$reference_samples), 7)
expect_equal(reference_samples$reference_samples[1], 'sample_8')
expect_equal(reference_samples$reference_samples[2], 'sample_4')
expect_equal(reference_samples$reference_samples[3], 'sample_2')
expect_equal(reference_samples$reference_samples[4], 'sample_3')
expect_equal(reference_samples$reference_samples[5], 'sample_7')
expect_equal(reference_samples$reference_samples[6], 'sample_5')
expect_equal(reference_samples$reference_samples[7], 'sample_6')
})


context("Testing exomedepth_method function")

test_that("basic test for exomedepth_method function with num_refs equal to 5",{
investigated_sample <- "sample_1"
num_refs <- 5
target_length <- c(1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000)
Y = matrix(as.integer(c(52, 53, 54, 56, 70, 147, 58, 51,
25, 22, 39, 31, 27, 217, 17, 27,
57, 61, 66, 65, 64, 177, 67, 59,
101, 100, 90, 85, 98, 182, 92, 103,
149, 154, 140, 160, 165, 213, 149, 162,
95, 90, 90, 98, 88, 262, 93, 103,
50, 55, 45, 52, 59, 135, 65, 55,
79, 57, 63, 90, 71, 216, 69, 66)), nrow=8, ncol=8, byrow = TRUE)
colnames(Y) <- c("sample_1", "sample_2", "sample_3", "sample_4", "sample_5", "sample_6", "sample_7", "sample_8")
reference_samples <- exomedepth_method(investigated_sample,
Y,
num_refs,
target_length)
expect_equal(length(reference_samples), 1)
expect_equal(length(reference_samples$reference_samples), num_refs)
expect_equal(reference_samples$reference_samples[1], 'sample_8')
expect_equal(reference_samples$reference_samples[2], 'sample_4')
expect_equal(reference_samples$reference_samples[3], 'sample_5')
expect_equal(reference_samples$reference_samples[4], 'sample_2')
expect_equal(reference_samples$reference_samples[5], 'sample_3')
})

test_that("basic test for exomedepth_method function with num_refs equal to 0 (auto)",{
investigated_sample <- "sample_1"
num_refs <- 0
target_length <- c(1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000)
Y = matrix(as.integer(c(52, 53, 54, 56, 70, 147, 58, 51,
25, 22, 39, 31, 27, 217, 17, 27,
57, 61, 66, 65, 64, 177, 67, 59,
101, 100, 90, 85, 98, 182, 92, 103,
149, 154, 140, 160, 165, 213, 149, 162,
95, 90, 90, 98, 88, 262, 93, 103,
50, 55, 45, 52, 59, 135, 65, 55,
79, 57, 63, 90, 71, 216, 69, 66)), nrow=8, ncol=8, byrow = TRUE)
colnames(Y) <- c("sample_1", "sample_2", "sample_3", "sample_4", "sample_5", "sample_6", "sample_7", "sample_8")
reference_samples <- exomedepth_method(investigated_sample,
Y,
num_refs,
target_length)
expect_equal(length(reference_samples), 1)
expect_equal(length(reference_samples$reference_samples), 6)
expect_equal(reference_samples$reference_samples[1], 'sample_8')
expect_equal(reference_samples$reference_samples[2], 'sample_4')
expect_equal(reference_samples$reference_samples[3], 'sample_5')
expect_equal(reference_samples$reference_samples[4], 'sample_2')
expect_equal(reference_samples$reference_samples[5], 'sample_3')
expect_equal(reference_samples$reference_samples[6], 'sample_7')
})

Loading

0 comments on commit a1dfe05

Please sign in to comment.