Mercurial > repos > jowong > prince_galaxy
diff prince_postprocess.py @ 0:88748989a22a draft default tip
planemo upload
author | jowong |
---|---|
date | Tue, 13 Nov 2018 11:41:37 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prince_postprocess.py Tue Nov 13 11:41:37 2018 -0500 @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +import sys +import argparse as ap +import re +parser = ap.ArgumentParser(prog='prince_postprocess', conflict_handler='resolve', + description="Postprocess galaxy PRINCE output") + +input = parser.add_argument_group('Input', '') +input.add_argument('-i', '--input', nargs=1, required=True, help="PRINCE OUTPUT") +input.add_argument('-s', '--sample', nargs='+', required=True, help="Sample names") +input.add_argument('-f', '--file', nargs='+', required=True, help="File of forward reads in galaxy convention") +if len(sys.argv) == 0: + parser.print_usage() + sys.exit(1) + +args = parser.parse_args() + +#print(args.input) +#sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.label.rstrip().lstrip()) +sample_dict={} +path_index = 0 +for path in args.file: + with open(path) as f: + for line in f: + sample_dict[re.sub(".*/","",line)] = sample[path_index] + path_index += 1 + + + + + + + +with open(args.input[0]) as prince_output: + with open('prince_postprocess_output.txt', 'w') as output: + x = 1 + index = 0 + for line in prince_output: + if x%2 == 0: + entries =line.rstrip().split(',') + sample = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', sample_dict[entries[0]]) + output.write(re.sub(entries[0], sample, line)) + index += 1 + else: + output.write(line) + x += 1 + #output.write("\n") + +