view trim.py @ 3:79be0752711d draft

Uploaded
author davidvanzessen
date Tue, 01 Jul 2014 08:27:57 -0400
parents
children 8e3d95d7f342
line wrap: on
line source

import argparse

#docs.python.org/dev/library/argparse.html
parser = argparse.ArgumentParser()
parser.add_argument("--input", help="Input folder with files")
parser.add_argument("--output", help="Output file")
parser.add_argument("--start", help="How many nucleotides to trim from the start", type=int)
parser.add_argument("--end", help="How many nucleotides to trim from the end", type=int)

args = parser.parse_args()
start = int(args.start)
end = int(args.end)

if end <= 0:
	import shutil
	shutil.copy(args.input, args.output)
	import sys
	sys.exit()

currentSeq = ""
currentId = ""

with open(args.input, 'r') as i:
	with open(args.output, 'w') as o:
		for line in i.readlines():
			if line[0] is ">":
				if currentSeq is not "" or currentId is not "":
					o.write(currentId)
					o.write(currentSeq[start:-end] + "\n")
				currentId = line
				currentSeq = ""
			else:
				currentSeq += line.rstrip()
		o.write(currentId)
		o.write(currentSeq.rstrip()[start:-end] + "\n")