diff addFileNameToFastaIDs @ 0:146ffed44f3f draft default tip

planemo upload
author rdvelazquez
date Wed, 20 Mar 2019 22:17:40 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/addFileNameToFastaIDs	Wed Mar 20 22:17:40 2019 -0400
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+
+# first argument is script name
+# second should be fasta path
+# third argument should be the text to prepend to the seq ids
+# fourth argument should be the path to save the fasta at
+originalFastaPath = sys.argv[1]
+textToPrepend = sys.argv[2]
+newFastaPath = sys.argv[3]
+
+newFastaString = ""
+
+with open(originalFastaPath) as fp:
+    line = fp.readline()
+    cnt = 1
+    while line:
+        if line.startswith(">"):
+            id = ">" + textToPrepend + "_" + line[1:]
+        else:
+            sequence = line
+            newFastaString += id + sequence
+        line = fp.readline()
+        cnt += 1
+
+f = open(newFastaPath, "w")
+f.write(newFastaString)