def loadmotif(infile, trimstart=0, trimend=0): from TAMO import MotifTools lines = loadlist(infile) if lines[0] == "A\tC\tG\tT": ma = [] for l in lines[1:]: p = l.split("\t") ma.append({ 'A': float(p[0]), 'C': float(p[1]), 'G': float(p[2]), 'T': float(p[3]) }) if trimend == 0: ma = ma[trimstart:] else: ma = ma[trimstart:-trimend] return MotifTools.Motif_from_counts(ma) elif lines[0][0] in 'ACGT': if trimend == 0: lines = lines[trimstart:] else: lines = lines[trimstart:-trimend] return MotifTools.Motif(lines) else: na = [] for line in lines: na.append(list(map(int, line.split()))) ma = [] for i in range(len(na[0])): ma.append({ 'A': na[0][i], 'C': na[1][i], 'G': na[2][i], 'T': na[3][i] }) return MotifTools.Motif_from_counts(ma)
def parse_block(name, block): mat = [] ACGT = {"A": 1, "C": 2, "G": 3, "T": 4} for i in block: L = i.strip().split() D = {'A': 0, 'C': 0, 'T': 0, 'G': 0} for j in ACGT.keys(): D[j] = float(L[ACGT[j]]) mat.append(D) m = MotifTools.Motif_from_counts(mat) m.source = name #print m._print_p() return m
motiflist.pop(blankindex) # Build matrix dictionaries and substitute the strings for the dictionaries for num in range(len(motiflist)): # Prepare emtpy list of dictionaries of the length of the motif tempmotif = [] motiflength = len(motiflist[num][1].strip().split('\t')) - 1 for item in range(motiflength): tempmotif.append({}) # Start filling in the dictionaries with the information in the matrix for line in range(1, 5): nucleotide = motiflist[num][line].strip().split('\t')[0] problist = motiflist[num][line].strip().split('\t')[1:] for position in range(motiflength): tempmotif[position][nucleotide] = float(problist[position]) # Save the list of dictionaries in the general variable motiflist[num] = tempmotif #print motiflist # TAMO CONVERSION # TAMO formated list of files tamomotifs = [] # Convert dictionaries found in sigmotifs and store them as TAMO motifs for motif in motiflist: tamomotif = MotifTools.Motif_from_counts(motif[:], beta=0.01, bg=bkgrddict) tamomotifs.append(tamomotif) MotifTools.save_motifs(tamomotifs, output)