def testIntronsSNPs(self): length = 0 t = 0 exon_id = 0 for x in range(self.mOffset, self.contigSize - self.mIncrement - self.mOffset, self.mIncrement): # exons for y in range(0, self.mExonSize): base = x + y base_x, base_y = self.toRange(base, base + 1) result = snp2counts.getCDSPosition( self.mExons, base_x, base_y, lcontig=self.contigSize, fasta=self.mFasta) self.assertEqual(result.strand, self.strand) self.assertEqual(result.cds_start, t) self.assertEqual(result.cds_end, t + 1) self.assertEqual(result.intron_start, None) self.assertEqual(result.intron_end, None) self.assertEqual(len(result.cds_seq) % 3, 0) self.assertEqual(result.nc_seq, None) self.assertEqual(result.nc_start, None) self.assertEqual(result.nc_end, None) self.assertEqual(result.exon_id, exon_id) self.assertEqual(result.intron_id, None) t += 1 exon_id += 1 # introns for y in range(self.mExonSize, self.mExonSize + self.mIntronSize): base = x + y base_x, base_y = self.toRange(base, base + 1) result = snp2counts.getCDSPosition( self.mExons, base_x, base_y, lcontig=self.contigSize, fasta=self.mFasta) self.assertEqual(result.strand, self.strand) self.assertEqual(result.cds_start, None) self.assertEqual(result.cds_end, None) self.assertEqual(result.cds_phase, None) self.assertEqual(result.intron_start, x + self.mExonSize) self.assertEqual( result.intron_end, x + self.mIntronSize + self.mExonSize) self.assertEqual(result.cds_seq, None) self.assertEqual(result.cds_seq_start, None) self.assertEqual(result.cds_seq_end, None) self.assertEqual(len(result.nc_seq), 1) self.assert_(result.nc_seq not in "abc") self.assertEqual(result.nc_start, base) self.assertEqual(result.nc_end, base + 1) self.assertEqual(result.exon_id, exon_id) self.assertEqual(result.intron_id, exon_id - 1)
def testIndels( self ): '''test with segments of size 5''' size = 5 length = 0 framed_length = (3 - self.frame ) % 3 phase = (3 - self.frame ) % 3 if self.strand == "+": motif = "123" else: motif = "321" for x in range( self.mOffset, self.contigSize - self.mIncrement - self.mOffset, self.mIncrement): for y in range( -2*size, self.mExonSize + 2*size): base = x+y if base < self.mOffset: continue base_x, base_y = self.toRange( base, base+size ) result = snp2counts.getCDSPosition( self.mExons, base_x, base_y, lcontig = self.contigSize, fasta = self.mFasta ) if -size < y < self.mExonSize: # overlap with coding sequence self.assertEqual( len(result.cds_seq) % 3, 0 ) self.assertEqual( result.cds_start, length ) if y < 0: self.assertEqual( result.cds_end, length + size + y ) else: self.assertEqual( result.cds_end, length + min( size, self.mExonSize - y ) ) self.assertEqual( result.cds_phase, phase) self.assertEqual( result.strand, self.strand ) ncodons = int(math.ceil( (result.cds_phase + result.cds_end - result.cds_start) / 3.0)) if self.frame == 0: self.assertEqual( result.cds_seq, motif * ncodons ) self.assertEqual( result.cds_seq_start, framed_length % 3 ) self.assertEqual( result.cds_seq_end, framed_length % 3 + min( size, size + y, self.mExonSize - y) ) if result.nc_end != None: self.assertEqual( result.cds_end - result.cds_start + (result.nc_end - result.nc_start), size ) self.assertEqual( len(result.nc_seq), (result.nc_end - result.nc_start)) else: self.assertEqual( result.cds_start, None ) self.assertEqual( result.cds_end, None ) self.assertEqual( result.cds_phase, None ) if y > self.mExonSize - size: self.assertEqual( result.intron_start, x + self.mExonSize) self.assertEqual( result.intron_end, x + self.mIntronSize + self.mExonSize ) elif y < 0: self.assertEqual( result.intron_start, x - self.mIntronSize) self.assertEqual( result.intron_end, x ) if 0 <= y < self.mExonSize: length += 1 framed_length += 1 phase += 1 if phase >= 3: phase = 0
def testCodingSNPs(self): length = 0 framed_length = (3 - self.frame) % 3 phase = (3 - self.frame) % 3 if self.strand == "+": motif = "123" else: motif = "321" for x in range(self.mOffset, self.contigSize - self.mOffset, self.mIncrement): for y in range(0, self.mExonSize): base = x + y rangex, rangey = self.toRange(base, base + 1) result = snp2counts.getCDSPosition(self.mExons, rangex, rangey, lcontig=self.contigSize, fasta=self.mFasta) self.assertEqual(result.strand, self.strand) self.assertEqual(result.cds_start, length) self.assertEqual(result.cds_end, length + 1) self.assertEqual(result.cds_phase, phase) self.assertEqual(result.intron_start, None) self.assertEqual(result.intron_end, None) self.assertEqual(len(result.cds_seq), 3) # print x, y, base, str(result) if self.frame == 0: self.assertEqual(result.cds_seq, motif) self.assertEqual(result.cds_seq_start, framed_length % 3) self.assertEqual(result.cds_seq_end, (framed_length % 3) + 1) self.assertEqual(result.nc_seq, None) self.assertEqual(result.nc_start, None) self.assertEqual(result.nc_end, None) if base in self.mSplitCodonsPrev: self.assertEqual( result.prev_exon_end, self.mSplitCodonsPrev[base]) else: self.assertEqual(result.prev_exon_end, None) if base in self.mSplitCodonsNext: self.assertEqual( result.next_exon_start, self.mSplitCodonsNext[base]) else: self.assertEqual(result.next_exon_start, None) length += 1 framed_length += 1 phase += 1 if phase >= 3: phase = 0
def testIndels(self): '''test with segments of size 5''' size = 5 length = 0 framed_length = (3 - self.frame) % 3 phase = (3 - self.frame) % 3 if self.strand == "+": motif = "123" else: motif = "321" for x in range(self.mOffset, self.contigSize - self.mIncrement - self.mOffset, self.mIncrement): for y in range(-2 * size, self.mExonSize + 2 * size): base = x + y if base < self.mOffset: continue base_x, base_y = self.toRange(base, base + size) result = snp2counts.getCDSPosition( self.mExons, base_x, base_y, lcontig=self.contigSize, fasta=self.mFasta) if -size < y < self.mExonSize: # overlap with coding sequence self.assertEqual(len(result.cds_seq) % 3, 0) self.assertEqual(result.cds_start, length) if y < 0: self.assertEqual(result.cds_end, length + size + y) else: self.assertEqual( result.cds_end, length + min(size, self.mExonSize - y)) self.assertEqual(result.cds_phase, phase) self.assertEqual(result.strand, self.strand) ncodons = int( math.ceil((result.cds_phase + result.cds_end - result.cds_start) / 3.0)) if self.frame == 0: self.assertEqual(result.cds_seq, motif * ncodons) self.assertEqual(result.cds_seq_start, framed_length % 3) self.assertEqual( result.cds_seq_end, framed_length % 3 + min(size, size + y, self.mExonSize - y)) if result.nc_end is not None: self.assertEqual( result.cds_end - result.cds_start + (result.nc_end - result.nc_start), size) self.assertEqual( len(result.nc_seq), (result.nc_end - result.nc_start)) else: self.assertEqual(result.cds_start, None) self.assertEqual(result.cds_end, None) self.assertEqual(result.cds_phase, None) if y > self.mExonSize - size: self.assertEqual(result.intron_start, x + self.mExonSize) self.assertEqual( result.intron_end, x + self.mIntronSize + self.mExonSize) elif y < 0: self.assertEqual(result.intron_start, x - self.mIntronSize) self.assertEqual(result.intron_end, x) if 0 <= y < self.mExonSize: length += 1 framed_length += 1 phase += 1 if phase >= 3: phase = 0