File: fasta.pyx

package info (click to toggle)
obitools 3.0.1~b26%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,756 kB
  • sloc: ansic: 24,299; python: 657; sh: 27; makefile: 21
file content (30 lines) | stat: -rwxr-xr-x 834 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#cython: language_level=3

cimport cython
from obitools3.dms.capi.obiview cimport NUC_SEQUENCE_COLUMN
from obitools3.utils cimport bytes2str


cdef class FastaFormat:
	
	def __init__(self, list tags=[], bint printNAKeys=False, bytes NAString=b"NA", bint NAIntTo0=False):
		self.headerFormatter = HeaderFormat("fasta",
										    tags=tags,
										    printNAKeys=printNAKeys,
										    NAString=NAString,
										    NAIntTo0=NAIntTo0)
		
	@cython.boundscheck(False)	
	def __call__(self, object data):
		cdef bytes brawseq      = data[NUC_SEQUENCE_COLUMN]
		cdef size_t lseq        = len(brawseq)
		cdef size_t k           = 0
		cdef list   lines       = []
		
		for k in range(0,lseq,60):
			lines.append(brawseq[k:(k+60)])
			
		brawseq = b'\n'.join(lines)
		
		return self.headerFormatter(data) + b"\n" + brawseq