From 6d5a94c699d1653a3ca76a9500082b8803cdaedf Mon Sep 17 00:00:00 2001 From: Lei Yan Date: Wed, 19 Jun 2013 20:58:40 +0000 Subject: Changed QTL parameter name to "get_qtl_info" on trait.py and other places it's called, like search_results.py Added other trait info fields to correlation results page --- wqflask/base/trait.py | 17 ++- wqflask/wqflask/correlation/show_corr_results.py | 126 ++++++++++++----------- wqflask/wqflask/search_results.py | 2 +- wqflask/wqflask/templates/correlation_page.html | 33 +++--- 4 files changed, 98 insertions(+), 80 deletions(-) (limited to 'wqflask') diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index f333d5a7..82e013ae 100755 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -28,7 +28,7 @@ class GeneralTrait(object): """ - def __init__(self, **kw): + def __init__(self, get_qtl_info=False, **kw): # xor assertion assert bool(kw.get('dataset')) != bool(kw.get('dataset_name')), "Needs dataset ob. xor name"; if kw.get('dataset_name'): @@ -41,6 +41,14 @@ class GeneralTrait(object): self.haveinfo = kw.get('haveinfo', False) self.sequence = kw.get('sequence') # Blat sequence, available for ProbeSet self.data = kw.get('data', {}) + + # Sets defaultst + self.locus = None + self.lrs = None + self.pvalue = None + self.mean = None + self.num_overlap = None + if kw.get('fullname'): name2 = value.split("::") @@ -52,8 +60,9 @@ class GeneralTrait(object): # Todo: These two lines are necessary most of the time, but perhaps not all of the time # So we could add a simple if statement to short-circuit this if necessary - self.retrieve_info() + self.retrieve_info(get_qtl_info=get_qtl_info) self.retrieve_sample_data() + def get_name(self): @@ -237,7 +246,7 @@ class GeneralTrait(object): #def items(self): # return self.__dict__.items() - def retrieve_info(self, QTL=False): + def retrieve_info(self, get_qtl_info=False): assert self.dataset, "Dataset doesn't exist" if self.dataset.type == 'Publish': query = """ @@ -347,7 +356,7 @@ class GeneralTrait(object): if result: self.homologeneid = result[0] - if QTL: + if get_qtl_info: if self.dataset.type == 'ProbeSet' and not self.cellid: traitQTL = g.db.execute(""" SELECT diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 3b8b7ba2..3b1ac87d 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -13,19 +13,10 @@ # This program is available from Source Forge: at GeneNetwork Project # (sourceforge.net/projects/genenetwork/). # -# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010) -# at rwilliams@uthsc.edu and xzhou15@uthsc.edu -# +# Contact Dr. Robert W. Williams at rwilliams@uthsc.edu # # # This module is used by GeneNetwork project (www.genenetwork.org) -# -# Created by GeneNetwork Core Team 2010/08/10 -# -# Last updated by NL 2011/02/11 -# Last updated by Christian Fernandez 2012/04/07 -# Refactored correlation calculation into smaller functions in preparation of -# separating html from existing code from __future__ import absolute_import, print_function, division @@ -34,7 +25,6 @@ import string import cPickle import os import time -#import pyXLWriter as xl import pp import math import collections @@ -103,29 +93,29 @@ class CorrelationResults(object): with Bench("Doing correlations"): helper_functions.get_species_dataset_trait(self, start_vars) self.dataset.group.read_genotype_file() - + corr_samples_group = start_vars['corr_samples_group'] - + self.sample_data = {} self.corr_method = start_vars['corr_sample_method'] - + #The two if statements below append samples to the sample list based upon whether the user #rselected Primary Samples Only, Other Samples Only, or All Samples - + primary_samples = (self.dataset.group.parlist + self.dataset.group.f1list + self.dataset.group.samplelist) - + #If either BXD/whatever Only or All Samples, append all of that group's samplelist if corr_samples_group != 'samples_other': self.process_samples(start_vars, primary_samples, ()) - + #If either Non-BXD/whatever or All Samples, get all samples from this_trait.data and #exclude the primary samples (because they would have been added in the previous #if statement if the user selected All Samples) if corr_samples_group != 'samples_primary': self.process_samples(start_vars, self.this_trait.data.keys(), primary_samples) - + self.target_dataset = data_set.create_dataset(start_vars['corr_dataset']) self.target_dataset.get_trait_data() @@ -141,61 +131,72 @@ class CorrelationResults(object): this_trait_values.append(sample_value) target_values.append(target_sample_value) - this_trait_values, target_values = normalize_values(this_trait_values, target_values) + this_trait_values, target_values, num_overlap = normalize_values(this_trait_values, + target_values) if self.corr_method == 'pearson': sample_r, sample_p = scipy.stats.pearsonr(this_trait_values, target_values) else: sample_r, sample_p = scipy.stats.spearmanr(this_trait_values, target_values) - self.correlation_data[trait] = [sample_r, sample_p] + self.correlation_data[trait] = [sample_r, sample_p, num_overlap] self.correlation_data = collections.OrderedDict(sorted(self.correlation_data.items(), key=lambda t: -abs(t[1][0]))) - self.correlation_data_slice = collections.OrderedDict() + self.correlation_results = [] + + #self.correlation_data_slice = collections.OrderedDict() for trait_counter, trait in enumerate(self.correlation_data.keys()[:300]): - trait_object = GeneralTrait(dataset=self.dataset, name=trait) - if self.dataset.type == 'ProbeSet': - trait_info = collections.OrderedDict( - correlation = float(self.correlation_data[trait][0]), - p_value = float(self.correlation_data[trait][1]), - symbol = trait_object.symbol, - alias = trait_object.alias, - description = trait_object.description, - chromosome = trait_object.chr, - mb = trait_object.mb - ) - if hasattr(trait_object, 'mean'): - trait_info[mean] = trait_object.mean - if hasattr(trait_object, 'lrs'): - trait_info[lrs] = trait_object.lrs - if hasattr(trait_object, 'locus_chr'): - trait_info[locus_chr] = trait_object.locus_chr - if hasattr(trait_object, 'locus_mb'): - trait_info[locus_mb] = trait_object.locus_mb - elif self.dataset.type == 'Geno': - trait_info = collections.OrderedDict( - correlation = float(self.correlation_data[trait][0]), - p_value = float(self.correlation_data[trait][1]), - symbol = trait_object.symbol, - alias = trait_object.alias, - description = trait_object.description, - chromosome = trait_object.chr, - mb = trait_object.mb - ) - else: # 'Publish' - trait_info = collections.OrderedDict( - correlation = float(self.correlation_data[trait][0]), - p_value = float(self.correlation_data[trait][1]), - symbol = trait_object.symbol, - alias = trait_object.alias, - description = trait_object.description, - chromosome = trait_object.chr, - mb = trait_object.mb - ) - self.correlation_data_slice[trait] = trait_info + trait_object = GeneralTrait(dataset=self.dataset, name=trait, get_qtl_info=True) + trait_object.sample_r = self.correlation_data[trait][0] + trait_object.sample_p = self.correlation_data[trait][1] + trait_object_num_overlap = self.correlation_data[trait][2] + self.correlation_results.append(trait_object) + + #self.correlation_data_slice[trait] = self.correlation_data[trait] + #self.correlation_data_slice[trait].append(trait_object) + #if self.dataset.type == 'ProbeSet': + # trait_info = collections.OrderedDict( + # correlation = float(self.correlation_data[trait][0]), + # p_value = float(self.correlation_data[trait][1]), + # symbol = trait_object.symbol, + # alias = trait_object.alias, + # description = trait_object.description, + # chromosome = trait_object.chr, + # mb = trait_object.mb + # ) + # if trait_object.mean: + # trait_info[mean] = trait_object.mean + # if hasattr(trait_object, 'mean'): + # trait_info[mean] = trait_object.mean + # if hasattr(trait_object, 'lrs'): + # trait_info[lrs] = trait_object.lrs + # if hasattr(trait_object, 'locus_chr'): + # trait_info[locus_chr] = trait_object.locus_chr + # if hasattr(trait_object, 'locus_mb'): + # trait_info[locus_mb] = trait_object.locus_mb + #elif self.dataset.type == 'Geno': + # trait_info = collections.OrderedDict( + # correlation = float(self.correlation_data[trait][0]), + # p_value = float(self.correlation_data[trait][1]), + # symbol = trait_object.symbol, + # alias = trait_object.alias, + # description = trait_object.description, + # chromosome = trait_object.chr, + # mb = trait_object.mb + # ) + #else: # 'Publish' + # trait_info = collections.OrderedDict( + # correlation = float(self.correlation_data[trait][0]), + # p_value = float(self.correlation_data[trait][1]), + # symbol = trait_object.symbol, + # alias = trait_object.alias, + # description = trait_object.description, + # chromosome = trait_object.chr, + # mb = trait_object.mb + # ) #XZ, 09/18/2008: get all information about the user selected database. #target_db_name = fd.corr_dataset @@ -1067,8 +1068,9 @@ def normalize_values(values_1, values_2): if values_1[i]!= None and values_2[i]!= None: X.append(values_1[i]) Y.append(values_2[i]) + num_overlap = len(X) - return (X, Y) + return (X, Y, num_overlap) def cal_correlation(values_1, values_2): diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index e171f1ab..4238aa7f 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -107,7 +107,7 @@ class SearchResultPage(object): print("foo locals are:", locals()) trait_id = result[0] this_trait = GeneralTrait(dataset=self.dataset, name=trait_id) - this_trait.retrieve_info(QTL=True) + this_trait.retrieve_info(get_qtl_info=True) self.trait_list.append(this_trait) self.dataset.get_trait_info(self.trait_list, species) diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index b06f7096..efbf689c 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -17,30 +17,37 @@ Trait + Symbol + Alias + Description + Location + Mean Expr + Max LRS + Max LRS Location {% if corr_method == 'pearson' %} Sample r + N Cases Sample p(r) {% else %} Sample rho Sample p(rho) {% endif %} - Symbol - Alias - Description - Location - {% for trait in correlation_data_slice %} + {% for trait in correlation_results %} - {{ trait }} - {{ correlation_data_slice[trait].correlation }} - {{ correlation_data_slice[trait].p_value }} - {{ correlation_data_slice[trait].symbol }} - {{ correlation_data_slice[trait].alias }} - {{ correlation_data_slice[trait].description }} - Chr{{ correlation_data_slice[trait].chromosome }}: {{ correlation_data_slice[trait].mb }} - {# {{ correlation_data_slice[trait][2].__dict__ }} #} + {{ trait.name }} + {{ trait.symbol }} + {{ trait.alias }} + {{ trait.description }} + Chr{{ trait.chr }}: {{ trait.mb }} + {{ trait.mean }} + {{ trait.lrs }} + Chr{{ trait.locus_chr }}: {{ trait.locus_mb }} + {{ trait.sample_r }} + {{ trait.num_overlap }} + {{ trait.sample_p }} {% endfor %} -- cgit v1.2.3 From 083e8a548f53c20d98d02a02093ac421673d6c03 Mon Sep 17 00:00:00 2001 From: Lei Yan Date: Wed, 19 Jun 2013 22:16:21 +0000 Subject: Fixed issue where the Mean Expr, Max LRS, and Max LRS Location columns in the correlation page weren't displaying --- wqflask/base/trait.py | 61 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'wqflask') diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 38b3a625..801d32c2 100755 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -268,7 +268,7 @@ class GeneralTrait(object): PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND PublishFreeze.Id = %s """ % (self.name, self.dataset.id) - traitInfo = g.db.execute(query).fetchone() + trait_info = g.db.execute(query).fetchone() #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. elif self.dataset.type == 'ProbeSet': @@ -285,8 +285,8 @@ class GeneralTrait(object): """ % (escape(display_fields_string), escape(self.dataset.name), escape(self.name)) - traitInfo = g.db.execute(query).fetchone() - #print("traitInfo is: ", pf(traitInfo)) + trait_info = g.db.execute(query).fetchone() + #print("trait_info is: ", pf(trait_info)) #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name # to avoid the problem of same marker name from different species. elif self.dataset.type == 'Geno': @@ -303,23 +303,24 @@ class GeneralTrait(object): """ % (escape(display_fields_string), escape(self.dataset.name), escape(self.name)) - traitInfo = g.db.execute(query).fetchone() - #print("traitInfo is: ", pf(traitInfo)) + trait_info = g.db.execute(query).fetchone() + #print("trait_info is: ", pf(trait_info)) else: #Temp type query = """SELECT %s FROM %s WHERE Name = %s """ % (string.join(self.dataset.display_fields,','), self.dataset.type, self.name) - traitInfo = g.db.execute(query).fetchone() + trait_info = g.db.execute(query).fetchone() #self.cursor.execute(query) - #traitInfo = self.cursor.fetchone() - if traitInfo: + #trait_info = self.cursor.fetchone() + if trait_info: self.haveinfo = True #XZ: assign SQL query result to trait attributes. for i, field in enumerate(self.dataset.display_fields): - setattr(self, field, str(traitInfo[i])) + print(" mike: {} -> {} - {}".format(field, type(trait_info[i]), trait_info[i])) + setattr(self, field, trait_info[i]) if self.dataset.type == 'Publish': self.confidential = 0 @@ -327,6 +328,10 @@ class GeneralTrait(object): self.confidential = 1 self.homologeneid = None + + print("self.geneid is:", self.geneid) + print(" type:", type(self.geneid)) + print("self.dataset.group.name is:", self.dataset.group.name) if self.dataset.type == 'ProbeSet' and self.dataset.group and self.geneid: #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. #XZ: So I have to test if geneid is number before execute the query. @@ -338,6 +343,8 @@ class GeneralTrait(object): # geneidIsNumber = False #if geneidIsNumber: + + query = """ SELECT HomologeneId @@ -349,6 +356,7 @@ class GeneralTrait(object): InbredSet.SpeciesId = Species.Id AND Species.TaxonomyId = Homologene.TaxonomyId """ % (escape(str(self.geneid)), escape(self.dataset.group.name)) + print("-> query is:", query) result = g.db.execute(query).fetchone() #else: # result = None @@ -358,33 +366,38 @@ class GeneralTrait(object): if get_qtl_info: if self.dataset.type == 'ProbeSet' and not self.cellid: - traitQTL = g.db.execute(""" + query = """ SELECT ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean FROM ProbeSetXRef, ProbeSet WHERE ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSet.Name = "%s" AND - ProbeSetXRef.ProbeSetFreezeId =%s - """, (self.name, self.dataset.id)).fetchone() + ProbeSet.Name = "{}" AND + ProbeSetXRef.ProbeSetFreezeId ={} + """.format(self.name, self.dataset.id) + trait_qtl = g.db.execute(query).fetchone() #self.cursor.execute(query) - #traitQTL = self.cursor.fetchone() - if traitQTL: - self.locus, self.lrs, self.pvalue, self.mean = traitQTL + #trait_qtl = self.cursor.fetchone() + if trait_qtl: + self.locus, self.lrs, self.pvalue, self.mean = trait_qtl if self.locus: - result = g.db.execute(""" + query = """ select Geno.Chr, Geno.Mb from Geno, Species - where Species.Name = '%s' and - Geno.Name = '%s' and + where Species.Name = '{}' and + Geno.Name = '{}' and Geno.SpeciesId = Species.Id - """, (species, self.locus)).fetchone() + """.format(self.dataset.group.species, self.locus) + print("query is:", query) + result = g.db.execute(query).fetchone() self.locus_chr = result[0] self.locus_mb = result[1] else: self.locus = self.locus_chr = self.locus_mb = self.lrs = self.pvalue = self.mean = "" + + if self.dataset.type == 'Publish': - traitQTL = g.db.execute(""" + trait_qtl = g.db.execute(""" SELECT PublishXRef.Locus, PublishXRef.LRS FROM @@ -395,9 +408,9 @@ class GeneralTrait(object): PublishFreeze.Id =%s """, (self.name, self.dataset.id)).fetchone() #self.cursor.execute(query) - #traitQTL = self.cursor.fetchone() - if traitQTL: - self.locus, self.lrs = traitQTL + #trait_qtl = self.cursor.fetchone() + if trait_qtl: + self.locus, self.lrs = trait_qtl else: self.locus = self.lrs = "" else: -- cgit v1.2.3 From 82bd8b61b4aed0b0ae07477afae37a846fab35c2 Mon Sep 17 00:00:00 2001 From: Lei Yan Date: Wed, 19 Jun 2013 22:20:40 +0000 Subject: Added nginx_conf directory to git tracking --- wqflask/other_config/nginx_conf/gn2python.conf | 41 ++++++++++++++++++++++ wqflask/other_config/nginx_conf/gn2python_lei.conf | 41 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 wqflask/other_config/nginx_conf/gn2python.conf create mode 100644 wqflask/other_config/nginx_conf/gn2python_lei.conf (limited to 'wqflask') diff --git a/wqflask/other_config/nginx_conf/gn2python.conf b/wqflask/other_config/nginx_conf/gn2python.conf new file mode 100644 index 00000000..f23e325f --- /dev/null +++ b/wqflask/other_config/nginx_conf/gn2python.conf @@ -0,0 +1,41 @@ +server { + # Modeled after http://flask.pocoo.org/docs/deploying/wsgi-standalone/ + listen 80; + + server_name gn2python.genenetwork.org; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + location ^~ /css/ { + root /gene/wqflask/wqflask/static/; + } + + location ^~ /javascript/ { + root /gene/wqflask/wqflask/static/; + } + +# location ^~ /image/ { +# root /gene/wqflask/wqflask/static/; +# } + + location ^~ /images/ { + root /gene/wqflask/wqflask/static/; + } + + ### New - added by Sam + #location ^~ /static/ { + # root /gene/wqflask/wqflask/static/; + #} + + location / { + proxy_pass http://127.0.0.1:5000/; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 40m; + } +} diff --git a/wqflask/other_config/nginx_conf/gn2python_lei.conf b/wqflask/other_config/nginx_conf/gn2python_lei.conf new file mode 100644 index 00000000..981bda28 --- /dev/null +++ b/wqflask/other_config/nginx_conf/gn2python_lei.conf @@ -0,0 +1,41 @@ +server { + # Modeled after http://flask.pocoo.org/docs/deploying/wsgi-standalone/ + listen 80; + + server_name gn2python_lei.genenetwork.org; + + access_log /var/log/nginx/lei_access.log; + error_log /var/log/nginx/lei_error.log; + + location ^~ /css/ { + root /gene/wqflask/wqflask/static/; + } + + location ^~ /javascript/ { + root /gene/wqflask/wqflask/static/; + } + +# location ^~ /image/ { +# root /gene/wqflask/wqflask/static/; +# } + + location ^~ /images/ { + root /gene/wqflask/wqflask/static/; + } + + ### New - added by Sam + #location ^~ /static/ { + # root /gene/wqflask/wqflask/static/; + #} + + location / { + proxy_pass http://127.0.0.1:5001/; + proxy_redirect off; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_read_timeout 40m; + } +} \ No newline at end of file -- cgit v1.2.3