aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/biweight.R23
-rw-r--r--gn3/computations/biweight.py25
-rw-r--r--gn3/computations/correlations.py7
-rw-r--r--gn3/computations/test_biweight.R25
4 files changed, 15 insertions, 65 deletions
diff --git a/gn3/computations/biweight.R b/gn3/computations/biweight.R
deleted file mode 100644
index e424360..0000000
--- a/gn3/computations/biweight.R
+++ /dev/null
@@ -1,23 +0,0 @@
-
-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])))
-
-}
-
-
-parsed_values <- ParseArgs(arg_values)
-
-cat((BiweightMidCorrelation(parsed_values[1],parsed_values[2]))) \ No newline at end of file
diff --git a/gn3/computations/biweight.py b/gn3/computations/biweight.py
index e598a5b..f5eecb2 100644
--- a/gn3/computations/biweight.py
+++ b/gn3/computations/biweight.py
@@ -1,20 +1,17 @@
-
-
-"""module contains script to call biweight mid\
-correlation in R"""
+"""module contains script to call biweight midcorrelation in R"""
import subprocess
-import os
-from pathlib import Path
+
from typing import List
+from typing import Tuple
-FILE_PATH = os.path.join(Path(__file__).parent.absolute(), "biweight.R")
+from gn3.settings import BIWEIGHT_RSCRIPT
-def call_biweight_script(trait_vals: List,
- target_vals: List,
- path_to_script: str = FILE_PATH,
- command: str = "Rscript"
- ):
+def calculate_biweight_corr(trait_vals: List,
+ target_vals: List,
+ path_to_script: str = BIWEIGHT_RSCRIPT,
+ command: str = "Rscript"
+ ) -> Tuple[float, float]:
'''biweight function'''
args_1 = ' '.join(str(trait_val) for trait_val in trait_vals)
@@ -23,4 +20,6 @@ def call_biweight_script(trait_vals: List,
results = subprocess.check_output(cmd, universal_newlines=True)
- return tuple([float(y) for y in results.split()])
+ (corr_coeff, p_val) = tuple([float(y) for y in results.split()])
+
+ return (corr_coeff, p_val)
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py
index 89d37fc..eae7ae4 100644
--- a/gn3/computations/correlations.py
+++ b/gn3/computations/correlations.py
@@ -7,7 +7,7 @@ from typing import Optional
from typing import Callable
import scipy.stats
-from gn3.computations.biweight import call_biweight_script
+from gn3.computations.biweight import calculate_biweight_corr
def map_shared_keys_to_values(target_sample_keys: List,
@@ -102,12 +102,11 @@ package :not packaged in guix
"""
try:
- results = call_biweight_script(x_val, y_val)
+ results = calculate_biweight_corr(x_val, y_val)
+ return results
except Exception as error:
raise error
- return results
-
def filter_shared_sample_keys(this_samplelist,
target_samplelist) -> Tuple[List, List]:
diff --git a/gn3/computations/test_biweight.R b/gn3/computations/test_biweight.R
deleted file mode 100644
index 599e733..0000000
--- a/gn3/computations/test_biweight.R
+++ /dev/null
@@ -1,25 +0,0 @@
-library(testthat)
-source("./biweight.R", chdir = TRUE)
-
-test_that("sum of vector", {
- results <- sum(c(1,2))
- expect_equal(results, 3)
-})
-
-
-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