def test_golay_module1(self): """switching the last base, decode() should recover the original barcode """ sent = golay.encode([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]) rec = sent[:-1] + 'C' # possible error here decoded, errors = golay.decode(rec) self.assertEqual(decoded, sent) self.assertLessThan(errors, 1.5) rec = sent[:-1] + 'T' # possible error here decoded, errors = golay.decode(rec) self.assertEqual(decoded, sent) self.assertLessThan(errors, 1.5)
def test_decode(self): """ decode should decode barcodes from tutorial""" barcodes = ['AGCACGAGCCTA', 'AACTCGTCGATG', 'ACAGACCACTCA', 'ACCAGCGACTAG', 'AGCAGCACTTGT', 'AACTGTGCGTAC', 'ACAGAGTCGGCT', 'ACCGCAGAGTCA', 'ACGGTGAGTGTC', ] for bc in barcodes: self.assertEqual(golay.decode(bc), (bc, 0)) for bc in barcodes: err_bc = 'C' + bc[1:] self.assertEqual(golay.decode(err_bc), (bc, 2))
def test_decode(self): """ decode should decode barcodes from tutorial""" barcodes = ['AGCACGAGCCTA', 'AACTCGTCGATG', 'ACAGACCACTCA', 'ACCAGCGACTAG', 'AGCAGCACTTGT', 'AACTGTGCGTAC', 'ACAGAGTCGGCT', 'ACCGCAGAGTCA', 'ACGGTGAGTGTC',] for bc in barcodes: self.assertEqual(golay.decode(bc),(bc,0)) for bc in barcodes: err_bc = 'C'+bc[1:] self.assertEqual(golay.decode(err_bc),(bc,2))
def test_golay600_2bit_errors(self): """ A->C, G->T errors should be 2 bit errors for all 600 barcodes """ for bc in golay600: if bc.count('A') == 0: continue # only check those with A's err_bc = bc.replace('A', 'C', 1) corr, num_errs = golay.decode(err_bc) self.assertEqual(corr, bc) self.assertEqual(num_errs, 2) for bc in golay600: if bc.count('G') == 0: continue # only check those with A's err_bc = bc.replace('G', 'T', 1) corr, num_errs = golay.decode(err_bc) self.assertEqual(corr, bc) self.assertEqual(num_errs, 2)
def test_golay_matches_old_code(self): """ decode should behave as micah's code did, i.e., same golay encoding this requires DEFAULT_NT_TO_BITS = { "A":"11", "C":"00", "T":"10", "G":"01"} """ NT_TO_BITS = {"A": "11", "C": "00", "T": "10", "G": "01"} original = 'GCATCGTCAACA' rec = 'GCATCGTCCACA' corr, nt_errs = golay.decode(rec, NT_TO_BITS) self.assertEqual(corr, original) self.assertEqual(nt_errs, 2)
def test_golay600_codes(self): """ all 600 codes should be left uncorrected, 0 errors""" for bc in golay600: corr, num_errs = golay.decode(bc) self.assertEqual(corr, bc) self.assertEqual(num_errs, 0)