def test_eq(self): s1 = easel.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 4])) s2 = easel.DigitalSequence(self.alphabet, name=b"seq2", sequence=bytearray([1, 2, 3, 3])) msa = easel.DigitalMSA(self.alphabet, sequences=[s1, s2]) msa2 = easel.DigitalMSA(self.alphabet, 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): arr = bytearray([0, 1, 2, 3]) seq1 = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) self.assertEqual(seq1, seq1) self.assertNotEqual(seq1, object()) seq2 = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) self.assertEqual(seq1, seq2) seq3 = easel.DigitalSequence(self.abc, name=b"OTHER", sequence=arr) self.assertNotEqual(seq1, seq3) arr2 = bytearray([0, 1, 2, 0]) seq4 = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr2) self.assertNotEqual(seq1, seq4)
def test_digitize_roundtrip(self): arr = bytearray([0, 1, 2, 3]) dsq1 = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) tsq1 = dsq1.textize() self.assertEqual(tsq1.name, dsq1.name) dsq2 = tsq1.digitize(self.abc) self.assertEqual(dsq1.name, dsq2.name) self.assertEqual(list(dsq1.sequence), list(dsq2.sequence)) self.assertEqual(dsq1, dsq2)
def test_copy(self): arr = bytearray([0, 1, 2, 3]) seq = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) # 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.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 4])) s2 = easel.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 3])) self.assertRaises(ValueError, easel.DigitalMSA, self.alphabet, sequences=[s1, s2])
def test_init_length_mismatch(self): s1 = easel.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 4])) s2 = easel.DigitalSequence(self.alphabet, name=b"seq2", sequence=bytearray([1, 2])) self.assertRaises(ValueError, easel.DigitalMSA, self.alphabet, sequences=[s1, s2])
def test_init_sequences(self): s1 = easel.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 4])) msa = easel.DigitalMSA(self.alphabet, sequences=[s1]) self.assertEqual(len(msa), 4) self.assertEqual(len(msa.sequences), 1) self.assertTrue(msa)
def test_eq_copy(self): s1 = easel.DigitalSequence(self.alphabet, name=b"seq1", sequence=bytearray([1, 2, 3, 4])) s2 = easel.DigitalSequence(self.alphabet, name=b"seq2", sequence=bytearray([1, 2, 3, 3])) msa = easel.DigitalMSA(self.alphabet, sequences=[s1, s2]) self.assertEqual(msa, msa.copy()) self.assertEqual(msa, copy.copy(msa))
def test_eq_not_seq(self): arr = bytearray([0, 1, 2, 3]) seq1 = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) self.assertNotEqual(seq1, 1) self.assertNotEqual(seq1, b"hello")
def test_setter_description(self): seq = easel.DigitalSequence(self.abc) 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.DigitalSequence(self.abc) self.assertEqual(seq.name, b"") seq.name = b"OTHER" self.assertEqual(seq.name, b"OTHER")
def test_init_kwargs(self): arr = bytearray([0, 1, 2, 3]) seq = easel.DigitalSequence(self.abc, name=b"TEST", sequence=arr) self.assertEqual(seq.name, b"TEST") self.assertEqual(bytearray(seq.sequence), arr) self.assertEqual(len(seq), 4)
def test_init_empty(self): seq = easel.DigitalSequence(self.abc) self.assertEqual(seq.name, b"") self.assertEqual(seq.sequence, bytearray()) self.assertEqual(len(seq), 0)