#Script to change the barcodes from strings to integers given a containment file output from the Architect workflow. #Needed because architect.py expects the barcode/well to be an integer. #Used mappings of each base to a digit to do the transformation. import sys import re import argparse base_dict = {} base_dict['A'] = '1' base_dict['C'] = '2' base_dict['T'] = '3' base_dict['G'] = '4' def make_int_string(barcode): new_string = "" for char in barcode: new_string = new_string + base_dict[char] return new_string if __name__ == "__main__": parser = argparse.ArgumentParser(description='Re-format barcodes in containment file so that they are numerical') parser.add_argument('containment_file', help='Containment file to re-format', type=str) parser.add_argument('output_file', help='Name for the output containment file', type=str) args = parser.parse_args() cont_file = args.containment_file infile = open(cont_file, 'r') outfile = open(args.output_file, 'w') for line in infile: line = line.strip() split_line = line.split('\t') barcode = split_line[2] int_barcode = make_int_string(barcode) newline = split_line[0] + '\t' + split_line[1] + '\t' + int_barcode + '\t' + split_line[3] + '\t' + split_line[4] + '\n' outfile.write(newline) infile.close() outfile.close()