61 lines
1.6 KiB
Cython
61 lines
1.6 KiB
Cython
|
|
cdef class HeaderFormat:
|
|
|
|
def __init__(self, bint fastaHeader=True, list tags=[], bint printNAKeys=False):
|
|
'''
|
|
|
|
@param fastaHeader:
|
|
@type fastaHeader: `bool`
|
|
|
|
@param tags:
|
|
@type tags: `list` of `bytes`
|
|
|
|
@param printNAKeys:
|
|
@type printNAKeys: `bool`
|
|
'''
|
|
|
|
self.tags = set(tags)
|
|
self.printNaKeys = printNAKeys
|
|
|
|
if fastaHeader:
|
|
self.start=">"
|
|
else:
|
|
self.start="@"
|
|
|
|
self.headerBufferLength = 1000
|
|
#self.headerBuffer = []
|
|
|
|
def __call__(self, dict data):
|
|
cdef str header
|
|
cdef dict tags = data['tags']
|
|
cdef set ktags
|
|
cdef list lines = [""]
|
|
cdef str tagline
|
|
|
|
if self.tags is not None and self.tags:
|
|
ktags = self.tags
|
|
else:
|
|
ktags = set(tags.keys())
|
|
|
|
for k in ktags:
|
|
if k in tags:
|
|
value = tags[k]
|
|
if value is not None or self.printNaKeys:
|
|
lines.append("%s=%s;" % (k,tags[k]))
|
|
|
|
if len(lines) > 1:
|
|
tagline=" ".join(lines)
|
|
else:
|
|
tagline=""
|
|
|
|
if data['definition'] is not None:
|
|
header = "%s%s%s %s" % (self.start,data['id'],
|
|
tagline,
|
|
data['definition'])
|
|
else:
|
|
header = "%s%s%s" % (self.start,data['id'],
|
|
tagline)
|
|
|
|
return header
|
|
|