def getPhenotypeInfo(self, db, where_condition): """ 2008-08-29 add -1 as a separator into phenotype_method_id_ls and others """ sys.stderr.write("Getting phenotype method info ...") rows = db.metadata.bind.execute("select distinct r.phenotype_method_id, p.biology_category_id from %s p, %s and p.id=r.phenotype_method_id order by p.biology_category_id, r.phenotype_method_id"\ %(PhenotypeMethod.table.name, where_condition)) phenotype_method_id_ls = [] phenotype_method_id2index = {} phenotype_method_label_ls = [] prev_biology_category_id = None no_of_separators = 0 for row in rows: if prev_biology_category_id == None: prev_biology_category_id = row.biology_category_id elif row.biology_category_id != prev_biology_category_id: prev_biology_category_id = row.biology_category_id #add a blank phenotype id as separator no_of_separators += 1 phenotype_method_id2index[-no_of_separators] = len( phenotype_method_id_ls) phenotype_method_id_ls.append(-no_of_separators) phenotype_method_label_ls.append('') phenotype_method_id2index[row.phenotype_method_id] = len( phenotype_method_id_ls) phenotype_method_id_ls.append(row.phenotype_method_id) pm = PhenotypeMethod.get(row.phenotype_method_id) phenotype_method_label_ls.append('%s_%s' % (pm.id, pm.short_name)) phenotype_info = PassingData() phenotype_info.phenotype_method_id2index = phenotype_method_id2index phenotype_info.phenotype_method_id_ls = phenotype_method_id_ls phenotype_info.phenotype_method_label_ls = phenotype_method_label_ls sys.stderr.write("Done.\n") return phenotype_info
def getPhenotypeInfo(self, db, where_condition): """ 2008-08-29 add -1 as a separator into phenotype_method_id_ls and others """ sys.stderr.write("Getting phenotype method info ...") rows = db.metadata.bind.execute("select distinct r.phenotype_method_id, p.biology_category_id from %s p, %s and p.id=r.phenotype_method_id order by p.biology_category_id, r.phenotype_method_id"\ %(PhenotypeMethod.table.name, where_condition)) phenotype_method_id_ls = [] phenotype_method_id2index = {} phenotype_method_label_ls = [] prev_biology_category_id = None no_of_separators = 0 for row in rows: if prev_biology_category_id == None: prev_biology_category_id = row.biology_category_id elif row.biology_category_id!=prev_biology_category_id: prev_biology_category_id = row.biology_category_id #add a blank phenotype id as separator no_of_separators += 1 phenotype_method_id2index[-no_of_separators] = len(phenotype_method_id_ls) phenotype_method_id_ls.append(-no_of_separators) phenotype_method_label_ls.append('') phenotype_method_id2index[row.phenotype_method_id] = len(phenotype_method_id_ls) phenotype_method_id_ls.append(row.phenotype_method_id) pm = PhenotypeMethod.get(row.phenotype_method_id) phenotype_method_label_ls.append('%s_%s'%(pm.id, pm.short_name)) phenotype_info = PassingData() phenotype_info.phenotype_method_id2index = phenotype_method_id2index phenotype_info.phenotype_method_id_ls = phenotype_method_id_ls phenotype_info.phenotype_method_label_ls = phenotype_method_label_ls sys.stderr.write("Done.\n") return phenotype_info
def getResultsMethodIDInfo(self, db, call_method_id_ls, min_distance, get_closest, min_MAF): """ 2008-09-05 use results_by_gene.id as main result id """ sys.stderr.write("Gettiing ResultsMethodIDInfo ...") results_method_id_info = PassingData() results_method_id_ls = [] results_method_id2index = {} results_method_id_label_ls = [] rows = db.metadata.bind.execute("select distinct rg.id, rg.results_method_id, r.analysis_method_id, r.phenotype_method_id, \ p.biology_category_id from %s rg, %s r, %s p \ where rg.results_method_id=r.id and p.id=r.phenotype_method_id and r.call_method_id in (%s) \ and rg.min_distance=%s and rg.get_closest=%s and rg.min_MAF>=%s-0.0001 and rg.min_MAF<=%s+0.0001 \ order by p.biology_category_id, r.phenotype_method_id, r.analysis_method_id"%(ResultsByGene.table.name, \ ResultsMethod.table.name, PhenotypeMethod.table.name, repr(call_method_id_ls)[1:-1], min_distance, get_closest, min_MAF, min_MAF)) prev_phenotype_method_id = None prev_biology_category_id = None no_of_separators = 0 for row in rows: if prev_biology_category_id==None: prev_biology_category_id = row.biology_category_id elif row.biology_category_id!=prev_biology_category_id: prev_biology_category_id = row.biology_category_id no_of_separators += 1 results_method_id2index[-no_of_separators] = len(results_method_id_ls) results_method_id_ls.append(-no_of_separators) results_method_id_label_ls.append('') if prev_phenotype_method_id == None: prev_phenotype_method_id = row.phenotype_method_id elif row.phenotype_method_id!=prev_phenotype_method_id: prev_phenotype_method_id = row.phenotype_method_id #add a blank phenotype id as separator no_of_separators += 1 results_method_id2index[-no_of_separators] = len(results_method_id_ls) results_method_id_ls.append(-no_of_separators) results_method_id_label_ls.append('') results_method_id2index[row.id] = len(results_method_id_ls) results_method_id_ls.append(row.id) am = AnalysisMethod.get(row.analysis_method_id) pm = PhenotypeMethod.get(row.phenotype_method_id) results_method_id_label_ls.append('%s_%s_%s'%(am.short_name, pm.short_name, pm.id)) results_method_id_info.results_method_id_ls = results_method_id_ls results_method_id_info.results_method_id2index = results_method_id2index results_method_id_info.results_method_id_label_ls = results_method_id_label_ls sys.stderr.write("%s results. Done.\n"%(len(results_method_id_ls))) return results_method_id_info
def findPhenotypeMethodGivenName(self, phenotype_name, db): """ 2009-7-30 find/create the db phenotype entry given phenotype_name """ session = db.session if phenotype_name: #if the short name is given, forget about phenotype_id if phenotype_name in self.phenotype_name2pm: return self.phenotype_name2pm.get(phenotype_name) pm = PhenotypeMethod.query.filter_by( short_name=phenotype_name).first() #try search the db first. if not pm: pm = PhenotypeMethod(short_name=phenotype_name) session.save(pm) session.flush() if self.report: sys.stderr.write("phenotype ID for %s is %s." % (phenotype_name, pm.id)) self.phenotype_name2pm[phenotype_name] = pm return pm