module

Fastx

Constants

NORMALIZE_IUPAC_BASE = begin table = StaticArray(UInt8, 256).new(0_u8) table[82] = table[114] = 82_u8 table[89] = table[121] = 89_u8 table[83] = table[115] = 83_u8 table[87] = table[119] = 87_u8 table[75] = table[107] = 75_u8 table[77] = table[109] = 77_u8 table[66] = table[98] = 66_u8 table[68] = table[100] = 68_u8 table[72] = table[104] = 72_u8 table[86] = table[118] = 86_u8 table end
NORMALIZE_STANDARD_BASE = begin table = StaticArray(UInt8, 256).new(0_u8) table[65] = table[97] = 65_u8 table[67] = table[99] = 67_u8 table[71] = table[103] = 71_u8 table[84] = table[116] = 84_u8 table[78] = table[110] = 78_u8 table end

Base normalization runs once per input byte. Lookup tables avoid repeated branch checks and keep this hot path small.

VERSION = {{ (`shards version /tmp/tmp.obOMIc/src/src/fastx`).chomp.stringify }}

Class methods

decode_bases(bases : Bytes) : String

Converts a UInt8 array (ASCII codes) to a DNA string.

Source
decode_bases(bases : Array(UInt8)) : String

Converts a UInt8 array (ASCII codes) to a DNA string.

Source
decode_bases(bases : Enumerable(UInt8)) : String

Converts a UInt8 array (ASCII codes) to a DNA string.

Source
decode_phred(scores : Bytes, offset = 33) : String

Converts a slice of Phred scores to a quality string.

Source
decode_phred(scores : Array(UInt8), offset = 33) : String

Converts an array of Phred scores to a quality string.

Source
decode_phred(scores : Enumerable(UInt8), offset = 33) : String

Converts an array of Phred scores to a quality string.

Source
encode_bases(sequence : Bytes, *, iupac : Bool = false, strict : Bool = false) : Slice(UInt8)

Converts a DNA sequence (Bytes or String) to a UInt8 slice, where each base is encoded as a single byte. When iupac is true, supports IUPAC nucleotide codes (R, Y, S, W, K, M, B, D, H, V). When iupac is false, only standard bases (A, C, G, T, N) are preserved. Non-recognized characters are converted to N (78u8). This representation is suitable for byte-wise or array processing.

Source
encode_bases(sequence : String, *, iupac : Bool = false, strict : Bool = false) : Slice(UInt8)

Converts a DNA sequence (Bytes or String) to a UInt8 slice, where each base is encoded as a single byte. When iupac is true, supports IUPAC nucleotide codes (R, Y, S, W, K, M, B, D, H, V). When iupac is false, only standard bases (A, C, G, T, N) are preserved. Non-recognized characters are converted to N (78u8). This representation is suitable for byte-wise or array processing.

Source
encode_phred(quality : Bytes, offset = 33) : Array(UInt8)

Converts a quality sequence (Bytes) to an array of Phred scores.

Source
encode_phred(quality : String, offset = 33) : Array(UInt8)

Converts a quality string to an array of Phred scores.

Source
normalize_base(c : UInt8, *, iupac : Bool = false, strict : Bool = false) : UInt8

Normalizes a single base character to uppercase. When iupac is true, supports IUPAC nucleotide codes (R, Y, S, W, K, M, B, D, H, V). When iupac is false, only standard bases (A, C, G, T, N) are preserved. Non-recognized characters are converted to N (78u8).

Source
open(filename : Path | String, mode = "r", format : Format | Nil = nil, &)

Opens a FASTA/FASTQ file with automatic format detection or explicit format. Yields the appropriate Reader/Writer to the block and automatically closes it.

Source
open(filename : Path | String, mode = "r", format : Format | Nil = nil)

Opens a FASTA/FASTQ file with automatic format detection or explicit format. Returns the appropriate Reader/Writer instance (manual close required).

Source

Nested types