firt version of a fastq parser

This commit is contained in:
2016-03-31 10:47:12 +02:00
parent f51a6df5b2
commit 1cd35b3359
5 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,47 @@
#cython: language_level=3
'''
Created on 25 mars 2016
@author: coissac
'''
import re
__ret__ = re.compile('''(([^ ]+)=('[^']*'|"[^"]*"|[^;]+); *)+?''')
cdef object __etag__(str x):
try:
v = eval(x,{},{})
except:
v = x
return v
cpdef tuple parseHeader(str header):
cdef list m
cdef dict tags
cdef str definition
cdef str ident
cdef str second
m=header[1:-1].split(maxsplit=1)
ident=m[0]
if len(m)==1:
tags={}
definition=''
else:
second=m[1]
m = __ret__.findall(second)
if m:
tags = dict([(a[1],__etag__(a[2])) for a in m])
definition = second.split(m[-1][0],1)[1].strip()
else:
tags = {}
definition = second.strip()
return ident,tags,definition