def test_count_fastq_sequences(self): """BarcodeCounter: count barcode sequences """ # Initialise counter object bc = BarcodeCounter() # Populate with sequences for r, incr in (((1, "AGGCAGAATCTTACGC"), 102), ((1, "TCCTGAGCTCTTACGC"), 10), ((1, "ACAGTGATTCTTTCCC"), 3), ((1, "ATGCTCGTCTCGCATC"), 1), ((2, "CGTACTAGTCTTACGC"), 95), ((2, "ATGTCAGATCTTTCCC"), 29), ((2, "AGGCAGAATCTTACGC"), 12), ((2, "CAGATCATTCTTTCCC"), 6), ((3, "GGACTCCTTCTTACGC"), 75), ((3, "ACCGATTCGCGCGTAG"), 74), ((3, "CCAGCAATATCGCGAG"), 2), ((3, "CCGCGTAAGCAATAGA"), 1)): lane, seq = r for i in xrange(incr): bc.count_barcode(seq, lane=lane) # Check contents self.assertEqual(bc.barcodes(), [ "AGGCAGAATCTTACGC", "CGTACTAGTCTTACGC", "GGACTCCTTCTTACGC", "ACCGATTCGCGCGTAG", "ATGTCAGATCTTTCCC", "TCCTGAGCTCTTACGC", "CAGATCATTCTTTCCC", "ACAGTGATTCTTTCCC", "CCAGCAATATCGCGAG", "ATGCTCGTCTCGCATC", "CCGCGTAAGCAATAGA" ]) # Lanes self.assertEqual(bc.lanes, [1, 2, 3]) # Counts for individual barcodes self.assertEqual(bc.counts("AGGCAGAATCTTACGC"), 114) self.assertEqual(bc.counts("AGGCAGAATCTTACGC", lane=1), 102) self.assertEqual(bc.counts("AGGCAGAATCTTACGC", lane=2), 12) self.assertEqual(bc.counts("AGGCAGAATCTTACGC", lane=3), 0) self.assertEqual(bc.counts_all("AGGCAGAATCTTACGC"), 114) self.assertEqual(bc.counts("CCGCGTAAGCAATAGA"), 1) self.assertEqual(bc.counts("CCGCGTAAGCAATAGA", lane=1), 0) self.assertEqual(bc.counts("CCGCGTAAGCAATAGA", lane=2), 0) self.assertEqual(bc.counts("CCGCGTAAGCAATAGA", lane=3), 1) self.assertEqual(bc.counts_all("CCGCGTAAGCAATAGA"), 1) # Read counts self.assertEqual(bc.nreads(), 410) self.assertEqual(bc.nreads(1), 116) self.assertEqual(bc.nreads(2), 142) self.assertEqual(bc.nreads(3), 152) # Lengths self.assertEqual(bc.barcode_lengths(), [16]) self.assertEqual(bc.barcode_lengths(1), [16]) self.assertEqual(bc.barcode_lengths(2), [16]) self.assertEqual(bc.barcode_lengths(3), [16])
elif length != barcode_length: logging.error("Lane %s has a mixture of " "barcode lengths" % lane) barcode_length = min(barcode_length, length) if barcode_length >= 6: mismatches = 1 else: mismatches = 0 # Check for collisions while mismatches and check_barcode_collisions( fp.name, mismatches): mismatches = mismatches - 1 # Check mismatches if mismatches is None: # Set according to barcode lengths found in counts barcode_length = min(counts.barcode_lengths(lane=lane)) if barcode_length >= 6: mismatches = 1 else: mismatches = 0 # Report the analysis report_barcodes(counts, lane=lane, cutoff=cutoff, sample_sheet=sample_sheet, mismatches=mismatches, reporter=reporter) if opts.report_file is not None: print "Writing report to %s" % opts.report_file reporter.write(filen=opts.report_file, title=opts.title) else: