aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/base')
-rwxr-xr-xwqflask/base/mrna_assay_tissue_data.py42
-rwxr-xr-xwqflask/base/species.py38
-rw-r--r--wqflask/base/trait.py44
-rwxr-xr-xwqflask/base/webqtlCaseData.py6
-rw-r--r--wqflask/base/webqtlConfig.py2
5 files changed, 66 insertions, 66 deletions
diff --git a/wqflask/base/mrna_assay_tissue_data.py b/wqflask/base/mrna_assay_tissue_data.py
index ba82057a..039f5d1f 100755
--- a/wqflask/base/mrna_assay_tissue_data.py
+++ b/wqflask/base/mrna_assay_tissue_data.py
@@ -12,30 +12,30 @@ from MySQLdb import escape_string as escape
from pprint import pformat as pf
class MrnaAssayTissueData(object):
-
+
def __init__(self, gene_symbols=None):
self.gene_symbols = gene_symbols
self.have_data = False
if self.gene_symbols == None:
self.gene_symbols = []
-
+
#print("self.gene_symbols:", self.gene_symbols)
-
+
self.data = collections.defaultdict(Bunch)
-
+
#self.gene_id_dict ={}
#self.data_id_dict = {}
#self.chr_dict = {}
#self.mb_dict = {}
#self.desc_dict = {}
#self.probe_target_desc_dict = {}
-
+
query = '''select t.Symbol, t.GeneId, t.DataId, t.Chr, t.Mb, t.description, t.Probe_Target_Description
from (
select Symbol, max(Mean) as maxmean
from TissueProbeSetXRef
where TissueProbeSetFreezeId=1 and '''
-
+
# Note that inner join is necessary in this query to get distinct record in one symbol group
# with highest mean value
# Due to the limit size of TissueProbeSetFreezeId table in DB,
@@ -43,11 +43,11 @@ class MrnaAssayTissueData(object):
if len(gene_symbols) == 0:
query += '''Symbol!='' and Symbol Is Not Null group by Symbol)
as x inner join TissueProbeSetXRef as t on t.Symbol = x.Symbol
- and t.Mean = x.maxmean;
+ and t.Mean = x.maxmean;
'''
else:
in_clause = db_tools.create_in_clause(gene_symbols)
-
+
#ZS: This was in the query, not sure why: http://docs.python.org/2/library/string.html?highlight=lower#string.lower
query += ''' Symbol in {} group by Symbol)
@@ -56,7 +56,7 @@ class MrnaAssayTissueData(object):
'''.format(in_clause)
results = g.db.execute(query).fetchall()
-
+
lower_symbols = []
for gene_symbol in gene_symbols:
if gene_symbol != None:
@@ -68,7 +68,7 @@ class MrnaAssayTissueData(object):
if symbol.lower() in lower_symbols:
#gene_symbols.append(symbol)
symbol = symbol.lower()
-
+
self.data[symbol].gene_id = result.GeneId
self.data[symbol].data_id = result.DataId
self.data[symbol].chr = result.Chr
@@ -85,21 +85,21 @@ class MrnaAssayTissueData(object):
#function: get one dictionary whose key is gene symbol and value is tissue expression data (list type).
#Attention! All keys are lower case!
###########################################################################
-
+
def get_symbol_values_pairs(self):
id_list = [self.data[symbol].data_id for symbol in self.data]
print("id_list:", id_list)
symbol_values_dict = {}
-
+
query = """SELECT TissueProbeSetXRef.Symbol, TissueProbeSetData.value
FROM TissueProbeSetXRef, TissueProbeSetData
WHERE TissueProbeSetData.Id IN {} and
TissueProbeSetXRef.DataId = TissueProbeSetData.Id""".format(db_tools.create_in_clause(id_list))
-
+
print("TISSUE QUERY:", query)
-
+
results = g.db.execute(query).fetchall()
for result in results:
if result.Symbol.lower() not in symbol_values_dict:
@@ -110,11 +110,11 @@ class MrnaAssayTissueData(object):
#for symbol in self.data:
# data_id = self.data[symbol].data_id
# symbol_values_dict[symbol] = self.get_tissue_values(data_id)
-
-
+
+
return symbol_values_dict
-
-
+
+
#def get_tissue_values(self, data_id):
# """Gets the tissue values for a particular gene"""
#
@@ -133,7 +133,7 @@ class MrnaAssayTissueData(object):
# # symbol_values_pairs[symbol] = None
#
# return tissue_values
-
+
########################################################################################################
#input: cursor, symbolList (list), dataIdDict(Dict): key is symbol
#output: SymbolValuePairDict(dictionary):one dictionary of Symbol and Value Pair.
@@ -154,7 +154,7 @@ class MrnaAssayTissueData(object):
# #descDict,
# #pTargetDescDict = getTissueProbeSetXRefInfo(
# # GeneNameLst=GeneNameLst,TissueProbeSetFreezeId=TissueProbeSetFreezeId)
-#
+#
# if len(tissue_data.gene_symbols):
# return get_symbol_values_pairs(tissue_data)
-
+
diff --git a/wqflask/base/species.py b/wqflask/base/species.py
index 52bd8297..79d867c8 100755
--- a/wqflask/base/species.py
+++ b/wqflask/base/species.py
@@ -24,21 +24,21 @@ class TheSpecies(object):
# for counter, genotype in enumerate(self.dataset.group.genotype):
# if len(genotype) > 1:
# chromosomes.append((genotype.name, counter))
- #
- # print("chromosomes is: ", pf(chromosomes))
- #
+ #
+ # print("chromosomes is: ", pf(chromosomes))
+ #
# return chromosomes
class IndChromosome(object):
def __init__(self, name, length):
self.name = name
self.length = length
-
+
@property
def mb_length(self):
"""Chromosome length in megabases"""
return self.length / 1000000
-
+
def set_cm_length(self, genofile_chr):
self.cm_length = genofile_chr[-1].cM - genofile_chr[0].cM
@@ -61,19 +61,19 @@ class Chromosomes(object):
for item in results:
self.chromosomes[item.OrderId] = IndChromosome(item.Name, item.Length)
-
+
self.set_mb_graph_interval()
#self.get_cm_length_list()
def set_mb_graph_interval(self):
"""Empirical megabase interval"""
-
+
if self.chromosomes:
self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12)
else:
self.mb_graph_interval = 1
-
+
#if self.chromosomes:
#assert self.chromosomes, "Have to add some code back in apparently to set it to 1"
#self.mb_graph_interval = self.get_genome_mb_length()/(len(self.chromosomes)*12)
@@ -94,30 +94,30 @@ class Chromosomes(object):
def get_cm_length_list(self):
"""Chromosome length in centimorgans
-
+
Calculates the length in centimorgans by subtracting the centimorgan position
of the last marker in a chromosome by the position of the first marker
-
+
"""
-
+
self.dataset.group.read_genotype_file()
-
+
self.cm_length_list = []
-
+
for chromosome in self.dataset.group.genotype:
self.cm_length_list.append(chromosome[-1].cM - chromosome[0].cM)
-
+
print("self.cm_length_list:", pf(self.cm_length_list))
-
+
assert len(self.cm_length_list) == len(self.chromosomes), "Uh-oh lengths should be equal!"
for counter, chromosome in enumerate(self.chromosomes.values()):
chromosome.cm_length = self.cm_length_list[counter]
#self.chromosomes[counter].cm_length = item
-
+
for key, value in self.chromosomes.items():
print("bread - %s: %s" % (key, pf(vars(value))))
-
-# Testing
-#if __name__ == '__main__':
+
+# Testing
+#if __name__ == '__main__':
# foo = dict(bar=dict(length)) \ No newline at end of file
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index a71d8157..b51b8c72 100644
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -69,11 +69,11 @@ class GeneralTrait(object):
self.retrieve_info(get_qtl_info=get_qtl_info)
if get_sample_info != False:
self.retrieve_sample_data()
-
-
+
+
def jsonable(self):
"""Return a dict suitable for using as json
-
+
Actual turning into json doesn't happen here though"""
return dict(name=self.name,
dataset=self.dataset.name,
@@ -258,10 +258,10 @@ class GeneralTrait(object):
PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND
PublishFreeze.Id = %s
""" % (self.name, self.dataset.id)
-
+
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':
@@ -310,27 +310,27 @@ class GeneralTrait(object):
if isinstance(trait_info[i], basestring):
holder = unicode(trait_info[i], "utf8", "ignore")
setattr(self, field, holder)
-
+
if self.dataset.type == 'Publish':
self.confidential = 0
if self.pre_publication_description and not self.pubmed_id:
self.confidential = 1
-
+
description = self.post_publication_description
-
+
#If the dataset is confidential and the user has access to confidential
#phenotype traits, then display the pre-publication description instead
#of the post-publication description
if self.confidential:
self.description_display = ""
-
+
#if not webqtlUtil.hasAccessToConfidentialPhenotypeTrait(
# privilege=self.dataset.privilege,
# userName=self.dataset.userName,
# authorized_users=self.authorized_users):
- #
+ #
# description = self.pre_publication_description
-
+
if description:
self.description_display = description.strip()
else:
@@ -343,8 +343,8 @@ class GeneralTrait(object):
if self.pubmed_id:
self.pubmed_link = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id
-
-
+
+
self.homologeneid = None
if self.dataset.type == 'ProbeSet' and self.dataset.group:
if self.geneid:
@@ -374,7 +374,7 @@ class GeneralTrait(object):
if result:
self.homologeneid = result[0]
-
+
description_string = unicode(str(self.description).strip(codecs.BOM_UTF8), 'utf-8')
target_string = unicode(str(self.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8')
@@ -410,7 +410,7 @@ class GeneralTrait(object):
#ZS: Put this in function currently called "convert_location_to_value"
self.location_repr = 'Chr%s: %.6f' % (self.chr, float(self.mb))
self.location_value = trait_location_value
-
+
if get_qtl_info:
#LRS and its location
@@ -481,7 +481,7 @@ class GeneralTrait(object):
self.locus = self.locus_chr = self.locus_mb = self.additive = ""
else:
self.locus = self.lrs = self.additive = ""
-
+
if (self.dataset.type == 'Publish' or self.dataset.type == "ProbeSet") and self.locus_chr != "" and self.locus_mb != "":
#XZ: LRS_location_value is used for sorting
try:
@@ -493,7 +493,7 @@ class GeneralTrait(object):
LRS_location_value = ord(str(self.locus_chr).upper()[0])*1000 + float(self.locus_mb)
self.LRS_location_repr = LRS_location_repr = 'Chr%s: %.6f' % (self.locus_chr, float(self.locus_mb))
- if self.lrs != "":
+ if self.lrs != "":
self.LRS_score_repr = LRS_score_repr = '%3.1f' % self.lrs
self.LRS_score_value = LRS_score_value = self.lrs
else:
@@ -712,7 +712,7 @@ def convert_location_to_value(chromosome, mb):
else:
location_value = (ord(str(chromosome).upper()[0])*1000 +
float(mb))
-
+
return location_value
@app.route("/trait/get_sample_data")
@@ -720,11 +720,11 @@ def get_sample_data():
params = request.args
trait = params['trait']
dataset = params['dataset']
-
+
trait_ob = GeneralTrait(name=trait, dataset_name=dataset)
-
+
return json.dumps([trait, {key: value.value for key, value in trait_ob.data.iteritems() }])
-
+
#jsonable_sample_data = {}
#for sample in trait_ob.data.iteritems():
# jsonable_sample_data[sample] = trait_ob.data[sample].value
diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py
index 99a34866..411b0d24 100755
--- a/wqflask/base/webqtlCaseData.py
+++ b/wqflask/base/webqtlCaseData.py
@@ -48,7 +48,7 @@ class webqtlCaseData(object):
if self.num_cases != None:
str += " ndata=%d" % self.num_cases
return str
-
+
@property
def class_outlier(self):
"""Template helper"""
@@ -56,14 +56,14 @@ class webqtlCaseData(object):
return "outlier"
else:
return ""
-
+
@property
def display_value(self):
if self.value:
return "%2.3f" % self.value
else:
return "x"
-
+
@property
def display_variance(self):
if self.variance:
diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py
index f6140ac3..f76d8140 100644
--- a/wqflask/base/webqtlConfig.py
+++ b/wqflask/base/webqtlConfig.py
@@ -5,7 +5,7 @@
# scripts. But rather than migrating everything in one go, we'll
# take it a step at a time. First the hard coded paths get replaced
# with those in utility/tools.py
-#
+#
#########################################
from utility.tools import valid_path, mk_dir, assert_dir, flat_files, TEMPDIR