Пример #1
0
    def testStopDouble(self):
        '''test two stop codons.'''
        ref = list(self.seq)
        ref[-3] = "T"
        for x in range(len(ref) - 3):
            s = list(ref)
            s[x] = "T"
            r = snp2counts.countEffectsOnTranscript(s, ref)
            self.assertEqual(r.ninserted_bases, 0)
            self.assertEqual(r.ninserted_codons, 0)
            self.assertEqual(r.ndeleted_bases, 0)
            self.assertEqual(r.ndeleted_codons, 0)
            self.assertEqual(r.noframe_codons, 0)
            self.assertEqual(r.nwrong_frames, 0)
            self.assertEqual(r.ncorrected_frames, 0)

            if x % 3 == 0:
                self.assertEqual(r.nstops, 2)
                self.assertEqual(r.first_stop, x // 3)
                # ignore last incomplete codon
                self.assertEqual(r.nstop_codons, 1)
            else:
                self.assertEqual(r.nstops, 1)
                self.assertEqual(r.first_stop, self.ncodons - 1)
                self.assertEqual(r.nstop_codons, 0)
Пример #2
0
    def testStop(self):
        '''test one stop codon.'''
        for x in range(len(self.seq)):
            s = list(self.seq)
            s[x] = "T"
            r = snp2counts.countEffectsOnTranscript(s, self.seq)
            # print s, str(r)
            self.assertEqual(r.ninserted_bases, 0)
            self.assertEqual(r.ninserted_codons, 0)
            self.assertEqual(r.ndeleted_bases, 0)
            self.assertEqual(r.ndeleted_codons, 0)
            self.assertEqual(r.noframe_codons, 0)
            self.assertEqual(r.nwrong_frames, 0)
            self.assertEqual(r.ncorrected_frames, 0)
            self.assertEqual(r.nsynonymous_codons, 0)

            if x % 3 == 0:
                self.assertEqual(r.nstops, 1)
                self.assertEqual(r.first_stop, x // 3)
                # ignore last incomplete codon
                if x < self.length - 3:
                    self.assertEqual(r.nstop_codons, 1)
                self.assertEqual(r.nnonsynonymous_codons, 0)
            else:
                self.assertEqual(r.nstops, 0)
                self.assertEqual(r.first_stop, self.ncodons)
                self.assertEqual(r.nstop_codons, 0)
                self.assertEqual(r.nnonsynonymous_codons, 1)
Пример #3
0
    def testMutation(self):
        '''test synonymous/nonsynonymous mutation.'''

        for x in range(len(self.seq)):
            s = list(self.seq)
            # aaa = K, aag = N
            s[x] = "G"
            r = snp2counts.countEffectsOnTranscript(s, self.seq)
            self.assertEqual(r.ninserted_bases, 0)
            self.assertEqual(r.ninserted_codons, 0)
            self.assertEqual(r.ndeleted_bases, 0)
            self.assertEqual(r.ndeleted_codons, 0)
            self.assertEqual(r.noframe_codons, 0)
            self.assertEqual(r.nwrong_frames, 0)
            self.assertEqual(r.ncorrected_frames, 0)
            self.assertEqual(r.nstops, 0)
            self.assertEqual(r.first_stop, self.ncodons)
            self.assertEqual(r.nstop_codons, 0)

            if x % 3 == 2:
                self.assertEqual(r.nsynonymous_codons, 1)
                self.assertEqual(r.nnonsynonymous_codons, 0)
            else:
                self.assertEqual(r.nsynonymous_codons, 0)
                self.assertEqual(r.nnonsynonymous_codons, 1)
Пример #4
0
    def testDeletion(self):
        '''test single deletion.'''

        for l in range(1, 7):
            for x in range(0, len(self.seq)):
                s = list(self.seq)
                todelete = min(l, self.length - x)
                for y in range(x, x + todelete):
                    s[y] = ""
                ncodons = self.ncodons - todelete // 3
                r = snp2counts.countEffectsOnTranscript(s, self.seq)
                # print s, str(r)

                self.assert_(r.ndeleted_codons + r.nunaffected_codons + r.nincomplete_codons +
                             r.nnonsynonymous_codons + r.nsynonymous_codons + r.nstop_codons <=
                             self.ncodons)

                self.assertEqual(r.ninserted_bases, 0)
                self.assertEqual(r.ninserted_codons, 0)
                self.assertEqual(r.ndeleted_bases, todelete)

                codon_start = (x // 3) * 3
                codon_end = x + l + (3 - (x + l) % 3) % 3
                affected_codons = (codon_end - codon_start) // 3
                deletion_codon_start = x + (3 - (x % 3)) % 3
                deletion_codon_end = min(self.length, ((x + l) // 3) * 3)

                # subtract fully deleted codons
                deleted_codons = max(
                    0, (deletion_codon_end - deletion_codon_start) // 3)
                self.assertEqual(r.ndeleted_codons, deleted_codons)

                inframe = x // 3

                # delete in-frame, multiple of 3
                if x % 3 == 0 and todelete % 3 == 0:
                    self.assertEqual(r.noframe_codons, 0)
                    self.assertEqual(r.nwrong_frames, 0)
                    self.assertEqual(r.ncorrected_frames, 0)
                    self.assertEqual(r.nsynonymous_codons, 0)

                # delete out-of-frame, multiple of 3
                elif x % 3 != 0 and todelete % 3 == 0:
                    self.assertEqual(
                        r.noframe_codons, affected_codons - deleted_codons)
                    self.assertEqual(r.nwrong_frames, 1)
                    self.assertEqual(r.ncorrected_frames, 1)

                # delete, but not multiple of 3
                else:
                    self.assertEqual(
                        r.noframe_codons, self.ncodons - inframe - deleted_codons)
                    self.assertEqual(r.nwrong_frames, 1)
                    self.assertEqual(r.ncorrected_frames, 0)
#                    self.assertEqual( r.nsynonymous_codons,
# self.ncodons - r.nincomplete_codons - inframe - deleted_codons)

                self.assertEqual(r.first_stop, (self.length - todelete) // 3)
                # self.assertEqual( r.nunaffected_codons, self.ncodons - (int(math.ceil( (x + todelete) / 3.0)) - x // 3) )
                self.assertEqual(r.nnonsynonymous_codons, 0)
Пример #5
0
    def testInsertion(self):
        '''test single insertion.'''

        for l in range(1, 7):
            for x in range(len(self.seq)):
                s = list(self.seq)
                s[x] = "A" * l + s[x]

                r = snp2counts.countEffectsOnTranscript(s, self.seq)
                # print s, str(r)
                self.assertEqual(r.ninserted_bases, l)
                if l % 3 == 0:
                    self.assertEqual(r.ninserted_codons, l // 3)
                    self.assertEqual(r.nwrong_frames, 0)

                self.assertEqual(r.ndeleted_bases, 0)
                self.assertEqual(r.ndeleted_codons, 0)
                unaffected = x // 3
                if l % 3 == 0:
                    self.assertEqual(r.noframe_codons, 0)
                    self.assertEqual(r.ncorrected_frames, 0)
                    self.assertEqual(r.nunaffected_codons, 20)
                    self.assertEqual(r.nsynonymous_codons, 0)
                else:
                    self.assertEqual(r.noframe_codons, self.ncodons - x / 3)
                    self.assertEqual(r.ncorrected_frames, 0)
                    self.assertEqual(r.nunaffected_codons, unaffected)

                self.assertEqual(r.first_stop, (self.length + l) // 3)
                self.assertEqual(r.nnonsynonymous_codons, 0)
Пример #6
0
    def testFrameCorrectionAdacent(self):
        '''test frame correction within a codon for
        two adjacent bases.

        Strictly speaking this should not happen as these
        would be called as substitutions.
        '''
        return

        for l in range(1, 7):
            for x in range(len(self.seq) - l):
                s = list(self.seq)
                todelete = l
                toinsert = l
                for y in range(x, x + todelete):
                    s[y] = ""
                s[x + todelete] = "A" * toinsert + s[x + todelete]
                ncodons = self.ncodons
                # print l,x,todelete, toinsert
                # print s
                r = snp2counts.countEffectsOnTranscript(s, self.seq)
                # print str(r)

                self.assert_(r.ndeleted_codons + r.nunaffected_codons + r.nincomplete_codons +
                             r.nnonsynonymous_codons + r.nsynonymous_codons + r.nstop_codons <=
                             self.ncodons)

                self.assertEqual(r.ninserted_codons, 0)

                if (x + todelete) % 3 != 0:
                    self.assertEqual(r.ninserted_bases, 0)
                    self.assertEqual(r.ndeleted_bases, 0)
                    self.assertEqual(r.noframe_codons, 0)
                else:
                    self.assertEqual(r.ninserted_bases, toinsert)
                    self.assertEqual(r.ndeleted_bases, todelete)
                    self.assertEqual(r.noframe_codons, 2)

                if x % 3 == 0 and todelete % 3 == 0:
                    self.assertEqual(r.ndeleted_codons, todelete / 3)
                else:
                    self.assertEqual(r.ndeleted_codons, 0)

                self.assert_(r.noframe_codons <= self.ncodons)

                self.assertEqual(r.nwrong_frames, 1)
                self.assertEqual(r.ncorrected_frames, 1)
                self.assertEqual(r.ntruncated_codons_stop, 0)
                # self.assertEqual( r.nunaffected_codons, self.ncodons )
                self.assertEqual(r.nsynonymous_codons, 0)
                self.assertEqual(r.nnonsynonymous_codons, 0)
Пример #7
0
 def testEmpty(self):
     r = snp2counts.countEffectsOnTranscript(self.seq, self.seq)
     self.assertEqual(r.ninserted_bases, 0)
     self.assertEqual(r.ninserted_codons, 0)
     self.assertEqual(r.ndeleted_bases, 0)
     self.assertEqual(r.ndeleted_codons, 0)
     self.assertEqual(r.noframe_codons, 0)
     self.assertEqual(r.nwrong_frames, 0)
     self.assertEqual(r.ncorrected_frames, 0)
     self.assertEqual(r.first_stop, self.ncodons)
     self.assertEqual(r.nstop_codons, 0)
     self.assertEqual(r.nstops, 0)
     self.assertEqual(r.nunaffected_codons, self.ncodons)
     self.assertEqual(r.nsynonymous_codons, 0)
     self.assertEqual(r.nnonsynonymous_codons, 0)
Пример #8
0
    def testFrameCorrection(self):
        '''test frame correction within a codon for
        two adjacent bases.

        Strictly speaking this should not happen as these
        would be called as substitutions.
        '''
        return
        for l in range(1, 7):
            for offset in range(1, 5):
                for x in range(len(self.seq) - (l + offset)):
                    s = list(self.seq)
                    todelete = l
                    toinsert = l
                    for y in range(x, x + todelete):
                        s[y] = ""

                    codon_start = (x // 3) * 3
                    codon_end = ((x + offset + todelete) // 3 + 1) * 3

                    s[x + todelete + offset] = "A" * toinsert + s[x + todelete]
                    ncodons = self.ncodons
                    # print "l=",l,"x=",x,"offest=",offset,"del=",todelete,
                    # "ins=",toinsert, "start=",codon_start, "end=", codon_end

                    naffected_codons = (codon_end - codon_start) // 3
                    if todelete % 3 == 0 and (x + todelete) // 3 != (x + todelete + offset) // 3:
                        # affected codons reduced, if offset includes full
                        # codons
                        naffected_codons -= (x + todelete +
                                             offset) // 3 - (x + todelete) // 3
                        # if offset > 3:
                        #    naffected_codons -= 1

                    # print s
                    r = snp2counts.countEffectsOnTranscript(s, self.seq)
                    # print str(r)

                    self.assertEqual(r.ninserted_codons, l // 3)

                    self.assertEqual(r.ninserted_bases, toinsert)
                    self.assertEqual(r.ndeleted_bases, todelete)

                    if l + offset <= 2 and x % 3 == 0 or (x % 3 == 0 and l % 3 == 0):
                        # within codon correction
                        self.assertEqual(r.noframe_codons, 0)
                        self.assertEqual(r.nwrong_frames, 0)
                        self.assertEqual(r.ncorrected_frames, 0)

                    else:
                        # between codon correction
                        self.assertEqual(r.ninserted_bases, toinsert)
                        self.assertEqual(r.ndeleted_bases, todelete)
                        self.assertEqual(r.noframe_codons, naffected_codons)
                        self.assertEqual(r.nwrong_frames, 1)
                        self.assertEqual(r.ncorrected_frames, 1)

                    if x % 3 == 0 and todelete % 3 == 0:
                        self.assertEqual(r.ndeleted_codons, todelete / 3)
                    else:
                        self.assertEqual(r.ndeleted_codons, 0)

                    self.assert_(r.noframe_codons <= self.ncodons)

                    self.assertEqual(r.first_stop, 0)

                    # self.assertEqual( r.nunaffected_codons, self.ncodons )
                    self.assertEqual(r.nsynonymous_codons, 0)
                    self.assertEqual(r.nnonsynonymous_codons, 0)