本文整理汇总了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