Mercurial > repos > jowong > add_sample_as_first_line
comparison add_sample_name_as_first_line.py @ 1:492848eff35d draft
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
author | jowong |
---|---|
date | Sun, 21 Oct 2018 09:37:06 -0400 |
parents | 231b21337c43 |
children | 74a9f37e2bc9 |
comparison
equal
deleted
inserted
replaced
0:231b21337c43 | 1:492848eff35d |
---|---|
1 import sys | 1 import sys |
2 import argparse | 2 import argparse |
3 import re | 3 import re |
4 | 4 |
5 def Parser(): | 5 def Parser(): |
6 the_parser = argparse.ArgumentParser(description="add sample name as first line of a tab 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 tab 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") | 8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path") |
9 the_parser.add_argument('--sample', required=True, action="store", type=str, help="sample name to add as the first line of input file") | 9 the_parser.add_argument('--label', 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) | |
15 #output=open(args.output, 'w') | |
14 | 16 |
15 sample_name = re.sub('[_12]*.fastq.gz', '', args.sample.rstrip().lstrip()) | 17 #print >> output, args.label |
18 #print >> output, input | |
19 | |
20 sample_name = re.sub('(_1.fastq.gz|_2.fastq.gz|.fastq.gz)', '', args.label.rstrip().lstrip()) | |
16 | 21 |
17 with open(args.input) as input: | 22 with open(args.input) as input: |
18 with open(args.output, 'w') as output: | 23 with open(args.output, 'w') as output: |
19 output.write(sample_name+"\n") | 24 output.write(sample_name+"\n") |
20 for line in input: | 25 for line in input: |
21 output.write(line) | 26 output.write(line) |
22 | 27 |
23 | 28 #input.close() |
29 #output.close() |