aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorAlexander Kabui2022-02-24 19:27:28 +0300
committerAlexander Kabui2022-02-24 19:27:28 +0300
commit86ead9b3d823e46350b5566b197463b5fdc46102 (patch)
tree607e9996f54ae9c23ce3a3b8b34b79da4a2d6f44 /wqflask
parent7c9e73f196575cd6d1de7df4430bc2b4ecb28466 (diff)
downloadgenenetwork2-86ead9b3d823e46350b5566b197463b5fdc46102.tar.gz
init replace rpy2 for pca
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/correlation_matrix/show_corr_matrix.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
index e7b16e77..9462f973 100644
--- a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
+++ b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
@@ -23,8 +23,6 @@ import math
import random
import string
-import rpy2.robjects as ro
-from rpy2.robjects.packages import importr
import numpy as np
import scipy
@@ -38,6 +36,12 @@ from utility import helper_functions
from utility import corr_result_helpers
from utility.redis_tools import get_redis_conn
+
+
+from gn3.computations.principal_component_analysis import compute_pca
+
+from gn3.computations.principal_component_analysis import process_factor_loadings_tdata
+
Redis = get_redis_conn()
THIRTY_DAYS = 60 * 60 * 24 * 30
@@ -174,7 +178,7 @@ class CorrelationMatrix:
self.pca_trait_ids = []
pca = self.calculate_pca(
list(range(len(self.traits))), corr_eigen_value, corr_eigen_vectors)
- self.loadings_array = self.process_loadings()
+ self.loadings_array = process_factor_loadings_tdata(self.loadings,len(self.trait_list))
else:
self.pca_works = "False"
except:
@@ -188,18 +192,12 @@ class CorrelationMatrix:
sample_data=self.sample_data,)
def calculate_pca(self, cols, corr_eigen_value, corr_eigen_vectors):
- base = importr('base')
- stats = importr('stats')
-
- corr_results_to_list = ro.FloatVector(
- [item for sublist in self.pca_corr_results for item in sublist])
-
- m = ro.r.matrix(corr_results_to_list, nrow=len(cols))
- eigen = base.eigen(m)
- pca = stats.princomp(m, cor="TRUE")
- self.loadings = pca.rx('loadings')
- self.scores = pca.rx('scores')
- self.scale = pca.rx('scale')
+
+
+ pca = compute_pca(self.pca_corr_results)
+
+ self.loadings = pca["components"]
+ self.scores = pca["scores"]
trait_array = zScore(self.trait_data_array)
trait_array_vectors = np.dot(corr_eigen_vectors, trait_array)