Beispiel #1
0
def mpat(tr, seqs) :
  dseqs = dict(seqs)
  for n in getPostOrder(tr) :
    data = n.data
    if not n.succ :
      data.seq = (None,dseqs[n.data.taxon])
    else :
      s1,s2 = [tr.node(x).data.seq for x in n.succ]
      if s1[1] :
        if s2[1] :
          a = calign.globalAlign(s1[1],s2[1])
          data.seq = (calign.createProfile(a),None)
        else :
          p1,p2 = calign.createProfile(s1[1:]), s2[0]
          #assert all([sum(x)==sum(p1[0]) for x in p1])
          #assert all([sum(x)==sum(p2[0]) for x in p2])
          pa = calign.prof2profAlign(p1,p2)
          data.seq = (trimp(pa),None)
          #print len(pa)
      else :
        p1 = s1[0]
        if s2[1] :
          p2 = calign.createProfile(s2[1:])
        else :
          p2 = s2[0]
        #assert all([sum(x)==sum(p1[0]) for x in p1])
        #assert all([sum(x)==sum(p2[0]) for x in p2])
        pa = calign.prof2profAlign(p1,p2)
        data.seq = (trimp(pa),None)
        #print len(pa)
        #import pdb; pdb.set_trace()
  assert n.id == tr.root
  return n.data.seq[0]
Beispiel #2
0
def mpa(tr, seqs, scores = defaultMatchScores, trimEnd = None) :
  dseqs = dict(seqs)
  #scores = (None,None,gapPenalty,feg)
  for n in getPostOrder(tr) :
    data = n.data
    if not n.succ :
      data.seq = (None,dseqs[n.data.taxon.strip("'")])
    else :
      s1,s2 = [tr.node(x).data.seq for x in n.succ]
      if s1[1] :
        if s2[1] :
          a = calign.globalAlign(s1[1],s2[1], scores = scores)
          data.seq = (calign.createProfile(a),None)
        else :
          p1,p2 = calign.createProfile(s1[1:]), s2[0]
          pa = calign.prof2profAlign(p1,p2, scores = scores)
          data.seq = (trimendsp(pa, trimEnd) if trimEnd is not None else pa,None)
          #print len(pa)
      else :
        p1 = s1[0]
        if s2[1] :
          p2 = calign.createProfile(s2[1:])
        else :
          p2 = s2[0]
        pa = calign.prof2profAlign(p1,p2, scores = scores)
        data.seq = (trimendsp(pa, trimEnd) if trimEnd is not None else pa,None)
        #print len(pa)
        #import pdb; pdb.set_trace()
  assert n.id == tr.root
  return n.data.seq[0]