@@ -0,0 +1,1308 @@
+#!/usr/bin/python%0A# filename: uaid_to_name.py%0A%0Aimport os%0Aimport glob%0Aimport argparse%0Afrom Bio import SeqIO%0A%0Aparser = argparse.ArgumentParser(%22Parses through merged MiSeq reads and appends the UAID to the sequence name.%22)%0Aparser.add_argument('-in', dest='input',required=True, help=%22The input FASTA file of UAID-barcoded sequences. If a directory is provided, all files in the directory will be iteratively processed.%22)%0Aparser.add_argument('-out', dest='output', required=True, help=%22Directory for the output files. Required.%22)%0Aparser.add_argument('-uaid', dest='uaid_length', type=int, default=20, help=%22Length of the UAID barcode. Default is 20.%22)%0Aargs = parser.parse_args()%0A%0A%0Adef list_files(d):  %0A%09return glob.glob(d + '/*')%0A%0Adef get_uaid(seq):%0A%09return seq%5B:args.uaid_length%5D%0A%0Adef get_output_handle(f):%0A%09o = os.path.join(args.output, os.path.basename(f))%0A%09open(o, 'w').write('')%0A%09return open(o, 'a')%0A%0Adef parse_uaids(f, out_handle):%0A%09for seq in SeqIO.parse(open(f, 'r'), 'fasta'):%0A%09%09index = get_uaid(str(seq.seq))%0A%09%09seq_id = '%7B0%7D_%7B1%7D'.format(seq.id, index)%0A%09%09trunc_seq = str(seq.seq)%5Bargs.uaid_length:%5D%0A%09%09out_handle.write('%3E%7B0%7D%5Cn%7B1%7D'.format(seq_id, trunc_seq))%0A%0Adef main():%0A%09files = list_files(args.input)%0A%09for f in files:%0A%09%09o = get_output_handle(f)%0A%09%09parse_uaids(f, o)%0A%0A%0Aif __name__ == '__main__':%0A%09main()

add uaid_to_name