예제 #1
0
	def getGeneInfo(self, plot_type_id=None):
		"""
		2008-10-17
			return data structure containing sorted gene list and its info
		"""
		SNPRegionPlot = model.Stock_250kDB.SNPRegionPlot
		SNPRegionPlotToGene = model.Stock_250kDB.SNPRegionPlotToGene
		rows = model.db.metadata.bind.execute("select g.gene_id, count(distinct s.phenotype_method_id) as count from %s g, %s s\
			where s.id=g.plot_id and s.plot_type_id=%s group by g.gene_id order by count desc, gene_id"\
			%(SNPRegionPlotToGene.table.name, SNPRegionPlot.table.name, plot_type_id))
		gene_ls = []
		gene_id2index = {}
		gene_label_ls = []
		gene_desc_names = ['gene_id', 'gene_symbol', 'type_of_gene', 'chr', 'start', 'stop', 'protein_label', 'protein_comment', 'protein_text']
		for row in rows:
			gene_id2index[row.gene_id] = len(gene_ls)
			matrix_of_gene_descriptions = hc.returnGeneDescLs(model.gene_annotation, gene_id_ls=[row.gene_id])
			if len(matrix_of_gene_descriptions)>0:
				gene_desc_ls = matrix_of_gene_descriptions[0]
				gene = PassingData(gene_id=row.gene_id, gene_symbol=gene_desc_ls[1], type_of_gene=gene_desc_ls[2], chr=gene_desc_ls[3],\
								start=gene_desc_ls[4], stop=gene_desc_ls[5], protein_label=gene_desc_ls[6], protein_comment=gene_desc_ls[7], \
								protein_text=gene_desc_ls[8])
			else:
				gene = PassingData(gene_id=row.gene_id)
			gene.count = row.count
			gene.snp_region_plot_ls = []
			gene_ls.append(gene)
			gene_label_ls.append(getattr(gene, 'gene_symbol', row.gene_id))
		gene_info = PassingData()
		gene_info.gene_id2index = gene_id2index
		gene_info.gene_ls = gene_ls
		gene_info.gene_label_ls = gene_label_ls
		return gene_info
예제 #2
0
	def show_plot(self, id=None, snp_region_plot_ids=None):
		"""
		2008-10-30
			add option snp_region_plot_ids for display_results_gene_one.html to call but not necessary. request.params is good enough.
		2008-10-17
			get request params: get_other_phenotypes, snp_region_plot_ids
		2008-10-06
		"""
		SNPRegionPlot = model.Stock_250kDB.SNPRegionPlot
		if id:
			c.snp_region_plot = SNPRegionPlot.get(id)
		else:
			c.snp_region_plot = None
		
		get_other_phenotypes = request.params.get('get_other_phenotypes', False)
		snp_region_plot_ids = request.params.get('snp_region_plot_ids', snp_region_plot_ids)
		if get_other_phenotypes:
			c.snp_region_plot_ls = SNPRegionPlot.query.filter_by(chromosome=c.snp_region_plot.chromosome).\
				filter_by(start=c.snp_region_plot.start).\
				filter_by(stop=c.snp_region_plot.stop).\
				filter_by(plot_type_id=c.snp_region_plot.plot_type_id).order_by(SNPRegionPlot.phenotype_method_id).all()
		elif snp_region_plot_ids:
			snp_region_plot_id_ls = snp_region_plot_ids.split(',')
			#snp_region_plot_id_ls = map(int, snp_region_plot_id_ls)
			c.snp_region_plot_ls = [SNPRegionPlot.get(int(snp_region_plot_id)) for snp_region_plot_id in snp_region_plot_id_ls]
		else:
			c.snp_region_plot_ls = []
		
		if c.snp_region_plot is None and len(c.snp_region_plot_ls)>0:
			c.snp_region_plot = c.snp_region_plot_ls[0]
		
		#plot_file_path = os.path.join(config['app_conf']['plots_store'], 'snp_region_plot_%s.png'%c.snp_region_plot.id)
		#if not os.path.isfile(plot_file_path):
		#	self.savePlot(c.snp_region_plot, plot_file_path)
		
		gene_annotation = model.gene_annotation
		gene_id_ls = [plot2gene.gene_id for plot2gene in c.snp_region_plot.plot2gene_ls]
		c.matrix_of_gene_descriptions = hc.returnGeneDescLs(gene_annotation, gene_id_ls)
		#print abc
		#raise Exception('Just testing the interactive debugger!')
		#c.matrix_of_gene_descriptions = []
		return render('/snp_region_plot_single.html')