File: fastq.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 (31 lines) | stat: -rwxr-xr-x 972 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
31
#cython: language_level=3

cimport cython
from obitools3.dms.capi.obiview cimport NUC_SEQUENCE_COLUMN
from obitools3.utils cimport bytes2str, str2bytes, tobytes


# TODO quality offset option?
cdef class FastqFormat:
	
	def __init__(self, list tags=[], bint printNAKeys=False, bytes NAString=b"NA", bint NAIntTo0=False):
		self.headerFormatter = HeaderFormat("fastq",
										    tags=tags,
										    printNAKeys=printNAKeys,
										    NAString=NAString,
                                            NAIntTo0=NAIntTo0)
		
	@cython.boundscheck(False)	
	def __call__(self, object data):
		
		cdef bytes quality	
		
		quality = None
		if hasattr(data, "quality_bytes"):
			quality = data.quality_bytes
		elif hasattr(data, "quality"):
			quality = tobytes(data.quality)
		if quality is None:
			raise AttributeError("No quality when exporting to fastq")  # TODO discuss
		
		return self.headerFormatter(data) + b"\n" + data[NUC_SEQUENCE_COLUMN] + b"\n+\n" + quality