diff options
author | BonfaceKilz | 2021-06-21 08:58:27 +0300 |
---|---|---|
committer | GitHub | 2021-06-21 08:58:27 +0300 |
commit | f949189dc727976a1574a57d3b0e895ff6598d07 (patch) | |
tree | e7e0634176d55afefa25467652b4f97601287837 /scripts/calculate_biweight.R | |
parent | d653a635d0efd2291754c18f51d31f91a1c0a25c (diff) | |
parent | 10140ab707021dd2dffb1b439f52a62e3d59c29a (diff) | |
download | genenetwork3-f949189dc727976a1574a57d3b0e895ff6598d07.tar.gz |
Merge pull request #20 from genenetwork/feature/biweight-correlation
add biweight r script and tests
Diffstat (limited to 'scripts/calculate_biweight.R')
-rw-r--r-- | scripts/calculate_biweight.R | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/calculate_biweight.R b/scripts/calculate_biweight.R new file mode 100644 index 0000000..bad93cb --- /dev/null +++ b/scripts/calculate_biweight.R @@ -0,0 +1,42 @@ + +library(testthat) +library(WGCNA) + +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))) + +} +BiweightMidCorrelation <- function(trait_val,target_val){ + + results <- bicorAndPvalue(c(trait_val),c(target_val)) + return ((c(c(results$bicor)[1],c(results$p)[1]))) + +} + + + +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)) +} + +parsed_values <- ParseArgs(arg_values) + +cat((BiweightMidCorrelation(parsed_values[1],parsed_values[2])))
\ No newline at end of file |