aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2016-04-05 21:46:06 +0000
committerzsloan2016-04-05 21:46:06 +0000
commit77bc01663a38b413d52d39de754b470a804afd97 (patch)
tree09fb331856867d78e2566004469803b44119cfc5
parentba40443dc45d95f77d0c75bf296c5cd38badd0d4 (diff)
downloadgenenetwork2-77bc01663a38b413d52d39de754b470a804afd97.tar.gz
Bootstrap test should now work correctly for qtl reaper mapping method on full genome view
There seems to be some issue with the way it does single chromosome bootstrap tests compared with GN1, though. It seems like GN1 completely re-runs the test for that specific chromosome, while GN2 just takes a subset from the previously calculated bootstraps
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression.py64
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression_gn1.py64
-rw-r--r--wqflask/wqflask/templates/marker_regression_gn1.html2
-rwxr-xr-xwqflask/wqflask/templates/show_trait_mapping_tools.html20
-rw-r--r--wqflask/wqflask/views.py4
5 files changed, 120 insertions, 34 deletions
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index 6ce35a6c..f08e47ca 100644
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -80,6 +80,8 @@ class MarkerRegression(object):
self.score_type = "LRS" #ZS: LRS or LOD
self.mapping_scale = "physic"
self.num_perm = 0
+ self.bootstrap_results = []
+
#ZS: This is passed to GN1 code for single chr mapping
self.selected_chr = -1
@@ -130,7 +132,7 @@ class MarkerRegression(object):
self.num_perm = 0
else:
self.num_perm = start_vars['num_perm']
- self.control = start_vars['control_marker']
+ self.control_marker = start_vars['control_marker']
self.do_control = start_vars['do_control']
self.method = start_vars['mapmethod_rqtl_geno']
self.model = start_vars['mapmodel_rqtl_geno']
@@ -143,17 +145,35 @@ class MarkerRegression(object):
if start_vars['num_perm'] == "":
self.num_perm = 0
else:
- self.num_perm = int(start_vars['num_perm'])
+ self.num_perm = int(start_vars['num_perm'])
if "startMb" in start_vars: #ZS: Check if first time page loaded, so it can default to ON
+ if "bootCheck" in start_vars:
+ self.bootCheck = "ON"
+ self.num_bootstrap = int(start_vars['num_bootstrap'])
+ else:
+ self.bootCheck = False
+ self.num_bootstrap = int(start_vars['num_bootstrap'])
if "additiveCheck" in start_vars:
self.additiveCheck = start_vars['additiveCheck']
else:
self.additiveCheck = False
else:
+ try:
+ if int(start_vars['num_bootstrap']) > 0:
+ self.bootCheck = "ON"
+ self.num_bootstrap = int(start_vars['num_bootstrap'])
+ else:
+ self.bootCheck = False
+ self.num_bootstrap = 0
+ #ZS: If some string that can't be converted to int is input for num_bootstrap
+ except:
+ self.num_bootstrap = 0
+ self.bootCheck = False
+
self.additiveCheck = "ON"
- self.control = start_vars['control_marker']
+ self.control_marker = start_vars['control_marker']
self.do_control = start_vars['do_control']
results = self.gen_reaper_results()
elif self.mapping_method == "plink":
@@ -447,7 +467,7 @@ class MarkerRegression(object):
def create_covariates(self, cross):
ro.globalenv["the_cross"] = cross
ro.r('genotypes <- pull.geno(the_cross)') # Get the genotype matrix
- userinputS = self.control.replace(" ", "").split(",") # TODO: sanitize user input, Never Ever trust a user
+ userinputS = self.control_marker.replace(" ", "").split(",") # TODO: sanitize user input, Never Ever trust a user
covariate_names = ', '.join('"{0}"'.format(w) for w in userinputS)
#print("Marker names of selected covariates:", covariate_names)
ro.r('covnames <- c(' + covariate_names + ')')
@@ -656,14 +676,40 @@ class MarkerRegression(object):
#print("samples:", trimmed_samples)
- if self.control != "" and self.do_control == "true":
- #print("CONTROL IS:", self.control)
+ if self.control_marker != "" and self.do_control == "true":
reaper_results = genotype.regression(strains = trimmed_samples,
- trait = trimmed_values,
- control = str(self.control))
+ trait = trimmed_values,
+ control = str(self.control_marker))
+ if self.bootCheck:
+ control_geno = []
+ control_geno2 = []
+ _FIND = 0
+ for _chr in genotype:
+ for _locus in _chr:
+ if _locus.name == self.control_marker:
+ control_geno2 = _locus.genotype
+ _FIND = 1
+ break
+ if _FIND:
+ break
+ if control_geno2:
+ _prgy = list(genotype.prgy)
+ for _strain in trimmed_samples:
+ _idx = _prgy.index(_strain)
+ control_geno.append(control_geno2[_idx])
+
+ self.bootstrap_results = genotype.bootstrap(strains = trimmed_samples,
+ trait = trimmed_values,
+ control = control_geno,
+ nboot = self.num_bootstrap)
else:
reaper_results = genotype.regression(strains = trimmed_samples,
- trait = trimmed_values)
+ trait = trimmed_values)
+
+ if self.bootCheck:
+ self.bootstrap_results = genotype.bootstrap(strains = trimmed_samples,
+ trait = trimmed_values,
+ nboot = self.num_bootstrap)
self.json_data['chr'] = []
self.json_data['pos'] = []
diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
index 739dc569..99f0ac99 100644
--- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py
+++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
@@ -227,24 +227,34 @@ class MarkerRegression(object):
self.nperm = int(start_vars['num_perm'])
else:
self.nperm = 0
+ if 'num_bootstrap' in start_vars.keys():
+ self.nboot = int(start_vars['num_bootstrap'])
+ else:
+ self.nboot = 0
if (start_vars['num_perm'] == "") or (start_vars['num_perm'] < 1):
self.permChecked = False
else:
self.permChecked = True
#self.permChecked = fd.formdata.getvalue('permCheck', True)
- #self.bootChecked = fd.formdata.getvalue('bootCheck', '')
- self.bootChecked = False #ZS: For now setting to False, I'll add this option later once rest of figure works
+
+ if 'bootCheck' in start_vars.keys():
+ self.bootChecked = start_vars['bootCheck']
+ else:
+ self.bootChecked = False
+ if 'bootstrap_results' in start_vars.keys():
+ self.bootResult = start_vars['bootstrap_results']
+ else:
+ self.bootResult = []
+
if 'do_control' in start_vars.keys():
self.doControl = start_vars['do_control']
else:
self.doControl = "false"
- if 'control' in start_vars.keys():
- self.controlLocus = start_vars['control']
+ if 'control_marker' in start_vars.keys():
+ self.controlLocus = start_vars['control_marker']
else:
self.controlLocus = ""
-
- #self.controlLocus = fd.formdata.getvalue('controlLocus', '')
#try:
self.selectedChr = int(start_vars['selected_chr'])
@@ -795,8 +805,8 @@ class MarkerRegression(object):
plotXScale = self.drawGraphBackground(canvas, gifmap, offset=newoffset, zoom= zoom, startMb=startMb, endMb = endMb)
#draw bootstap
- #if self.bootChecked and not self.multipleInterval:
- # self.drawBootStrapResult(canvas, fd.nboot, drawAreaHeight, plotXScale, offset=newoffset)
+ if self.bootChecked and not self.multipleInterval:
+ self.drawBootStrapResult(canvas, self.nboot, drawAreaHeight, plotXScale, offset=newoffset)
# Draw clickable region and gene band if selected
if self.plotScale == 'physic' and self.selectedChr > -1:
@@ -843,17 +853,31 @@ class MarkerRegression(object):
BootCoord = []
i = 0
startX = xLeftOffset
- for j, _chr in enumerate(self.genotype):
- BootCoord.append( [])
- for _locus in _chr:
- if self.plotScale == 'physic':
- Xc = startX + (_locus.Mb-self.startMb)*plotXScale
- else:
- Xc = startX + (_locus.cM-_chr[0].cM)*plotXScale
- BootCoord[-1].append([Xc, self.bootResult[i]])
- i += 1
- startX += (self.ChrLengthDistList[j] + self.GraphInterval)*plotXScale
-
+
+ if self.selectedChr == -1: #ZS: If viewing full genome/all chromosomes
+ for j, _chr in enumerate(self.genotype):
+ BootCoord.append( [])
+ for _locus in _chr:
+ if self.plotScale == 'physic':
+ Xc = startX + (_locus.Mb-self.startMb)*plotXScale
+ else:
+ Xc = startX + (_locus.cM-_chr[0].cM)*plotXScale
+ BootCoord[-1].append([Xc, self.bootResult[i]])
+ i += 1
+ startX += (self.ChrLengthDistList[j] + self.GraphInterval)*plotXScale
+ else:
+ for j, _chr in enumerate(self.genotype):
+ if _chr.name == self.ChrList[self.selectedChr][0]:
+ BootCoord.append( [])
+ for _locus in _chr:
+ if _chr.name == self.ChrList[self.selectedChr][0]:
+ if self.plotScale == 'physic':
+ Xc = startX + (_locus.Mb-self.startMb)*plotXScale
+ else:
+ Xc = startX + (_locus.cM-_chr[0].cM)*plotXScale
+ BootCoord[-1].append([Xc, self.bootResult[i]])
+ i += 1
+
#reduce bootResult
if self.selectedChr > -1:
maxBootBar = 80.0
@@ -1134,7 +1158,7 @@ class MarkerRegression(object):
string1 = 'Mapping for Dataset: %s, mapping on All Chromosomes' % self.dataset.group.name
else:
string1 = 'Mapping for Dataset: %s, mapping on Chromosome %s' % (self.dataset.group.name, self.ChrList[self.selectedChr][0])
- if self.controlLocus:
+ if self.controlLocus and self.doControl != "false":
string2 = 'Using %s as control' % self.controlLocus
else:
string2 = 'Using Haldane mapping function with no control for other QTLs'
diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html
index 107b1869..88fb0e89 100644
--- a/wqflask/wqflask/templates/marker_regression_gn1.html
+++ b/wqflask/wqflask/templates/marker_regression_gn1.html
@@ -22,6 +22,7 @@
<input type="hidden" name="selected_chr" value="{{ selectedChr }}">
<input type="hidden" name="manhattan_plot">
<input type="hidden" name="num_perm">
+ <input type="hidden" name="num_bootstrap" value="{{ nboot }}">
<input type="hidden" name="do_control" value="{{ doControl }}">
<input type="hidden" name="control_marker" value="{{ controlLocus }}">
<input type="hidden" name="mapmethod_rqtl_geno" value="{{ mapmethod_rqtl_geno }}">
@@ -69,6 +70,7 @@
</div>
<div class="col-xs-4" style="padding: 0px;">
{% if mapping_method == "reaper" %}
+ <input type="checkbox" name="bootCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if bootChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Bootstrap Test <br>
<input type="checkbox" name="additiveCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if additiveChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Allele Effects<br>
{% endif %}
<input type="checkbox" name="showGenes" class="checkbox" style="display: inline; margin-top: 0px;" {% if geneChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Gene Track </span> <span style="color:red;">*</span><br>
diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html
index 6252f6f4..620a4631 100755
--- a/wqflask/wqflask/templates/show_trait_mapping_tools.html
+++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html
@@ -188,6 +188,12 @@
</div>
</div>
<div class="mapping_method_fields form-group">
+ <label for="mapping_bootstraps" class="col-xs-3 control-label">Bootstraps</label>
+ <div style="margin-left: 20px;" class="col-xs-4 controls">
+ <input name="num_bootstrap" value="2000" type="text" class="form-control">
+ </div>
+ </div>
+ <div class="mapping_method_fields form-group">
<label for="control_for" class="col-xs-3 control-label">Control&nbsp;for</label>
<div style="margin-left: 20px;" class="col-xs-4 controls">
{% if dataset.type == 'ProbeSet' and this_trait.locus_chr != "" %}
@@ -204,12 +210,15 @@
No
</label>
</div>
- </div>
-<!--
+ </div>
+
+<!--
<div class="mapping_method_fields form-group">
- <label for="mapping_bootstraps" class="col-xs-3 control-label" title="Bootstrapping Resamples">Bootstrap</label>
- <div style="margin-left: 20px;" class="col-xs-4 controls">
- <input name="mapping_bootstraps" value="2000" type="text" class="form-control">
+ <label for="mapping_bootstraps" class="col-xs-3 control-label" title="Bootstrapping Resamples">Bootstrap Test (n=2000)</label>
+ <div class="col-xs-4 controls">
+ <label>
+ <input type="checkbox" name="bootCheck" id="bootCheck"> Bootstrap Test (n=2000)
+ </label>
</div>
</div>
@@ -228,6 +237,7 @@
</div>
-->
+
<div class="mapping_method_fields form-group">
<label style="text-align:left;" class="col-xs-12 control-label">Manhattan Plot</label>
<div class="col-xs-12 controls">
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 98c75710..9d0fd131 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -348,6 +348,10 @@ def marker_regression_page():
'score_type',
'suggestive',
'num_perm',
+ 'permCheck',
+ 'num_bootstrap',
+ 'bootCheck',
+ 'bootstrap_results',
'maf',
'manhattan_plot',
'control_marker',