about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xwqflask/wqflask/interval_mapping/interval_mapping.py97
-rwxr-xr-xwqflask/wqflask/marker_regression/marker_regression.py1
-rw-r--r--wqflask/wqflask/my_pylmm/pyLMM/lmm.py2
-rw-r--r--wqflask/wqflask/static/new/css/interval_mapping.css21
-rw-r--r--wqflask/wqflask/static/new/css/marker_regression.css4
-rw-r--r--wqflask/wqflask/static/new/javascript/bar_chart.coffee326
-rw-r--r--wqflask/wqflask/static/new/javascript/bar_chart.js196
-rw-r--r--wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee2
-rw-r--r--wqflask/wqflask/static/new/javascript/dataset_select_menu.js2
-rw-r--r--wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee10
-rw-r--r--wqflask/wqflask/static/new/javascript/get_traits_from_collection.js10
-rw-r--r--wqflask/wqflask/static/new/javascript/interval_mapping.coffee70
-rw-r--r--wqflask/wqflask/static/new/javascript/interval_mapping.js31
-rw-r--r--wqflask/wqflask/static/new/javascript/marker_regression.coffee8
-rw-r--r--wqflask/wqflask/static/new/javascript/marker_regression.js7
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.coffee9
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js7
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee5
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js7
-rw-r--r--wqflask/wqflask/templates/collections/list.html2
-rw-r--r--wqflask/wqflask/templates/interval_mapping.html15
-rw-r--r--wqflask/wqflask/templates/show_trait.html6
-rw-r--r--wqflask/wqflask/templates/show_trait_mapping_tools.html16
-rw-r--r--wqflask/wqflask/templates/show_trait_statistics_new.html22
-rw-r--r--wqflask/wqflask/views.py1
25 files changed, 599 insertions, 278 deletions
diff --git a/wqflask/wqflask/interval_mapping/interval_mapping.py b/wqflask/wqflask/interval_mapping/interval_mapping.py
index de7a2704..f0985cc2 100755
--- a/wqflask/wqflask/interval_mapping/interval_mapping.py
+++ b/wqflask/wqflask/interval_mapping/interval_mapping.py
@@ -37,8 +37,6 @@ class IntervalMapping(object):
 
     def __init__(self, start_vars, temp_uuid):
 
-        print("TESTING!!!")
-
         #Currently only getting trait data for one trait, but will need
         #to change this to accept multiple traits once the collection page is implemented
         helper_functions.get_species_dataset_trait(self, start_vars)
@@ -57,7 +55,11 @@ class IntervalMapping(object):
  
         self.set_options(start_vars)
  
-        self.gen_qtl_results(tempdata)
+        if self.method == "qtl_reaper":
+            self.gen_reaper_results(tempdata)
+        else:
+            self.gen_pylmm_results(tempdata)
+        #self.gen_qtl_results(tempdata)
 
         #Get chromosome lengths for drawing the interval map plot
         chromosome_mb_lengths = {}
@@ -78,6 +80,7 @@ class IntervalMapping(object):
         #self.plot_scale = start_vars['scale']
         #if self.plotScale == 'physic' and not fd.genotype.Mbmap:
         #    self.plotScale = 'morgan'
+        self.method = start_vars['mapping_method']
         self.num_permutations = int(start_vars['num_permutations'])
         #self.do_bootstrap = start_vars['do_bootstrap']
         self.selected_chr = start_vars['chromosome']
@@ -125,9 +128,6 @@ class IntervalMapping(object):
             #                                                  variance = variances,
             #                                                  control = self.control_locus)
             #else:
-            #reaper_results = self.dataset.group.genotype.regression(strains = trimmed_samples,
-            #                                              trait = trimmed_values,
-            #                                              control = self.control_locus)
             reaper_results = genotype.regression(strains = trimmed_samples,
                                                           trait = trimmed_values,
                                                           control = self.control_locus)
@@ -139,8 +139,6 @@ class IntervalMapping(object):
             #else:
             print("strains:", trimmed_samples)
             print("trait:", trimmed_values)
-            #reaper_results = self.dataset.group.genotype.regression(strains = trimmed_samples,
-            #                                              trait = trimmed_values)
             reaper_results = genotype.regression(strains = trimmed_samples,
                                                           trait = trimmed_values)
 
@@ -152,29 +150,70 @@ class IntervalMapping(object):
             qtl = {"lrs": qtl.lrs, "locus": locus, "additive": qtl.additive}
             self.qtl_results.append(qtl)
 
-        #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, 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)
-        #
-        #genotype_matrix = np.array(trimmed_genotype_data).T
-        
-        #t_stats, p_values = lmm.run(
-        #    pheno_vector,
-        #    genotype_matrix,
-        #    restricted_max_likelihood=True,
-        #    refit=False,
-        #    temp_data=tempdata
-        #)
-        
-        #self.dataset.group.markers.add_pvalues(p_values)
+    def gen_reaper_results(self, tempdata):
+        genotype = self.dataset.group.read_genotype_file()
+
+        samples, values, variances = self.this_trait.export_informative()
+
+        trimmed_samples = []
+        trimmed_values = []
+        for i in range(0, len(samples)):
+            if samples[i] in self.dataset.group.samplelist:
+                trimmed_samples.append(samples[i])
+                trimmed_values.append(values[i])
+                
+        self.lrs_array = genotype.permutation(strains = trimmed_samples,
+                                                   trait = trimmed_values, 
+                                                   nperm= self.num_permutations)
+        self.suggestive = self.lrs_array[int(self.num_permutations*0.37-1)]
+        self.significant = self.lrs_array[int(self.num_permutations*0.95-1)]
+
+        print("samples:", trimmed_samples)
+
+        if self.control_locus:
+            reaper_results = genotype.regression(strains = trimmed_samples,
+                                                          trait = trimmed_values,
+                                                          control = self.control_locus)
+        else:
+            reaper_results = genotype.regression(strains = trimmed_samples,
+                                                          trait = trimmed_values)
+
+        #Need to convert the QTL objects that qtl reaper returns into a json serializable dictionary
+        self.qtl_results = []
+        for qtl in reaper_results:
+            reaper_locus = qtl.locus
+            locus = {"name":reaper_locus.name, "chr":reaper_locus.chr, "cM":reaper_locus.cM, "Mb":reaper_locus.Mb}
+            qtl = {"lrs_value": qtl.lrs, "chr":reaper_locus.chr, "Mb":reaper_locus.Mb,
+                   "cM":reaper_locus.cM, "name":reaper_locus.name, "additive":qtl.additive}
+            self.qtl_results.append(qtl)
+            
+    def gen_pylmm_results(self, tempdata):
+        print("USING PYLMM")
+        self.dataset.group.get_markers()
         
-        #self.qtl_results = self.dataset.group.markers.markers
+        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, 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)
+            
+            genotype_matrix = np.array(trimmed_genotype_data).T
+            
+            t_stats, p_values = lmm.run(
+                pheno_vector,
+                genotype_matrix,
+                restricted_max_likelihood=True,
+                refit=False,
+                temp_data=tempdata
+            )
+            
+            print("p_values:", p_values)
+            self.dataset.group.markers.add_pvalues(p_values)
+            self.qtl_results = self.dataset.group.markers.markers
 
     def gen_qtl_results_2(self, tempdata):
         """Generates qtl results for plotting interval map"""
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index 334ce631..006c586b 100755
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -91,7 +91,6 @@ class MarkerRegression(object):
             )
         
         self.dataset.group.markers.add_pvalues(p_values)
-
         self.qtl_results = self.dataset.group.markers.markers
 
 
diff --git a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
index 6ef1669b..60d36b8d 100644
--- a/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
+++ b/wqflask/wqflask/my_pylmm/pyLMM/lmm.py
@@ -107,8 +107,6 @@ def run_human(pheno_vector,
 
         with Bench("Create list of inputs"):
             inputs = list(plink_input)
-            
-        print("len(genotypes): ", len(inputs))
 
         with Bench("Divide into chunks"):
             results = chunks.divide_into_chunks(inputs, 64)
diff --git a/wqflask/wqflask/static/new/css/interval_mapping.css b/wqflask/wqflask/static/new/css/interval_mapping.css
index 9d23ba25..5ebf7742 100644
--- a/wqflask/wqflask/static/new/css/interval_mapping.css
+++ b/wqflask/wqflask/static/new/css/interval_mapping.css
@@ -1,27 +1,32 @@
-.manhattan_plot .y_axis path,

-.manhattan_plot .y_axis line {

+.interval_map .y_axis path,

+.interval_map .y_axis line {

     fill: none;

     stroke: black;

     shape-rendering: crispEdges;

 }

-.manhattan_plot .y_axis text {

+.interval_map .y_axis text {

     font-family: sans-serif;

     font-size: 14px;

 }

 

-.manhattan_plot .x_axis path,

-.manhattan_plot .x_axis line {

+.interval_map .x_axis path,

+.interval_map .x_axis line {

     fill: none;

     stroke: black;

     shape-rendering: crispEdges;

 }

-.manhattan_plot .x_axis text {

+.interval_map .x_axis text {

     text-anchor: end;

     font-family: sans-serif;

     font-size: 8px;

 }

 

-rect {

+interval_map rect {

     stroke: WhiteSmoke;

-    fill: lightgrey;

+    fill: white;

+}

+

+interval_map path {

+    stroke: steelblue;

+    stroke-width: 1;

 }
\ No newline at end of file
diff --git a/wqflask/wqflask/static/new/css/marker_regression.css b/wqflask/wqflask/static/new/css/marker_regression.css
index 054ef93e..a737c97e 100644
--- a/wqflask/wqflask/static/new/css/marker_regression.css
+++ b/wqflask/wqflask/static/new/css/marker_regression.css
@@ -21,10 +21,10 @@
     font-size: 8px;
 }
 
-rect {
+/*rect {
     stroke: WhiteSmoke;
     fill: lightgrey;
-}
+}*/
 /*rect {
     stroke: WhiteSmoke;
     fill: Azure;
diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.coffee b/wqflask/wqflask/static/new/javascript/bar_chart.coffee
index 412185d8..e1bb36e1 100644
--- a/wqflask/wqflask/static/new/javascript/bar_chart.coffee
+++ b/wqflask/wqflask/static/new/javascript/bar_chart.coffee
@@ -2,11 +2,12 @@ root = exports ? this
 
 class Bar_Chart
     constructor: (@sample_list, @sample_group) ->
+        @sort_by = "name"
         @get_samples()
         console.log("sample names:", @sample_names)
         if @sample_attr_vals.length > 0
             @get_distinct_attr_vals()
-            @get_attr_color_dict()
+            @get_attr_color_dict(@distinct_attr_vals)
         
         #Used to calculate the bottom margin so sample names aren't cut off
         longest_sample_name = d3.max(sample.length for sample in @sample_names)
@@ -28,17 +29,19 @@ class Bar_Chart
         @create_graph()
         
         d3.select("#color_attribute").on("change", =>
-            attribute = $("#color_attribute").val()
-            if $("#update_bar_chart").html() == 'Sort By Name' 
+            @attribute = $("#color_attribute").val()
+            console.log("attr_color_dict:", @attr_color_dict)
+            #if $("#update_bar_chart").html() == 'Sort By Name'
+            if @sort_by = "name" 
                 @svg.selectAll(".bar")
                     .data(@sorted_samples())
                     .transition()
                     .duration(1000)
                     .style("fill", (d) =>
-                        if attribute == "None"
+                        if @attribute == "None"
                             return "steelblue"
                         else
-                            return @attr_color_dict[attribute][d[2][attribute]]
+                            return @attr_color_dict[@attribute][d[2][@attribute]]
                     )
                     .select("title")
                     .text((d) =>
@@ -50,86 +53,196 @@ class Bar_Chart
                     .transition()
                     .duration(1000)
                     .style("fill", (d) =>
-                        if attribute == "None"
+                        if @attribute == "None"
                             return "steelblue"
                         else
-                            return @attr_color_dict[attribute][d[2][attribute]]
+                            return @attr_color_dict[@attribute][d[2][@attribute]]
                     )
-            @add_legend(attribute, @distinct_attr_vals[attribute])
+            @add_legend(@attribute, @distinct_attr_vals[@attribute])
         )
-    
-    
-        d3.select("#update_bar_chart").on("click", =>
-            if @attributes.length > 0
-                attribute = $("#color_attribute").val()
-            if $("#update_bar_chart").html() == 'Sort By Value' 
-                $("#update_bar_chart").html('Sort By Name')
-                sortItems = (a, b) ->
-                    return a[1] - b[1]
 
-                @svg.selectAll(".bar")
-                    .data(@sorted_samples())
-                    .transition()
-                    .duration(1000)
-                    .attr("y", (d) =>
-                        return @y_scale(d[1])
-                    )
-                    .attr("height", (d) =>
-                        return @plot_height - @y_scale(d[1])
-                    )
-                    .style("fill", (d) =>
-                        if @attributes.length > 0
-                            return @attr_color_dict[attribute][d[2][attribute]]
-                        else
-                            return "steelblue"
-                    )
-                    .select("title")
-                    .text((d) =>
-                        return d[1]
-                    )
-                sorted_sample_names = (sample[0] for sample in @sorted_samples())
-                x_scale = d3.scale.ordinal()
-                    .domain(sorted_sample_names)
-                    .rangeBands([0, @plot_width], .1)
-                $('.x.axis').remove()
-                @add_x_axis(x_scale)
-            else
-                $("#update_bar_chart").html('Sort By Value')
-                @svg.selectAll(".bar")
-                    .data(@samples)
-                    .transition()
-                    .duration(1000)
-                    .attr("y", (d) =>
-                        return @y_scale(d[1])
-                    )
-                    .attr("height", (d) =>
-                        return @plot_height - @y_scale(d[1])
-                    )
-                    .style("fill", (d) =>
-                        if @attributes.length > 0
-                            return @attr_color_dict[attribute][d[2][attribute]]
-                        else
-                            return "steelblue"
-                    )
-                    .select("title")
-                    .text((d) =>
-                        return d[1]
-                    )
-                x_scale = d3.scale.ordinal()
-                    .domain(@sample_names)
-                    .rangeBands([0, @plot_width], .1)
-                $('.x.axis').remove()
-                @add_x_axis(x_scale)
+        $(".sort_by_value").on("click", =>
+            console.log("sorting by value")
+            @sort_by = "value"
+            if @attributes.length > 0
+                @attribute = $("#color_attribute").val()
+            #sortItems = (a, b) ->
+            #    return a[1] - b[1]
+            @rebuild_bar_graph(@sorted_samples())
+            #@svg.selectAll(".bar")
+            #    .data(@sorted_samples())
+            #    .transition()
+            #    .duration(1000)
+            #    .attr("y", (d) =>
+            #        return @y_scale(d[1])
+            #    )
+            #    .attr("height", (d) =>
+            #        return @plot_height - @y_scale(d[1])
+            #    )
+            #    .select("title")
+            #    .text((d) =>
+            #        return d[1]
+            #    )
+            #    #.style("fill", (d) =>
+            #    #    if @attributes.length > 0
+            #    #        return @attr_color_dict[attribute][d[2][attribute]]
+            #    #    else
+            #    #        return "steelblue"
+            #    #)
+            #sorted_sample_names = (sample[0] for sample in @sorted_samples())
+            #x_scale = d3.scale.ordinal()
+            #    .domain(sorted_sample_names)
+            #    .rangeBands([0, @plot_width], .1)
+            #$('.x.axis').remove()
+            #@add_x_axis(x_scale)
+        )
+        
+        $(".sort_by_name").on("click", =>
+            console.log("sorting by name")
+            @sort_by = "name"
+            if @attributes.length > 0
+                @attribute = $("#color_attribute").val()
+            @rebuild_bar_graph(@samples)
+            #@svg.selectAll(".bar")
+            #    .data(@samples)
+            #    .transition()
+            #    .duration(1000)
+            #    .attr("y", (d) =>
+            #        return @y_scale(d[1])
+            #    )
+            #    .attr("height", (d) =>
+            #        return @plot_height - @y_scale(d[1])
+            #    )
+            #    .select("title")
+            #    .text((d) =>
+            #        return d[1]
+            #    )
+            #    .style("fill", (d) =>
+            #        if @attributes.length > 0
+            #            return @attr_color_dict[attribute][d[2][attribute]]
+            #        else
+            #            return "steelblue"
+            #    )
+            #x_scale = d3.scale.ordinal()
+            #    .domain(@sample_names)
+            #    .rangeBands([0, @plot_width], .1)
+            #$('.x.axis').remove()
+            #@add_x_axis(x_scale)
         )
         
+        
+        
+        #d3.select(".update_bar_chart").on("click", =>
+        #    console.log("THIS IS:", $(this))
+        #    sort_by = $(this).val()
+        #    console.log("sort_by: ", sort_by)
+        #    if @attributes.length > 0
+        #        attribute = $("#color_attribute").val()
+        #    if sort_by = "value"
+        #        console.log("sorting by value")
+        #        sortItems = (a, b) ->
+        #            return a[1] - b[1]
+        #
+        #        @svg.selectAll(".bar")
+        #            .data(@sorted_samples())
+        #            .transition()
+        #            .duration(1000)
+        #            .attr("y", (d) =>
+        #
+        #                return @y_scale(d[1])
+        #            )
+        #            .attr("height", (d) =>
+        #                return @plot_height - @y_scale(d[1])
+        #            )
+        #            .style("fill", (d) =>
+        #                if @attributes.length > 0
+        #                    return @attr_color_dict[attribute][d[2][attribute]]
+        #                else
+        #                    return "steelblue"
+        #            )
+        #            .select("title")
+        #            .text((d) =>
+        #                return d[1]
+        #            )
+        #        sorted_sample_names = (sample[0] for sample in @sorted_samples())
+        #        x_scale = d3.scale.ordinal()
+        #            .domain(sorted_sample_names)
+        #            .rangeBands([0, @plot_width], .1)
+        #        $('.x.axis').remove()
+        #        @add_x_axis(x_scale)
+        #    else
+        #        console.log("sorting by name")
+        #        #$("#update_bar_chart").html('Sort By Value')
+        #        @svg.selectAll(".bar")
+        #            .data(@samples)
+        #            .transition()
+        #            .duration(1000)
+        #            .attr("y", (d) =>
+        #                return @y_scale(d[1])
+        #            )
+        #            .attr("height", (d) =>
+        #                return @plot_height - @y_scale(d[1])
+        #            )
+        #            .style("fill", (d) =>
+        #                if @attributes.length > 0
+        #                    return @attr_color_dict[attribute][d[2][attribute]]
+        #                else
+        #                    return "steelblue"
+        #            )
+        #            .select("title")
+        #            .text((d) =>
+        #                return d[1]
+        #            )
+        #        x_scale = d3.scale.ordinal()
+        #            .domain(@sample_names)
+        #            .rangeBands([0, @plot_width], .1)
+        #        $('.x.axis').remove()
+        #        @add_x_axis(x_scale)
+        #)
+        
         d3.select("#color_by_trait").on("click", =>
-            @color_by_trait()
+            @open_trait_selection()
+            
         )
 
-    get_attr_color_dict: () ->
+
+    rebuild_bar_graph: (samples) ->
+        console.log("samples:", samples)
+        @svg.selectAll(".bar")
+            .data(samples)
+            .transition()
+            .duration(1000)
+            .attr("y", (d) =>
+                return @y_scale(d[1])
+            )
+            .attr("height", (d) =>
+                return @plot_height - @y_scale(d[1])
+            )
+            .select("title")
+            .text((d) =>
+                return d[1]
+            )
+            .style("fill", (d) =>
+                if @attributes.length > 0 and @attribute != "None"
+                    console.log("@attribute:", @attribute)
+                    console.log("d[2]", d[2])
+                    console.log("the_color:", @attr_color_dict[@attribute][d[2][@attribute]])
+                    return @attr_color_dict[@attribute][d[2][@attribute]]
+                else
+                    return "steelblue"
+            )
+        sample_names = (sample[0] for sample in samples)
+        console.log("sample_names2:", sample_names)
+        x_scale = d3.scale.ordinal()
+            .domain(sample_names)
+            .rangeBands([0, @plot_width], .1)
+        $('.x.axis').remove()
+        @add_x_axis(x_scale)
+
+    get_attr_color_dict: (vals) ->
         @attr_color_dict = {}
-        console.log("distinct_attr_vals:", @distinct_attr_vals)
-        for own key, distinct_vals of @distinct_attr_vals
+        console.log("vals:", vals)
+        for own key, distinct_vals of vals
             this_color_dict = {}
             if distinct_vals.length < 10
                 color = d3.scale.category10()
@@ -137,6 +250,8 @@ class Bar_Chart
                     this_color_dict[value] = color(i)
             else
                 console.log("distinct_values:", distinct_vals)
+                #Check whether all values are numbers, and if they are get a corresponding
+                #color gradient
                 if _.every(distinct_vals, (d) =>
                     if isNaN(d)
                         return false
@@ -146,13 +261,24 @@ class Bar_Chart
                     color_range = d3.scale.linear()
                                     .domain([d3.min(distinct_vals),
                                             d3.max(distinct_vals)])
-                                    .range([0,4])
+                                    .range([0,255])
                     for value, i in distinct_vals
-                        console.log("color_range(value):", color_range(parseInt(value)))
-                        this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value)))
+                        console.log("color_range(value):", parseInt(color_range(value)))
+                        this_color_dict[value] = d3.rgb(parseInt(color_range(value)),0, 0)
+                        #this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value)))
                         #this_color_dict[value] = "rgb(0, 0, " + color_range(parseInt(value)) + ")"
             @attr_color_dict[key] = this_color_dict
 
+    convert_into_colors: (values) ->
+        color_range = d3.scale.linear()
+                        .domain([d3.min(values),
+                                d3.max(values)])
+                        .range([0,255])
+        for value, i in values
+            console.log("color_range(value):", color_range(parseInt(value)))
+            this_color_dict[value] = d3.rgb(color_range(parseInt(value)),0, 0)
+            #this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value)))
+
     get_samples: () ->
         @sample_names = (sample.name for sample in @sample_list when sample.value != null)
         @sample_vals = (sample.value for sample in @sample_list when sample.value != null)
@@ -304,7 +430,7 @@ class Bar_Chart
                             return d
                         )
 
-    color_by_trait: () ->
+    open_trait_selection: () ->
         $('#collections_holder').load('/collections/list?color_by_trait #collections_list', =>
             $.colorbox(
                 inline: true
@@ -317,6 +443,50 @@ class Bar_Chart
             #    console.log("contents:", $(element).contents())
             #    $(element).contents().unwrap()
         )
+    
+    color_by_trait: (trait_sample_data) ->
+        console.log("BXD1:", trait_sample_data["BXD1"])
+        console.log("trait_sample_data:", trait_sample_data)
+        trimmed_samples = @trim_values(trait_sample_data)
+        distinct_values = {}
+        distinct_values["collection_trait"] = @get_distinct_values(trimmed_samples)
+        @get_attr_color_dict(distinct_values)
+        if $("#update_bar_chart").html() == 'Sort By Name' 
+            @svg.selectAll(".bar")
+                .data(@sorted_samples())
+                .transition()
+                .duration(1000)
+                .style("fill", (d) =>
+                    return @attr_color_dict["collection_trait"][trimmed_samples[d[0]]]
+                )
+                .select("title")
+                .text((d) =>
+                    return d[1]
+                )
+        else
+            @svg.selectAll(".bar")
+                .data(@samples)
+                .transition()
+                .duration(1000)
+                .style("fill", (d) =>
+                    return @attr_color_dict["collection_trait"][trimmed_samples[d[0]]]
+                )
+        
+    
+    trim_values: (trait_sample_data) ->
+        trimmed_samples = {}
+        for sample in @sample_names
+            if sample of trait_sample_data
+                trimmed_samples[sample] = trait_sample_data[sample]
+        console.log("trimmed_samples:", trimmed_samples)
+        return trimmed_samples
 
+    get_distinct_values: (samples) ->
+        distinct_values = _.uniq(_.values(samples))
+        console.log("distinct_values:", distinct_values)
+        return distinct_values
+        #distinct_values = []
+        #for sample in samples
+        #    if samples[sample] in distinct_values
 
 root.Bar_Chart = Bar_Chart
\ No newline at end of file
diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.js b/wqflask/wqflask/static/new/javascript/bar_chart.js
index e4279d41..b02ee1da 100644
--- a/wqflask/wqflask/static/new/javascript/bar_chart.js
+++ b/wqflask/wqflask/static/new/javascript/bar_chart.js
@@ -13,11 +13,12 @@
         _this = this;
       this.sample_list = sample_list;
       this.sample_group = sample_group;
+      this.sort_by = "name";
       this.get_samples();
       console.log("sample names:", this.sample_names);
       if (this.sample_attr_vals.length > 0) {
         this.get_distinct_attr_vals();
-        this.get_attr_color_dict();
+        this.get_attr_color_dict(this.distinct_attr_vals);
       }
       longest_sample_name = d3.max((function() {
         var _i, _len, _ref, _results;
@@ -46,100 +47,94 @@
       this.create_scales();
       this.create_graph();
       d3.select("#color_attribute").on("change", function() {
-        var attribute;
-        attribute = $("#color_attribute").val();
-        if ($("#update_bar_chart").html() === 'Sort By Name') {
+        _this.attribute = $("#color_attribute").val();
+        console.log("attr_color_dict:", _this.attr_color_dict);
+        if (_this.sort_by = "name") {
           _this.svg.selectAll(".bar").data(_this.sorted_samples()).transition().duration(1000).style("fill", function(d) {
-            if (attribute === "None") {
+            if (_this.attribute === "None") {
               return "steelblue";
             } else {
-              return _this.attr_color_dict[attribute][d[2][attribute]];
+              return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
             }
           }).select("title").text(function(d) {
             return d[1];
           });
         } else {
           _this.svg.selectAll(".bar").data(_this.samples).transition().duration(1000).style("fill", function(d) {
-            if (attribute === "None") {
+            if (_this.attribute === "None") {
               return "steelblue";
             } else {
-              return _this.attr_color_dict[attribute][d[2][attribute]];
+              return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
             }
           });
         }
-        return _this.add_legend(attribute, _this.distinct_attr_vals[attribute]);
+        return _this.add_legend(_this.attribute, _this.distinct_attr_vals[_this.attribute]);
       });
-      d3.select("#update_bar_chart").on("click", function() {
-        var attribute, sortItems, sorted_sample_names, x_scale;
+      $(".sort_by_value").on("click", function() {
+        console.log("sorting by value");
+        _this.sort_by = "value";
         if (_this.attributes.length > 0) {
-          attribute = $("#color_attribute").val();
+          _this.attribute = $("#color_attribute").val();
         }
-        if ($("#update_bar_chart").html() === 'Sort By Value') {
-          $("#update_bar_chart").html('Sort By Name');
-          sortItems = function(a, b) {
-            return a[1] - b[1];
-          };
-          _this.svg.selectAll(".bar").data(_this.sorted_samples()).transition().duration(1000).attr("y", function(d) {
-            return _this.y_scale(d[1]);
-          }).attr("height", function(d) {
-            return _this.plot_height - _this.y_scale(d[1]);
-          }).style("fill", function(d) {
-            if (_this.attributes.length > 0) {
-              return _this.attr_color_dict[attribute][d[2][attribute]];
-            } else {
-              return "steelblue";
-            }
-          }).select("title").text(function(d) {
-            return d[1];
-          });
-          sorted_sample_names = (function() {
-            var _i, _len, _ref, _results;
-            _ref = this.sorted_samples();
-            _results = [];
-            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-              sample = _ref[_i];
-              _results.push(sample[0]);
-            }
-            return _results;
-          }).call(_this);
-          x_scale = d3.scale.ordinal().domain(sorted_sample_names).rangeBands([0, _this.plot_width], .1);
-          $('.x.axis').remove();
-          return _this.add_x_axis(x_scale);
-        } else {
-          $("#update_bar_chart").html('Sort By Value');
-          _this.svg.selectAll(".bar").data(_this.samples).transition().duration(1000).attr("y", function(d) {
-            return _this.y_scale(d[1]);
-          }).attr("height", function(d) {
-            return _this.plot_height - _this.y_scale(d[1]);
-          }).style("fill", function(d) {
-            if (_this.attributes.length > 0) {
-              return _this.attr_color_dict[attribute][d[2][attribute]];
-            } else {
-              return "steelblue";
-            }
-          }).select("title").text(function(d) {
-            return d[1];
-          });
-          x_scale = d3.scale.ordinal().domain(_this.sample_names).rangeBands([0, _this.plot_width], .1);
-          $('.x.axis').remove();
-          return _this.add_x_axis(x_scale);
+        return _this.rebuild_bar_graph(_this.sorted_samples());
+      });
+      $(".sort_by_name").on("click", function() {
+        console.log("sorting by name");
+        _this.sort_by = "name";
+        if (_this.attributes.length > 0) {
+          _this.attribute = $("#color_attribute").val();
         }
+        return _this.rebuild_bar_graph(_this.samples);
       });
       d3.select("#color_by_trait").on("click", function() {
-        return _this.color_by_trait();
+        return _this.open_trait_selection();
       });
     }
 
-    Bar_Chart.prototype.get_attr_color_dict = function() {
-      var color, color_range, distinct_vals, i, key, this_color_dict, value, _i, _j, _len, _len1, _ref, _results,
+    Bar_Chart.prototype.rebuild_bar_graph = function(samples) {
+      var sample, sample_names, x_scale,
+        _this = this;
+      console.log("samples:", samples);
+      this.svg.selectAll(".bar").data(samples).transition().duration(1000).attr("y", function(d) {
+        return _this.y_scale(d[1]);
+      }).attr("height", function(d) {
+        return _this.plot_height - _this.y_scale(d[1]);
+      }).select("title").text(function(d) {
+        return d[1];
+      }).style("fill", function(d) {
+        if (_this.attributes.length > 0 && _this.attribute !== "None") {
+          console.log("@attribute:", _this.attribute);
+          console.log("d[2]", d[2]);
+          console.log("the_color:", _this.attr_color_dict[_this.attribute][d[2][_this.attribute]]);
+          return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
+        } else {
+          return "steelblue";
+        }
+      });
+      sample_names = (function() {
+        var _i, _len, _results;
+        _results = [];
+        for (_i = 0, _len = samples.length; _i < _len; _i++) {
+          sample = samples[_i];
+          _results.push(sample[0]);
+        }
+        return _results;
+      })();
+      console.log("sample_names2:", sample_names);
+      x_scale = d3.scale.ordinal().domain(sample_names).rangeBands([0, this.plot_width], .1);
+      $('.x.axis').remove();
+      return this.add_x_axis(x_scale);
+    };
+
+    Bar_Chart.prototype.get_attr_color_dict = function(vals) {
+      var color, color_range, distinct_vals, i, key, this_color_dict, value, _i, _j, _len, _len1, _results,
         _this = this;
       this.attr_color_dict = {};
-      console.log("distinct_attr_vals:", this.distinct_attr_vals);
-      _ref = this.distinct_attr_vals;
+      console.log("vals:", vals);
       _results = [];
-      for (key in _ref) {
-        if (!__hasProp.call(_ref, key)) continue;
-        distinct_vals = _ref[key];
+      for (key in vals) {
+        if (!__hasProp.call(vals, key)) continue;
+        distinct_vals = vals[key];
         this_color_dict = {};
         if (distinct_vals.length < 10) {
           color = d3.scale.category10();
@@ -156,11 +151,11 @@
               return true;
             }
           })) {
-            color_range = d3.scale.linear().domain([d3.min(distinct_vals), d3.max(distinct_vals)]).range([0, 4]);
+            color_range = d3.scale.linear().domain([d3.min(distinct_vals), d3.max(distinct_vals)]).range([0, 255]);
             for (i = _j = 0, _len1 = distinct_vals.length; _j < _len1; i = ++_j) {
               value = distinct_vals[i];
-              console.log("color_range(value):", color_range(parseInt(value)));
-              this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value)));
+              console.log("color_range(value):", parseInt(color_range(value)));
+              this_color_dict[value] = d3.rgb(parseInt(color_range(value)), 0, 0);
             }
           }
         }
@@ -169,6 +164,18 @@
       return _results;
     };
 
+    Bar_Chart.prototype.convert_into_colors = function(values) {
+      var color_range, i, value, _i, _len, _results;
+      color_range = d3.scale.linear().domain([d3.min(values), d3.max(values)]).range([0, 255]);
+      _results = [];
+      for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
+        value = values[i];
+        console.log("color_range(value):", color_range(parseInt(value)));
+        _results.push(this_color_dict[value] = d3.rgb(color_range(parseInt(value)), 0, 0));
+      }
+      return _results;
+    };
+
     Bar_Chart.prototype.get_samples = function() {
       var attr_vals, attribute, key, sample, _i, _j, _len, _len1, _ref, _ref1;
       this.sample_names = (function() {
@@ -320,7 +327,7 @@
       });
     };
 
-    Bar_Chart.prototype.color_by_trait = function() {
+    Bar_Chart.prototype.open_trait_selection = function() {
       var _this = this;
       return $('#collections_holder').load('/collections/list?color_by_trait #collections_list', function() {
         $.colorbox({
@@ -331,6 +338,49 @@
       });
     };
 
+    Bar_Chart.prototype.color_by_trait = function(trait_sample_data) {
+      var distinct_values, trimmed_samples,
+        _this = this;
+      console.log("BXD1:", trait_sample_data["BXD1"]);
+      console.log("trait_sample_data:", trait_sample_data);
+      trimmed_samples = this.trim_values(trait_sample_data);
+      distinct_values = {};
+      distinct_values["collection_trait"] = this.get_distinct_values(trimmed_samples);
+      this.get_attr_color_dict(distinct_values);
+      if ($("#update_bar_chart").html() === 'Sort By Name') {
+        return this.svg.selectAll(".bar").data(this.sorted_samples()).transition().duration(1000).style("fill", function(d) {
+          return _this.attr_color_dict["collection_trait"][trimmed_samples[d[0]]];
+        }).select("title").text(function(d) {
+          return d[1];
+        });
+      } else {
+        return this.svg.selectAll(".bar").data(this.samples).transition().duration(1000).style("fill", function(d) {
+          return _this.attr_color_dict["collection_trait"][trimmed_samples[d[0]]];
+        });
+      }
+    };
+
+    Bar_Chart.prototype.trim_values = function(trait_sample_data) {
+      var sample, trimmed_samples, _i, _len, _ref;
+      trimmed_samples = {};
+      _ref = this.sample_names;
+      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+        sample = _ref[_i];
+        if (sample in trait_sample_data) {
+          trimmed_samples[sample] = trait_sample_data[sample];
+        }
+      }
+      console.log("trimmed_samples:", trimmed_samples);
+      return trimmed_samples;
+    };
+
+    Bar_Chart.prototype.get_distinct_values = function(samples) {
+      var distinct_values;
+      distinct_values = _.uniq(_.values(samples));
+      console.log("distinct_values:", distinct_values);
+      return distinct_values;
+    };
+
     return Bar_Chart;
 
   })();
diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee b/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee
index 16590e26..af53bd09 100644
--- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee
+++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.coffee
@@ -104,7 +104,7 @@ $ ->
             defaults =
                 species: "mouse"
                 group: "BXD"
-                type: "Hippocampus"
+                type: "Hippocampus mRNA"
                 dataset: "HC_M2_0606_P"
 
         for item in [['species', 'group']
diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js
index 5c5b433a..3a2f044f 100644
--- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js
+++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js
@@ -111,7 +111,7 @@
         defaults = {
           species: "mouse",
           group: "BXD",
-          type: "Hippocampus",
+          type: "Hippocampus mRNA",
           dataset: "HC_M2_0606_P"
         };
       }
diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee
index f1d41cbe..db398809 100644
--- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee
+++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee
@@ -1,9 +1,11 @@
+root = exports ? this
 
 console.log("before get_traits_from_collection")
 
 # Going to be used to hold collection list
 # So we can repopulate it when the back button is clicked
 collection_list = null
+this_trait_data = null
 
 collection_click = () ->
     console.log("Clicking on:", $(this))
@@ -16,7 +18,7 @@ collection_click = () ->
         url: this_collection_url,
         success: process_traits
       )
-    
+
 trait_click = () ->
     console.log("Clicking on:", $(this))
     trait = $(this).find('.trait').text()
@@ -28,9 +30,12 @@ trait_click = () ->
         url: this_trait_url,
         success: color_by_trait
       )
+    $.colorbox.close()
 
 color_by_trait =  (trait_sample_data, textStatus, jqXHR) ->
-    console.log('in color_by_trait:', trait_sample_data)
+    #trait_sample_data = trait_sample_data
+    #console.log('in color_by_trait:', trait_sample_data)
+    root.bar_chart.color_by_trait(trait_sample_data)
 
 process_traits = (trait_data, textStatus, jqXHR) ->
     console.log('in process_traits with trait_data:', trait_data)
@@ -65,3 +70,4 @@ $ ->
     $(document).on("click", ".collection_line", collection_click)
     $(document).on("click", ".trait_line", trait_click)
     $(document).on("click", "#back_to_collections", back_to_collections)
+    
diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js
index 104c411d..fac543f8 100644
--- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js
+++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js
@@ -1,11 +1,15 @@
 // Generated by CoffeeScript 1.6.1
 (function() {
-  var back_to_collections, collection_click, collection_list, color_by_trait, process_traits, trait_click;
+  var back_to_collections, collection_click, collection_list, color_by_trait, process_traits, root, this_trait_data, trait_click;
+
+  root = typeof exports !== "undefined" && exports !== null ? exports : this;
 
   console.log("before get_traits_from_collection");
 
   collection_list = null;
 
+  this_trait_data = null;
+
   collection_click = function() {
     var this_collection_url;
     console.log("Clicking on:", $(this));
@@ -34,8 +38,10 @@
     });
   };
 
+  $.colorbox.close();
+
   color_by_trait = function(trait_sample_data, textStatus, jqXHR) {
-    return console.log('in color_by_trait:', trait_sample_data);
+    return root.bar_chart.color_by_trait(trait_sample_data);
   };
 
   process_traits = function(trait_data, textStatus, jqXHR) {
diff --git a/wqflask/wqflask/static/new/javascript/interval_mapping.coffee b/wqflask/wqflask/static/new/javascript/interval_mapping.coffee
index 78265f27..81db186b 100644
--- a/wqflask/wqflask/static/new/javascript/interval_mapping.coffee
+++ b/wqflask/wqflask/static/new/javascript/interval_mapping.coffee
@@ -66,30 +66,30 @@ $ ->
                 chr_lengths.push(this_length)

                 cumulative_chr_lengths.push(total_length + this_length)

                 total_length += this_length

-

+    

             console.log("chr_lengths: ", chr_lengths)

-

+    

             return [chr_lengths, cumulative_chr_lengths]

-

+    

         create_coordinates: () -> 

             chr_lengths = []

             chr_seen = []

             for result in js_data.qtl_results

-                if result.locus.chr == "X"

+                if result.chr == "X"

                     chr_length = parseFloat(@chromosomes[20])

                 else

-                    chr_length = parseFloat(@chromosomes[result.locus.chr])

-                if not(result.locus.chr in chr_seen)

-                    chr_seen.push(result.locus.chr) 

+                    chr_length = parseFloat(@chromosomes[result.chr])

+                if not(result.chr in chr_seen)

+                    chr_seen.push(result.chr) 

                     chr_lengths.push(chr_length) 

-                    if result.locus.chr != "1"

+                    if result.chr != "1"

                         @total_length += parseFloat(chr_lengths[chr_lengths.length - 2])

-                @x_coords.push(@total_length + parseFloat(result.locus.Mb))

-                @y_coords.push(result.lrs)

-                @marker_names.push(result.locus.name)

+                @x_coords.push(@total_length + parseFloat(result.Mb))

+                @y_coords.push(result.lrs_value)

+                @marker_names.push(result.name)

             @total_length += parseFloat(chr_lengths[chr_lengths.length-1])

             #console.log("chr_lengths: ", chr_lengths)

-

+    

         create_svg: () ->

             svg = d3.select("#interval_map")

                 .append("svg")

@@ -98,7 +98,7 @@ $ ->
                 .attr("height", @plot_height+@y_buffer)

             

             return svg

-

+    

         create_graph: () ->

             @add_border()

             @add_x_axis()

@@ -107,13 +107,13 @@ $ ->
             @fill_chr_areas()

             @add_chr_labels()

             @connect_markers()

-

+    

         add_border: () ->

             border_coords = [[@y_buffer, @plot_height, @x_buffer, @x_buffer],

                              [@y_buffer, @plot_height, @plot_width, @plot_width],

                              [@y_buffer, @y_buffer, @x_buffer, @plot_width],

                              [@plot_height, @plot_height, @x_buffer, @plot_width]]

-

+    

             @svg.selectAll("line")

                 .data(border_coords)

                 .enter()

@@ -131,16 +131,16 @@ $ ->
                     return d[3]

                 )             

                 .style("stroke", "#000")

-

+    

         create_scales: () ->

             @x_scale = d3.scale.linear()

                 .domain([0, d3.max(@x_coords)])

                 .range([@x_buffer, @plot_width])

-

+    

             @y_scale = d3.scale.linear()

                 .domain([0, @y_max])

                 .range([@plot_height, @y_buffer])

-

+    

         create_x_axis_tick_values: () ->

             tick_vals = []

             for val in [25..@cumulative_chr_lengths[0]] when val%25 == 0

@@ -159,13 +159,13 @@ $ ->
                     

             #console.log("tick_vals:", tick_vals)

             return tick_vals

-

+    

         add_x_axis: () ->

             xAxis = d3.svg.axis()

                     .scale(@x_scale)

                     .orient("bottom")

                     .tickValues(@create_x_axis_tick_values())

-

+    

             next_chr = 1

             tmp_tick_val = 0

             xAxis.tickFormat((d) =>

@@ -183,7 +183,7 @@ $ ->
                         tick_val = tmp_tick_val

                 return (tick_val)

             )

-

+    

             @svg.append("g")

                 .attr("class", "x_axis")

                 .attr("transform", "translate(0," + @plot_height + ")")

@@ -196,7 +196,7 @@ $ ->
                     )

                     #.attr("dy", "-1.0em")                        

                                     

-

+    

         add_y_axis: () ->

             yAxis = d3.svg.axis()

                     .scale(@y_scale)

@@ -207,7 +207,7 @@ $ ->
                 .attr("class", "y_axis")

                 .attr("transform", "translate(" + @x_buffer + ",0)")

                 .call(yAxis)

-

+    

         add_chr_lines: () ->

             @svg.selectAll("line")

                 .data(@cumulative_chr_lengths, (d) =>

@@ -215,10 +215,10 @@ $ ->
                 )

                 .enter()

                 .append("line")

-                .attr("x1", @x_scale)

-                .attr("x2", @x_scale)

                 .attr("y1", @y_buffer)

                 .attr("y2", @plot_height)

+                .attr("x1", @x_scale)

+                .attr("x2", @x_scale)

                 .style("stroke", "#ccc")

                 

         fill_chr_areas: () ->

@@ -239,8 +239,9 @@ $ ->
                 .attr("width", (d) =>

                     return @x_scale(d[0])

                 )

-                .attr("height", @plot_height-@y_buffer)                

-

+                .attr("height", @plot_height-@y_buffer)

+                .attr("fill", "white")

+    

         add_chr_labels: () ->

             chr_names = []

             for key of @chromosomes

@@ -263,12 +264,13 @@ $ ->
                 .attr("text-anchor", "middle")

                 .attr("font-family", "sans-serif")

                 .attr("font-size", "18px")

-                .attr("fill", "grey")

-

+                #.attr("fill", "grey")

+    

         connect_markers: () ->

-            @svg.selectAll("path")

+            @svg.selectAll("line")

                 .data(@plot_coordinates)

                 .enter()

+                .append("line")

                 .attr("x1", (d, i) =>

                     if i == 0

                         return @x_buffer

@@ -287,7 +289,9 @@ $ ->
                 .attr("y2", (d) =>

                     return @plot_height - ((@plot_height-@y_buffer) * d[1]/@y_max)

                 )

-

-    console.time('Create manhattan plot')

+                .style("stroke", "black")

+    

+    console.time('Create interval map')

+    console.log("TESTING")

     new Interval_Map(600, 1200)

-    console.timeEnd('Create manhattan plot')
\ No newline at end of file
+    console.timeEnd('Create interval map')
\ No newline at end of file
diff --git a/wqflask/wqflask/static/new/javascript/interval_mapping.js b/wqflask/wqflask/static/new/javascript/interval_mapping.js
index 5ae8ffab..3a2ce6d7 100644
--- a/wqflask/wqflask/static/new/javascript/interval_mapping.js
+++ b/wqflask/wqflask/static/new/javascript/interval_mapping.js
@@ -85,21 +85,21 @@
         _ref = js_data.qtl_results;
         for (_i = 0, _len = _ref.length; _i < _len; _i++) {
           result = _ref[_i];
-          if (result.locus.chr === "X") {
+          if (result.chr === "X") {
             chr_length = parseFloat(this.chromosomes[20]);
           } else {
-            chr_length = parseFloat(this.chromosomes[result.locus.chr]);
+            chr_length = parseFloat(this.chromosomes[result.chr]);
           }
-          if (!(_ref1 = result.locus.chr, __indexOf.call(chr_seen, _ref1) >= 0)) {
-            chr_seen.push(result.locus.chr);
+          if (!(_ref1 = result.chr, __indexOf.call(chr_seen, _ref1) >= 0)) {
+            chr_seen.push(result.chr);
             chr_lengths.push(chr_length);
-            if (result.locus.chr !== "1") {
+            if (result.chr !== "1") {
               this.total_length += parseFloat(chr_lengths[chr_lengths.length - 2]);
             }
           }
-          this.x_coords.push(this.total_length + parseFloat(result.locus.Mb));
-          this.y_coords.push(result.lrs);
-          this.marker_names.push(result.locus.name);
+          this.x_coords.push(this.total_length + parseFloat(result.Mb));
+          this.y_coords.push(result.lrs_value);
+          this.marker_names.push(result.name);
         }
         return this.total_length += parseFloat(chr_lengths[chr_lengths.length - 1]);
       };
@@ -205,7 +205,7 @@
         var _this = this;
         return this.svg.selectAll("line").data(this.cumulative_chr_lengths, function(d) {
           return d;
-        }).enter().append("line").attr("x1", this.x_scale).attr("x2", this.x_scale).attr("y1", this.y_buffer).attr("y2", this.plot_height).style("stroke", "#ccc");
+        }).enter().append("line").attr("y1", this.y_buffer).attr("y2", this.plot_height).attr("x1", this.x_scale).attr("x2", this.x_scale).style("stroke", "#ccc");
       };
 
       Interval_Map.prototype.fill_chr_areas = function() {
@@ -220,7 +220,7 @@
           }
         }).attr("y", this.y_buffer).attr("width", function(d) {
           return _this.x_scale(d[0]);
-        }).attr("height", this.plot_height - this.y_buffer);
+        }).attr("height", this.plot_height - this.y_buffer).attr("fill", "white");
       };
 
       Interval_Map.prototype.add_chr_labels = function() {
@@ -237,12 +237,12 @@
           return d[0];
         }).attr("x", function(d) {
           return _this.x_scale(d[2] - d[1] / 2);
-        }).attr("y", this.plot_height * 0.1).attr("dx", "0em").attr("text-anchor", "middle").attr("font-family", "sans-serif").attr("font-size", "18px").attr("fill", "grey");
+        }).attr("y", this.plot_height * 0.1).attr("dx", "0em").attr("text-anchor", "middle").attr("font-family", "sans-serif").attr("font-size", "18px");
       };
 
       Interval_Map.prototype.connect_markers = function() {
         var _this = this;
-        return this.svg.selectAll("path").data(this.plot_coordinates).enter().attr("x1", function(d, i) {
+        return this.svg.selectAll("line").data(this.plot_coordinates).enter().append("line").attr("x1", function(d, i) {
           if (i === 0) {
             return _this.x_buffer;
           } else {
@@ -258,15 +258,16 @@
           return parseFloat(_this.x_buffer) + ((parseFloat(_this.plot_width) - parseFloat(_this.x_buffer)) * d[0] / parseFloat(_this.x_max));
         }).attr("y2", function(d) {
           return _this.plot_height - ((_this.plot_height - _this.y_buffer) * d[1] / _this.y_max);
-        });
+        }).style("stroke", "black");
       };
 
       return Interval_Map;
 
     })();
-    console.time('Create manhattan plot');
+    console.time('Create interval map');
+    console.log("TESTING");
     new Interval_Map(600, 1200);
-    return console.timeEnd('Create manhattan plot');
+    return console.timeEnd('Create interval map');
   });
 
 }).call(this);
diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.coffee b/wqflask/wqflask/static/new/javascript/marker_regression.coffee
index 2892987e..f5f13c27 100644
--- a/wqflask/wqflask/static/new/javascript/marker_regression.coffee
+++ b/wqflask/wqflask/static/new/javascript/marker_regression.coffee
@@ -49,10 +49,10 @@ $ ->
 
         get_chr_lengths: () ->
             ###
-            Gets a list of both individual and cumulative (the position of one on the graph
-            is its own length plus the lengths of all preceding chromosomes) lengths in order
-            to draw the vertical lines separating chromosomes and the chromosome labels
-            
+            #Gets a list of both individual and cumulative (the position of one on the graph
+            #is its own length plus the lengths of all preceding chromosomes) lengths in order
+            #to draw the vertical lines separating chromosomes and the chromosome labels
+            #
             ###
             
             console.log("@chromosomes: ", @chromosomes)
diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.js b/wqflask/wqflask/static/new/javascript/marker_regression.js
index ffcf1a75..cdf37671 100644
--- a/wqflask/wqflask/static/new/javascript/marker_regression.js
+++ b/wqflask/wqflask/static/new/javascript/marker_regression.js
@@ -57,9 +57,10 @@
 
       Manhattan_Plot.prototype.get_chr_lengths = function() {
         /*
-        Gets a list of both individual and cumulative (the position of one on the graph
-        is its own length plus the lengths of all preceding chromosomes) lengths in order
-        to draw the vertical lines separating chromosomes and the chromosome labels
+        #Gets a list of both individual and cumulative (the position of one on the graph
+        #is its own length plus the lengths of all preceding chromosomes) lengths in order
+        #to draw the vertical lines separating chromosomes and the chromosome labels
+        #
         */
 
         var chr_lengths, cumulative_chr_lengths, key, this_length, total_length;
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee
index 7d23345f..1df033d6 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.coffee
+++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee
@@ -1,3 +1,5 @@
+root = exports ? this
+
 console.log("start_b")
 
 # this is our isNumber, do not confuse with the underscore.js one
@@ -62,10 +64,10 @@ $ ->
     sample_lists = js_data.sample_lists
     sample_group_types = js_data.sample_group_types
 
-    new Bar_Chart(sample_lists[0])
+    $("#update_bar_chart.btn-group").button()
+    root.bar_chart = new Bar_Chart(sample_lists[0])
     new Box_Plot(sample_lists[0])
 
-
     $('.bar_chart_samples_group').change ->
         $('#bar_chart').remove()
         $('#bar_chart_container').append('<div id="bar_chart"></div>')
@@ -77,7 +79,8 @@ $ ->
         else if group == "samples_all"
             all_samples = sample_lists[0].concat sample_lists[1]
             new Bar_Chart(all_samples)
-            
+        #$(".btn-group").button()
+
     $('.box_plot_samples_group').change ->
         $('#box_plot').remove()
         $('#box_plot_container').append('<div id="box_plot"></div>')
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 718e365a..90fa8228 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -1,9 +1,11 @@
 // Generated by CoffeeScript 1.6.1
 (function() {
-  var Stat_Table_Rows, is_number,
+  var Stat_Table_Rows, is_number, root,
     __hasProp = {}.hasOwnProperty,
     __slice = [].slice;
 
+  root = typeof exports !== "undefined" && exports !== null ? exports : this;
+
   console.log("start_b");
 
   is_number = function(o) {
@@ -59,7 +61,8 @@
     var block_by_attribute_value, block_by_index, block_outliers, change_stats_value, create_value_dropdown, edit_data_change, export_sample_table_data, get_sample_table_data, hide_no_value, hide_tabs, make_table, on_corr_method_change, populate_sample_attributes_values_dropdown, process_id, reset_samples_table, sample_group_types, sample_lists, show_hide_outliers, stats_mdp_change, update_stat_values;
     sample_lists = js_data.sample_lists;
     sample_group_types = js_data.sample_group_types;
-    new Bar_Chart(sample_lists[0]);
+    $("#update_bar_chart.btn-group").button();
+    root.bar_chart = new Bar_Chart(sample_lists[0]);
     new Box_Plot(sample_lists[0]);
     $('.bar_chart_samples_group').change(function() {
       var all_samples, group;
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 8571753e..df9bfc9d 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee
+++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee
@@ -53,6 +53,7 @@ $ ->
         return false
 
     $("#interval_mapping_compute").click(() =>
+        console.log("In interval mapping")
         $("#progress_bar_container").modal()
         url = "/interval_mapping"
         form_data = $('#trait_data_form').serialize()
@@ -118,8 +119,12 @@ $ ->
 
     composite_mapping_fields = ->
         $(".composite_fields").toggle()
+    mapping_method_fields = ->
+        $(".mapping_method_fields").toggle()
+        
 
     $("#use_composite_choice").change(composite_mapping_fields)
+    $("#mapping_method_choice").change(mapping_method_fields)
 
 
     #### Todo: Redo below so its like submit_special and requires no js hardcoding
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 1153b8ef..b474bd80 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js
@@ -5,7 +5,7 @@
   root = typeof exports !== "undefined" && exports !== null ? exports : this;
 
   $(function() {
-    var composite_mapping_fields, get_progress, submit_special, toggle_enable_disable, update_time_remaining,
+    var composite_mapping_fields, get_progress, mapping_method_fields, submit_special, toggle_enable_disable, update_time_remaining,
       _this = this;
     submit_special = function() {
       var url;
@@ -64,6 +64,7 @@
     };
     $("#interval_mapping_compute").click(function() {
       var form_data, url;
+      console.log("In interval mapping");
       $("#progress_bar_container").modal();
       url = "/interval_mapping";
       form_data = $('#trait_data_form').serialize();
@@ -128,7 +129,11 @@
     composite_mapping_fields = function() {
       return $(".composite_fields").toggle();
     };
+    mapping_method_fields = function() {
+      return $(".mapping_method_fields").toggle();
+    };
     $("#use_composite_choice").change(composite_mapping_fields);
+    $("#mapping_method_choice").change(mapping_method_fields);
     toggle_enable_disable = function(elem) {
       return $(elem).prop("disabled", !$(elem).prop("disabled"));
     };
diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html
index ac621a61..354723d0 100644
--- a/wqflask/wqflask/templates/collections/list.html
+++ b/wqflask/wqflask/templates/collections/list.html
@@ -35,7 +35,7 @@
         </table>
 
         {# if "color_by_trait" in params #}
-        <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script>
+<!--        <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script>-->
         {# endif #}
         
         </div>
diff --git a/wqflask/wqflask/templates/interval_mapping.html b/wqflask/wqflask/templates/interval_mapping.html
index 25de2dc1..e4e08388 100644
--- a/wqflask/wqflask/templates/interval_mapping.html
+++ b/wqflask/wqflask/templates/interval_mapping.html
@@ -1,7 +1,6 @@
 {% extends "base.html" %}

 {% block title %}Interval Mapping{% endblock %}

 {% block css %}

-    <link rel="stylesheet" type="text/css" href="/static/packages/jqplot/jquery.jqplot.min.css" />

     <link rel="stylesheet" type="text/css" href="/static/new/css/interval_mapping.css" />

     <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" />

     <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" />

@@ -31,7 +30,9 @@
                 <tr>

                     <td>Index</td>

                     <td>LRS Score</td>

+                    {% if method == "qtl_reaper" %}

                     <td>Additive Effect</td>

+                    {% endif %}

                     <td>Chr</td>

                     <td>Mb</td>

                     <td>Locus</td>

@@ -41,11 +42,13 @@
                 {% for marker in qtl_results %}

                 <tr>

                     <td>{{ loop.index }}</td>

-                    <td>{{ marker.lrs|float }}</td>

+                    <td>{{ marker.lrs_value|float }}</td>

+                    {% if method == "qtl_reaper" %}

                     <td>{{ marker.additive|float }}</td>

-                    <td>{{ marker.locus.chr|int }}</td>

-                    <td>{{ marker.locus.Mb|float  }}</td>

-                    <td>{{ marker.locus.name }}</td>

+                    {% endif %}

+                    <td>{{ marker.chr|int }}</td>

+                    <td>{{ marker.Mb|float  }}</td>

+                    <td>{{ marker.name }}</td>

                 </tr>

                 {% endfor %}

             </tbody>

@@ -63,7 +66,7 @@
     </script>

 

     <!--[if lt IE 9]>

-        <script language="javascript" type="text/javascript" src="/static/packages/jqplot/excanvas.js"></script>

+<!--        <script language="javascript" type="text/javascript" src="/static/packages/jqplot/excanvas.js"></script>-->

     <![endif]-->

     <script language="javascript" type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>

     <script language="javascript" type="text/javascript" src="/static/new/javascript/interval_mapping.js"></script>

diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index ec729e1c..86891bb0 100644
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -2,6 +2,7 @@
 {% block title %}Trait Data and Analysis{% endblock %}
 {% block css %}
     <link rel="stylesheet" type="text/css" href="/static/new/css/marker_regression.css" />
+    <link rel="stylesheet" type="text/css" href="/static/new/css/interval_mapping.css" />
     <link rel="stylesheet" type="text/css" href="/static/new/css/bar_chart.css" />
     <link rel="stylesheet" type="text/css" href="/static/new/css/box_plot.css" />
     <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" />
@@ -55,10 +56,11 @@
 
     <script type="text/javascript" src="/static/new/javascript/stats.js"></script>
     <script type="text/javascript" src="/static/new/javascript/box.js"></script>
+    <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script>    
     <script type="text/javascript" src="/static/new/javascript/bar_chart.js"></script>
     <script type="text/javascript" src="/static/new/javascript/box_plot.js"></script>
-    <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script>
-    <script type="text/javascript" src="/static/new/javascript/show_trait.js"></script>
+    
     <script type="text/javascript" src="/static/new/javascript/show_trait_mapping_tools.js"></script>
+    <script type="text/javascript" src="/static/new/javascript/show_trait.js"></script>
     <script type="text/javascript" src="/static/new/javascript/validation.js"></script>
 {% endblock %}
diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html
index a835a41b..58ee8982 100644
--- a/wqflask/wqflask/templates/show_trait_mapping_tools.html
+++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html
@@ -17,6 +17,16 @@
             <div class="tab-content">
                 <div class="tab-pane active" id="interval_mapping">
                     <div class="control-group">
+                        <label for="mapping_method" class="control-label">Mapping Method</label>
+                        <div class="controls" id="mapping_method_choice">
+                            <select name="mapping_method">
+                                <option value="qtl_reaper">H&K Regression</option>
+                                <option value="pylmm">Linear Mixed</option>
+                            </select>
+                        </div>
+                    </div>
+                    
+                    <div class="control-group">
                         <label for="chromosome" class="control-label">Chromosome</label>
                         <div class="controls">
                             <select name="chromosome">
@@ -28,14 +38,14 @@
                         </div>
                     </div>
     
-                    <div class="control-group">
+                    <div class="control-group mapping_method_fields">
                         <label for="mapping_permutations" class="control-label">Permutations (n)</label>
                         <div class="controls">
                             <input name="num_permutations" value="2000" type="text" />
                         </div>
                     </div>
     
-                    <div class="control-group">
+                    <div class="control-group mapping_method_fields">
                         <label for="mapping_bootstraps" class="control-label"
                                title="Bootstrapping Resamples">Bootstrap (n)</label>
                         <div class="controls">
@@ -44,7 +54,7 @@
                     </div>
 
 
-                    <div class="control-group">
+                    <div class="control-group mapping_method_fields">
                         <label class="control-label"><b>Composite Mapping</b></label>
                         <div class="controls" id="use_composite_choice">                      
                             <label class="radio inline">
diff --git a/wqflask/wqflask/templates/show_trait_statistics_new.html b/wqflask/wqflask/templates/show_trait_statistics_new.html
index 33538626..6d6b1d24 100644
--- a/wqflask/wqflask/templates/show_trait_statistics_new.html
+++ b/wqflask/wqflask/templates/show_trait_statistics_new.html
@@ -30,13 +30,23 @@
                             {% endfor %}
                         </select>
                     </div>
-                    {% endif %}
-                    <button type="button" class="btn" id="update_bar_chart">
+                {% endif %}
+                    <div id="update_bar_chart" class="btn-group">
+                      <button type="button" class="btn btn-default sort_by_name" value="name">
+                        <i class="icon-resize-horizontal"></i> Sort By Name
+                      </button>
+                      <button type="button" class="btn btn-default sort_by_value" value="value">
+                        <i class="icon-signal"></i> Sort By Value
+                      </button>
+                    </div>
+<!--                    <button type="button" class="btn" id="update_bar_chart">
                         <i class="icon-resize-vertical"></i> Sort By Value
-                    </button>
-                    <button type="button" class="btn" id="color_by_trait">
-                        <i class="icon-tint"></i> Color by Trait
-                    </button>
+                    </button>-->
+                    <div class="btn-group">
+                        <button type="button" class="btn" id="color_by_trait">
+                            <i class="icon-tint"></i> Color by Trait
+                        </button>
+                    </div>
                     <div id="bar_chart_container">
                         <div id="bar_chart"></div>
                     </div>
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index b528f2b1..828199c5 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -258,6 +258,7 @@ def interval_mapping_page():
     wanted = (
         'trait_id',
         'dataset',
+        'mapping_method',
         'chromosome',
         'num_permutations',
         'do_bootstraps',