diff options
Diffstat (limited to 'wqflask')
11 files changed, 157 insertions, 83 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 58bed865..f3648b80 100755 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -549,6 +549,9 @@ class GeneralTrait(object): if self.alias: alias = string.replace(self.alias, ";", " ") alias = string.join(string.split(alias), ", ") + else: + alias = 'Not available' + return alias diff --git a/wqflask/wqflask/interval_mapping/interval_mapping.py b/wqflask/wqflask/interval_mapping/interval_mapping.py index 5eb901f7..5511826a 100755 --- a/wqflask/wqflask/interval_mapping/interval_mapping.py +++ b/wqflask/wqflask/interval_mapping/interval_mapping.py @@ -57,13 +57,8 @@ class IntervalMapping(object): self.set_options(start_vars) self.json_data = {} - - #if self.method == "qtl_reaper": self.json_data['lodnames'] = ['lod.hk'] 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 = {} @@ -93,13 +88,7 @@ class IntervalMapping(object): def set_options(self, start_vars): """Sets various options (physical/genetic mapping, # permutations, which chromosome""" - #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_perm']) - #self.do_bootstrap = start_vars['do_bootstrap'] - #self.selected_chr = start_vars['chromosome'] if start_vars['manhattan_plot'] == "true": self.manhattan_plot = True else: @@ -112,9 +101,6 @@ class IntervalMapping(object): self.control_locus = start_vars['control_locus'] else: self.control_locus = None - #self.weighted_regression = start_vars['weighted'] - #self.lrs_lod = start_vars['lrs_lod'] - def gen_qtl_results(self, tempdata): """Generates qtl results for plotting interval map""" @@ -134,7 +120,7 @@ class IntervalMapping(object): #if self.weighted_regression: # self.lrs_array = self.genotype.permutation(strains = trimmed_samples, # trait = trimmed_values, - # variance = _vars, + # variance = variances, # nperm=self.num_permutations) #else: self.lrs_array = genotype.permutation(strains = trimmed_samples, @@ -175,12 +161,6 @@ class IntervalMapping(object): self.json_data['markernames'] = [] for qtl in reaper_results: reaper_locus = qtl.locus - #if reaper_locus.chr == "20": - # print("changing to X") - # self.json_data['chr'].append("X") - #else: - # self.json_data['chr'].append(reaper_locus.chr) - ##self.json_data['chr'].append(reaper_locus.chr) self.json_data['pos'].append(reaper_locus.Mb) self.json_data['lod.hk'].append(qtl.lrs) self.json_data['markernames'].append(reaper_locus.name) diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py new file mode 100644 index 00000000..b1ab780c --- /dev/null +++ b/wqflask/wqflask/marker_regression/gemma_mapping.py @@ -0,0 +1,44 @@ +import os + +from base import webqtlConfig + +def run_gemma(this_dataset, samples, vals): + """Generates p-values for each marker using GEMMA""" + + print("INSIDE GEMMA_MAPPING") + + gen_pheno_txt_file(this_dataset, samples, vals) + + os.chdir("{}gemma".format(webqtlConfig.HTMLPATH)) + + gemma_command = './gemma -bfile %s -k output_%s.cXX.txt -lmm 1 -o output/%s_output' % (this_dataset.group.name, + this_dataset.group.name, + this_dataset.group.name) + print("gemma_command:" + gemma_command) + + os.system(gemma_command) + + included_markers, p_values = parse_gemma_output(this_dataset) + + return included_markers, p_values + +def gen_pheno_txt_file(this_dataset, samples, vals): + """Generates phenotype file for GEMMA""" + + with open("{}gemma/{}.fam".format(webqtlConfig.HTMLPATH, this_dataset.group.name), "w") as outfile: + for i, sample in enumerate(samples): + outfile.write(str(sample) + " " + str(sample) + " 0 0 0 " + str(vals[i]) + "\n") + +def parse_gemma_output(this_dataset): + included_markers = [] + p_values = [] + with open("{}gemma/output/{}_output.assoc.txt".format(webqtlConfig.HTMLPATH, this_dataset.group.name)) as output_file: + for line in output_file: + if line.startswith("chr"): + continue + else: + included_markers.append(line.split("\t")[1]) + p_values.append(float(line.split("\t")[10])) + + print("p_values: ", p_values) + return included_markers, p_values
\ No newline at end of file diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 67e1df0d..49521bd6 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -32,6 +32,10 @@ from base import data_set from base import species from base import webqtlConfig from utility import webqtlUtil +#from wqflask.marker_regression import qtl_reaper_mapping +#from wqflask.marker_regression import plink_mapping +from wqflask.marker_regression import gemma_mapping +#from wqflask.marker_regression import rqtl_mapping from wqflask.my_pylmm.data import prep_data from wqflask.my_pylmm.pyLMM import lmm from wqflask.my_pylmm.pyLMM import input @@ -82,7 +86,10 @@ class MarkerRegression(object): self.dataset.group.get_markers() if self.mapping_method == "gemma": - qtl_results = self.run_gemma() + included_markers, p_values = gemma_mapping.run_gemma(self.dataset, self.samples, self.vals) + self.dataset.group.get_specified_markers(markers = included_markers) + self.dataset.group.markers.add_pvalues(p_values) + qtl_results = self.dataset.group.markers.markers elif self.mapping_method == "rqtl_plink": qtl_results = self.run_rqtl_plink() elif self.mapping_method == "rqtl_geno": @@ -97,9 +104,7 @@ class MarkerRegression(object): if start_vars['pair_scan'] == "true": self.pair_scan = True - print("pair scan:", self.pair_scan) - print("DOING RQTL GENO") qtl_results = self.run_rqtl_geno() print("qtl_results:", qtl_results) elif self.mapping_method == "plink": @@ -166,11 +171,11 @@ class MarkerRegression(object): chromosomes = chromosome_mb_lengths, qtl_results = self.filtered_markers, ) + def run_gemma(self): """Generates p-values for each marker using GEMMA""" - #filename = webqtlUtil.genRandStr("{}_{}_".format(self.dataset.group.name, self.this_trait.name)) self.gen_pheno_txt_file() os.chdir("/home/zas1024/gene/web/gemma") @@ -391,9 +396,23 @@ class MarkerRegression(object): return pheno_as_string def process_pair_scan_results(self, result): - results = [] + pair_scan_results = [] + + result = result[1] + output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)] + print("R/qtl scantwo output:", output) + + for i, line in enumerate(result.iter_row()): + marker = {} + marker['name'] = result.rownames[i] + marker['chr1'] = output[i][0] + marker['Mb'] = output[i][1] + marker['chr2'] = int(output[i][2]) + pair_scan_results.append(marker) + + print("pair_scan_results:", pair_scan_results) - return results + return pair_scan_results def process_rqtl_results(self, result): # TODO: how to make this a one liner and not copy the stuff in a loop qtl_results = [] diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 929f5abb..836a0be5 100755 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -283,13 +283,13 @@ class ShowTrait(object): # else: # pass - g.db.execute("SELECT Name FROM InbredSet WHERE Name=%s", self.dataset.group.name) + result = g.db.execute("SELECT Name FROM InbredSet WHERE Name=%s", self.dataset.group.name) if this_trait: addSelectionButton = HT.Href(url="#redirect", onClick="addRmvSelection('%s', document.getElementsByName('%s')[0], 'addToSelection');" % (self.dataset.group.name, 'dataInput')) addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="addselect", alt="Add To Collection", title="Add To Collection", style="border:none;") #addSelectionButton.append(addSelectionButton_img) addSelectionText = "Add" - elif self.cursor.fetchall(): + elif result.fetchall(): addSelectionButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('%s')[0], 'addRecord');" % ('dataInput')) addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="", alt="Add To Collection", title="Add To Collection", style="border:none;") #addSelectionButton.append(addSelectionButton_img) @@ -368,7 +368,7 @@ class ShowTrait(object): blatsequence = '' for seqt in seqs: if int(seqt[1][-1]) % 2 == 1: - blatsequence += string.strip(seqt[0]) + blatsequence += string.strip(seqt[0])## NEEDED FOR UCSC GENOME BROWSER LINK #--------Hongqiang add this part in order to not only blat ProbeSet, but also blat Probe blatsequence = '%3E'+this_trait.name+'%0A'+blatsequence+'%0A' @@ -469,52 +469,25 @@ class ShowTrait(object): #XZ: Resource Links: if this_trait.symbol: - linkStyle = "background:#dddddd;padding:2" - tSpan = HT.Span(style="font-family:verdana,serif;font-size:13px") - #XZ,12/26/2008: Gene symbol may contain single quotation mark. #For example, Affymetrix, mouse430v2, 1440338_at, the symbol is 2'-Pde (geneid 211948) #I debug this by using double quotation marks. if _Species == "rat": - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #symatlas_species = "Rattus norvegicus" - - #self.cursor.execute("SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = '%s'" % this_trait.symbol) - self.cursor.execute('SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = "%s"' % this_trait.symbol) - try: - kgId, chr, txst, txen = self.cursor.fetchall()[0] + result = g.db.execute("SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = %s", (this_trait.symbol)).fetchone() + if result != None: + kgId, chr, txst, txen = result[0], result[1], result[2], result[3] if chr and txst and txen and kgId: txst = int(txst*1000000) txen = int(txen*1000000) - #tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ - # title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('rn3',kgId,chr,txst,txen),Class="fs14 fwn"), style=linkStyle) - # , " "*2) - except: - pass if _Species == "mouse": - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #symatlas_species = "Mus musculus" - - #self.cursor.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = '%s'" % this_trait.symbol) - #try: print("this_trait.symbol:", this_trait.symbol) result = g.db.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = %s", (this_trait.symbol)).fetchone() if result != None: this_chr, txst, txen = result[0], result[1], result[2] - #this_chr, txst, txen = g.db.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = %s", (this_trait.symbol)).fetchone() if this_chr and txst and txen and this_trait.refseq_transcriptid : txst = int(txst*1000000) txen = int(txen*1000000) - #tSpan.append(HT.Span(HT.Href(text= 'UCSC',target="mainFrame",\ - # title= 'Info from UCSC Genome Browser', url = webqtlConfig.UCSC_REFSEQ % ('mm9', - # this_trait.refseq_transcriptid, - # this_chr, - # txst, - # txen), - # Class="fs14 fwn"), style=linkStyle) - # , " "*2) + ## NEEDED FOR UCSC GENOME BROWSER LINK #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more #tSpan.append(HT.Span(HT.Href(text= 'SymAtlas',target="mainFrame",\ 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 a87d3537..881ea74d 100755 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee @@ -79,8 +79,8 @@ open_mapping_results = (data) -> $.colorbox( html: data href: "#mapping_results_holder" - height: "80%" - width: "80%" + height: "90%" + width: "90%" ) showalert = (message,alerttype) -> @@ -154,8 +154,8 @@ $("#plink_compute").click(() => $("#static_progress_bar_container").modal() url = "/marker_regression" $('input[name=method]').val("plink") - $('input[name=mapping_display_all]').val($('input[name=display_all_plink]').val()) - $('input[name=suggestive]').val($('input[name=suggestive_plink]').val()) + #$('input[name=mapping_display_all]').val($('input[name=display_all_plink]').val()) + #$('input[name=suggestive]').val($('input[name=suggestive_plink]').val()) $('input[name=maf]').val($('input[name=maf_plink]').val()) form_data = $('#trait_data_form').serialize() console.log("form_data is:", form_data) @@ -164,11 +164,12 @@ $("#plink_compute").click(() => ) $("#gemma_compute").click(() => + console.log("RUNNING GEMMA") $("#static_progress_bar_container").modal() url = "/marker_regression" $('input[name=method]').val("gemma") - $('input[name=mapping_display_all]').val($('input[name=display_all_gemma]').val()) - $('input[name=suggestive]').val($('input[name=suggestive_gemma]').val()) + #$('input[name=mapping_display_all]').val($('input[name=display_all_gemma]').val()) + #$('input[name=suggestive]').val($('input[name=suggestive_gemma]').val()) $('input[name=maf]').val($('input[name=maf_gemma]').val()) form_data = $('#trait_data_form').serialize() console.log("form_data is:", form_data) 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 c8988cdc..1779df4b 100755 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js @@ -99,8 +99,8 @@ open_mapping_results = function(data) { return $.colorbox({ html: data, href: "#mapping_results_holder", - height: "80%", - width: "80%" + height: "90%", + width: "90%" }); }; @@ -187,11 +187,10 @@ $("#plink_compute").click((function(_this) { $("#gemma_compute").click((function(_this) { return function() { var form_data, url; + console.log("RUNNING GEMMA"); $("#static_progress_bar_container").modal(); url = "/marker_regression"; $('input[name=method]').val("gemma"); - $('input[name=mapping_display_all]').val($('input[name=display_all_gemma]').val()); - $('input[name=suggestive]').val($('input[name=suggestive_gemma]').val()); $('input[name=maf]').val($('input[name=maf_gemma]').val()); form_data = $('#trait_data_form').serialize(); console.log("form_data is:", form_data); diff --git a/wqflask/wqflask/templates/new_security/login_user.html b/wqflask/wqflask/templates/new_security/login_user.html index 81e8b53a..a66a85d6 100755 --- a/wqflask/wqflask/templates/new_security/login_user.html +++ b/wqflask/wqflask/templates/new_security/login_user.html @@ -24,18 +24,18 @@ <h4>Already have an account? Sign in here.</h4> - <form class="form-horizontal" action="/n/login" method="POST" name="login_user_form"> + <form class="form-horizontal" action="/n/login" method="POST" name="login_user_form" id="loginUserForm"> <fieldset> <div class="form-group"> <label style="text-align:left;" class="col-xs-1 control-label" for="email_address">Email Address</label> - <div style="margin-left:20px;" class="col-xs-10"> + <div style="margin-left:20px;" class="col-xs-4"> <input id="email_address" class="focused" name="email_address" type="text" value=""> </div> </div> <div class="form-group"> <label style="text-align:left;" class="col-xs-1 control-label" for="password">Password</label> - <div style="margin-left:20px;" class="col-xs-3 controls"> + <div style="margin-left:20px;" class="col-xs-4 controls"> <input id="password" name="password" type="password" value=""> <br /> <a href="/n/forgot_password">Forgot your password?</a><br/> @@ -45,14 +45,14 @@ <div class="form-group"> <label class="col-xs-1 control-label" for="remember"></label> - <div style="margin-left:20px;" class="col-xs-3 controls"> + <div style="margin-left:20px;" class="col-xs-4 controls"> <input id="remember" name="remember" type="checkbox" value="y"> <b>Remember me</b> </div> </div> <div class="form-group"> <label class="col-xs-1 control-label" for="submit"></label> - <div style="margin-left:20px;" class="col-xs-3 controls"> + <div style="margin-left:20px;" class="col-xs-4 controls"> <input id="next" name="next" type="hidden" value=""> <input class="btn btn-primary" id="submit" name="submit" type="submit" value="Sign in"> </div> @@ -66,9 +66,42 @@ {% endblock %} +{% block css %} +<style type="text/css"> +input.error{ + border:1px solid #FF0000 !important; +} + +label.error,div.error{ + font-weight:normal; + color:#FF0000 !important; +} +</style> +{% endblock %} + {% block js %} <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>--> + <script type="text/javascript" src="/static/new/packages/ValidationPlugin/dist/jquery.validate.min.js"></script> + <script> + $(document).ready(function () { + $("#loginUserForm").validate({ + onkeyup: false, + onsubmit: true, + onfocusout: function(element) { $(element).valid(); }, + rules: { + email_address: { + required: true, + email: true + }, + password: { + required: true + } + } + }); + }); + </script> + {% include "new_security/_scripts.html" %} {% endblock %} diff --git a/wqflask/wqflask/templates/pair_scan_results.html b/wqflask/wqflask/templates/pair_scan_results.html index 869dabed..f46d7cbf 100644 --- a/wqflask/wqflask/templates/pair_scan_results.html +++ b/wqflask/wqflask/templates/pair_scan_results.html @@ -33,6 +33,28 @@ <h2> Results </h2> + <table cellpadding="0" cellspacing="0" border="0" id="pair_scan_results" class="table table-hover table-striped table-bordered"> + <thead> + <tr> + <td>Index</td> + <td>Locus</td> + <td>Chr 1</td> + <td>Mb</td> + <td>Chr 2</td> + </tr> + </thead> + <tbody> + {% for marker in pair_scan_results %} + <tr> + <td>{{loop.index}}</td> + <td>{{marker.name}}</td> + <td>{{marker.chr1}}</td> + <td>{{marker.Mb}}</td> + <td>{{marker.chr2}}</td> + </tr> + {% endfor %} + </tbody> + </table> </div> </div> diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 731f6fbd..c7c2a62f 100755 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -42,7 +42,7 @@ <button class="btn btn-default" id="deselect_all"><span class="glyphicon glyphicon-remove"></span> Deselect All</button> <button class="btn btn-default" id="invert"><span class="glyphicon glyphicon-resize-vertical"></span> Invert</button> <button class="btn btn-default" id="add"><span class="glyphicon glyphicon-plus-sign"></span> Add</button> - <button class="btn btn-primary pull-right"><span class="glyphicon glyphicon-download"></span> Download Table</button> + <button class="btn btn-primary"><span class="glyphicon glyphicon-download"></span> Download Table</button> <br /> <br /> <table class="table table-hover table-striped" id='trait_table'> diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html index 426a5c5d..27504e51 100755 --- a/wqflask/wqflask/templates/show_trait_mapping_tools.html +++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html @@ -217,16 +217,16 @@ <div style="padding: 20px" class="form-horizontal"> <div class="mapping_method_fields form-group"> <label for="maf_plink" class="col-xs-2 control-label">Minor allele threshold</label> - <div style="margin-left: 20px;" class="col-xs-1 controls"> + <div style="margin-left: 20px;" class="col-xs-2 controls"> <input name="maf_plink" value="0.01" type="text" class="form-control"> </div> </div> </div> <div class="form-group"> - <label for="gemma_compute" class="col-xs-1 control-label"></label> + <label for="plink_compute" class="col-xs-1 control-label"></label> <div style="margin-left:20px;" class="col-xs-4 controls"> - <button id="gemma_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> + <button id="plink_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> Compute </button> </div> @@ -237,16 +237,16 @@ <div style="padding: 20px" class="form-horizontal"> <div class="mapping_method_fields form-group"> <label for="maf_gemma" class="col-xs-2 control-label">Minor allele threshold</label> - <div style="margin-left: 20px;" class="col-xs-1 controls"> + <div style="margin-left: 20px;" class="col-xs-2 controls"> <input name="maf_gemma" value="0.01" type="text" class="form-control"> </div> </div> </div> <div class="form-group"> - <label for="plink_compute" class="col-xs-1 control-label"></label> + <label for="gemma_compute" class="col-xs-1 control-label"></label> <div style="margin-left:20px;" class="col-xs-4 controls"> - <button id="plink_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> + <button id="gemma_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> Compute </button> </div> |