changeset 3:423d320bc1ba draft default tip

Uploaded
author davidvanzessen
date Mon, 13 Mar 2017 05:52:29 -0400
parents 44ec2a1009fc
children
files trim.py
diffstat 1 files changed, 19 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/trim.py	Wed Dec 21 10:23:19 2016 -0500
+++ b/trim.py	Mon Mar 13 05:52:29 2017 -0400
@@ -22,38 +22,25 @@
 	import sys
 	sys.exit()
 	
-
+def trim(string, s, e):
+	if e == 0:
+		return string[s:]
+	else:
+		return string[s:-e]
 
 currentSeq = ""
 currentId = ""
-
-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")
+with open(args.input, 'r') as i, open(args.output, 'w') as o:
+	for line in i:
+		print "ID:", currentId
+		if line[0] == ">":
+			currentSeq = trim(currentSeq, start, end)
+			if len(currentId) > 0 and len(currentSeq) > 0:
+				o.write(currentId)
+				o.write(currentSeq + "\n")
+			currentId = line
+			currentSeq = ""
+		else:
+			currentSeq += line.rstrip()
+	o.write(currentId)
+	o.write(currentSeq + "\n")