aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/do_search.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/wqflask/do_search.py')
-rw-r--r--wqflask/wqflask/do_search.py103
1 files changed, 93 insertions, 10 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py
index a2eddfc6..1b1b56fb 100644
--- a/wqflask/wqflask/do_search.py
+++ b/wqflask/wqflask/do_search.py
@@ -20,17 +20,18 @@ class DoSearch(object):
# Used to translate search phrases into classes
search_types = dict()
- def __init__(self, search_term, search_operator, dataset):
+ def __init__(self, search_term, search_operator=None, dataset=None):
self.search_term = search_term
# Make sure search_operator is something we expect
assert search_operator in (None, "=", "<", ">", "<=", ">="), "Bad search operator"
self.search_operator = search_operator
self.dataset = dataset
- print("self.dataset is boo: ", type(self.dataset), pf(self.dataset))
- print("self.dataset.group is: ", pf(self.dataset.group))
-
- #Get group information for dataset and the species id
- self.species_id = webqtlDatabaseFunction.retrieve_species_id(self.dataset.group.name)
+
+ if self.dataset:
+ print("self.dataset is boo: ", type(self.dataset), pf(self.dataset))
+ print("self.dataset.group is: ", pf(self.dataset.group))
+ #Get group information for dataset and the species id
+ self.species_id = webqtlDatabaseFunction.retrieve_species_id(self.dataset.group.name)
def execute(self, query):
"""Executes query and returns results"""
@@ -57,8 +58,42 @@ class DoSearch(object):
@classmethod
def get_search(cls, search_type):
+ print("search_types are:", pf(cls.search_types))
return cls.search_types[search_type]
+class QuickMrnaAssaySearch(DoSearch):
+ """A general search for mRNA assays"""
+
+ DoSearch.search_types['quick_mrna_assay'] = "QuickMrnaAssaySearch"
+
+ base_query = """SELECT ProbeSet.Name as ProbeSet_Name,
+ ProbeSet.Symbol as ProbeSet_Symbol,
+ ProbeSet.description as ProbeSet_Description,
+ ProbeSet.Chr_num as ProbeSet_Chr_Num,
+ ProbeSet.Mb as ProbeSet_Mb,
+ ProbeSet.name_num as ProbeSet_name_num
+ FROM ProbeSet """
+
+ header_fields = ['',
+ 'Record ID',
+ 'Symbol',
+ 'Location']
+
+ def run(self):
+ """Generates and runs a search for assays across all mRNA expression datasets"""
+
+ print("Running ProbeSetSearch")
+ query = self.base_query + """WHERE (MATCH (ProbeSet.Name,
+ ProbeSet.description,
+ ProbeSet.symbol,
+ ProbeSet.alias)
+ AGAINST ('%s' IN BOOLEAN MODE))
+ """ % (escape(self.search_term[0]))
+
+ print("final query is:", pf(query))
+
+ return self.execute(query)
+
class MrnaAssaySearch(DoSearch):
"""A search within an mRNA expression dataset"""
@@ -124,7 +159,7 @@ class MrnaAssaySearch(DoSearch):
return self.execute(query)
-
+
class PhenotypeSearch(DoSearch):
"""A search within a phenotype dataset"""
@@ -198,9 +233,57 @@ class PhenotypeSearch(DoSearch):
query = self.compile_final_query(where_clause = self.get_fields_clause())
- results = self.execute(query)
- print("in [df] run results are:", results)
- return results
+ return self.execute(query)
+
+class QuickPhenotypeSearch(PhenotypeSearch):
+ """A search across all phenotype datasets"""
+
+ DoSearch.search_types['quick_phenotype'] = "QuickPhenotypeSearch"
+
+ base_query = """SELECT Species.Name as Species_Name,
+ PublishFreeze.FullName as Dataset_Name,
+ PublishFreeze.Name,
+ PublishXRef.Id,
+ PublishFreeze.createtime as thistable,
+ Publication.PubMed_ID as Publication_PubMed_ID,
+ Phenotype.Post_publication_description as Phenotype_Name
+ FROM Phenotype,
+ PublishFreeze,
+ Publication,
+ PublishXRef,
+ InbredSet,
+ Species """
+
+ search_fields = ('Phenotype.Post_publication_description',
+ 'Phenotype.Pre_publication_description',
+ 'Phenotype.Pre_publication_abbreviation',
+ 'Phenotype.Post_publication_abbreviation',
+ 'Phenotype.Lab_code',
+ 'Publication.PubMed_ID',
+ 'Publication.Abstract',
+ 'Publication.Title',
+ 'Publication.Authors')
+
+ def compile_final_query(self, where_clause = ''):
+ """Generates the final query string"""
+
+ query = (self.base_query +
+ """WHERE %s
+ PublishXRef.PhenotypeId = Phenotype.Id and
+ PublishXRef.PublicationId = Publication.Id and
+ PublishXRef.InbredSetId = InbredSet.Id and
+ InbredSet.SpeciesId = Species.Id""" % where_clause)
+
+ print("query is:", pf(query))
+
+ return query
+
+ def run(self):
+ """Generates and runs a search across all phenotype datasets"""
+
+ query = self.compile_final_query(where_clause = self.get_fields_clause())
+
+ return self.execute(query)
class GenotypeSearch(DoSearch):
"""A search within a genotype dataset"""