aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorAlexander Kabui2021-06-16 13:41:28 +0300
committerAlexander Kabui2021-06-16 13:41:28 +0300
commitc0931bda121c1b39e1ae2adc7bfa49c2ca207a4d (patch)
tree7dd793ee03bdd7d0f85130623d40f4606db99214 /gn3/computations
parentceaea7930b0205993b9357bd1317fefe0c51b3b6 (diff)
downloadgenenetwork3-c0931bda121c1b39e1ae2adc7bfa49c2ca207a4d.tar.gz
refactor script and add tests
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/biweight.R14
-rw-r--r--gn3/computations/test_biweight.R28
2 files changed, 36 insertions, 6 deletions
diff --git a/gn3/computations/biweight.R b/gn3/computations/biweight.R
index 8730536..e424360 100644
--- a/gn3/computations/biweight.R
+++ b/gn3/computations/biweight.R
@@ -1,10 +1,11 @@
library(WGCNA)
-FetchArgs <- function(){
- myArgs <- commandArgs(trailingOnly = TRUE)
- trait_vals <- as.numeric(unlist(strsplit(myArgs[1], split=" ")))
- target_vals <- as.numeric(unlist(strsplit(myArgs[2], split=" ")))
+arg_values <- commandArgs(trailingOnly = TRUE)
+ParseArgs <- function(args){
+
+ trait_vals <- as.numeric(unlist(strsplit(args[1], split=" ")))
+ target_vals <- as.numeric(unlist(strsplit(args[2], split=" ")))
return(list(trait_vals= c(trait_vals),target_vals = c(target_vals)))
@@ -13,9 +14,10 @@ BiweightMidCorrelation <- function(trait_val,target_val){
results <- bicorAndPvalue(c(trait_val),c(target_val))
return ((c(c(results$bicor)[1],c(results$p)[1])))
+
}
-results <- (BiweightMidCorrelation(FetchArgs()[1],FetchArgs()[2]))
+parsed_values <- ParseArgs(arg_values)
-cat(results) \ No newline at end of file
+cat((BiweightMidCorrelation(parsed_values[1],parsed_values[2]))) \ No newline at end of file
diff --git a/gn3/computations/test_biweight.R b/gn3/computations/test_biweight.R
new file mode 100644
index 0000000..149c8b6
--- /dev/null
+++ b/gn3/computations/test_biweight.R
@@ -0,0 +1,28 @@
+library(testthat)
+source("./biweight.R", chdir = TRUE)
+
+test_that("sum of vector", {
+ results <- sum(c(1,2))
+ expect_equal(results, 3)
+})
+
+
+
+test
+
+test_that("biweight results"),{
+ vec_1 = c(1,2,3,4)
+ vec_2 = c(1,2,3,4)
+
+ results = BiweightMidCorrelation(vec_1,vec_2)
+ expect_equal(c(1.0,0.0),results)
+}
+
+
+test_that("parsing args "),{
+ my_args = c("1 2 3 4","5 6 7 8")
+ results <- ParseArgs(my_args)
+
+ expect_equal(results[1],c(1,2,3,4))
+ expect_equal(results[2],c(5,6,7,8))
+} \ No newline at end of file