def print_meme_motif(word, nsites, ev_string, aln, alph): # make the PWM pwm = sequence.PWM(alph) pwm.setFromAlignment(aln) # print PWM in MEME format alen = alph.getLen() w = len(word) print("\nMOTIF %s\nletter-probability matrix: alength= %d w= %d nsites= %d E= %s" % \ (word, alen, w, nsites, ev_string)) for row in pwm.pretty(): print(row) print("")
def get_freqs_and_nsites(w, dists, offsets, seqs, alph): """ Get PWMs and numbers of sites for each exact Hamming distance. Returns (freqs[d], nsites[d]). """ freqs = [] nsites = [] # iterate over hamming distances for d in range(w+1): # get alignments for a hamming distance == d aln = get_aln_from_dists_and_offsets(w, d, d, dists, offsets, seqs, alph) # make frequency matrix pwm = sequence.PWM(alph) pwm.setFromAlignment(aln) freqs.append(pwm.getFreq()) nsites.append(len(aln)) #print "getting freqs for d", d return freqs, nsites