| 0 | 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) |