def calculate(A, n, p, H, dist): """ A: Alphabet (unicode string) n: length of random text (int) p: desired number of occurences of pattern words (int) H: pattern (dict - see above) dist: description of probability distribution (dict - see above) """ if H["type"]=="list": mode = 0 elif H["type"]=="random": mode = 1 elif H["type"]=="pssm/cutoff": mode = 2 elif H["type"]=="pssm/footprints": mode = 3 elif H["type"]=="word/mismatches": mode = 4 elif H["type"]=="consensus": mode = 5 if dist["type"]=="markov": order = int(dist["order"]) elif dist["type"]=="bernoulli": order = 0 elif dist["type"]=="dhmm": order = -1 elif dist["type"]=="hmm": order = -2 #sys.stderr.write("Order: "+str(order)+"\n"+\ # "Mode: "+str(mode)+"\n"+\ # "n: "+str(n)+"\n"+\ # "p: "+str(p)+"\n") ret = sf.set_input_data(order, mode, n, p) if ret!=0: return __error_text__(ret), 0.0, "", [] if dist["type"]=="markov": ret = sf.analis_alp_mark_data(A, dist["probs"], dist["initial_probs"]) elif dist["type"]=="bernoulli": ret = sf.analis_alp_bern_data(A, dist["probs"]) elif dist["type"]=="dhmm": ret = sf.analis_alp_dhhm_data(A, len(dist["probs"]), dist["probs"], dist["trans"]) elif dist["type"]=="hmm": ret = sf.analis_alp_hhm_data(A, len(dist["probs"]), dist["probs"]) if ret!=0: return __error_text__(ret), 0.0, "", [] if H["type"]=="list": ret = sf.analis_pattern_data_0(H["words"]) elif H["type"]=="random": ret = sf.analis_pattern_data_1(H["word_count"], H["word_length"], H["probs"]) elif H["type"].startswith("pssm"): if H["type"]=="pssm/footprints": footprints = H["footprints"] cutoff = 0.0 else: footprints = [] cutoff = H["cutoff"] ret = sf.analis_pattern_data_2_3(len(H["pssm"]), footprints, H["pssm"], cutoff) elif H["type"]=="word/mismatches": ret = sf.analis_pattern_data_4(H["word"], int(H["mismatches"]), H["constpositions"]) elif H["type"]=="consensus": ret = sf.analis_pattern_data_5(H["word"], H["alphabet"]) if ret!=0: return __error_text__(ret), 0.0, "", [] err_no, result, report, res_words = sf.main() return __error_text__(err_no), result, report, res_words
def func_test(noccur,tlen,mode,patparam,order,alpfile): import sf sf.set_input_data(order,mode,tlen,noccur) f = open(alpfile,"r") if order == 0: order,alpmas,bernprob = read_alp_Bern(f) print bernprob sf.analis_alp_bern_data(alpmas, bernprob) elif order > 0: order,alpmas,markovprob = read_alp_Mark(f) print order print alpmas print "Probs" for i in range(len(markovprob)): print markovprob[i] sf.analis_alp_mark_data(alpmas,markovprob,[0.3,0.3,0.2,0.2]) elif order == -1: order,alpmas,nstates,dhhmprob,dhhmtrans = read_alp_DHHM(f) print nstates print "Probs" for i in range(nstates): print dhhmprob[i] print "Trans" for i in range(nstates): print dhhmtrans[i] sf.analis_alp_dhhm_data(alpmas, nstates, dhhmprob, dhhmtrans) elif order == -2: order,alpmas,nstates,hhmprob = read_alp_HHM(f) print order print alpmas print nstates for i in range(nstates): print "State",i for j in range(nstates): print hhmprob[i][j] sf.analis_alp_hhm_data(alpmas,nstates,hhmprob) f.close() param = patparam.split() print param if mode == 0: f = open(patparam,"r") words = read_pat_0(f) f.close() sf.analis_pattern_data_0(words) elif mode == 1: nwords = int(param[0]) wordlen = int(param[1]) sf.analis_pattern_data_1(nwords, wordlen, []) elif mode == 2: f = open(param[0],"r") wordlen,pssmmas = read_pat_2(f) f.close() print wordlen for i in range(wordlen): print pssmmas[i] thr = float(param[1]) sf. analis_pattern_data_2_3(wordlen,[],pssmmas,thr) elif mode == 4: motif = param[0] nreplace = int(param[1]) constpos = map(lambda i: int(param[i]), range(2,len(param))) print "ConstPos ",constpos sf.analis_pattern_data_4(motif, nreplace, constpos) elif mode == 5: consensus = patparam consalp = [u'SATC', u'LMAGC', u'NACGT']#['NACTG','SAC','LTG','PATG'] sf.analis_pattern_data_5(consensus, consalp) err,prob,report,words = sf.main() print "Prob ",prob return prob