diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/utility/helper_functions.py | 6 | ||||
-rwxr-xr-x | wqflask/wqflask/marker_regression/marker_regression.py | 35 | ||||
-rwxr-xr-x | wqflask/wqflask/show_trait/show_trait.py | 2 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/marker_regression.coffee | 57 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/marker_regression.js | 43 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 2 |
6 files changed, 97 insertions, 48 deletions
diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py index 920d9ac6..d2567b63 100644 --- a/wqflask/utility/helper_functions.py +++ b/wqflask/utility/helper_functions.py @@ -2,14 +2,16 @@ from __future__ import absolute_import, print_function, division from base.trait import GeneralTrait from base import data_set +from base.species import TheSpecies -def get_dataset_and_trait(self, start_vars): +def get_species_dataset_trait(self, start_vars): #assert type(read_genotype) == type(bool()), "Expecting boolean value for read_genotype" self.dataset = data_set.create_dataset(start_vars['dataset']) + self.species = TheSpecies(dataset=self.dataset) self.this_trait = GeneralTrait(dataset=self.dataset.name, name=start_vars['trait_id'], cellid=None) #if read_genotype: self.dataset.group.read_genotype_file() - self.genotype = self.dataset.group.genotype
\ No newline at end of file + self.genotype = self.dataset.group.genotype diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 81bf3825..50739614 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -24,6 +24,7 @@ from utility import Plot, Bunch from wqflask.interval_analyst import GeneUtil from base.trait import GeneralTrait from base import data_set +from base import species from base.templatePage import templatePage from utility import webqtlUtil, helper_functions from base import webqtlConfig @@ -60,7 +61,7 @@ class MarkerRegression(object): #print("start_vars are: ", pf(start_vars)) - helper_functions.get_dataset_and_trait(self, start_vars) + helper_functions.get_species_dataset_trait(self, start_vars) self.num_perm = int(start_vars['num_perm']) @@ -306,7 +307,14 @@ class MarkerRegression(object): # end: common part with human data + chromosome_mb_lengths = {} + for key in self.species.chromosomes.chromosomes.keys(): + chromosome_mb_lengths[key] = self.species.chromosomes.chromosomes[key].mb_length + + print("chromosomes is:", pf(chromosome_mb_lengths)) + self.js_data = dict( + chromosomes = chromosome_mb_lengths, qtl_results = self.pure_qtl_results, lrs_values = self.lrs_values, ) @@ -476,25 +484,24 @@ class MarkerRegression(object): #prep_data.PrepData(self.vals, genotype_data) pheno_vector = np.array([float(val) for val in self.vals if val!="x"]) - print("genotypes was:", pf(trimmed_genotype_data)) - for item in trimmed_genotype_data: - if type(item) != type(list()): - print(" --->", type(item)) - for counter, part in enumerate(item): - if type(part) != type(float()): - print(" ------>", type(part), " : ", part) - if counter % 100 == 0: - print(" ------>", type(part)) + #for item in trimmed_genotype_data: + # if type(item) != type(list()): + # print(" --->", type(item)) + # for counter, part in enumerate(item): + # if type(part) != type(float()): + # print(" ------>", type(part), " : ", part) + # if counter % 100 == 0: + # print(" ------>", type(part)) genotypes = np.array(trimmed_genotype_data).T - print("genotypes is:", pf(genotypes)) + #print("genotypes is:", pf(genotypes)) #genotypes = np.genfromtxt(os.path.join(webqtlConfig.TMPDIR, # self.dataset.group.name + '.snps.new')).T - print("pheno_vector is:", pf(pheno_vector.shape)) - print("genotypes is:", pf(genotypes.shape)) + #print("pheno_vector is:", pf(pheno_vector.shape)) + #print("genotypes is:", pf(genotypes.shape)) kinship_matrix = lmm.calculateKinship(genotypes) - print("kinship_matrix is:", pf(kinship_matrix)) + #print("kinship_matrix is:", pf(kinship_matrix)) lmm_ob = lmm.LMM(pheno_vector, kinship_matrix) lmm_ob.fit() diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 33ea6e86..720515c1 100755 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -38,7 +38,7 @@ class ShowTrait(object): print("in ShowTrait, kw are:", kw) self.trait_id = kw['trait_id'] - helper_functions.get_dataset_and_trait(self, kw) + helper_functions.get_species_dataset_trait(self, kw) #self.dataset = create_dataset(kw['dataset']) # diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.coffee b/wqflask/wqflask/static/new/javascript/marker_regression.coffee index 41632723..6bdb3ac6 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.coffee +++ b/wqflask/wqflask/static/new/javascript/marker_regression.coffee @@ -4,7 +4,9 @@ $ -> constructor: -> @qtl_results = js_data.qtl_results + @chromosomes = js_data.chromosomes @max_chr = @get_max_chr() + @cumulative_chr_lengths = @get_cumulative_chr_lengths() @plot_height = 500 @plot_width = 1000 @@ -31,9 +33,22 @@ $ -> max_chr = chr return max_chr + get_cumulative_chr_lengths: () -> + cumulative_chr_lengths = [] + total_length = 0 + for key of @chromosomes + this_length = @chromosomes[key] + cumulative_chr_lengths.push(total_length + this_length) + total_length += this_length + console.log("lengths:", cumulative_chr_lengths) + return cumulative_chr_lengths + get_coordinates: () -> + total_length = 0 + chr_lengths = [] for result in js_data.qtl_results + chr_length = @chromosomes[result.chr] chr = parseInt(result.chr) if _.isNaN(chr) if result.chr == "X" @@ -41,9 +56,17 @@ $ -> else if result.chr == "Y" chr = @max_chr + 2 - @x_coords.push(((chr-1) * 200) + parseFloat(result.Mb)) + @x_coords.push(total_length + parseFloat(result.Mb)) @y_coords.push(result.lrs_value) @marker_names.push(result.name) + + if chr_length in chr_lengths + continue + else + chr_lengths.push(chr_length) + total_length += chr_length + + console.log("chr_lengths are:", @chr_lengths) display_info: (d) -> @@ -56,20 +79,20 @@ $ -> .attr("width", @plot_width) .attr("height", @plot_height) - svg.selectAll("text") - .data(@plot_coordinates) - .enter() - .append("text") - .attr("x", (d) => - return (@plot_width * d[0]/@x_max) - ) - .attr("y", (d) => - return @plot_height - ((0.8*@plot_height) * d[1]/@y_max) - ) - .text((d) => d[2]) - .attr("font-family", "sans-serif") - .attr("font-size", "12px") - .attr("fill", "black"); + #svg.selectAll("text") + # .data(@plot_coordinates) + # .enter() + # .append("text") + # .attr("x", (d) => + # return (@plot_width * d[0]/@x_max) + # ) + # .attr("y", (d) => + # return @plot_height - ((0.8*@plot_height) * d[1]/@y_max) + # ) + # .text((d) => d[2]) + # .attr("font-family", "sans-serif") + # .attr("font-size", "12px") + # .attr("fill", "black"); svg.selectAll("circle") .data(@plot_coordinates) @@ -116,7 +139,7 @@ $ -> ) .on("mouseout", () => d3.select(d3.event.target).classed("d3_highlight", false) - .attr("r", 2) + .attr("r", 2) .attr("fill", "black") ) .attr("title", "foobar") @@ -132,7 +155,7 @@ $ -> .range([0, @plot_height]) svg.selectAll("line") - .data(x.ticks(@max_chr)) + .data(@cumulative_chr_lengths) .enter() .append("line") .attr("x1", x) diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.js b/wqflask/wqflask/static/new/javascript/marker_regression.js index 68e04034..19fec21e 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.js +++ b/wqflask/wqflask/static/new/javascript/marker_regression.js @@ -1,5 +1,6 @@ // Generated by CoffeeScript 1.3.3 (function() { + var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; $(function() { var Manhattan_Plot; @@ -7,7 +8,9 @@ function Manhattan_Plot() { this.qtl_results = js_data.qtl_results; + this.chromosomes = js_data.chromosomes; this.max_chr = this.get_max_chr(); + this.cumulative_chr_lengths = this.get_cumulative_chr_lengths(); this.plot_height = 500; this.plot_width = 1000; this.x_coords = []; @@ -37,12 +40,27 @@ return max_chr; }; + Manhattan_Plot.prototype.get_cumulative_chr_lengths = function() { + var cumulative_chr_lengths, key, this_length, total_length; + cumulative_chr_lengths = []; + total_length = 0; + for (key in this.chromosomes) { + this_length = this.chromosomes[key]; + cumulative_chr_lengths.push(total_length + this_length); + total_length += this_length; + } + console.log("lengths:", cumulative_chr_lengths); + return cumulative_chr_lengths; + }; + Manhattan_Plot.prototype.get_coordinates = function() { - var chr, result, _i, _len, _ref, _results; + var chr, chr_length, chr_lengths, result, total_length, _i, _len, _ref; + total_length = 0; + chr_lengths = []; _ref = js_data.qtl_results; - _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; + chr_length = this.chromosomes[result.chr]; chr = parseInt(result.chr); if (_.isNaN(chr)) { if (result.chr === "X") { @@ -51,11 +69,17 @@ chr = this.max_chr + 2; } } - this.x_coords.push(((chr - 1) * 200) + parseFloat(result.Mb)); + this.x_coords.push(total_length + parseFloat(result.Mb)); this.y_coords.push(result.lrs_value); - _results.push(this.marker_names.push(result.name)); + this.marker_names.push(result.name); + if (__indexOf.call(chr_lengths, chr_length) >= 0) { + continue; + } else { + chr_lengths.push(chr_length); + total_length += chr_length; + } } - return _results; + return console.log("chr_lengths are:", this.chr_lengths); }; Manhattan_Plot.prototype.display_info = function(d) { @@ -66,13 +90,6 @@ var svg, x, y, _this = this; svg = d3.select("#manhattan_plots").append("svg").style('border', '2px solid black').attr("width", this.plot_width).attr("height", this.plot_height); - svg.selectAll("text").data(this.plot_coordinates).enter().append("text").attr("x", function(d) { - return _this.plot_width * d[0] / _this.x_max; - }).attr("y", function(d) { - return _this.plot_height - ((0.8 * _this.plot_height) * d[1] / _this.y_max); - }).text(function(d) { - return d[2]; - }).attr("font-family", "sans-serif").attr("font-size", "12px").attr("fill", "black"); svg.selectAll("circle").data(this.plot_coordinates).enter().append("circle").attr("cx", function(d) { return _this.plot_width * d[0] / _this.x_max; }).attr("cy", function(d) { @@ -84,7 +101,7 @@ }).attr("title", "foobar"); x = d3.scale.linear().domain([0, this.x_max]).range([0, this.plot_width]); y = d3.scale.linear().domain([0, this.y_max]).range([0, this.plot_height]); - return svg.selectAll("line").data(x.ticks(this.max_chr)).enter().append("line").attr("x1", x).attr("x2", x).attr("y1", 0).attr("y2", this.plot_height).style("stroke", "#ccc"); + return svg.selectAll("line").data(this.cumulative_chr_lengths).enter().append("line").attr("x1", x).attr("x2", x).attr("y1", 0).attr("y2", this.plot_height).style("stroke", "#ccc"); }; return Manhattan_Plot; diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 81777742..5f2df8a4 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -154,7 +154,7 @@ def marker_regression_page(): template_vars.js_data = json.dumps(template_vars.js_data, default=json_default_handler, indent=" ") - print("[dub] js_data after dump:", template_vars.js_data) + #print("[dub] js_data after dump:", template_vars.js_data) #print("marker_regression template_vars:", pf(template_vars.__dict__)) return render_template("marker_regression.html", **template_vars.__dict__) |