From 4852779011acb075e97e22f25db4fa7373ec1c73 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Mon, 16 Mar 2015 18:21:44 +0000 Subject: Moved setting of geno variable into non-human --- wqflask/wqflask/my_pylmm/pyLMM/lmm.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py index 58d7593d..16073d2c 100644 --- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py +++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py @@ -731,8 +731,7 @@ def gn2_redis(key,species,is_testing=False): print('kinship', np.array(params['kinship_matrix'])) print('pheno', np.array(params['pheno_vector'])) - geno = np.array(params['genotype_matrix']) - print('geno', geno.shape, geno) + # sys.exit(1) if species == "human" : @@ -743,6 +742,9 @@ def gn2_redis(key,species,is_testing=False): refit = params['refit'], tempdata = tempdata) else: + geno = np.array(params['genotype_matrix']) + print('geno', geno.shape, geno) + ps, ts = run_other(pheno_vector = np.array(params['pheno_vector']), genotype_matrix = geno, restricted_max_likelihood = params['restricted_max_likelihood'], -- cgit v1.2.3 From b4ce1da2b8a376472ed87b80b97ef7ce1b3d9314 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 17 Mar 2015 18:07:39 +0000 Subject: Moved scatter-plot to the right of options instead of below --- wqflask/wqflask/do_search.py | 11 ++++++++++- wqflask/wqflask/static/new/javascript/scatter-matrix.js | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index 31dc11b5..921a4a47 100755 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -382,11 +382,20 @@ class RifSearch(MrnaAssaySearch): DoSearch.search_types['RIF'] = "RifSearch" - def run(self): + def get_where_clause(self): where_clause = """( %s.symbol = GeneRIF_BASIC.symbol and MATCH (GeneRIF_BASIC.comment) AGAINST ('+%s' IN BOOLEAN MODE)) """ % (self.dataset.type, self.search_term[0]) + return where_clause + + def run(self): + #where_clause = """( %s.symbol = GeneRIF_BASIC.symbol and + # MATCH (GeneRIF_BASIC.comment) + # AGAINST ('+%s' IN BOOLEAN MODE)) """ % (self.dataset.type, self.search_term[0]) + + where_clause = self.get_where_clause() + from_clause = ", GeneRIF_BASIC " query = self.compile_final_query(from_clause, where_clause) diff --git a/wqflask/wqflask/static/new/javascript/scatter-matrix.js b/wqflask/wqflask/static/new/javascript/scatter-matrix.js index 38cdc75b..15385b00 100644 --- a/wqflask/wqflask/static/new/javascript/scatter-matrix.js +++ b/wqflask/wqflask/static/new/javascript/scatter-matrix.js @@ -57,7 +57,7 @@ ScatterMatrix.prototype.render = function () { .attr('class', 'scatter-matrix-container'); var control = container.append('div') .attr('class', 'scatter-matrix-control') - .style({'float':'left'}) + .style({'float':'left', 'margin-right':'50px'}) var svg = container.append('div') .attr('class', 'scatter-matrix-svg') .style({'float':'right'}) -- cgit v1.2.3 From 85ffbfeb6379120c25b0bf589d568bb1453f778b Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 17 Mar 2015 18:08:44 +0000 Subject: Improved rqtl code --- .../wqflask/marker_regression/marker_regression.py | 184 +++++++++++++++++---- 1 file changed, 148 insertions(+), 36 deletions(-) diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index fa680f5f..99f23676 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -13,7 +13,7 @@ import os import collections import uuid -import rpy2.robjects as robjects +import rpy2.robjects as ro import numpy as np from scipy import linalg @@ -79,7 +79,7 @@ class MarkerRegression(object): self.num_perm = start_vars['num_perm'] self.control = start_vars['control_marker'] - print("doing rqtl_geno") + print("DOING RQTL GENO") qtl_results = self.run_rqtl_geno() print("qtl_results:", qtl_results) elif self.mapping_method == "plink": @@ -88,8 +88,9 @@ class MarkerRegression(object): elif self.mapping_method == "pylmm": print("RUNNING PYLMM") self.num_perm = start_vars['num_perm'] - if int(self.num_perm) > 0: - self.run_permutations(str(temp_uuid)) + if self.num_perm != "": + if int(self.num_perm) > 0: + self.run_permutations(str(temp_uuid)) qtl_results = self.gen_data(str(temp_uuid)) else: print("RUNNING NOTHING") @@ -229,6 +230,136 @@ class MarkerRegression(object): count, p_values = self.parse_rqtl_output(plink_output_filename) def run_rqtl_geno(self): + + print("CORRECT FUNCTION BEING CALLED") + + ## Get pointers to some common R functions + r_library = ro.r["library"] # Map the library function + r_c = ro.r["c"] # Map the c function + + print(r_library("qtl")) # Load R/qtl + + ## Get pointers to some R/qtl functions + scanone = ro.r["scanone"] # Map the scanone function + calc_genoprob = ro.r["calc.genoprob"] # Map the calc.genoprob function + read_cross = ro.r["read.cross"] # Map the read.cross function + write_cross = ro.r["write.cross"] # Map the write.cross function + + + cross_object = read_cross(file = "BXD.csvr", format = "csvr", dir="/home/zas1024/PLINK2RQTL/test", genotypes = r_c("B","H","D")) + + if self.manhattan_plot: + cross_object = calc_genoprob(cross_object) + else: + cross_object = calc_genoprob(cross_object, step=1, stepwidth="max") + + # Add the phenotype + cross_object = self.add_phenotype(cross_object, self.sanitize_rqtl_phenotype()) + # for debug: write_cross(cross_object, "csvr", "test.csvr") + # Scan for QTLs + # TODO: use addcovar, and permutations + if(self.control.replace(" ", "") != ""): + covar = self.create_covariatesShort(cross_object) + result_data_frame = scanone(cross_object, pheno = "the_pheno", addcovar = covar) + else: + result_data_frame = scanone(cross_object, pheno = "the_pheno") + qtl_results = self.process_rqtl_results(result_data_frame) + + return qtl_results + + def add_phenotype(self, cross, pheno_as_string): + ro.globalenv["the_cross"] = cross + ro.r('the_cross$pheno <- cbind(pull.pheno(the_cross), the_pheno = '+ pheno_as_string +')') + return ro.r["the_cross"] + + + def create_covariatesShort(self, cross): + ro.globalenv["the_cross"] = cross + ro.r('genotypes <- pull.geno(the_cross)') # Get genotype matrix + userinputS = self.control.replace(" ", "").split(",") # TODO sanitize user input !!! never trust a user + covariate_names = ', '.join('"{0}"'.format(w) for w in userinputS) + print(covariate_names) + ro.r('covariates <- genotypes[,c(' + covariate_names + ')]') # get covariate matrix, + print("COVARIATES:", ro.r["covariates"]) + return ro.r["covariates"] + + + def create_covariates(self): + if self.control != "": + control_markers = self.control.split(",") + control_string = "" + for i, control in enumerate(control_markers): + control_trait = GeneralTrait(name=str(control), dataset_name=str(self.dataset.group.name + "Geno")) + control_vals = [] + for sample in self.dataset.group.samplelist: + if sample in control_trait.data: + control_vals.append(control_trait.data[sample].value) + else: + control_vals.append("x") + print("control_vals:", control_vals) + control_as_string = "c(" + for j, val2 in enumerate(control_vals): + if val2 == "x": + if j < (len(control_vals) - 1): + control_as_string += "NA," + else: + control_as_string += "NA" + else: + if j < (len(control_vals) - 1): + control_as_string += str(val2) + "," + else: + control_as_string += str(val2) + #if i < (len(control_vals) - 1): + # control_as_string += str(new_val2) + "," + #else: + # control_as_string += str(new_val2) + control_as_string += ")" + print("control_as_string:", control_as_string) + if i < (len(control_markers)-1): + control_string += control_as_string + "," + else: + control_string += control_as_string + + robjects.r('covariates <- cbind( '+ control_string +')') + + + def sanitize_rqtl_phenotype(self): + pheno_as_string = "c(" + null_pos = [] + for i, val in enumerate(self.vals): + if val == "x": + null_pos.append(i) + if i < (len(self.vals) - 1): + pheno_as_string += "NA," + else: + pheno_as_string += "NA" + else: + if i < (len(self.vals) - 1): + pheno_as_string += str(val) + "," + else: + pheno_as_string += str(val) + pheno_as_string += ")" + return pheno_as_string + + def process_rqtl_results(self, result): + #TODO how to make this a one liner and not copy the stuff in a loop + qtl_results = [] + + output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)] + print("output", output) + + for i, line in enumerate(result.iter_row()): + marker = {} + marker['name'] = result.rownames[i] + marker['chr'] = output[i][0] + marker['Mb'] = output[i][1] + marker['lod_score'] = output[i][2] + + qtl_results.append(marker) + + return qtl_results + + def run_rqtl_geno_old(self): robjects.packages.importr("qtl") robjects.r('the_cross <- read.cross(format="csvr", dir="/home/zas1024/PLINK2RQTL/test", file="BXD.csvr")') if self.manhattan_plot: @@ -236,14 +367,6 @@ class MarkerRegression(object): else: robjects.r('the_cross <- calc.genoprob(the_cross, step=1, stepwidth="max")') pheno_as_string = "c(" - #for i, val in enumerate(self.vals): - # if val == "x": - # new_val == "NULL" - # else: - # new_val = val - # if i < (len(self.vals) - 1): - # pheno_as_string += str(new_val) + "," - # else: pheno_as_string += str(new_val) null_pos = [] for i, val in enumerate(self.vals): if val == "x": @@ -300,14 +423,19 @@ class MarkerRegression(object): control_string += control_as_string robjects.r('covariates <- cbind( '+ control_string +')') - - r_string = 'scanone(the_cross, pheno.col="the_pheno", n.cluster=16, n.perm='+self.num_perm+', addcovar=covariates, intcovar=covariates[,'+ str(len(control_markers)) +'])' + #Scan for QTL + r_string = 'scanone(the_cross, pheno.col="the_pheno", addcovar=covariates)' + #r_string = 'scanone(the_cross, pheno.col="the_pheno", n.cluster=16, n.perm='+self.num_perm+', addcovar=covariates, intcovar=covariates[,'+ str(len(control_markers)) +'])' print("r_string:", r_string) - + + # extract the profile + if int(self.num_perm) > 0: + # Do permutation + r_string = 'scanone(the_cross, pheno.col="the_pheno", n.cluster=16, addcovar=covariates, intcovar=covariates[,'+ str(len(control_markers)) +'])' + # Extract the tresholds thresholds = robjects.r(r_string) self.suggestive, self.significant = self.process_rqtl_perm_results(thresholds) - r_string = 'scanone(the_cross, pheno.col="the_pheno", n.cluster=16, addcovar=covariates, intcovar=covariates[,'+ str(len(control_markers)) +'])' #r_string = 'scanone(the_cross, pheno.col='+pheno_as_string+', addcovar='+control_as_string+')' @@ -323,6 +451,8 @@ class MarkerRegression(object): result_data_frame = robjects.r(r_string) #print("results:", result_data_frame) + print("before process rqtl results") + qtl_results = self.process_rqtl_results(result_data_frame) return qtl_results @@ -339,24 +469,6 @@ class MarkerRegression(object): return self.suggestive, self.significant - - def process_rqtl_results(self, result): - qtl_results = [] - - output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)] - print("output", output) - - - for i, line in enumerate(result.iter_row()): - marker = {} - marker['name'] = result.rownames[i] - marker['chr'] = output[i][0] - marker['Mb'] = output[i][1] - marker['lod_score'] = output[i][2] - - qtl_results.append(marker) - - return qtl_results def run_plink(self): @@ -394,8 +506,8 @@ class MarkerRegression(object): self.dataset.group.markers.add_pvalues(p_values) return self.dataset.group.markers.markers - - + + def gen_pheno_txt_file_plink(self, pheno_filename = ''): ped_sample_list = self.get_samples_from_ped_file() output_file = open("%s%s.txt" % (webqtlConfig.TMPDIR, pheno_filename), "wb") -- cgit v1.2.3 From fe3f8d1602dc16bd22cf407ed94e5060249eed03 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 17 Mar 2015 18:37:03 +0000 Subject: Added files for bootstrap icons and scatter-plot css file --- wqflask/wqflask/static/new/css/scatter-matrix.css | 40 ++++ .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 20335 bytes .../fonts/glyphicons-halflings-regular.svg | 229 +++++++++++++++++++++ .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 41280 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 23320 bytes 5 files changed, 269 insertions(+) create mode 100644 wqflask/wqflask/static/new/css/scatter-matrix.css create mode 100644 wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.eot create mode 100644 wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.svg create mode 100644 wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.ttf create mode 100644 wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.woff diff --git a/wqflask/wqflask/static/new/css/scatter-matrix.css b/wqflask/wqflask/static/new/css/scatter-matrix.css new file mode 100644 index 00000000..147903be --- /dev/null +++ b/wqflask/wqflask/static/new/css/scatter-matrix.css @@ -0,0 +1,40 @@ +#scatter-matrix { font-size: 14px; } + +.axis { shape-rendering: crispEdges; } +.axis line { stroke: #ddd; stroke-width: 1px; } +.axis path { display: none; } +.axis text { font-size: 0.8em; } + +rect.extent { fill: #000; fill-opacity: .125; stroke: #fff; } +rect.frame { fill: #fff; fill-opacity: .7; stroke: #aaa; } + +circle { fill: #ccc; fill-opacity: .5; } + +.legend circle { fill-opacity: 1; } +.legend text { font-size: 18px; font-style: oblique; } + +.cell text { pointer-events: none; } + +.color-0 { fill: #800; } +.color-1 { fill: #080; } +.color-2 { fill: #008; } +.color-3 { fill: #440; } +.color-4 { fill: #044; } +.color-5 { fill: #404; } +.color-6 { fill: #400; } +.color-7 { fill: #040; } +.color-8 { fill: #004; } +.color-9 { fill: #cc0; } +.color-10 { fill: #0cc; } +.color-11 { fill: #c0c; } +.color-12 { fill: #880; } +.color-13 { fill: #088; } +.color-14 { fill: #808; } +.color-15 { fill: #c00; } +.color-16 { fill: #0c0; } +.color-17 { fill: #00c; } + +.scatter-matrix-filter-control ul { list-style: none; padding-left: 10px; } +.scatter-matrix-variable-control ul { list-style: none; padding-left: 10px; } +.scatter-matrix-drill-control ul { list-style: none; padding-left: 10px; } + diff --git a/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.eot b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.eot new file mode 100644 index 00000000..4a4ca865 Binary files /dev/null and b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.eot differ diff --git a/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.svg b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.svg new file mode 100644 index 00000000..25691af8 --- /dev/null +++ b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.svg @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.ttf b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.ttf new file mode 100644 index 00000000..67fa00bf Binary files /dev/null and b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.ttf differ diff --git a/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.woff b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.woff new file mode 100644 index 00000000..8c54182a Binary files /dev/null and b/wqflask/wqflask/static/packages/bootstrap/fonts/glyphicons-halflings-regular.woff differ -- cgit v1.2.3 From 69e509720d9242972a49635ef0fd8e725a7d9cc6 Mon Sep 17 00:00:00 2001 From: DannyArends Date: Tue, 17 Mar 2015 19:39:39 +0100 Subject: Converting an absolute path to a relative path --- wqflask/base/data_set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 8965e1d1..489bd374 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -79,7 +79,7 @@ class Dataset_Types(object): def __init__(self): self.datasets = {} - file_name = "/home/zas1024/gene/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json" + file_name = "wqflask/static/new/javascript/dataset_menu_structure.json" with open(file_name, 'r') as fh: data = json.load(fh) -- cgit v1.2.3