comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:231b21337c43
1 import sys
2 import argparse
3 import re
4
5 def Parser():
6 the_parser = argparse.ArgumentParser(description="add sample name as first line of a tab file")
7 the_parser.add_argument('--input', required=True, action="store", type=str, help="input tab file")
8 the_parser.add_argument('--output', required=True, action="store", type=str, help="output file")
9 the_parser.add_argument('--sample', required=True, action="store", type=str, help="sample name to add as the first line of input file")
10 args = the_parser.parse_args()
11 return args
12
13 args=Parser()
14
15 sample_name = re.sub('[_12]*.fastq.gz', '', args.sample.rstrip().lstrip())
16
17 with open(args.input) as input:
18 with open(args.output, 'w') as output:
19 output.write(sample_name+"\n")
20 for line in input:
21 output.write(line)
22
23