def test_decode_barcode_8_ok(self): """ Should decode valid codewords w/o error """ self.assertEqual(decode_barcode_8(self.valid_bc_1), (self.valid_bc_1, 0)) self.assertEqual(decode_barcode_8(self.valid_bc_2), (self.valid_bc_2, 0)) self.assertEqual(decode_barcode_8(self.valid_bc_3), (self.valid_bc_3, 0)) self.assertEqual(decode_barcode_8(self.valid_bc_4), (self.valid_bc_4, 0)) self.assertEqual(decode_barcode_8(self.valid_bc_5), (self.valid_bc_5, 0))
def attempt_bc_correction(curr_bc, all_bcs, barcode_type = "golay_12"): """ Gets corrected barcode and number of errors curr_bc: current barcode sequence to attempt correction with all_bcs: List of all barcode sequences. barcode_type: Specified barcode, can be golay_12, hamming_8, variable_length, or an integer specifying length. """ # First check for exact matches corrected_bc = get_exact_bc_matches(curr_bc, all_bcs) if corrected_bc: return corrected_bc, 0 if barcode_type == "golay_12": corrected_bc, num_errors = decode_golay_12(curr_bc) elif barcode_type == "hamming_8": corrected_bc, num_errors = decode_barcode_8(curr_bc) elif barcode_type == 0: corrected_bc, num_errors = ('', 0) else: corrected_bc, num_errors = correct_barcode(curr_bc, all_bcs) return corrected_bc, num_errors
def test_decode_barcode_8_one_error(self): """ Should correct single bit errors w/o error """ self.assertEqual(decode_barcode_8(self.single_error_1), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_2), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_3), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_4), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_5), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_6), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_7), (self.single_error_ref, 0.5)) self.assertEqual(decode_barcode_8(self.single_error_8), (self.single_error_ref, 0.5))
def test_decode_barcode_8_two_error(self): """ Should raise error when double error detected """ self.assertEqual(decode_barcode_8(self.double_error_1), (None, 1)) self.assertEqual(decode_barcode_8(self.double_error_1), (None, 1)) self.assertEqual(decode_barcode_8(self.double_error_1), (None, 1)) self.assertEqual(decode_barcode_8(self.double_error_1), (None, 1))
## in versions 1.2.0 through 1.3.*, and a try/except to handle errors from ## versions 1.4.0 or later. numpy_version = re.split("[^\d]", numpy_version) numpy_version = tuple([int(i) for i in numpy_version if i.isdigit()]) if numpy_version < (1,3,0): numpy_histogram = histogram def histogram(a, bins=10, range=None, normed=False, weights=None): return numpy_histogram(a,bins=bins,range=range,\ normed=normed,weights=weights,new=True) # Supported barcode types - need to adapt these functions to ignore list # of valid barcodes that the generic decoder requires BARCODE_TYPES = { "golay_12":(12, lambda bc, bcodes: decode_golay_12(bc)), "hamming_8":(8, lambda bc, bcodes: decode_barcode_8(bc)), # The decode function for variable length barcode does nothing - # it's just provided to comply with the interface of the other # barcode types. The returned barcode is always the same as the # one passed in, and the number of mismatches is always 0. The # length is None, corresponding to variable length. "variable_length":(None, lambda bc, bcodes: (bc, 0))} def get_infile(filename): """Returns filehandle, allowing gzip input.""" if filename.endswith(".gz"): fin = GzipFile(filename, "rb") else: fin = open(filename, "U") return fin