From c540d661c9603f33b46edf2f6c8fd6b95bab8b38 Mon Sep 17 00:00:00 2001
From: zsloan
Date: Thu, 29 Aug 2019 17:09:46 -0500
Subject: Fixed issue where LOD to LRS conversions weren't showing up correctly
 in the table

Fixed issue where non-LOCO GEMMA wasn't working correctly
---
 .../wqflask/marker_regression/display_mapping_results.py | 10 +++++-----
 wqflask/wqflask/marker_regression/gemma_mapping.py       |  2 +-
 wqflask/wqflask/marker_regression/run_mapping.py         | 16 ++++++++--------
 wqflask/wqflask/templates/mapping_results.html           |  4 ++--
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py
index 1d5843d4..911219f4 100644
--- a/wqflask/wqflask/marker_regression/display_mapping_results.py
+++ b/wqflask/wqflask/marker_regression/display_mapping_results.py
@@ -229,10 +229,10 @@ class DisplayMappingResults(object):
             self.covariates = start_vars['covariates']
         if 'maf' in start_vars.keys():
             self.maf = start_vars['maf']
+        if 'output_files' in start_vars.keys():
+            self.output_files = start_vars['output_files']
         if 'use_loco' in start_vars.keys() and self.mapping_method == "gemma":
             self.use_loco = start_vars['use_loco']
-            if self.use_loco == "True":
-                self.output_files = start_vars['output_files']
 
         if 'reaper_version' in start_vars.keys() and self.mapping_method == "reaper":
             self.reaper_version = start_vars['reaper_version']
@@ -1702,7 +1702,7 @@ class DisplayMappingResults(object):
         #ZS: Needed to pass to genome browser
         js_data = json.loads(self.js_data)
         if self.LRS_LOD == "LRS":
-            js_data['max_score'] = LRS_LOD_Max/4.16
+            js_data['max_score'] = LRS_LOD_Max/4.61
         else:
             js_data['max_score'] = LRS_LOD_Max
         self.js_data = json.dumps(js_data)
@@ -2068,9 +2068,9 @@ class DisplayMappingResults(object):
         #########################################
         myCanvas = pid.PILCanvas(size=(400,300))
         if 'lod_score' in self.qtlresults[0] and self.LRS_LOD == "LRS":
-            perm_output = [value*4.16 for value in self.perm_output]
+            perm_output = [value*4.61 for value in self.perm_output]
         elif 'lod_score' not in self.qtlresults[0] and self.LRS_LOD == "LOD":
-            perm_output = [value/4.16 for value in self.perm_output]
+            perm_output = [value/4.61 for value in self.perm_output]
         else:
             perm_output = self.perm_output
 
diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py
index 8d59a392..5b34e837 100644
--- a/wqflask/wqflask/marker_regression/gemma_mapping.py
+++ b/wqflask/wqflask/marker_regression/gemma_mapping.py
@@ -109,7 +109,7 @@ def run_gemma(this_trait, this_dataset, samples, vals, covariates, use_loco, maf
         return marker_obs, gwa_output_filename
     else:
         marker_obs = parse_loco_output(this_dataset, gwa_output_filename)
-        return marker_obs
+        return marker_obs, gwa_output_filename
 
 def gen_pheno_txt_file(this_dataset, genofile_name, vals, trait_filename):
     """Generates phenotype file for GEMMA"""
diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py
index af5d0206..56d901fc 100644
--- a/wqflask/wqflask/marker_regression/run_mapping.py
+++ b/wqflask/wqflask/marker_regression/run_mapping.py
@@ -181,18 +181,18 @@ class RunMapping(object):
         self.dataset.group.get_markers()
         if self.mapping_method == "gemma":
             self.first_run = True
-            self.output_files= None
+            self.output_files = None
+            if 'output_files' in start_vars:
+                self.output_files = start_vars['output_files']
             if 'first_run' in start_vars: #ZS: check if first run so existing result files can be used if it isn't (for example zooming on a chromosome, etc)
                 self.first_run = False
-                if 'output_files' in start_vars:
-                    self.output_files = start_vars['output_files']
             self.score_type = "-log(p)"
             self.manhattan_plot = True
             with Bench("Running GEMMA"):
                 if self.use_loco == "True":
                     marker_obs, self.output_files = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run, self.output_files)
                 else:
-                    marker_obs = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run)
+                    marker_obs, self.output_files = gemma_mapping.run_gemma(self.this_trait, self.dataset, self.samples, self.vals, self.covariates, self.use_loco, self.maf, self.first_run, self.output_files)
             results = marker_obs
         elif self.mapping_method == "rqtl_plink":
             results = self.run_rqtl_plink()
@@ -397,7 +397,7 @@ class RunMapping(object):
 
               if self.mapping_method != "gemma":
                   if self.score_type == "LRS":
-                      significant_for_browser = self.significant / 4.16
+                      significant_for_browser = self.significant / 4.61
                   else:
                       significant_for_browser = self.significant
 
@@ -521,15 +521,15 @@ def trim_markers_for_figure(markers):
             else:
                 filtered_markers.append(marker)
         else:
-            if marker[score_type] < 4.16:
+            if marker[score_type] < 4.61:
                 if low_counter % 20 == 0:
                     filtered_markers.append(marker)
                 low_counter += 1
-            elif 4.16 <= marker[score_type] < (2*4.16):
+            elif 4.61 <= marker[score_type] < (2*4.61):
                 if med_counter % 10 == 0:
                     filtered_markers.append(marker)
                 med_counter += 1
-            elif (2*4.16) <= marker[score_type] <= (3*4.16):
+            elif (2*4.61) <= marker[score_type] <= (3*4.61):
                 if high_counter % 2 == 0:
                     filtered_markers.append(marker)
                 high_counter += 1
diff --git a/wqflask/wqflask/templates/mapping_results.html b/wqflask/wqflask/templates/mapping_results.html
index 189f8abc..373bae1e 100644
--- a/wqflask/wqflask/templates/mapping_results.html
+++ b/wqflask/wqflask/templates/mapping_results.html
@@ -250,11 +250,11 @@
                 {% if 'lod_score' in marker %}
                 <td align="right">{{ '%0.2f' | format(marker.lod_score|float) }}</td>
                 {% else %}
-                <td align="right">{{ '%0.2f' | format(marker.lrs_value|float / 4.16) }}</td>
+                <td align="right">{{ '%0.2f' | format(marker.lrs_value|float / 4.61) }}</td>
                 {% endif %}
                 {% else %}
                 {% if 'lod_score' in marker %}
-                <td align="right">{{ '%0.2f' | format(marker.lod_score|float * 4.16) }}</td>
+                <td align="right">{{ '%0.2f' | format(marker.lod_score|float * 4.61) }}</td>
                 {% else %}
                 <td align="right">{{ '%0.2f' | format(marker.lrs_value|float) }}</td>
                 {% endif %}
-- 
cgit v1.2.3