comparison RaGOO/ragoo_utilities/GFFReader.py @ 13:b9a3aeb162ab draft default tip

Uploaded
author dereeper
date Mon, 26 Jul 2021 18:22:37 +0000
parents
children
comparison
equal deleted inserted replaced
12:68a9ec9ce51e 13:b9a3aeb162ab
1 #!/usr/bin/env python
2
3
4 class GFFLine:
5
6 def __init__(self, in_fields):
7 self.seqname = in_fields[0]
8 self.source = in_fields[1]
9 self.feature = in_fields[2]
10 self.start = int(in_fields[3])
11 self.end = int(in_fields[4])
12 self.score = in_fields[5]
13 self.strand = in_fields[6]
14 self.frame = in_fields[7]
15 self.attribute = in_fields[8]
16
17 def __str__(self):
18 all_atts = [
19 self.seqname,
20 self.source,
21 self.feature,
22 self.start,
23 self.end,
24 self.score,
25 self.strand,
26 self.frame,
27 self.attribute
28 ]
29 all_atts = [str(i) for i in all_atts]
30 return '\t'.join(all_atts)
31
32
33 class GFFReader:
34
35 def __init__(self, in_gff_file):
36 self.gff_file = in_gff_file
37
38 def parse_gff(self):
39 with open(self.gff_file) as f:
40 for line in f:
41 if not line.startswith('#'):
42 L1 = line.rstrip().split('\t')
43 yield GFFLine(L1)