Mercurial > repos > jowong > add_sample_as_first_line
annotate add_sample_name_as_first_line.py @ 3:98f9da980bf5 draft default tip
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit f3fe76f6cbf17b0ec4162065206483652a6519b7-dirty
author | jowong |
---|---|
date | Fri, 09 Nov 2018 12:27:57 -0500 |
parents | 74a9f37e2bc9 |
children |
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") |
2
74a9f37e2bc9
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit f3fe76f6cbf17b0ec4162065206483652a6519b7-dirty
jowong
parents:
1
diff
changeset
|
9 the_parser.add_argument('--sample', 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 |
3
98f9da980bf5
planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit f3fe76f6cbf17b0ec4162065206483652a6519b7-dirty
jowong
parents:
2
diff
changeset
|
20 sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.sample.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() |