def MafMotifScorer(species, maf, motifs): width = len(maf.components[0].text) headers = [(c.src, c.start, c.end) for c in maf.components] # expand block rows to full mafBlockSpecies = [ specName.src.split('.')[0] for specName in maf.components ] alignlist = [] for sp in species: try: i = mafBlockSpecies.index(sp) alignlist.append(maf.components[i].text) except ValueError: alignlist.append([NaN for n in range(width)]) alignrows = pwmx.Align(alignlist, headers) # record gap positions filter = pwmx.score_align_gaps(alignrows) # score motif if isinstance(motifs, list): scoremax = {} for string in motifs: scoremax[string] = pwmx.score_align_motif(alignrows, string, filter) else: scoremax = pwmx.score_align_motif(alignrows, motifs, filter) yield scoremax, width, headers
def MafMotifScorer(species,maf,motifs): width = len(maf.components[0].text) headers = [ (c.src,c.start,c.end) for c in maf.components] # expand block rows to full mafBlockSpecies = [specName.src.split('.')[0] for specName in maf.components] alignlist = [] for sp in species: try: i = mafBlockSpecies.index( sp ) alignlist.append( maf.components[i].text ) except ValueError: alignlist.append( [ NaN for n in range( width ) ] ) alignrows = pwmx.Align( alignlist, headers ) # record gap positions filter = pwmx.score_align_gaps( alignrows ) # score motif #print >>sys.stderr, headers if isinstance( motifs, list): scoremax = {} for string in motifs: scoremax[string] = pwmx.score_align_motif( alignrows, string, filter ) else: scoremax = pwmx.score_align_motif( alignrows, motif, filter ) yield scoremax,width,headers
def MafBlockScorer(pwm,species,maf): width = len(maf.components[0].text) headers = [ (c.src,c.start,c.end) for c in maf.components] # expand block rows to full mafBlockSpecies = [specName.src.split('.')[0] for specName in maf.components] alignlist = [] for sp in species: try: i = mafBlockSpecies.index( sp ) alignlist.append( maf.components[i].text ) except ValueError: alignlist.append( [ NaN for n in range( width ) ] ) alignrows = pwmx.Align( alignlist ) scoremax = {} # record gap positions filter = pwmx.score_align_gaps( alignrows ) # score pwm models for model in pwm.keys(): #print >>sys.stderr,"%s_%d_%d" % headers[0],width,model scoremax[model] = pwm[model].score_align( alignrows, filter ) yield scoremax,width,headers