Mercurial > repos > jowong > add_sample_as_first_line
annotate 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 |
rev | line source |
---|---|
0
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
1 import sys |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
2 import argparse |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
3 import re |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
4 |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
5 def Parser(): |
1
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
6 the_parser = argparse.ArgumentParser(description="add label to first line of file") |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input file") |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file path") |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
9 the_parser.add_argument('--label', required=True, action="store", type=str, help="label to add in the first line") |
0
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
10 args = the_parser.parse_args() |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
11 return args |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
12 |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
13 args=Parser() |
1
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
14 #input=open(args.input) |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
15 #output=open(args.output, 'w') |
0
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
16 |
1
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
17 #print >> output, args.label |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
18 #print >> output, input |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
19 |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
20 sample_name = re.sub('(_1.fastq.gz|_2.fastq.gz|.fastq.gz)', '', args.label.rstrip().lstrip()) |
0
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
21 |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
22 with open(args.input) as input: |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
23 with open(args.output, 'w') as output: |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
24 output.write(sample_name+"\n") |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
25 for line in input: |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
26 output.write(line) |
231b21337c43
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff
changeset
|
27 |
1
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
28 #input.close() |
492848eff35d
planemo upload commit 4c49b8443e44f12121afe9786a92133a7a487c7b-dirty
jowong
parents:
0
diff
changeset
|
29 #output.close() |