diff gff2Togff3.py @ 19:a7f57cf408e8 draft

planemo upload commit ff6c810cf2b46e59b45738700e68431743e4b83d
author yating-l
date Fri, 12 Aug 2016 12:03:46 -0400
parents
children 211c9b3a5c15
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gff2Togff3.py	Fri Aug 12 12:03:46 2016 -0400
@@ -0,0 +1,42 @@
+
+from Group import Group
+
+class Convertor:
+    def __init__(self, input, output):
+        with open(input) as self.f:
+            self.li = [line.rstrip().split("\t") for line in self.f]
+        self.gff3 = open(output, "w")
+        self.gff3.write("##gff-version 3\n")
+
+    def convert(self):
+        index = 0
+        while index in range(0, len(self.li)):
+            index = self.groupAsgene(index)
+        self.gff3.close()
+                
+                    
+    def groupAsgene(self, start = 0):
+        gene = self.li[start][8]
+        index = len(self.li)
+        for i in range(start+1, len(self.li)):
+            line = self.li[i]
+            if gene != line[8]:
+                index = i
+                break
+        if index >= len(self.li):
+            group = self.li[start:len(self.li)]
+        else:
+            group = self.li[start:index]
+        g = Group(group)
+        g.writer(self.gff3)
+        return index
+
+   
+        
+
+if __name__ == "__main__":
+    file = Convertor("dbia3.gff", "test.txt")
+    file.convert()
+
+
+    
\ No newline at end of file