From 8151d877e79eda65808f16a968db3e488afa3380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Mon, 9 Jan 2023 12:30:36 +1100 Subject: [PATCH] Subtype from XAMReader and XAMWriter --- CHANGELOG.md | 4 ++++ src/XAM.jl | 5 +++++ src/bam/bam.jl | 2 +- src/bam/reader.jl | 6 +++--- src/bam/writer.jl | 2 +- src/sam/reader.jl | 2 +- src/sam/sam.jl | 2 +- src/sam/writer.jl | 2 +- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ed8c7b..cd21a88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added BAM.Reader index support for BAI object ([#56](https://github.com/BioJulia/XAM.jl/pull/56/files)) +### Changed + +- Subtype from XAMReader and XAMWriter from common abstract types. + ## [0.3.1] ### Changed diff --git a/src/XAM.jl b/src/XAM.jl index 2c5bad1..b3f5e4c 100644 --- a/src/XAM.jl +++ b/src/XAM.jl @@ -1,9 +1,14 @@ module XAM +using BioGenerics + export SAM, BAM +abstract type XAMReader <: BioGenerics.IO.AbstractReader end +abstract type XAMWriter <: BioGenerics.IO.AbstractWriter end + """ flag(record::Union{SAM.Record, BAM.Record})::UInt16 diff --git a/src/bam/bam.jl b/src/bam/bam.jl index b3591d7..41aea12 100644 --- a/src/bam/bam.jl +++ b/src/bam/bam.jl @@ -6,7 +6,7 @@ module BAM using BioGenerics using GenomicFeatures using XAM.SAM -import ..XAM: flag +import ..XAM: flag, XAMReader, XAMWriter import BGZFStreams import BioAlignments diff --git a/src/bam/reader.jl b/src/bam/reader.jl index 3dd2f7f..c1686c0 100644 --- a/src/bam/reader.jl +++ b/src/bam/reader.jl @@ -8,9 +8,9 @@ Create a data reader of the BAM file format. # Arguments * `input`: data source -* `index=nothing`: filepath to a random access index (currently *bai* is supported) or BAI object +* `index=nothing`: filepath to a random access index (currently *bai* is supported) or BAI object """ -mutable struct Reader{T} <: BioGenerics.IO.AbstractReader +mutable struct Reader{T} <: XAMReader stream::BGZFStreams.BGZFStream{T} header::SAM.Header start_offset::BGZFStreams.VirtualOffset @@ -124,7 +124,7 @@ init_bam_index(index::AbstractString) = BAI(index) init_bam_index(index::BAI) = index init_bam_index(index::Nothing) = nothing init_bam_index(index) = error("unrecognizable index argument") - + function _read!(reader::Reader, record) unsafe_read( reader.stream, diff --git a/src/bam/writer.jl b/src/bam/writer.jl index 81bdf23..8c4268f 100644 --- a/src/bam/writer.jl +++ b/src/bam/writer.jl @@ -10,7 +10,7 @@ Create a data writer of the BAM file format. * `output`: data sink * `header`: SAM header object """ -mutable struct Writer <: BioGenerics.IO.AbstractWriter +mutable struct Writer <: XAMWriter stream::BGZFStreams.BGZFStream end diff --git a/src/sam/reader.jl b/src/sam/reader.jl index 46fd286..f38044f 100644 --- a/src/sam/reader.jl +++ b/src/sam/reader.jl @@ -1,7 +1,7 @@ # SAM Reader # ========= -mutable struct Reader{S <: TranscodingStream} <: BioGenerics.IO.AbstractReader +mutable struct Reader{S <: TranscodingStream} <: XAMReader state::State{S} header::Header end diff --git a/src/sam/sam.jl b/src/sam/sam.jl index fcd0821..0e25d39 100644 --- a/src/sam/sam.jl +++ b/src/sam/sam.jl @@ -11,7 +11,7 @@ import BioGenerics.Exceptions: missingerror import BioGenerics.Automa: State import BioSequences import TranscodingStreams: TranscodingStreams, TranscodingStream -import ..XAM: flag +import ..XAM: flag, XAMReader, XAMWriter using Printf: @sprintf diff --git a/src/sam/writer.jl b/src/sam/writer.jl index 801ed68..c16a346 100644 --- a/src/sam/writer.jl +++ b/src/sam/writer.jl @@ -10,7 +10,7 @@ Create a data writer of the SAM file format. * `output`: data sink * `header=Header()`: SAM header object """ -mutable struct Writer <: BioGenerics.IO.AbstractWriter +mutable struct Writer <: XAMWriter stream::IO function Writer(output::IO, header::Header=Header())