Mercurial > repos > yating-l > snap
comparison gff2Togff3.py @ 19:a7f57cf408e8 draft
planemo upload commit ff6c810cf2b46e59b45738700e68431743e4b83d
author | yating-l |
---|---|
date | Fri, 12 Aug 2016 12:03:46 -0400 |
parents | |
children | 211c9b3a5c15 |
comparison
equal
deleted
inserted
replaced
18:1debdbe657cd | 19:a7f57cf408e8 |
---|---|
1 | |
2 from Group import Group | |
3 | |
4 class Convertor: | |
5 def __init__(self, input, output): | |
6 with open(input) as self.f: | |
7 self.li = [line.rstrip().split("\t") for line in self.f] | |
8 self.gff3 = open(output, "w") | |
9 self.gff3.write("##gff-version 3\n") | |
10 | |
11 def convert(self): | |
12 index = 0 | |
13 while index in range(0, len(self.li)): | |
14 index = self.groupAsgene(index) | |
15 self.gff3.close() | |
16 | |
17 | |
18 def groupAsgene(self, start = 0): | |
19 gene = self.li[start][8] | |
20 index = len(self.li) | |
21 for i in range(start+1, len(self.li)): | |
22 line = self.li[i] | |
23 if gene != line[8]: | |
24 index = i | |
25 break | |
26 if index >= len(self.li): | |
27 group = self.li[start:len(self.li)] | |
28 else: | |
29 group = self.li[start:index] | |
30 g = Group(group) | |
31 g.writer(self.gff3) | |
32 return index | |
33 | |
34 | |
35 | |
36 | |
37 if __name__ == "__main__": | |
38 file = Convertor("dbia3.gff", "test.txt") | |
39 file.convert() | |
40 | |
41 | |
42 |