Exemplo n.º 1
0
def funcionprincipal(dato,variable,opciones):
    from rpy import r
    lista=dato.query(variable)
    diccionario = {}
    diccionario["KS"] = {}
    if opciones[u"Distribución"]=="Uniforme":
        resultado=r.ks_test(lista,"runif")
    elif opciones[u"Distribución"]=="Normal":
        resultado=r.ks_test(lista,"rnorm")
    diccionario["KS"]["Variable"] = str(variable)
    diccionario["KS"][u"Significación"]=resultado["p.value"]
    return diccionario
Exemplo n.º 2
0
def _calcKS_(scores,exp_scores=None):
	ret = {}
	ret["D"] = -1
	try:
		from rpy import r
		if exp_scores:
			res = r.ks_test(scores,exp_scores)
		else:
			res = r.ks_test(scores,"punif")
		ret = res["statistic"]
		ret["p.value"] = res["p.value"]
	except Exception, message:
		print "Calculating KS failed??",message
Exemplo n.º 3
0
	def run(self):
		"""
		01-06-06
		01-14-06
			add kolmogorov-smirnov test
		
			--db_connect()
			--get_gene_id2mt_no_set()
			--get_ortholog_pairs()
				--get_homo_genes_for_2_tax_ids()
			--get_tfbs_similarity_ls()
				--calculate_tfbs_similarity()
			--draw_tfbs_similarity_ls_histogram()
		"""
		(conn, curs) =  db_connect(self.hostname, self.dbname, self.schema)
		if self.type==1:
			gene_id2mt_no_set = self.get_gene_id2mt_no_set(curs)
		elif self.type==2:
			if self.input_fname_list==[]:
				sys.stderr.write("Please specify -i, type=2 needs that.\n")
				sys.exit(2)
			prom_id2gene_id = self.get_prom_id2gene_id(curs)
			mt_id2no = self.get_mt_id2no(curs)
			gene_id2mt_no_set = self.get_gene_id2mt_no_set_from_file(self.input_fname_list, mt_id2no, prom_id2gene_id)
		#get ortholog pairs
		bad_ortholog_fname = '%s.bad_ortholog'%self.output_prefix
		hs_gene_id_list, mm_gene_id_list = self.get_ortholog_pairs(curs, bad_ortholog_fname)
		
		tfbs_similarity_ls = self.get_tfbs_similarity_ls(hs_gene_id_list, mm_gene_id_list, gene_id2mt_no_set)
		ortholog_pair_hist_fname = '%s_ortholog_pair_hist.png'%self.output_prefix
		self.draw_tfbs_similarity_ls_histogram(tfbs_similarity_ls, ortholog_pair_hist_fname)
		
		#random
		random.shuffle(mm_gene_id_list)
		random_tfbs_similarity_ls = self.get_tfbs_similarity_ls(hs_gene_id_list, mm_gene_id_list, gene_id2mt_no_set)
		random_pair_hist_fname = '%s_random_pair_hist.png'%self.output_prefix
		self.draw_tfbs_similarity_ls_histogram(random_tfbs_similarity_ls, random_pair_hist_fname)
		
		#do a kolmogorov-smirnov test
		ks_result = r.ks_test(tfbs_similarity_ls,random_tfbs_similarity_ls)
		print "kolmogorov-smirnov test p-value:", ks_result['p.value']