diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/do_search.py | 114 | ||||
-rw-r--r-- | wqflask/wqflask/search_results.py | 19 |
2 files changed, 119 insertions, 14 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index 2641431c..4517d9f5 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -5,6 +5,8 @@ from __future__ import print_function, division from pprint import pformat as pf +from dbFunction import webqtlDatabaseFunction + class DoSearch(object): """Parent class containing parameters/functions used for all searches""" @@ -45,6 +47,10 @@ class ProbeSetSearch(DoSearch): DoSearch.search_types['ProbeSet'] = "ProbeSetSearch" + #Get group information for dataset and the species id + self.dataset.get_group() + self.species_id = webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.dataset.group) + base_query = """SELECT ProbeSet.Name as TNAME, 0 as thistable, ProbeSetXRef.Mean as TMEAN, @@ -224,7 +230,9 @@ class WikiSearch(ProbeSetSearch): where_clause = """%s.symbol = GeneRIF.symbol and GeneRIF.versionId=0 and GeneRIF.display>0 and (GeneRIF.comment REGEXP '%s' or GeneRIF.initial = '%s') - """ % (self.dataset.type, "[[:<:]]"+self.search_term+"[[:>:]]", self.search_term) + """ % (self.dataset.type, + "[[:<:]]"+self.search_term+"[[:>:]]", + self.search_term) from_clause = ", GeneRIF " query = self.compile_final_query(from_clause, where_clause) @@ -255,6 +263,107 @@ class GoSearch(ProbeSetSearch): return self.execute(query) +class LrsSearch(ProbeSetSearch): + """Searches for genes with a QTL within the given LRS values + + LRS searches can take 2 different forms: + - LRS=(min_LRS max_LRS) + - LRS=(mine_LRS max_LRS chromosome start_Mb end_Mb) + where min/max_LRS represent the range of LRS scores and start/end_Mb represent + the range in megabases on the given chromosome + + """ + + DoSearch.search_types['LRS'] = 'LrsSearch' + + self.species_id = webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, + self.dataset.group) + +class CisLrsSearch(LrsSearch): + """Searches for genes on a particular chromosome with a cis-eQTL within the given LRS values + + A cisLRS search can take 2 forms: + - cisLRS=(min_LRS max_LRS) + - cisLRS=(min_LRS max_LRS mb_buffer) + where min/max_LRS represent the range of LRS scores and the mb_buffer is the range around + a particular QTL where its eQTL would be considered "cis". If there is no third parameter, + mb_buffer will default to 5 megabases. + + A QTL is a cis-eQTL if a gene's expression is regulated by a QTL in roughly the same area + (where the area is determined by the mb_buffer that the user can choose. + """ + # This is tentatively a child of LrsSearch; I'll need to check what code, if any, overlaps + # between this and the LrsSearch code. In the original code, commands are divided by + # the number of inputs they take, so these commands are completely separate + + DoSearch.search_types['CISLRS'] = "CisLrsSearch" + + def run(self): + if len(self.search_term) == 3: + lower_limit, upper_limit, min_threshold = int(value) for value in self.search_term + + where_clause = """ %sXRef.LRS > %s and + %sXRef.LRS < %s and + %sXRef.Locus = Geno.name and + Geno.SpeciesId = %s and + %s.Chr = Geno.Chr and + ABS(%s.Mb-Geno.Mb) < %s """ % ( + self.dataset.type, + min(lower_limit, upper_limit) + self.dataset.type, + max(lower_limit, upper_limit, + self.dataset.type, + + ) + + else: + NeedSomeErrorHere + + + return None + + +#itemCmd = item[0] +#lowerLimit = float(item[1]) +#upperLimit = float(item[2]) +# +#if itemCmd.upper() in ("TRANSLRS", "CISLRS"): +# if item[3]: +# mthresh = float(item[3]) +# clauseItem = " %sXRef.LRS > %2.7f and %sXRef.LRS < %2.7f " % \ +# (self.dbType, min(lowerLimit, upperLimit), self.dbType, max(lowerLimit, upperLimit)) +# if itemCmd.upper() == "CISLRS": +# clauseItem += """ and %sXRef.Locus = Geno.name and Geno.SpeciesId = %s and %s.Chr = Geno.Chr and ABS(%s.Mb-Geno.Mb) < %2.7f """ % (self.dbType, self.speciesId, self.dbType, self.dbType, mthresh) +# DescriptionText.append(HT.Span(' with a ', HT.U('cis-QTL'), ' having an LRS between %g and %g using a %g Mb exclusion buffer' % (min(lowerLimit, upperLimit), max(lowerLimit, upperLimit), mthresh))) +# else: +# clauseItem += """ and %sXRef.Locus = Geno.name and Geno.SpeciesId = %s and (%s.Chr != Geno.Chr or (%s.Chr != Geno.Chr and ABS(%s.Mb-Geno.Mb) > %2.7f)) """ % (self.dbType, self.speciesId, self.dbType, self.dbType, self.dbType, mthresh) +# DescriptionText.append(HT.Span(' with a ', HT.U('trans-QTL'), ' having an LRS between %g and %g using a %g Mb exclusion buffer' % (min(lowerLimit, upperLimit), max(lowerLimit, upperLimit), mthresh))) +# query.append(" (%s) " % clauseItem) +# self.orderByDefalut = "LRS" +# else: +# pass +#elif itemCmd.upper() in ("RANGE"): +# #XZ, 03/05/2009: Xiaodong changed Data to ProbeSetData +# clauseItem = " (select Pow(2, max(value) -min(value)) from ProbeSetData where Id = ProbeSetXRef.dataId) > %2.7f and (select Pow(2, max(value) -min(value)) from ProbeSetData where Id = ProbeSetXRef.dataId) < %2.7f " % (min(lowerLimit, upperLimit), max(lowerLimit, upperLimit)) +# query.append(" (%s) " % clauseItem) +# DescriptionText.append(HT.Span(' with a range of expression that varied between %g and %g' % (min(lowerLimit, upperLimit), max(lowerLimit, upperLimit)), " (fold difference)")) +#else: +# clauseItem = " %sXRef.%s > %2.7f and %sXRef.%s < %2.7f " % \ +# (self.dbType, itemCmd, min(lowerLimit, upperLimit), self.dbType, itemCmd, max(lowerLimit, upperLimit)) +# query.append(" (%s) " % clauseItem) +# self.orderByDefalut = itemCmd +# DescriptionText.append(HT.Span(' with ', HT.U(itemCmd), ' between %g and %g' % (min(lowerLimit, upperLimit), max(lowerLimit, upperLimit)))) + + +class MeanSearch(ProbeSetSearch): + """Searches for genes expressed within an interval (log2 units) determined by the user""" + + DoSearch.search_types['MEAN'] = "MeanSearch" + + def run(self): + + return None + if __name__ == "__main__": ### Usually this will be used as a library, but call it from the command line for testing @@ -283,7 +392,8 @@ if __name__ == "__main__": #results = ProbeSetSearch("salt", dataset, cursor, db_conn).run() #results = RifSearch("diabetes", dataset, cursor, db_conn).run() - results = WikiSearch("nicotine", dataset, cursor, db_conn).run() + #results = WikiSearch("nicotine", dataset, cursor, db_conn).run() + results = CisLrsSearch(['9','99','10'], dataset, cursor, db_conn).run() #results = PhenotypeSearch("brain", dataset, cursor, db_conn).run() #results = GenotypeSearch("rs13475699", dataset, cursor, db_conn).run() #results = GoSearch("0045202", dataset, cursor, db_conn).run() diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index a97ea8fd..6ba4d94a 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -259,7 +259,7 @@ class SearchResultPage(templatePage): for a_search in self.search_terms: print("[kodak] item is:", pf(a_search)) search_term = a_search['search_term'] - search_type = a_search['key'] + search_type = string.upper(a_search['key']) if not search_type: # We fall back to the dataset type as the key to get the right object search_type = self.dataset.type @@ -543,7 +543,6 @@ class SearchResultPage(templatePage): #XZ, 06/05/2009: It is neccessary to turn on nowrap this_trait.mean = repr = "%2.3f" % mean - tr.append(TDCell(HT.TD(repr, Class=className, align='right', nowrap='ON'),repr, mean)) #LRS and its location LRS_score_repr = 'N/A' @@ -581,17 +580,13 @@ class SearchResultPage(templatePage): this_trait.LRS_location_repr = LRS_location_repr = 'Chr %s: %.4f Mb' % (LRS_Chr, float(LRS_Mb) ) LRS_flag = 0 - #tr.append(TDCell(HT.TD(HT.Href(text=LRS_score_repr,url="javascript:showIntervalMapping('%s', '%s : %s')" % (formName, this_trait.db.shortname, this_trait.name), Class="fs12 fwn"), Class=className, align='right', nowrap="on"),LRS_score_repr, LRS_score_value)) - tr.append(TDCell(HT.TD(LRS_score_repr, Class=className, align='right', nowrap="on"), LRS_score_repr, LRS_score_value)) - tr.append(TDCell(HT.TD(LRS_location_repr, Class=className, nowrap="on"), LRS_location_repr, LRS_location_value)) + #if LRS_flag: + #tr.append(TDCell(HT.TD(LRS_score_repr, Class=className), LRS_score_repr, LRS_score_value)) + #tr.append(TDCell(HT.TD(LRS_location_repr, Class=className), LRS_location_repr, LRS_location_value)) - if LRS_flag: - tr.append(TDCell(HT.TD(LRS_score_repr, Class=className), LRS_score_repr, LRS_score_value)) - tr.append(TDCell(HT.TD(LRS_location_repr, Class=className), LRS_location_repr, LRS_location_value)) - - else: - tr.append(TDCell(HT.TD("N/A", Class=className), "N/A", "N/A")) - tr.append(TDCell(HT.TD("N/A", Class=className), "N/A", "N/A")) + #else: + #tr.append(TDCell(HT.TD("N/A", Class=className), "N/A", "N/A")) + #tr.append(TDCell(HT.TD("N/A", Class=className), "N/A", "N/A")) tblobj_body.append(tr) |