예제 #1
0
	def type(self, id=None):
		ScoreRankHistogram = model.Stock_250kDB.ScoreRankHistogram
		ScoreRankHistogramType = model.Stock_250kDB.ScoreRankHistogramType
		query = ScoreRankHistogram.query
		if id is None:
			id = request.params.get('id', 1)
		hist_type_id = id
		
		extra_condition = 's.hist_type_id=%s'%hist_type_id
		
		c.phenotype_info  = hc.getPhenotypeInfo(ScoreRankHistogram.table.name, extra_condition)
		c.list_info = hc.getListTypeInfo(ScoreRankHistogram.table.name, extra_condition)
		
		c.hist_type = ScoreRankHistogramType.get(hist_type_id)
		rows = query.filter_by(hist_type_id=hist_type_id).all()
		data_matrix = numpy.zeros([len(c.list_info.list_type_id_ls), len(c.phenotype_info.phenotype_method_id_ls)], numpy.int)
		data_matrix[:] = -1
		counter = 0
		for row in rows:
			row_index = c.list_info.list_type_id2index[row.list_type_id]
			col_index = c.phenotype_info.phenotype_method_id2index[row.phenotype_method_id]
			data_matrix[row_index, col_index] = row.id
			counter +=1
		c.counter = counter
		c.data_matrix = data_matrix
		return render('/score_rank_histgram_type.html')
예제 #2
0
	def type_by_snp(self, id=None):
		"""
		2008-10-17
			display SNP region plots in a matrix fashion by spanning the phenotype axis.
		"""
		SNPRegionPlot = model.Stock_250kDB.SNPRegionPlot
		if id is None:
			id = request.params.get('id', 1)
		extra_condition = 's.plot_type_id=%s'%id
		
		c.phenotype_info  = hc.getPhenotypeInfo(SNPRegionPlot.table.name, extra_condition)
		c.snp_info = self.getSNPInfo(plot_type_id=id)
		
		data_matrix = numpy.zeros([len(c.snp_info.snp_ls), len(c.phenotype_info.phenotype_method_id_ls)], numpy.int)
		data_matrix[:] = -1
		counter = 0
		
		rows = SNPRegionPlot.query.filter_by(plot_type_id=id).all()
		for row in rows:
			snp_key = (row.chromosome, row.start, row.stop)
			row_index = c.snp_info.snp2index[snp_key]
			col_index = c.phenotype_info.phenotype_method_id2index[row.phenotype_method_id]
			data_matrix[row_index, col_index] = row.id
			counter +=1
		c.counter = counter
		c.data_matrix = data_matrix
		return render('/snp_region_plot_type_by_snp.html')
예제 #3
0
	def type_by_gene(self, id=None):
		"""
		2008-10-17
		"""
		SNPRegionPlot = model.Stock_250kDB.SNPRegionPlot
		SNPRegionPlotToGene = model.Stock_250kDB.SNPRegionPlotToGene
		if id is None:
			id = request.params.get('id', 1)
		extra_condition = 's.plot_type_id=%s'%id
		
		c.phenotype_info  = hc.getPhenotypeInfo(SNPRegionPlot.table.name, extra_condition)
		c.gene_info = self.getGeneInfo(plot_type_id=id)
		
		data_matrix = numpy.zeros([len(c.gene_info.gene_ls), len(c.phenotype_info.phenotype_method_id_ls)], numpy.int)
		#data_matrix[:] = -1
		counter = 0
		
		rows = SNPRegionPlotToGene.query.filter(SNPRegionPlotToGene.snp_region_plot.has(plot_type_id=id)).all()
		for row in rows:
			row_index = c.gene_info.gene_id2index[row.gene_id]
			c.gene_info.gene_ls[row_index].snp_region_plot_ls.append(row.snp_region_plot)
			col_index = c.phenotype_info.phenotype_method_id2index[row.snp_region_plot.phenotype_method_id]
			data_matrix[row_index, col_index] = row.snp_region_plot.id
			counter +=1
		for row_index in range(len(c.gene_info.gene_ls)):
			c.gene_info.gene_ls[row_index].snp_region_plot_ls.sort(lambda x, y: int(x.phenotype_method_id-y.phenotype_method_id))	#comparison function must return int. and long is NOT int.
			c.gene_info.gene_ls[row_index].snp_region_plot_id_ls = [str(snp_region_plot.id) for snp_region_plot in c.gene_info.gene_ls[row_index].snp_region_plot_ls]
		c.counter = counter
		c.data_matrix = data_matrix
		return render('/snp_region_plot_type_by_gene.html')
예제 #4
0
	def getPhenotypeMethodLs(call_method_id):
		"""
		2009-1-30
		"""
		affiliated_table_name = model.Stock_250kDB.ResultsMethod.table.name
		extra_condition = 's.call_method_id=%s'%(call_method_id)
		phenotype_info  = hc.getPhenotypeInfo(affiliated_table_name=affiliated_table_name, extra_condition=extra_condition)
		phenotype_method_ls = []
		for i in range(len(phenotype_info.phenotype_method_id_ls)):
			phenotype_method_id = phenotype_info.phenotype_method_id_ls[i]
			phenotype_method_label = phenotype_info.phenotype_method_label_ls[i]
			phenotype_method_ls.append([phenotype_method_id, phenotype_method_label])
		return phenotype_method_ls
예제 #5
0
	def getPhenotypeMethodLs(self, call_method_id=None, affiliated_table_name=None):
		"""
		2009-4-6
			copied from DisplayResults.py
		"""
		#call_method_id = request.params.getone('call_method_id')
		#affiliated_table_name = model.Stock_250kDB.ResultsMethod.table.name
		#extra_condition = 's.call_method_id=%s'%(call_method_id)
		
		extra_condition = ''
		phenotype_info  = hc.getPhenotypeInfo(affiliated_table_name=affiliated_table_name, extra_condition=extra_condition)
		phenotype_method_ls = []
		for i in range(len(phenotype_info.phenotype_method_id_ls)):
			phenotype_method_id = str(phenotype_info.phenotype_method_id_ls[i])
			phenotype_method_label = phenotype_info.phenotype_method_label_ls[i]
			phenotype_method_ls.append([phenotype_method_id, phenotype_method_label])
		return phenotype_method_ls
예제 #6
0
	def getPhenotypeMethodLsGivenType(type_id, call_method_id, extra_table_name=None):
		"""
		2009-2-22
			add argument extra_table_name
		2008-12-30
		"""
		affiliated_table_name = model.Stock_250kDB.ResultsMethod.table.name
		if not extra_table_name:
			extra_table_name = model.Stock_250kDB.CandidateGeneTopSNPTestRM.table.name
		extra_tables = ' %s c '%extra_table_name
		extra_condition = 'c.results_id=s.id and c.type_id=%s and s.call_method_id=%s'%(type_id, call_method_id)
		phenotype_info  = hc.getPhenotypeInfo(affiliated_table_name=affiliated_table_name, extra_condition=extra_condition,
											extra_tables=extra_tables)
		phenotype_method_ls = []
		for i in range(len(phenotype_info.phenotype_method_id_ls)):
			phenotype_method_id = phenotype_info.phenotype_method_id_ls[i]
			phenotype_method_label = phenotype_info.phenotype_method_label_ls[i]
			phenotype_method_ls.append([phenotype_method_id, phenotype_method_label])
		return phenotype_method_ls
예제 #7
0
	def getPhenotypeMethodLsGivenType(type_id, extra_table_name=None):
		"""
		2009-4-13
			added results_gene2type into the condition to restrict phenotype_methods
			type_id is actually used now.
		2009-3-4
		"""
		affiliated_table_name = model.Stock_250kDB.ResultsMethod.table.name
		type = ScoreRankHistogramType.get(type_id)
		call_method_id = type.call_method_id
		if not extra_table_name:
			extra_table_name = model.Stock_250kDB.ResultsGene.table.name
		extra_tables = ' %s c, %s y'%(extra_table_name, "results_gene2type")
		extra_condition = 'c.results_id=s.id and s.call_method_id=%s and y.score_rank_histogram_type_id=%s and y.results_gene_id=c.id'%\
				(call_method_id, type_id)
		phenotype_info  = hc.getPhenotypeInfo(affiliated_table_name=affiliated_table_name, extra_condition=extra_condition,
											extra_tables=extra_tables)
		phenotype_method_ls = []
		for i in range(len(phenotype_info.phenotype_method_id_ls)):
			phenotype_method_id = phenotype_info.phenotype_method_id_ls[i]
			phenotype_method_label = phenotype_info.phenotype_method_label_ls[i]
			phenotype_method_ls.append([phenotype_method_id, phenotype_method_label])
		return phenotype_method_ls, call_method_id
예제 #8
0
	def call_method(self, id=None):
		if id is None:
			id = request.params.get('id', 17)
		
		MAFVsScorePlot = model.Stock_250kDB.MAFVsScorePlot
		affiliated_table_name = model.Stock_250kDB.ResultsMethod.table.name
		extra_condition = 's.call_method_id=%s and s.id=m.results_method_id'%id
		extra_tables = '%s m'%model.Stock_250kDB.MAFVsScorePlot.table.name
		c.phenotype_info  = hc.getPhenotypeInfo(affiliated_table_name, extra_condition, extra_tables)
		c.analysis_info = hc.getAnalysisMethodInfo(affiliated_table_name, extra_condition, extra_tables)
		
		rows = MAFVsScorePlot.query.filter(MAFVsScorePlot.results_method.has(call_method_id=id))
		data_matrix = numpy.zeros([len(c.phenotype_info.phenotype_method_id_ls), len(c.analysis_info.id_ls)], numpy.int)
		data_matrix[:] = -1
		counter = 0
		for row in rows:
			row_index = c.phenotype_info.phenotype_method_id2index[row.results_method.phenotype_method_id]
			col_index = c.analysis_info.id2index[row.results_method.analysis_method_id]
			data_matrix[row_index, col_index] = row.id
			counter +=1
		c.counter = counter
		c.data_matrix = data_matrix
		c.call_method_id = id
		return render('/maf_vs_score_call_method.html')
예제 #9
0
	def getOverlappingDataAcrossPhenotypes(self, no_of_top_snps=1000):
		"""
		2009-11-30
		"""
		call_method_id = int(request.params.get('call_method_id', config['app_conf']['published_call_method_id']))
		no_of_top_snps = int(request.params.get('no_of_top_snps', no_of_top_snps))
		phenotype_info = hc.getPhenotypeInfo(affiliated_table_name=model.Stock_250kDB.AssociationOverlappingStat.table.name, \
											extra_condition="s.call_method_id=%s"%call_method_id, extra_tables=None, \
											with_category_separator=False)
		overlapping_type_info = hc.getAssociationOverlappingTypeInfo(affiliated_table_name=model.Stock_250kDB.AssociationOverlappingStat.table.name, \
																	extra_condition="s.call_method_id=%s"%call_method_id, extra_tables=None)
		
		#construct the full data and turn it into json
		column_name_type_ls = [("label", ("string","ID Name")), ("date", ("date", "Date")), ("phenotype_method_id", ("number", "Phenotype ID")), \
							("phenotype_name", ("string", "Phenotype Name")), \
							("category", ("string","Category")), ]
		no_of_non_stat_cols = len(column_name_type_ls)
		for i in range(len(overlapping_type_info.list_type_label_ls)):
			column_name_type_ls.append(('%s'%overlapping_type_info.list_type_id_ls[i], ("number", overlapping_type_info.list_type_label_ls[i])))
		return_ls = []
		
		for i in range(len(phenotype_info.phenotype_method_id2index)):
			entry = {}
			for column_name_type in column_name_type_ls[no_of_non_stat_cols:]:	# set the default value for the overlapping stats
				column_name = column_name_type[0]
				column_type = column_name_type[1][0]
				entry[column_name] = None
			return_ls.append(entry)
		
		rows = model.Stock_250kDB.AssociationOverlappingStat.query.filter_by(call_method_id=call_method_id).filter_by(no_of_top_snps=no_of_top_snps)
		
		for row in rows:
			phenotype_index = phenotype_info.phenotype_method_id2index[row.phenotype_method_id]
			entry = return_ls[phenotype_index]
			for column_name_type in column_name_type_ls[:no_of_non_stat_cols]:	# only the info related to phenotype part
				column_name = column_name_type[0]
				column_type = column_name_type[1][0]
				
				if column_type=='string':
					default_value = ''
				elif column_type=='date':
					default_value = datetime.date(2050, 1, 1)
				else:
					default_value = None
				
				if column_name == 'phenotype_name':
					pm = model.Stock_250kDB.PhenotypeMethod.get(row.phenotype_method_id)
					column_value = pm.short_name
				elif column_name=='category':
					pm = model.Stock_250kDB.PhenotypeMethod.get(row.phenotype_method_id)
					if pm.biology_category:
						column_value = pm.biology_category.short_name
					else:
						column_value = None
				elif column_name=='label':
					pm = model.Stock_250kDB.PhenotypeMethod.get(row.phenotype_method_id)
					column_value = '%s %s'%(row.phenotype_method_id, pm.short_name)
				else:
					column_value = getattr(row, column_name, default_value)
					if column_value is None:
						column_value = default_value
				entry[column_name] = column_value
			# set the overlapping stat
			column_name = '%s'%row.overlapping_type_id
			entry[column_name] = row.no_of_overlapping_snps
		
		description = dict(column_name_type_ls)
		data_table = gviz_api.DataTable(description)
		data_table.LoadData(return_ls)
		column_ls = [row[0] for row in column_name_type_ls]
		json_result = data_table.ToJSon(columns_order=column_ls)	#ToJSonResponse only works with google.visualization.Query
		response.headers['Content-Type'] = 'application/json'
		return json_result
예제 #10
0
	def type(cls, id=None, TypeClass=model.Stock_250kDB.CandidateGeneTopSNPTestRMType, \
			template='/display_top_snp_test_rm_type.html', \
			phenotype_id_ls_str = '1-7,39-61,80-82,9-13,32-38,65-74', \
			list_type_id_ls_str = '3,6,8,28,51,64,65,68,71,76,129,24,29,30,130,131',\
			analysis_method_id_ls_str = '1,5,6,7',\
			figure_type=1, call_method_id=17):
		"""
		2009-10-13
			allow user to specify phenotype_id_ls_str and list_type_id_ls_str in URL
			add figure_type argument:
				1: candidate vs non-candidate ratio (in db beforehand)
				2: 2D matrix-plot of pvalue for enrichment statistic. row is cutoff. column is distance between gene and SNP.
			add call_method_id argument
			add argument analysis_method_id_ls_str
		2008-10-30
			generalized so that DisplayResultsGene could call it
		"""
		ResultsMethod = model.Stock_250kDB.ResultsMethod
		
		if id is None:
			id = request.params.get('id', '1')
		
		phenotype_id_ls_str = request.params.get('phenotype_id_ls_str', phenotype_id_ls_str)	# 2009-10-13
		list_type_id_ls_str = request.params.get('list_type_id_ls_str', list_type_id_ls_str)	# 2009-10-13
		analysis_method_id_ls_str  = request.params.get('analysis_method_id_ls_str', analysis_method_id_ls_str)	# 2009-10-13
		c.figure_type = request.params.get('figure_type', figure_type)	# 2009-10-13
		call_method_id = request.params.get('call_method_id', call_method_id)	# 2009-10-13
		
		phenotype_id_ls = getListOutOfStr(phenotype_id_ls_str, data_type=str)
		
		list_type_id_ls = getListOutOfStr(list_type_id_ls_str, data_type=str)
		analysis_method_id_ls = getListOutOfStr(analysis_method_id_ls_str, data_type=int)
		
		#extra_tables = ' %s c '%(CandidateGeneTopSNPTestRM.table.name)
		extra_condition = 'p.id in (%s)'%(','.join(phenotype_id_ls))
		
		c.phenotype_info  = hc.getPhenotypeInfo(extra_condition=extra_condition, extra_tables=None)
		#extra_condition = 's.type_id =%s'%id
		extra_condition = 'p.id in (%s)'%(','.join(list_type_id_ls))
		
		c.list_info = hc.getListTypeInfo(extra_condition=extra_condition)
		
		data_matrix = []
		no_of_rows = len(c.list_info.list_type_id_ls)
		no_of_cols = len(c.phenotype_info.phenotype_method_id_ls)
		for i in range(no_of_rows):
			data_matrix.append([None]*no_of_cols)
		
		c.type = TypeClass.get(id)
		
		#2008-10-29 a faster way to come up the data_matrix but data is not guaranteed inside
		rows = ResultsMethod.query.filter(ResultsMethod.phenotype_method_id.in_(map(int, phenotype_id_ls))).\
			filter(ResultsMethod.analysis_method_id.in_(analysis_method_id_ls)).\
			filter_by(call_method_id=call_method_id).\
			order_by(ResultsMethod.analysis_method_id)
		counter = 0
		for row in rows:
			col_index = c.phenotype_info.phenotype_method_id2index.get(row.phenotype_method_id)
			if col_index is None:
				continue
			for list_type_id, row_index in c.list_info.list_type_id2index.iteritems():
				if list_type_id>0:
					if data_matrix[row_index][col_index] is None:
						data_matrix[row_index][col_index] = []
					data_matrix[row_index][col_index].append((row.id, row.analysis_method.short_name))
					counter +=1
		"""
		rows = CandidateGeneTopSNPTestRM.query.filter_by(type_id=id)
		
		for row in rows:
			row_index = c.list_info.list_type_id2index[row.list_type_id]
			col_index = c.phenotype_info.phenotype_method_id2index[row.result.phenotype_method_id]
			if data_matrix[row_index][col_index] is None:
				data_matrix[row_index][col_index] = Set()
			data_matrix[row_index][col_index].add(row.results_id)
			counter +=1
		"""
		c.counter = counter
		c.data_matrix = data_matrix
		return render(template)