Mercurial > repos > jowong > prince_galaxy
comparison prince_postprocess.py @ 8:63f3743c2ae4 draft
planemo upload
| author | jowong |
|---|---|
| date | Tue, 13 Nov 2018 12:19:53 -0500 |
| parents | 82569b47df8d |
| children | 5b816b501285 |
comparison
equal
deleted
inserted
replaced
| 7:0032da940600 | 8:63f3743c2ae4 |
|---|---|
| 6 parser = ap.ArgumentParser(prog='prince_postprocess', conflict_handler='resolve', | 6 parser = ap.ArgumentParser(prog='prince_postprocess', conflict_handler='resolve', |
| 7 description="Postprocess galaxy PRINCE output") | 7 description="Postprocess galaxy PRINCE output") |
| 8 | 8 |
| 9 input = parser.add_argument_group('Input', '') | 9 input = parser.add_argument_group('Input', '') |
| 10 input.add_argument('-i', '--input', nargs=1, required=True, help="PRINCE OUTPUT") | 10 input.add_argument('-i', '--input', nargs=1, required=True, help="PRINCE OUTPUT") |
| 11 input.add_argument('-s', '--sample', nargs='*', required=True, help="Sample names") | 11 input.add_argument('-s', '--sample', nargs='+', required=True, help="Sample names") |
| 12 | 12 input.add_argument('-f', '--file', nargs='+', required=True, help="File of forward reads in galaxy convention") |
| 13 if len(sys.argv) == 0: | 13 if len(sys.argv) == 0: |
| 14 parser.print_usage() | 14 parser.print_usage() |
| 15 sys.exit(1) | 15 sys.exit(1) |
| 16 | 16 |
| 17 args = parser.parse_args() | 17 args = parser.parse_args() |
| 18 | 18 |
| 19 #print(args.input) | 19 #print(args.input) |
| 20 #sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.label.rstrip().lstrip()) | 20 #sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.label.rstrip().lstrip()) |
| 21 sample_dict={} | |
| 22 path_index = 0 | |
| 23 for path in args.file: | |
| 24 with open(path) as f: | |
| 25 for line in f: | |
| 26 sample_dict[re.sub(".*/","",line)] = sample[path_index] | |
| 27 path_index += 1 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 21 | 34 |
| 22 with open(args.input[0]) as prince_output: | 35 with open(args.input[0]) as prince_output: |
| 23 with open('prince_postprocess_output.txt', 'w') as output: | 36 with open('prince_postprocess_output.txt', 'w') as output: |
| 24 x = 1 | 37 x = 1 |
| 25 index = 0 | 38 index = 0 |
| 26 for line in prince_output: | 39 for line in prince_output: |
| 27 if x%2 == 0: | 40 if x%2 == 0: |
| 28 sample = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.sample[index]) | 41 entries =line.rstrip().split(',') |
| 29 output.write(re.sub('.*.dat', sample, line)) | 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)) | |
| 30 index += 1 | 44 index += 1 |
| 31 else: | 45 else: |
| 32 output.write(line) | 46 output.write(line) |
| 33 x += 1 | 47 x += 1 |
| 34 #output.write("\n") | 48 #output.write("\n") |
