예제 #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 getGeneListTypeLsGivenTypeAndPhenotypeMethodAndAnalysisMethod():
		"""
		2009-3-4
			called by getGeneListTypeLsGivenTypeAndPhenotypeMethodAndAnalysisMethodJson()
		"""
		#if not affiliated_table_name:
		#	affiliated_table_name = model.Stock_250kDB.CandidateGeneTopSNPTestRM.table.name	#alias is 's'
		#extra_tables = ' %s c '%model.Stock_250kDB.ResultsMethod.table.name
		#extra_condition = 's.results_id=c.id and s.type_id=%s and c.call_method_id=%s and c.phenotype_method_id=%s and c.analysis_method_id=%s'%\
		#	(type_id, call_method_id, phenotype_method_id, analysis_method_id)
		list_info = hc.getListTypeInfo(affiliated_table_name=None, extra_condition=None, extra_tables=None)
		
		ls = [[0, u'No candidate gene list. (All SNPs)']]
		for i in range(len(list_info.list_type_id_ls)):
			id = list_info.list_type_id_ls[i]
			label = list_info.list_type_label_ls[i]
			ls.append([id, label])
		return ls
예제 #3
0
	def getGeneListTypeLsGivenTypeAndPhenotypeMethodAndAnalysisMethod(type_id, call_method_id, phenotype_method_id, analysis_method_id, affiliated_table_name=None):
		"""
		2009-2-22
			add argument affiliated_table_name (but not used)
		2008-12-30
		"""
		if not affiliated_table_name:
			affiliated_table_name = model.Stock_250kDB.CandidateGeneTopSNPTestRM.table.name	#alias is 's'
		extra_tables = ' %s c '%model.Stock_250kDB.ResultsMethod.table.name
		extra_condition = 's.results_id=c.id and s.type_id=%s and c.call_method_id=%s and c.phenotype_method_id=%s and c.analysis_method_id=%s'%\
			(type_id, call_method_id, phenotype_method_id, analysis_method_id)
		list_info = hc.getListTypeInfo(affiliated_table_name, extra_condition=extra_condition, extra_tables=extra_tables)
		
		ls = []
		
		for i in range(len(list_info.list_type_id_ls)):
			id = list_info.list_type_id_ls[i]
			label = list_info.list_type_label_ls[i]
			ls.append([id, label])
		return ls
예제 #4
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)