當前位置: 首頁>>代碼示例>>Python>>正文


Python PassingData.permData方法代碼示例

本文整理匯總了Python中pymodule.PassingData.permData方法的典型用法代碼示例。如果您正苦於以下問題:Python PassingData.permData方法的具體用法?Python PassingData.permData怎麽用?Python PassingData.permData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pymodule.PassingData的用法示例。


在下文中一共展示了PassingData.permData方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getTestResult

# 需要導入模塊: from pymodule import PassingData [as 別名]
# 或者: from pymodule.PassingData import permData [as 別名]
	def getTestResult(self, session, rm, TestResultClass, pd):
		"""
		2008-10-30
			get one instance of CandidateGeneTopSNPTestRM for CandidateGeneTopSNPTestRMNullData
			
			if it's in db, fetch it
			it not, generate one
		"""
		starting_rank = getattr(pd, 'starting_rank', 1)	#from which rank to look down for top snps
		commit = getattr(pd, 'commit', 0)	#2008-10-30 save objects right away
		need_permData = getattr(pd, 'need_permData', 0)	#2008-10-30 a flag indicating whether permData is needed
		
		return_data = PassingData(result=None, permData=None)
		
		candidate_gene_set = self.dealWithCandidateGeneList(pd.list_type_id, return_set=True)	#internal cache
		param_data = PassingData(results_directory=pd.results_directory, candidate_gene_set=candidate_gene_set, \
									min_MAF=pd.min_MAF, allow_two_sample_overlapping=pd.allow_two_sample_overlapping,\
									no_of_top_lines=pd.no_of_top_snps, no_of_top_snps=pd.no_of_top_snps, \
									starting_rank=starting_rank, \
									min_score=pd.min_score,\
									need_chr_pos_ls=1, )	#need_chr_pos_ls is for null_distribution_type_id=2/3
		
		result = None
		if pd.type_id:	#the type is already in database. now check if the same top snp test has been done or not
			result = self.returnResultFromDB(TestResultClass, pd.results_id, pd.list_type_id, starting_rank,
											pd.type_id, pd.min_distance, pd.no_of_top_snps, pd.min_score)
		if result is None:	#2008-10-30 it's still None, need to generate the observed data	
			permData = self.prepareDataForPermutationRankTest(rm, pd.snps_context_wrapper, param_data)
			if permData is None:
				if self.debug:
					sys.stderr.write("No permData from prepareDataForPermutationRankTest().\n")
				return return_data
			
			score_range = permData.score_range
			candidate_sample_size = len(permData.candidate_gene_snp_rank_ls)
			non_candidate_sample_size = len(permData.non_candidate_gene_snp_rank_ls)
			if candidate_sample_size<pd.min_sample_size or non_candidate_sample_size<pd.min_sample_size:	#don't look at how many non-candidates are (different from whole genome rank test)
				if self.debug:
					sys.stderr.write("Ignore. sample size less than %s. %s vs %s.\n"%(pd.min_sample_size, candidate_sample_size, non_candidate_sample_size))
				return_data.permData = permData
				return return_data
			if pd.type_id:	# and pd.min_score is not None:	#2008-11-04 comment the 2nd condition because no_of_top_snps could be set over the total no. use this to check.
				#2008-10-28 check db again because no_of_top_snps=candidate_sample_size+non_candidate_sample_size.
				#sometimes, different min_score cutoff gives same no_of_top_snps.
				result = self.returnResultFromDB(TestResultClass, pd.results_id, pd.list_type_id, starting_rank,
												pd.type_id, pd.min_distance, candidate_sample_size+non_candidate_sample_size)
			if result is None:
				import rpy
				
				candidate_gw_size = self.dealWithNoOfSNPsAssociatedWithCandidateGeneList(pd.list_type_id, rm, pd)	#cache is internally going on
				x = candidate_sample_size
				m = candidate_gw_size
				n = permData.no_of_total_snps - m
				k = candidate_sample_size + non_candidate_sample_size
				
				
				result = TestResultClass(list_type_id=pd.list_type_id)	#2008-10-30 no pvalue
				result.pvalue = rpy.r.phyper(x-1,m,n,k,lower_tail = rpy.r.FALSE)
				result.results_id = pd.results_id
				result.candidate_sample_size = candidate_sample_size
				result.non_candidate_sample_size = non_candidate_sample_size
				result.min_distance = pd.min_distance
				result.candidate_gw_size = candidate_gw_size
				result.non_candidate_gw_size = permData.no_of_total_snps - candidate_gw_size
				result.no_of_top_snps = candidate_sample_size + non_candidate_sample_size
				result.starting_rank = starting_rank
				result.type_id = pd.type_id
				if score_range:
					result.max_score = score_range[0]
					if pd.min_score is not None:
						result.min_score = pd.min_score
					else:
						result.min_score = score_range[1]
				session.save(result)	#2008-11-04 put in the session cache
				if commit:
					try:
						session.flush()
					except:
						session.expunge(result)
						sys.stderr.write("Exception happened for results_method_id=%s, list_type_id=%s.\n"%(result.results_id, result.list_type_id))
						for column in result.c.keys():
							sys.stderr.write("\t%s=%s.\n"%(column, getattr(result, column)))
						traceback.print_exc()
						sys.stderr.write('%s.\n'%repr(sys.exc_info()))
						result = None
		elif need_permData:
			permData = self.prepareDataForPermutationRankTest(rm, pd.snps_context_wrapper, param_data)
		else:
			permData = None
		return_data = PassingData(result=result, permData=permData)
		return return_data
開發者ID:,項目名稱:,代碼行數:93,代碼來源:


注:本文中的pymodule.PassingData.permData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。