diff trim.py @ 4:8e3d95d7f342 draft

Uploaded
author davidvanzessen
date Mon, 07 Jul 2014 05:49:20 -0400
parents 79be0752711d
children 35b55f1c0c59
line wrap: on
line diff
--- a/trim.py	Tue Jul 01 08:27:57 2014 -0400
+++ b/trim.py	Mon Jul 07 05:49:20 2014 -0400
@@ -2,8 +2,8 @@
 
 #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("--input", help="Input fasta")
+parser.add_argument("--output", help="Output fasta")
 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)
 
@@ -11,25 +11,44 @@
 start = int(args.start)
 end = int(args.end)
 
-if end <= 0:
+if end <= 0 and start <= 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")
+if end is 0:
+	with open(args.input, 'r') as i:
+		with open(args.output, 'w') as o:
+			for line in i.readlines():
+				if line[0] is ">":
+					currentSeq = currentSeq[start:]
+					if currentSeq is not "" and currentId is not "":
+						o.write(currentId)
+						o.write(currentSeq + "\n")
+					currentId = line
+					currentSeq = ""
+				else:
+					currentSeq += line.rstrip()
+			o.write(currentId)
+			o.write(currentSeq[start:] + "\n")
+else:
+	with open(args.input, 'r') as i:
+		with open(args.output, 'w') as o:
+			for line in i.readlines():
+				if line[0] is ">":
+					currentSeq = currentSeq[start:-end]
+					if currentSeq is not "" and currentId is not "":
+						o.write(currentId)
+						o.write(currentSeq + "\n")
+					currentId = line
+					currentSeq = ""
+				else:
+					currentSeq += line.rstrip()
+			o.write(currentId)
+			o.write(currentSeq[start:-end] + "\n")