Mercurial > repos > yating-l > snap
comparison gff2Togff3.py @ 0:57299471d6c1 draft default tip
planemo upload commit 402a746f69e9f1dbb57007536fc36dc6ce3180de
author | yating-l |
---|---|
date | Wed, 12 Apr 2017 17:37:47 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:57299471d6c1 |
---|---|
1 import argparse | |
2 import sys | |
3 import fileinput | |
4 from Group import Group | |
5 | |
6 def main(): | |
7 parser = argparse.ArgumentParser(description='Get a gff file and the output gff3 file') | |
8 parser.add_argument('--input', help='input gff file') | |
9 parser.add_argument('--output', help='output gff3 file', required=True) | |
10 args = parser.parse_args() | |
11 input = args.input | |
12 output = args.output | |
13 if not sys.stdin.isatty(): | |
14 c = Convertor(sys.stdin, output) | |
15 else: | |
16 c = Convertor(input, output) | |
17 c.convert() | |
18 | |
19 class Convertor: | |
20 def __init__(self, input, output): | |
21 if type(input) is str: | |
22 with open(input) as self.f: | |
23 self.li = [line.rstrip().split("\t") for line in self.f] | |
24 else: | |
25 self.li = [line.rstrip().split("\t") for line in input] | |
26 self.gff3 = open(output, "w") | |
27 self.gff3.write("##gff-version 3\n") | |
28 | |
29 def convert(self): | |
30 index = 0 | |
31 while index in range(0, len(self.li)): | |
32 index = self.groupAsgene(index) | |
33 self.gff3.close() | |
34 | |
35 | |
36 def groupAsgene(self, start = 0): | |
37 gene = self.li[start][8] | |
38 index = len(self.li) | |
39 for i in range(start+1, len(self.li)): | |
40 line = self.li[i] | |
41 if gene != line[8]: | |
42 index = i | |
43 break | |
44 if index >= len(self.li): | |
45 group = self.li[start:len(self.li)] | |
46 else: | |
47 group = self.li[start:index] | |
48 g = Group(group) | |
49 g.writer(self.gff3) | |
50 return index | |
51 | |
52 | |
53 | |
54 | |
55 if __name__ == "__main__": | |
56 main() | |
57 | |
58 | |
59 |