Mercurial > repos > rdvelazquez > rdv_fasta_tools
comparison addFileNameToFastaIDs @ 0:146ffed44f3f draft default tip
planemo upload
| author | rdvelazquez |
|---|---|
| date | Wed, 20 Mar 2019 22:17:40 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:146ffed44f3f |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import sys | |
| 4 | |
| 5 # first argument is script name | |
| 6 # second should be fasta path | |
| 7 # third argument should be the text to prepend to the seq ids | |
| 8 # fourth argument should be the path to save the fasta at | |
| 9 originalFastaPath = sys.argv[1] | |
| 10 textToPrepend = sys.argv[2] | |
| 11 newFastaPath = sys.argv[3] | |
| 12 | |
| 13 newFastaString = "" | |
| 14 | |
| 15 with open(originalFastaPath) as fp: | |
| 16 line = fp.readline() | |
| 17 cnt = 1 | |
| 18 while line: | |
| 19 if line.startswith(">"): | |
| 20 id = ">" + textToPrepend + "_" + line[1:] | |
| 21 else: | |
| 22 sequence = line | |
| 23 newFastaString += id + sequence | |
| 24 line = fp.readline() | |
| 25 cnt += 1 | |
| 26 | |
| 27 f = open(newFastaPath, "w") | |
| 28 f.write(newFastaString) |
