Mercurial > repos > jowong > add_sample_as_first_line
comparison add_sample_name_as_first_line.py @ 2:74a9f37e2bc9 draft
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit f3fe76f6cbf17b0ec4162065206483652a6519b7-dirty
author | jowong |
---|---|
date | Fri, 26 Oct 2018 17:52:33 -0400 |
parents | 492848eff35d |
children | 98f9da980bf5 |
comparison
equal
deleted
inserted
replaced
1:492848eff35d | 2:74a9f37e2bc9 |
---|---|
4 | 4 |
5 def Parser(): | 5 def Parser(): |
6 the_parser = argparse.ArgumentParser(description="add label to first line of file") | 6 the_parser = argparse.ArgumentParser(description="add label to first line of file") |
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input file") | 7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input file") |
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path") | 8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path") |
9 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in the first line") | 9 the_parser.add_argument('--sample', required=True, action="store", type=str, help="label to add in the first line") |
10 args = the_parser.parse_args() | 10 args = the_parser.parse_args() |
11 return args | 11 return args |
12 | 12 |
13 args=Parser() | 13 args=Parser() |
14 #input=open(args.input) | 14 #input=open(args.input) |
15 #output=open(args.output, 'w') | 15 #output=open(args.output, 'w') |
16 | 16 |
17 #print >> output, args.label | 17 #print >> output, args.label |
18 #print >> output, input | 18 #print >> output, input |
19 | 19 |
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 | 21 |
22 with open(args.input) as input: | 22 with open(args.input) as input: |
23 with open(args.output, 'w') as output: | 23 with open(args.output, 'w') as output: |
24 output.write(sample_name+"\n") | 24 output.write(sample_name+"\n") |
25 for line in input: | 25 for line in input: |