| 4 | 1 #!/usr/bin/env python | 
|  | 2 | 
|  | 3 import sys | 
|  | 4 import argparse as ap | 
|  | 5 import re | 
|  | 6 parser = ap.ArgumentParser(prog='prince_postprocess', conflict_handler='resolve', | 
|  | 7                            description="Postprocess galaxy PRINCE output") | 
|  | 8 | 
|  | 9 input = parser.add_argument_group('Input', '') | 
|  | 10 input.add_argument('-i', '--input', nargs=1, required=True, help="PRINCE OUTPUT") | 
| 8 | 11 input.add_argument('-s', '--sample', nargs='+', required=True, help="Sample names") | 
|  | 12 input.add_argument('-f', '--file', nargs='+', required=True, help="File of forward reads in galaxy convention") | 
| 4 | 13 if len(sys.argv) == 0: | 
|  | 14     parser.print_usage() | 
|  | 15     sys.exit(1) | 
|  | 16 | 
|  | 17 args = parser.parse_args() | 
|  | 18 | 
|  | 19 #print(args.input) | 
|  | 20 #sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.label.rstrip().lstrip()) | 
| 8 | 21 sample_dict={} | 
|  | 22 path_index = 0 | 
|  | 23 for path in args.file: | 
|  | 24 	with open(path) as f: | 
|  | 25 		for line in f: | 
| 9 | 26 			sample_dict[re.sub(".*/","",line.rstrip())] = args.sample[path_index] | 
| 8 | 27 	path_index += 1 | 
|  | 28 | 
|  | 29 | 
|  | 30 | 
|  | 31 | 
|  | 32 | 
|  | 33 | 
| 4 | 34 | 
|  | 35 with open(args.input[0]) as prince_output: | 
|  | 36 	with open('prince_postprocess_output.txt', 'w') as output: | 
|  | 37 		x = 1 | 
|  | 38 		index = 0 | 
|  | 39 		for line in prince_output: | 
|  | 40 			if x%2 == 0: | 
| 8 | 41 				entries =line.rstrip().split(',') | 
|  | 42                                 sample = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', sample_dict[entries[0]]) | 
|  | 43 				output.write(re.sub(entries[0], sample, line)) | 
| 4 | 44 				index += 1 | 
|  | 45 			else: | 
|  | 46 				output.write(line) | 
|  | 47 			x += 1 | 
|  | 48 		#output.write("\n") | 
|  | 49 | 
|  | 50 |