From 4e407f0f276ac469fa379dda35245e3ef8ac3ba9 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Fri, 5 Apr 2013 19:43:09 +0000 Subject: Got Nick's code working with the MDP datasets under the BXD group, but with only BXD strains --- .../wqflask/marker_regression/marker_regression.py | 14 +++++--- wqflask/wqflask/my_pylmm/pyLMM/lmm.py | 37 +++++++++++++++------- .../static/new/javascript/marker_regression.coffee | 2 ++ .../static/new/javascript/marker_regression.js | 2 ++ .../new/javascript/show_trait_mapping_tools.coffee | 6 ++++ .../new/javascript/show_trait_mapping_tools.js | 7 ++++ wqflask/wqflask/views.py | 2 +- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index f67c595a..5f4f9be8 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -9,6 +9,7 @@ import string import sys import os import collections +import pdb import numpy as np from scipy import linalg @@ -67,13 +68,13 @@ class MarkerRegression(object): pheno_vector = np.array([val == "x" and np.nan or float(val) for val in self.vals]) if self.dataset.group.species == "human": - p_values, t_stats = self.gen_human_results(pheno_vector) + p_values, t_stats = self.gen_human_results(pheno_vector, tempdata) else: genotype_data = [marker['genotypes'] for marker in self.dataset.group.markers.markers] no_val_samples = self.identify_empty_samples() - trimmed_genotype_data = self.trim_genotypes(genotype_data, no_val_samples) - + trimmed_genotype_data = self.trim_genotypes(genotype_data, no_value_samples=[]) + pdb.set_trace() genotype_matrix = np.array(trimmed_genotype_data).T print("pheno_vector is: ", pf(pheno_vector)) @@ -92,10 +93,12 @@ class MarkerRegression(object): self.qtl_results = self.dataset.group.markers.markers - def gen_human_results(self, pheno_vector): + def gen_human_results(self, pheno_vector, tempdata): file_base = os.path.join(webqtlConfig.PYLMM_PATH, self.dataset.group.name) + tempdata.store("percent_complete", 0) plink_input = input.plink(file_base, type='b') + tempdata.store("percent_complete", 0.1) pheno_vector = pheno_vector.reshape((len(pheno_vector), 1)) covariate_matrix = np.ones((pheno_vector.shape[0],1)) @@ -106,7 +109,8 @@ class MarkerRegression(object): pheno_vector, covariate_matrix, plink_input, - kinship_matrix + kinship_matrix, + temp_data=tempdata ) return p_values, t_stats diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py index e60f7b02..4de77173 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py @@ -23,6 +23,7 @@ import numpy as np from scipy import linalg from scipy import optimize from scipy import stats +import pdb from pprint import pformat as pf @@ -43,10 +44,10 @@ def run_human(pheno_vector, if v.sum(): pheno_vector = pheno_vector[keep] - print("pheno_vector shape is now: ", pf(pheno_vector.shape)) + #print("pheno_vector shape is now: ", pf(pheno_vector.shape)) covariate_matrix = covariate_matrix[keep,:] - print("kinship_matrix shape is: ", pf(kinship_matrix.shape)) - print("len(keep) is: ", pf(keep.shape)) + #print("kinship_matrix shape is: ", pf(kinship_matrix.shape)) + #print("len(keep) is: ", pf(keep.shape)) kinship_matrix = kinship_matrix[keep,:][:,keep] n = kinship_matrix.shape[0] @@ -58,13 +59,21 @@ def run_human(pheno_vector, # Buffers for pvalues and t-stats p_values = [] t_stats = [] + + plink_input.getSNPIterator() + total_snps = plink_input.numSNPs + count = 0 with Bench("snp iterator loop"): for snp, this_id in plink_input: - if count > 1000: - break + #if count > 1000: + # break count += 1 + percent_complete = (float(count) / total_snps) * 100 + print("percent_complete: ", pf(percent_complete)) + temp_data.store("percent_complete", percent_complete) + x = snp[keep].reshape((n,1)) #x[[1,50,100,200,3000],:] = np.nan v = np.isnan(x).reshape((-1,)) @@ -104,9 +113,12 @@ def run_human(pheno_vector, if refit: lmm_ob.fit(X=x) ts, ps, beta, betaVar = lmm_ob.association(x) + p_values.append(ps) t_stats.append(ts) + print("p_values: ", pf(p_values)) + return p_values, t_stats @@ -188,14 +200,13 @@ def calculate_kinship(genotype_matrix, temp_data): #print("m is:", m) keep = [] for counter in range(m): - print("type of genotype_matrix[:,counter]:", pf(genotype_matrix[:,counter])) + #print("type of genotype_matrix[:,counter]:", pf(genotype_matrix[:,counter])) #Checks if any values in column are not numbers not_number = np.isnan(genotype_matrix[:,counter]) - print("type of not_number:", type(not_number)) #Gets vector of values for column (no values in vector if not all values in col are numbers) marker_values = genotype_matrix[True - not_number, counter] - print("type of marker_values is:", type(marker_values)) + #print("type of marker_values is:", type(marker_values)) #Gets mean of values in vector values_mean = marker_values.mean() @@ -270,7 +281,10 @@ def GWAS(pheno_vector, p_values = [] t_statistics = [] - + + n = genotype_matrix.shape[0] + m = genotype_matrix.shape[1] + for counter in range(m): x = genotype_matrix[:,counter].reshape((n, 1)) v = np.isnan(x).reshape((-1,)) @@ -343,6 +357,7 @@ class LMM: #x = Y != -9 x = True - np.isnan(Y) + #pdb.set_trace() if not x.sum() == len(Y): if self.verbose: sys.stderr.write("Removing %d missing values from Y\n" % ((True - x).sum())) Y = Y[x] @@ -362,8 +377,8 @@ class LMM: self.K = K self.Kva = Kva self.Kve = Kve - print("self.Kva is: ", pf(self.Kva)) - print("self.Kve is: ", pf(self.Kve)) + #print("self.Kva is: ", pf(self.Kva)) + #print("self.Kve is: ", pf(self.Kve)) self.Y = Y self.X0 = X0 self.N = self.K.shape[0] diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.coffee b/wqflask/wqflask/static/new/javascript/marker_regression.coffee index 3e14ab6b..78b6fdbc 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.coffee +++ b/wqflask/wqflask/static/new/javascript/marker_regression.coffee @@ -4,10 +4,12 @@ $ -> @qtl_results = js_data.qtl_results console.log("qtl_results are:", @qtl_results) @chromosomes = js_data.chromosomes + console.log("chromosomes: ", @chromosomes) @total_length = 0 @max_chr = @get_max_chr() + console.log("max_chr is: ", @max_chr) @x_coords = [] @y_coords = [] diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.js b/wqflask/wqflask/static/new/javascript/marker_regression.js index 09470daf..25d88ec0 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.js +++ b/wqflask/wqflask/static/new/javascript/marker_regression.js @@ -13,8 +13,10 @@ this.qtl_results = js_data.qtl_results; console.log("qtl_results are:", this.qtl_results); this.chromosomes = js_data.chromosomes; + console.log("chromosomes: ", this.chromosomes); this.total_length = 0; this.max_chr = this.get_max_chr(); + console.log("max_chr is: ", this.max_chr); this.x_coords = []; this.y_coords = []; this.marker_names = []; diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee index 157f56a9..22427e4f 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee @@ -37,6 +37,12 @@ $ -> type: "POST" url: url data: form_data + error: (xhr, ajaxOptions, thrownError) => + alert("some error occurred") + console.log(xhr) + clearInterval(this.my_timer) + $('#progress_bar_container').modal('hide') + $("body").html("error") success: (data) => clearInterval(this.my_timer) $('#progress_bar_container').modal('hide') diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js index 78459692..daf9b273 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js @@ -46,6 +46,13 @@ type: "POST", url: url, data: form_data, + error: function(xhr, ajaxOptions, thrownError) { + alert("some error occurred"); + console.log(xhr); + clearInterval(_this.my_timer); + $('#progress_bar_container').modal('hide'); + return $("body").html("error"); + }, success: function(data) { clearInterval(_this.my_timer); $('#progress_bar_container').modal('hide'); diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 7f5f88e0..c303e0d1 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -168,7 +168,7 @@ def marker_regression_page(): if key in wanted or key.startswith(('value:')): start_vars[key] = value - version = "v13" + version = "v14" key = "marker_regression:{}:".format(version) + json.dumps(start_vars, sort_keys=True) with Bench("Loading cache"): result = Redis.get(key) -- cgit v1.2.3