annotate add_sample_name_as_first_line.py @ 0:231b21337c43 draft

planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
author jowong
date Thu, 27 Sep 2018 17:05:18 -0400
parents
children 492848eff35d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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():
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
6 the_parser = argparse.ArgumentParser(description="add sample name as first line of a tab file")
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tab file")
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file")
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
9 the_parser.add_argument('--sample', required=True, action="store", type=str, help="sample name to add as the first line of input file")
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()
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
14
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
15 sample_name = re.sub('[_12]*.fastq.gz', '', args.sample.rstrip().lstrip())
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
16
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
17 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
18 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
19 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
20 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
21 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
22
231b21337c43 planemo upload for repository https://github.com/jowong4/add_sample_name_as_first_line_of_file commit 462cf96a681fad46e20321feec5996d1e558a0d3
jowong
parents:
diff changeset
23