Beispiel #1
0
 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)
Beispiel #2
0
 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 main():

    args = parser.parse_args()
    input_dir = args.input_dir
    output_dir = args.output_dir
    linker = args.linker
    filetype = args.type

    i = 0

    output_fastx_fp = os.path.join(output_dir,'remultiplexed.' + filetype)
    output_fastx = open(output_fastx_fp, 'w')
    output_map_fp = os.path.join(output_dir,'remultiplexed_map.' + filetype + '.txt')
    output_map = open(output_map_fp, 'w')
    output_map.write("#SampleID\tBarcodeSequence\tLinkerPrimerSequence\tReads\tDescription\n")



    for fastx in os.listdir(input_dir):
        if fastx.endswith(filetype):
            try:
                fastx_file = open(os.path.join(input_dir,fastx),'Ur')
            except IOError:
                print "Could not open file ", fastx
                continue

            i += 1

            barcode_seq = encode([int(x) for x in list(str(bin(i))[2:].zfill(12))])

            barcode_qual = "I"*12

            reads = 0
            if filetype in ('fastq','fq','fsq','fnq'):
                for header, seq, qual in MinimalFastqParser(fastx_file):
                    reads += 1
                    output_fastx.write("@%s\n" % header)
                    output_fastx.write("{0}{1}\n".format(barcode_seq,seq))
                    output_fastx.write("+%s\n" % header)
                    output_fastx.write("{0}{1}\n".format(barcode_qual,qual))
            elif filetype in ('fasta','fa','fsa','fna'):
                for header, seq in MinimalFastaParser(fastx_file):
                    reads += 1
                    output_fastx.write(">%s\n" % header)
                    output_fastx.write("{0}{1}\n".format(barcode_seq,seq))

            output_map.write("{0}\t{1}\t{2}\t{3}\t{4}\n".format(fastx,barcode_seq,linker,reads,fastx))

    output_map.close()
    output_fastx.close()