Mercurial > repos > davidvanzessen > sff_extract_demultiplex
comparison trim.py @ 3:423d320bc1ba draft default tip
Uploaded
| author | davidvanzessen |
|---|---|
| date | Mon, 13 Mar 2017 05:52:29 -0400 |
| parents | cb08a27e5fc2 |
| children |
comparison
equal
deleted
inserted
replaced
| 2:44ec2a1009fc | 3:423d320bc1ba |
|---|---|
| 20 import shutil | 20 import shutil |
| 21 shutil.copy(args.input, args.output) | 21 shutil.copy(args.input, args.output) |
| 22 import sys | 22 import sys |
| 23 sys.exit() | 23 sys.exit() |
| 24 | 24 |
| 25 | 25 def trim(string, s, e): |
| 26 if e == 0: | |
| 27 return string[s:] | |
| 28 else: | |
| 29 return string[s:-e] | |
| 26 | 30 |
| 27 currentSeq = "" | 31 currentSeq = "" |
| 28 currentId = "" | 32 currentId = "" |
| 29 | 33 with open(args.input, 'r') as i, open(args.output, 'w') as o: |
| 30 if end is 0: | 34 for line in i: |
| 31 with open(args.input, 'r') as i: | 35 print "ID:", currentId |
| 32 with open(args.output, 'w') as o: | 36 if line[0] == ">": |
| 33 for line in i.readlines(): | 37 currentSeq = trim(currentSeq, start, end) |
| 34 if line[0] is ">": | 38 if len(currentId) > 0 and len(currentSeq) > 0: |
| 35 currentSeq = currentSeq[start:] | 39 o.write(currentId) |
| 36 if currentSeq is not "" and currentId is not "": | 40 o.write(currentSeq + "\n") |
| 37 o.write(currentId) | 41 currentId = line |
| 38 o.write(currentSeq + "\n") | 42 currentSeq = "" |
| 39 currentId = line | 43 else: |
| 40 currentSeq = "" | 44 currentSeq += line.rstrip() |
| 41 else: | 45 o.write(currentId) |
| 42 currentSeq += line.rstrip() | 46 o.write(currentSeq + "\n") |
| 43 o.write(currentId) | |
| 44 o.write(currentSeq[start:] + "\n") | |
| 45 else: | |
| 46 with open(args.input, 'r') as i: | |
| 47 with open(args.output, 'w') as o: | |
| 48 for line in i.readlines(): | |
| 49 if line[0] is ">": | |
| 50 currentSeq = currentSeq[start:-end] | |
| 51 if currentSeq is not "" and currentId is not "": | |
| 52 o.write(currentId) | |
| 53 o.write(currentSeq + "\n") | |
| 54 currentId = line | |
| 55 currentSeq = "" | |
| 56 else: | |
| 57 currentSeq += line.rstrip() | |
| 58 o.write(currentId) | |
| 59 o.write(currentSeq[start:-end] + "\n") |
