Previous changeset 2:44ec2a1009fc (2016-12-21) |
Commit message:
Uploaded |
modified:
trim.py |
b |
diff -r 44ec2a1009fc -r 423d320bc1ba trim.py --- 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") |