view 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
line wrap: on
line source

import sys
import argparse
import re

def Parser():
  the_parser = argparse.ArgumentParser(description="add sample name as first line of a tab file")
  the_parser.add_argument('--input', required=True, action="store", type=str, help="input tab file")
  the_parser.add_argument('--output', required=True,  action="store", type=str, help="output file")
  the_parser.add_argument('--sample', required=True, action="store", type=str, help="sample name to add as the first line of input file")
  args = the_parser.parse_args()
  return args

args=Parser()

sample_name = re.sub('[_12]*.fastq.gz', '', args.sample.rstrip().lstrip())

with open(args.input) as input:
	with open(args.output, 'w') as output:
		output.write(sample_name+"\n")
		for line in input:
			output.write(line)