diff trim.py @ 3:79be0752711d draft

Uploaded
author davidvanzessen
date Tue, 01 Jul 2014 08:27:57 -0400
parents
children 8e3d95d7f342
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trim.py	Tue Jul 01 08:27:57 2014 -0400
@@ -0,0 +1,35 @@
+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")