def test_eq(self): s1 = easel.TextSequence(name=b"seq1", sequence="ATGC") s2 = easel.TextSequence(name=b"seq2", sequence="ATGG") msa = easel.TextMSA(sequences=[s1, s2]) msa2 = easel.TextMSA(sequences=[s1, s2]) self.assertEqual(msa, msa2) msa2.name = b"other" self.assertNotEqual(msa, msa2) self.assertNotEqual(msa, 1) self.assertNotEqual(msa, [s1, s2])
def test_eq(self): seq1 = easel.TextSequence(name=b"TEST", sequence="ATGC") self.assertEqual(seq1, seq1) self.assertNotEqual(seq1, object()) seq2 = easel.TextSequence(name=b"TEST", sequence="ATGC") self.assertEqual(seq1, seq2) seq3 = easel.TextSequence(name=b"OTHER", sequence="ATGC") self.assertNotEqual(seq1, seq3) seq4 = easel.TextSequence(name=b"TEST", sequence="ATGT") self.assertNotEqual(seq1, seq4)
def test_digitize_roundtrip(self): seq1 = easel.TextSequence(name=b"TEST", sequence="ATGC") dsq1 = seq1.digitize(easel.Alphabet.dna()) self.assertEqual(seq1.name, dsq1.name) seq2 = dsq1.textize() self.assertEqual(seq1.name, seq2.name) self.assertEqual(seq1, seq2)
def test_reverse_complement_protein(self): seq = easel.TextSequence(sequence="MEMLP") with warnings.catch_warnings(): warnings.simplefilter('error') self.assertRaises(Warning, seq.reverse_complement) with warnings.catch_warnings(): warnings.simplefilter('ignore') rc = seq.reverse_complement() self.assertEqual(rc.sequence, "NNKNK")
def test_copy(self): seq = easel.TextSequence(name=b"TEST", sequence="ATGC") # copy the sequence cpy = seq.copy() # check the copy is equal and attributes are equal self.assertEqual(seq, cpy) self.assertEqual(seq.name, cpy.name) self.assertEqual(seq.checksum(), cpy.checksum()) # check attributes can be read even after the original object # is (hopefully) deallocated, to make sure internal strings were copied del seq gc.collect() self.assertEqual(cpy.name, b"TEST") # check `copy.copy` works too cpy2 = copy.copy(cpy) self.assertEqual(cpy, cpy2) self.assertEqual(cpy.name, cpy2.name)
def test_init_duplicate_names(self): s1 = easel.TextSequence(name=b"seq1", sequence="ATGC") s2 = easel.TextSequence(name=b"seq1", sequence="ATTC") self.assertRaises(ValueError, easel.TextMSA, sequences=[s1, s2])
def test_init_length_mismatch(self): s1 = easel.TextSequence(name=b"seq1", sequence="ATGC") s2 = easel.TextSequence(name=b"seq2", sequence="AT") self.assertRaises(ValueError, easel.TextMSA, sequences=[s1, s2])
def test_reverse_complement_inplace(self): seq = easel.TextSequence(sequence="ATGC") seq.reverse_complement(inplace=True) self.assertEqual(seq.sequence, "GCAT")
def test_reverse_complement(self): seq = easel.TextSequence(sequence="ATGC") rc = seq.reverse_complement() self.assertEqual(rc.sequence, "GCAT")
def test_write_roundtrip(self): seq = easel.TextSequence(name=b"ecoRI", sequence="GAATTC") with io.BytesIO() as buffer: seq.write(buffer) seq2 = easel.SequenceFile.parse(buffer.getvalue(), "fasta") self.assertEqual(seq, seq2)
def test_eq_not_seq(self): seq1 = easel.TextSequence(name=b"TEST", sequence="ATGC") self.assertNotEqual(seq1, 1) self.assertNotEqual(seq1, b"hello")
def test_setter_description(self): seq = easel.TextSequence() self.assertIs(seq.description, b"") seq.description = b"a test sequence" self.assertEqual(seq.description, b"a test sequence")
def test_setter_name(self): seq = easel.TextSequence() self.assertEqual(seq.name, b"") seq.name = b"OTHER" self.assertEqual(seq.name, b"OTHER")
def test_init_kwargs(self): seq = easel.TextSequence(name=b"TEST", sequence="ATGC") self.assertEqual(seq.name, b"TEST") self.assertEqual(seq.sequence, "ATGC") self.assertEqual(len(seq), 4)
def test_init_empty(self): seq = easel.TextSequence() self.assertEqual(seq.name, b"") self.assertEqual(seq.sequence, "") self.assertEqual(len(seq), 0)
def test_eq_copy(self): s1 = easel.TextSequence(name=b"seq1", sequence="ATGC") s2 = easel.TextSequence(name=b"seq2", sequence="ATGG") msa = easel.TextMSA(sequences=[s1, s2]) self.assertEqual(msa, msa.copy()) self.assertEqual(msa, copy.copy(msa))
def test_init_sequences(self): s1 = easel.TextSequence(name=b"seq1", sequence="ATGC") msa = easel.TextMSA(sequences=[s1]) self.assertEqual(len(msa), 4) self.assertEqual(len(msa.sequences), 1) self.assertTrue(msa)
def test_reverse_complement_protein(self): abc = easel.Alphabet.amino() seq = easel.TextSequence(sequence="MEMLP").digitize(abc) self.assertRaises(ValueError, seq.reverse_complement) self.assertRaises(ValueError, seq.reverse_complement, inplace=True)