def setUp(self): """Initialize values to be used in tests """ self.d1 = DNASequence('GATTACA', id="d1") self.d2 = DNASequence('TTG', id="d2") self.d1_lower = DNASequence('gattaca', id="d1") self.d2_lower = DNASequence('ttg', id="d2") self.r1 = RNASequence('GAUUACA', id="r1") self.r2 = RNASequence('UUG', id="r2") self.r3 = RNASequence('U-----UGCC--', id="r3") self.i1 = DNASequence('GATXACA', id="i1") self.seqs1 = [self.d1, self.d2] self.seqs1_lower = [self.d1_lower, self.d2_lower] self.seqs2 = [self.r1, self.r2, self.r3] self.seqs3 = self.seqs1 + self.seqs2 self.seqs1_t = [('d1', 'GATTACA'), ('d2', 'TTG')] self.seqs2_t = [('r1', 'GAUUACA'), ('r2', 'UUG'), ('r3', 'U-----UGCC--')] self.seqs3_t = self.seqs1_t + self.seqs2_t self.s1 = SequenceCollection(self.seqs1) self.s1_lower = SequenceCollection(self.seqs1_lower) self.s2 = SequenceCollection(self.seqs2) self.s3 = SequenceCollection(self.seqs3) self.empty = SequenceCollection([]) self.invalid_s1 = SequenceCollection([self.i1])
def setUp(self): self.d1 = DNASequence('..ACC-GTTGG..', id="d1") self.d2 = DNASequence('TTACCGGT-GGCC', id="d2") self.d3 = DNASequence('.-ACC-GTTGC--', id="d3") self.r1 = RNASequence('UUAU-', id="r1") self.r2 = RNASequence('ACGUU', id="r2") self.seqs1 = [self.d1, self.d2, self.d3] self.seqs2 = [self.r1, self.r2] self.seqs1_t = [('d1', '..ACC-GTTGG..'), ('d2', 'TTACCGGT-GGCC'), ('d3', '.-ACC-GTTGC--')] self.seqs2_t = [('r1', 'UUAU-'), ('r2', 'ACGUU')] self.a1 = Alignment(self.seqs1) self.a2 = Alignment(self.seqs2) self.a3 = Alignment(self.seqs2, score=42.0, start_end_positions=[(0, 3), (5, 9)]) self.a4 = Alignment(self.seqs2, score=-42.0, start_end_positions=[(1, 4), (6, 10)]) # no sequences self.empty = Alignment([]) # sequences, but no positions self.no_positions = Alignment([RNA('', id='a'), RNA('', id='b')])
def test_omit_gap_positions(self): expected = self.a2 self.assertEqual(self.a2.omit_gap_positions(1.0), expected) self.assertEqual(self.a2.omit_gap_positions(0.51), expected) r1 = RNASequence('UUAU', id="r1") r2 = RNASequence('ACGU', id="r2") expected = Alignment([r1, r2]) self.assertEqual(self.a2.omit_gap_positions(0.49), expected) r1 = RNASequence('UUAU', id="r1") r2 = RNASequence('ACGU', id="r2") expected = Alignment([r1, r2]) self.assertEqual(self.a2.omit_gap_positions(0.0), expected) self.assertEqual(self.empty.omit_gap_positions(0.0), self.empty) self.assertEqual(self.empty.omit_gap_positions(0.49), self.empty) self.assertEqual(self.empty.omit_gap_positions(1.0), self.empty) # Test to ensure floating point precision bug isn't present. See the # tests for Alignment.position_frequencies for more details. seqs = [] for i in range(33): seqs.append(DNA('-.', id=str(i))) aln = Alignment(seqs) self.assertEqual(aln.omit_gap_positions(1 - np.finfo(float).eps), Alignment([DNA('', id=str(i)) for i in range(33)]))
def test_reverse_complement(self): self.assertEqual(self.b1.reverse_complement(), RNASequence("UGUAAUC")) self.assertEqual(self.b2.reverse_complement(), RNASequence("GGUACCGGU")) self.assertRaises(BiologicalSequenceError, self.b3.reverse_complement) self.assertEqual(self.b4.reverse_complement(), RNASequence("NVHDBMRSWYK"))
def test_nondegenerates_mixed_degens(self): exp = [ RNASequence('AGC'), RNASequence('AGU'), RNASequence('GGC'), RNASequence('GGU') ] obs = sorted(RNASequence('RGY').nondegenerates(), key=str) self.assertEqual(obs, exp)
def test_nondegenerates_gap_mixed_case(self): exp = [ RNASequence('-A.a'), RNASequence('-A.c'), RNASequence('-C.a'), RNASequence('-C.c') ] obs = sorted(RNASequence('-M.m').nondegenerates(), key=str) self.assertEqual(obs, exp)
def test_iupac_degenerate_characters(self): exp = set([ 'B', 'D', 'H', 'K', 'M', 'N', 'S', 'R', 'W', 'V', 'Y', 'b', 'd', 'h', 'k', 'm', 'n', 's', 'r', 'w', 'v', 'y' ]) self.assertEqual(self.b1.iupac_degenerate_characters(), exp) self.assertEqual(RNASequence.iupac_degenerate_characters(), exp)
def test_iupac_degeneracies(self): exp = { 'B': set(['C', 'U', 'G']), 'D': set(['A', 'U', 'G']), 'H': set(['A', 'C', 'U']), 'K': set(['U', 'G']), 'M': set(['A', 'C']), 'N': set(['A', 'C', 'U', 'G']), 'S': set(['C', 'G']), 'R': set(['A', 'G']), 'W': set(['A', 'U']), 'V': set(['A', 'C', 'G']), 'Y': set(['C', 'U']), 'b': set(['c', 'u', 'g']), 'd': set(['a', 'u', 'g']), 'h': set(['a', 'c', 'u']), 'k': set(['u', 'g']), 'm': set(['a', 'c']), 'n': set(['a', 'c', 'u', 'g']), 's': set(['c', 'g']), 'r': set(['a', 'g']), 'w': set(['a', 'u']), 'v': set(['a', 'c', 'g']), 'y': set(['c', 'u']) } self.assertEqual(self.b1.iupac_degeneracies(), exp) self.assertEqual(RNASequence.iupac_degeneracies(), exp)
def test_iupac_characters(self): exp = { 'A', 'C', 'B', 'D', 'G', 'H', 'K', 'M', 'N', 'S', 'R', 'U', 'W', 'V', 'Y', 'a', 'c', 'b', 'd', 'g', 'h', 'k', 'm', 'n', 's', 'r', 'u', 'w', 'v', 'y' } self.assertEqual(self.b1.iupac_characters(), exp) self.assertEqual(RNASequence.iupac_characters(), exp)
def generator(): yield BiologicalSequence('ACGT', id='', description='', quality=range(4)) yield RNASequence('GAU', id=' foo \t\t bar ', description='') yield DNASequence('TAG', id='', description='foo\n\n bar\n') yield BiologicalSequence('A', id='foo', description='bar baz', quality=[42])
def test_complement_map(self): exp = { '-': '-', '.': '.', 'A': 'U', 'C': 'G', 'B': 'V', 'D': 'H', 'G': 'C', 'H': 'D', 'K': 'M', 'M': 'K', 'N': 'N', 'S': 'S', 'R': 'Y', 'U': 'A', 'W': 'W', 'V': 'B', 'Y': 'R', 'a': 'u', 'c': 'g', 'b': 'v', 'd': 'h', 'g': 'c', 'h': 'd', 'k': 'm', 'm': 'k', 'n': 'n', 's': 's', 'r': 'y', 'u': 'a', 'w': 'w', 'v': 'b', 'y': 'r' } self.assertEqual(self.b1.complement_map(), exp) self.assertEqual(RNASequence.complement_map(), exp)
def test_omit_gap_positions(self): """omitting gap positions functions as expected """ expected = self.a2 self.assertEqual(self.a2.omit_gap_positions(1.0), expected) self.assertEqual(self.a2.omit_gap_positions(0.51), expected) r1 = RNASequence('UUAU', id="r1") r2 = RNASequence('ACGU', id="r2") expected = Alignment([r1, r2]) self.assertEqual(self.a2.omit_gap_positions(0.49), expected) r1 = RNASequence('UUAU', id="r1") r2 = RNASequence('ACGU', id="r2") expected = Alignment([r1, r2]) self.assertEqual(self.a2.omit_gap_positions(0.0), expected) self.assertEqual(self.empty.omit_gap_positions(0.0), self.empty) self.assertEqual(self.empty.omit_gap_positions(0.49), self.empty) self.assertEqual(self.empty.omit_gap_positions(1.0), self.empty)
def test_iter_positions(self): actual = list(self.a2.iter_positions()) expected = [[RNASequence(j) for j in i] for i in ['UA', 'UC', 'AG', 'UU', '-U']] self.seqs2_t = [('r1', 'UUAU-'), ('r2', 'ACGUU')] self.assertEqual(actual, expected) actual = list(self.a2.iter_positions(constructor=str)) expected = [list('UA'), list('UC'), list('AG'), list('UU'), list('-U')] self.seqs2_t = [('r1', 'UUAU-'), ('r2', 'ACGUU')] self.assertEqual(actual, expected)
def setUp(self): self.empty = RNASequence('') self.b1 = RNASequence('GAUUACA') self.b2 = RNASequence('ACCGGUACC', id="test-seq-2", description="A test sequence", quality=range(9)) self.b3 = RNASequence( 'ACCGGTACC', id="bad-seq-1", description="Not a RNA sequence") self.b4 = RNASequence( 'MRWSYKVHDBN', id="degen", description="All of the degenerate bases") self.b5 = RNASequence('.G--AUUAC-A...')
def test_iupac_standard_characters(self): exp = set("ACGUacgu") self.assertEqual(self.b1.iupac_standard_characters(), exp) self.assertEqual(RNASequence.iupac_standard_characters(), exp)
def test_iupac_degenerate_characters(self): exp = set(['B', 'D', 'H', 'K', 'M', 'N', 'S', 'R', 'W', 'V', 'Y', 'b', 'd', 'h', 'k', 'm', 'n', 's', 'r', 'w', 'v', 'y']) self.assertEqual(self.b1.iupac_degenerate_characters(), exp) self.assertEqual(RNASequence.iupac_degenerate_characters(), exp)
def setUp(self): self.empty = RNASequence('') self.b1 = RNASequence('GAUUACA') self.b2 = RNASequence('ACCGGUACC', id="test-seq-2", description="A test sequence") self.b3 = RNASequence('ACCGGTACC', id="bad-seq-1", description="Not a RNA sequence") self.b4 = RNASequence('MRWSYKVHDBN', id="degen", description="All of the degenerate bases") self.b5 = RNASequence('.G--AUUAC-A...')
def test_complement(self): self.assertEqual(self.b1.complement(), RNASequence("CUAAUGU")) self.assertEqual(self.b2.complement(), RNASequence("UGGCCAUGG")) self.assertRaises(BiologicalSequenceError, self.b3.complement) self.assertEqual(self.b4.complement(), RNASequence("KYWSRMBDHVN")) self.assertEqual(self.b5.complement(), RNASequence(".C--UAAUG-U..."))
class RNASequenceTests(TestCase): def setUp(self): self.empty = RNASequence('') self.b1 = RNASequence('GAUUACA') self.b2 = RNASequence( 'ACCGGUACC', id="test-seq-2", description="A test sequence") self.b3 = RNASequence( 'ACCGGTACC', id="bad-seq-1", description="Not a RNA sequence") self.b4 = RNASequence( 'MRWSYKVHDBN', id="degen", description="All of the degenerate bases") self.b5 = RNASequence('.G--AUUAC-A...') def test_alphabet(self): exp = { 'A', 'C', 'B', 'D', 'G', 'H', 'K', 'M', 'N', 'S', 'R', 'U', 'W', 'V', 'Y', 'a', 'c', 'b', 'd', 'g', 'h', 'k', 'm', 'n', 's', 'r', 'u', 'w', 'v', 'y' } self.assertEqual(self.b1.alphabet(), exp) self.assertEqual(RNASequence.alphabet(), exp) def test_gap_alphabet(self): self.assertEqual(self.b1.gap_alphabet(), set('-.')) def test_complement_map(self): exp = { '-': '-', '.': '.', 'A': 'U', 'C': 'G', 'B': 'V', 'D': 'H', 'G': 'C', 'H': 'D', 'K': 'M', 'M': 'K', 'N': 'N', 'S': 'S', 'R': 'Y', 'U': 'A', 'W': 'W', 'V': 'B', 'Y': 'R', 'a': 'u', 'c': 'g', 'b': 'v', 'd': 'h', 'g': 'c', 'h': 'd', 'k': 'm', 'm': 'k', 'n': 'n', 's': 's', 'r': 'y', 'u': 'a', 'w': 'w', 'v': 'b', 'y': 'r' } self.assertEqual(self.b1.complement_map(), exp) self.assertEqual(RNASequence.complement_map(), exp) def test_iupac_standard_characters(self): exp = set("ACGUacgu") self.assertEqual(self.b1.iupac_standard_characters(), exp) self.assertEqual(RNASequence.iupac_standard_characters(), exp) def test_iupac_degeneracies(self): exp = { 'B': set(['C', 'U', 'G']), 'D': set(['A', 'U', 'G']), 'H': set(['A', 'C', 'U']), 'K': set(['U', 'G']), 'M': set(['A', 'C']), 'N': set(['A', 'C', 'U', 'G']), 'S': set(['C', 'G']), 'R': set(['A', 'G']), 'W': set(['A', 'U']), 'V': set(['A', 'C', 'G']), 'Y': set(['C', 'U']), 'b': set(['c', 'u', 'g']), 'd': set(['a', 'u', 'g']), 'h': set(['a', 'c', 'u']), 'k': set(['u', 'g']), 'm': set(['a', 'c']), 'n': set(['a', 'c', 'u', 'g']), 's': set(['c', 'g']), 'r': set(['a', 'g']), 'w': set(['a', 'u']), 'v': set(['a', 'c', 'g']), 'y': set(['c', 'u']) } self.assertEqual(self.b1.iupac_degeneracies(), exp) self.assertEqual(RNASequence.iupac_degeneracies(), exp) def test_iupac_degenerate_characters(self): exp = set(['B', 'D', 'H', 'K', 'M', 'N', 'S', 'R', 'W', 'V', 'Y', 'b', 'd', 'h', 'k', 'm', 'n', 's', 'r', 'w', 'v', 'y']) self.assertEqual(self.b1.iupac_degenerate_characters(), exp) self.assertEqual(RNASequence.iupac_degenerate_characters(), exp) def test_iupac_characters(self): exp = { 'A', 'C', 'B', 'D', 'G', 'H', 'K', 'M', 'N', 'S', 'R', 'U', 'W', 'V', 'Y', 'a', 'c', 'b', 'd', 'g', 'h', 'k', 'm', 'n', 's', 'r', 'u', 'w', 'v', 'y' } self.assertEqual(self.b1.iupac_characters(), exp) self.assertEqual(RNASequence.iupac_characters(), exp) def test_complement(self): self.assertEqual(self.b1.complement(), RNASequence("CUAAUGU")) self.assertEqual(self.b2.complement(), RNASequence("UGGCCAUGG")) self.assertRaises(BiologicalSequenceError, self.b3.complement) self.assertEqual(self.b4.complement(), RNASequence("KYWSRMBDHVN")) self.assertEqual(self.b5.complement(), RNASequence(".C--UAAUG-U...")) def test_reverse_complement(self): self.assertEqual(self.b1.reverse_complement(), RNASequence("UGUAAUC")) self.assertEqual(self.b2.reverse_complement(), RNASequence("GGUACCGGU")) self.assertRaises(BiologicalSequenceError, self.b3.reverse_complement) self.assertEqual(self.b4.reverse_complement(), RNASequence("NVHDBMRSWYK")) def test_unsupported_characters(self): self.assertEqual(self.b1.unsupported_characters(), set()) self.assertEqual(self.b2.unsupported_characters(), set()) self.assertEqual(self.b3.unsupported_characters(), set('T')) self.assertEqual(self.b4.unsupported_characters(), set()) def test_has_unsupported_characters(self): self.assertFalse(self.b1.has_unsupported_characters()) self.assertFalse(self.b2.has_unsupported_characters()) self.assertTrue(self.b3.has_unsupported_characters()) self.assertFalse(self.b4.has_unsupported_characters()) def test_is_reverse_complement(self): self.assertFalse(self.b1.is_reverse_complement(self.b1)) self.assertTrue( self.b1.is_reverse_complement(RNASequence('UGUAAUC'))) self.assertTrue( self.b4.is_reverse_complement(RNASequence('NVHDBMRSWYK'))) def test_nondegenerates_invalid(self): with self.assertRaises(BiologicalSequenceError): list(RNASequence('AZA').nondegenerates()) def test_nondegenerates_empty(self): self.assertEqual(list(self.empty.nondegenerates()), [self.empty]) def test_nondegenerates_no_degens(self): self.assertEqual(list(self.b1.nondegenerates()), [self.b1]) def test_nondegenerates_all_degens(self): # Same chars. exp = [RNASequence('CC'), RNASequence('CG'), RNASequence('GC'), RNASequence('GG')] # Sort based on sequence string, as order is not guaranteed. obs = sorted(RNASequence('SS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Different chars. exp = [RNASequence('AC'), RNASequence('AG'), RNASequence('GC'), RNASequence('GG')] obs = sorted(RNASequence('RS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Odd number of chars. obs = list(RNASequence('NNN').nondegenerates()) self.assertEqual(len(obs), 4**3) def test_nondegenerates_mixed_degens(self): exp = [RNASequence('AGC'), RNASequence('AGU'), RNASequence('GGC'), RNASequence('GGU')] obs = sorted(RNASequence('RGY').nondegenerates(), key=str) self.assertEqual(obs, exp) def test_nondegenerates_gap_mixed_case(self): exp = [RNASequence('-A.a'), RNASequence('-A.c'), RNASequence('-C.a'), RNASequence('-C.c')] obs = sorted(RNASequence('-M.m').nondegenerates(), key=str) self.assertEqual(obs, exp)
def missing_qual_gen(): for seq in (RNASequence('A', quality=[42]), BiologicalSequence('AG'), DNASequence('GG', quality=[41, 40])): yield seq
def blank_seq_gen(): for seq in (DNASequence('A'), BiologicalSequence(''), RNASequence('GG')): yield seq
class RNASequenceTests(TestCase): def setUp(self): self.empty = RNASequence('') self.b1 = RNASequence('GAUUACA') self.b2 = RNASequence('ACCGGUACC', id="test-seq-2", description="A test sequence") self.b3 = RNASequence('ACCGGTACC', id="bad-seq-1", description="Not a RNA sequence") self.b4 = RNASequence('MRWSYKVHDBN', id="degen", description="All of the degenerate bases") self.b5 = RNASequence('.G--AUUAC-A...') def test_alphabet(self): exp = { 'A', 'C', 'B', 'D', 'G', 'H', 'K', 'M', 'N', 'S', 'R', 'U', 'W', 'V', 'Y', 'a', 'c', 'b', 'd', 'g', 'h', 'k', 'm', 'n', 's', 'r', 'u', 'w', 'v', 'y' } self.assertEqual(self.b1.alphabet(), exp) self.assertEqual(RNASequence.alphabet(), exp) def test_gap_alphabet(self): self.assertEqual(self.b1.gap_alphabet(), set('-.')) def test_complement_map(self): exp = { '-': '-', '.': '.', 'A': 'U', 'C': 'G', 'B': 'V', 'D': 'H', 'G': 'C', 'H': 'D', 'K': 'M', 'M': 'K', 'N': 'N', 'S': 'S', 'R': 'Y', 'U': 'A', 'W': 'W', 'V': 'B', 'Y': 'R', 'a': 'u', 'c': 'g', 'b': 'v', 'd': 'h', 'g': 'c', 'h': 'd', 'k': 'm', 'm': 'k', 'n': 'n', 's': 's', 'r': 'y', 'u': 'a', 'w': 'w', 'v': 'b', 'y': 'r' } self.assertEqual(self.b1.complement_map(), exp) self.assertEqual(RNASequence.complement_map(), exp) def test_iupac_standard_characters(self): exp = set("ACGUacgu") self.assertEqual(self.b1.iupac_standard_characters(), exp) self.assertEqual(RNASequence.iupac_standard_characters(), exp) def test_iupac_degeneracies(self): exp = { 'B': set(['C', 'U', 'G']), 'D': set(['A', 'U', 'G']), 'H': set(['A', 'C', 'U']), 'K': set(['U', 'G']), 'M': set(['A', 'C']), 'N': set(['A', 'C', 'U', 'G']), 'S': set(['C', 'G']), 'R': set(['A', 'G']), 'W': set(['A', 'U']), 'V': set(['A', 'C', 'G']), 'Y': set(['C', 'U']), 'b': set(['c', 'u', 'g']), 'd': set(['a', 'u', 'g']), 'h': set(['a', 'c', 'u']), 'k': set(['u', 'g']), 'm': set(['a', 'c']), 'n': set(['a', 'c', 'u', 'g']), 's': set(['c', 'g']), 'r': set(['a', 'g']), 'w': set(['a', 'u']), 'v': set(['a', 'c', 'g']), 'y': set(['c', 'u']) } self.assertEqual(self.b1.iupac_degeneracies(), exp) self.assertEqual(RNASequence.iupac_degeneracies(), exp) def test_iupac_degenerate_characters(self): exp = set([ 'B', 'D', 'H', 'K', 'M', 'N', 'S', 'R', 'W', 'V', 'Y', 'b', 'd', 'h', 'k', 'm', 'n', 's', 'r', 'w', 'v', 'y' ]) self.assertEqual(self.b1.iupac_degenerate_characters(), exp) self.assertEqual(RNASequence.iupac_degenerate_characters(), exp) def test_iupac_characters(self): exp = { 'A', 'C', 'B', 'D', 'G', 'H', 'K', 'M', 'N', 'S', 'R', 'U', 'W', 'V', 'Y', 'a', 'c', 'b', 'd', 'g', 'h', 'k', 'm', 'n', 's', 'r', 'u', 'w', 'v', 'y' } self.assertEqual(self.b1.iupac_characters(), exp) self.assertEqual(RNASequence.iupac_characters(), exp) def test_complement(self): self.assertEqual(self.b1.complement(), RNASequence("CUAAUGU")) self.assertEqual(self.b2.complement(), RNASequence("UGGCCAUGG")) self.assertRaises(BiologicalSequenceError, self.b3.complement) self.assertEqual(self.b4.complement(), RNASequence("KYWSRMBDHVN")) self.assertEqual(self.b5.complement(), RNASequence(".C--UAAUG-U...")) def test_reverse_complement(self): self.assertEqual(self.b1.reverse_complement(), RNASequence("UGUAAUC")) self.assertEqual(self.b2.reverse_complement(), RNASequence("GGUACCGGU")) self.assertRaises(BiologicalSequenceError, self.b3.reverse_complement) self.assertEqual(self.b4.reverse_complement(), RNASequence("NVHDBMRSWYK")) def test_unsupported_characters(self): self.assertEqual(self.b1.unsupported_characters(), set()) self.assertEqual(self.b2.unsupported_characters(), set()) self.assertEqual(self.b3.unsupported_characters(), set('T')) self.assertEqual(self.b4.unsupported_characters(), set()) def test_has_unsupported_characters(self): self.assertFalse(self.b1.has_unsupported_characters()) self.assertFalse(self.b2.has_unsupported_characters()) self.assertTrue(self.b3.has_unsupported_characters()) self.assertFalse(self.b4.has_unsupported_characters()) def test_is_reverse_complement(self): self.assertFalse(self.b1.is_reverse_complement(self.b1)) self.assertTrue(self.b1.is_reverse_complement(RNASequence('UGUAAUC'))) self.assertTrue( self.b4.is_reverse_complement(RNASequence('NVHDBMRSWYK'))) def test_nondegenerates_invalid(self): with self.assertRaises(BiologicalSequenceError): list(RNASequence('AZA').nondegenerates()) def test_nondegenerates_empty(self): self.assertEqual(list(self.empty.nondegenerates()), [self.empty]) def test_nondegenerates_no_degens(self): self.assertEqual(list(self.b1.nondegenerates()), [self.b1]) def test_nondegenerates_all_degens(self): # Same chars. exp = [ RNASequence('CC'), RNASequence('CG'), RNASequence('GC'), RNASequence('GG') ] # Sort based on sequence string, as order is not guaranteed. obs = sorted(RNASequence('SS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Different chars. exp = [ RNASequence('AC'), RNASequence('AG'), RNASequence('GC'), RNASequence('GG') ] obs = sorted(RNASequence('RS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Odd number of chars. obs = list(RNASequence('NNN').nondegenerates()) self.assertEqual(len(obs), 4**3) def test_nondegenerates_mixed_degens(self): exp = [ RNASequence('AGC'), RNASequence('AGU'), RNASequence('GGC'), RNASequence('GGU') ] obs = sorted(RNASequence('RGY').nondegenerates(), key=str) self.assertEqual(obs, exp) def test_nondegenerates_gap_mixed_case(self): exp = [ RNASequence('-A.a'), RNASequence('-A.c'), RNASequence('-C.a'), RNASequence('-C.c') ] obs = sorted(RNASequence('-M.m').nondegenerates(), key=str) self.assertEqual(obs, exp)
def test_is_reverse_complement(self): self.assertFalse(self.b1.is_reverse_complement(self.b1)) self.assertTrue(self.b1.is_reverse_complement(RNASequence('UGUAAUC'))) self.assertTrue( self.b4.is_reverse_complement(RNASequence('NVHDBMRSWYK')))
def test_nondegenerates_all_degens(self): # Same chars. exp = [ RNASequence('CC'), RNASequence('CG'), RNASequence('GC'), RNASequence('GG') ] # Sort based on sequence string, as order is not guaranteed. obs = sorted(RNASequence('SS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Different chars. exp = [ RNASequence('AC'), RNASequence('AG'), RNASequence('GC'), RNASequence('GG') ] obs = sorted(RNASequence('RS').nondegenerates(), key=str) self.assertEqual(obs, exp) # Odd number of chars. obs = list(RNASequence('NNN').nondegenerates()) self.assertEqual(len(obs), 4**3)
def test_nondegenerates_invalid(self): with self.assertRaises(BiologicalSequenceError): list(RNASequence('AZA').nondegenerates())