A first version of the fasta parser
This commit is contained in:
8
python/obitools3/parsers/fasta.pxd
Normal file
8
python/obitools3/parsers/fasta.pxd
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
|
from .header cimport parseHeader
|
||||||
|
from ..files.universalopener cimport uopen
|
||||||
|
from ..files.linebuffer cimport LineBuffer
|
||||||
|
|
||||||
|
|
||||||
|
|
46
python/obitools3/parsers/fasta.pyx
Normal file
46
python/obitools3/parsers/fasta.pyx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
|
'''
|
||||||
|
Created on 30 mars 2016
|
||||||
|
|
||||||
|
@author: coissac
|
||||||
|
'''
|
||||||
|
|
||||||
|
def fastaIterator(lineiterator, int buffersize=100000000):
|
||||||
|
cdef LineBuffer lb
|
||||||
|
cdef str ident
|
||||||
|
cdef str definition
|
||||||
|
cdef dict tags
|
||||||
|
cdef list s
|
||||||
|
|
||||||
|
if isinstance(lineiterator,(str,bytes)):
|
||||||
|
lineiterator=uopen(lineiterator)
|
||||||
|
|
||||||
|
if isinstance(lineiterator, LineBuffer):
|
||||||
|
lb=lineiterator
|
||||||
|
else:
|
||||||
|
lb=LineBuffer(lineiterator,buffersize)
|
||||||
|
|
||||||
|
i = iter(lb)
|
||||||
|
line = next(i)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
ident,tags,definition = parseHeader(line)
|
||||||
|
s = []
|
||||||
|
line = next(i)
|
||||||
|
while line[0]!='>':
|
||||||
|
s.append(line[0:-1])
|
||||||
|
line = next(i)
|
||||||
|
sequence = "".join(s)
|
||||||
|
quality = None
|
||||||
|
|
||||||
|
yield { "id" : ident,
|
||||||
|
"definition" : definition,
|
||||||
|
"sequence" : sequence,
|
||||||
|
"quality" : quality,
|
||||||
|
"tags" : tags,
|
||||||
|
"annotation" : {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user