示例#1
0
 def backtrace(self, first, second, f):
     m, n = f.shape
     alignments = list()
     alignment = self.emptyAlignment(first, second)
     if self.minScore is None:
         minScore = self.bestScore(f)
     else:
         minScore = self.minScore
     for i in range(m):
         for j in range(n):
             if f[i, j] >= minScore:
                 self.backtraceFrom(first, second, f, i, j, alignments,
                                    alignment)
     return alignments
示例#2
0
 def __unicode__(self):
     first = [text_type(e) for e in self.first.elements]
     second = [text_type(e) for e in self.second.elements]
     for i in range(len(first)):
         n = max(len(first[i]), len(second[i]))
         format = u'%-' + text_type(n) + u's'
         first[i] = format % first[i]
         second[i] = format % second[i]
     return u'%s\n%s' % (u' '.join(first), u' '.join(second))
示例#3
0
    def computeAlignmentMatrix(self, first, second):
        m = len(first) + 1
        n = len(second) + 1
        f = numpy.zeros((m, n), int)
        for i in range(1, m):
            for j in range(1, n):
                # Match elements.
                ab = f[i - 1, j - 1] \
                    + self.scoring(first[i - 1], second[j - 1])

                # Gap on sequenceA.
                ga = f[i, j - 1] + self.gapScore

                # Gap on sequenceB.
                gb = f[i - 1, j] + self.gapScore

                f[i, j] = max(0, max(ab, max(ga, gb)))
        return f
示例#4
0
 def __str__(self):
     first = [str(e) for e in self.first.elements]
     second = [str(e) for e in self.second.elements]
     for i in range(len(first)):
         n = max(len(first[i]), len(second[i]))
         format = '%-' + str(n) + 's'
         first[i] = format % first[i]
         second[i] = format % second[i]
     return '%s\n%s' % (' '.join(first), ' '.join(second))