1
0
Fork 0
mirror of https://github.com/MillironX/XAM.jl.git synced 2024-11-23 10:19:56 +00:00

Migrate to BioGenerics

Basic find and replace.
This commit is contained in:
Ciarán O'Mara 2020-02-02 22:50:25 +11:00
parent e8ad60b086
commit c4f3c4b0df
10 changed files with 53 additions and 62 deletions

View file

@ -7,7 +7,7 @@ version = "0.1.1"
Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b"
BGZFStreams = "28d598bf-9b8f-59f1-b38c-5a06b4a0f5e6" BGZFStreams = "28d598bf-9b8f-59f1-b38c-5a06b4a0f5e6"
BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e" BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e"
BioCore = "37cfa864-2cd6-5c12-ad9e-b6597d696c81" BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea"
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59" BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d" BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
GenomicFeatures = "899a7d2d-5c61-547b-bef9-6698a8d05446" GenomicFeatures = "899a7d2d-5c61-547b-bef9-6698a8d05446"
@ -18,7 +18,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Automa = "0.7, 0.8" Automa = "0.7, 0.8"
BGZFStreams = "0.3" BGZFStreams = "0.3"
BioAlignments = "2" BioAlignments = "2"
BioCore = "2" BioGenerics = "0.1"
BioSequences = "2" BioSequences = "2"
BufferedStreams = "1" BufferedStreams = "1"
GenomicFeatures = "2" GenomicFeatures = "2"

View file

@ -3,7 +3,7 @@
module BAM module BAM
using BioCore using BioGenerics
using GenomicFeatures using GenomicFeatures
using XAM.SAM using XAM.SAM
@ -11,7 +11,7 @@ import BGZFStreams
import BioAlignments import BioAlignments
import Indexes import Indexes
import BioSequences import BioSequences
import BioCore: isfilled, header import BioGenerics: isfilled, header
import GenomicFeatures: eachoverlap import GenomicFeatures: eachoverlap

View file

@ -10,7 +10,7 @@ Create a data reader of the BAM file format.
* `input`: data source * `input`: data source
* `index=nothing`: filepath to a random access index (currently *bai* is supported) * `index=nothing`: filepath to a random access index (currently *bai* is supported)
""" """
mutable struct Reader{T} <: BioCore.IO.AbstractReader mutable struct Reader{T} <: BioGenerics.IO.AbstractReader
stream::BGZFStreams.BGZFStream{T} stream::BGZFStreams.BGZFStream{T}
header::SAM.Header header::SAM.Header
start_offset::BGZFStreams.VirtualOffset start_offset::BGZFStreams.VirtualOffset
@ -23,7 +23,7 @@ function Base.eltype(::Type{Reader{T}}) where T
return Record return Record
end end
function BioCore.IO.stream(reader::Reader) function BioGenerics.IO.stream(reader::Reader)
return reader.stream return reader.stream
end end

View file

@ -566,42 +566,42 @@ function Base.values(record::Record)
end end
# BioCore Methods # BioGenerics Methods
# ----------- # -----------
function BioCore.isfilled(record::Record) function BioGenerics.isfilled(record::Record)
return record.block_size != 0 return record.block_size != 0
end end
function BioCore.seqname(record::Record) function BioGenerics.seqname(record::Record)
return tempname(record) return tempname(record)
end end
function BioCore.hasseqname(record::Record) function BioGenerics.hasseqname(record::Record)
return hastempname(record) return hastempname(record)
end end
function BioCore.sequence(record::Record) function BioGenerics.sequence(record::Record)
return sequence(record) return sequence(record)
end end
function BioCore.hassequence(record::Record) function BioGenerics.hassequence(record::Record)
return hassequence(record) return hassequence(record)
end end
function BioCore.leftposition(record::Record) function BioGenerics.leftposition(record::Record)
return position(record) return position(record)
end end
function BioCore.hasleftposition(record::Record) function BioGenerics.hasleftposition(record::Record)
return hasposition(record) return hasposition(record)
end end
function BioCore.rightposition(record::Record) function BioGenerics.rightposition(record::Record)
return rightposition(record) return rightposition(record)
end end
function BioCore.hasrightposition(record::Record) function BioGenerics.hasrightposition(record::Record)
return hasrightposition(record) return hasrightposition(record)
end end

View file

@ -10,7 +10,7 @@ Create a data writer of the BAM file format.
* `output`: data sink * `output`: data sink
* `header`: SAM header object * `header`: SAM header object
""" """
mutable struct Writer <: BioCore.IO.AbstractWriter mutable struct Writer <: BioGenerics.IO.AbstractWriter
stream::BGZFStreams.BGZFStream stream::BGZFStreams.BGZFStream
end end
@ -25,7 +25,7 @@ function Writer(stream::BGZFStreams.BGZFStream, header::SAM.Header)
return Writer(stream) return Writer(stream)
end end
function BioCore.IO.stream(writer::Writer) function BioGenerics.IO.stream(writer::Writer)
return writer.stream return writer.stream
end end

View file

@ -1,12 +1,12 @@
# SAM Reader # SAM Reader
# ========= # =========
mutable struct Reader <: BioCore.IO.AbstractReader mutable struct Reader <: BioGenerics.IO.AbstractReader
state::BioCore.Ragel.State state::BioGenerics.Ragel.State
header::Header header::Header
function Reader(input::BufferedStreams.BufferedInputStream) function Reader(input::BufferedStreams.BufferedInputStream)
reader = new(BioCore.Ragel.State(sam_header_machine.start_state, input), Header()) reader = new(BioGenerics.Ragel.State(sam_header_machine.start_state, input), Header())
readheader!(reader) readheader!(reader)
reader.state.cs = sam_body_machine.start_state reader.state.cs = sam_body_machine.start_state
return reader return reader
@ -25,7 +25,7 @@ function Reader(input::IO)
return Reader(BufferedStreams.BufferedInputStream(input)) return Reader(BufferedStreams.BufferedInputStream(input))
end end
function BioCore.IO.stream(reader::Reader) function BioGenerics.IO.stream(reader::Reader)
return reader.state.stream return reader.state.stream
end end
@ -184,36 +184,36 @@ const sam_metainfo_actions = Dict(
:metainfo_dict_key => :(push!(record.dictkey, (mark2:p-1) .- offset)), :metainfo_dict_key => :(push!(record.dictkey, (mark2:p-1) .- offset)),
:metainfo_dict_val => :(push!(record.dictval, (mark2:p-1) .- offset)), :metainfo_dict_val => :(push!(record.dictval, (mark2:p-1) .- offset)),
:metainfo => quote :metainfo => quote
BioCore.ReaderHelper.resize_and_copy!(record.data, data, offset+1:p-1) BioGenerics.ReaderHelper.resize_and_copy!(record.data, data, offset+1:p-1)
record.filled = (offset+1:p-1) .- offset record.filled = (offset+1:p-1) .- offset
end, end,
:anchor => :(), :anchor => :(),
:mark1 => :(mark1 = p), :mark1 => :(mark1 = p),
:mark2 => :(mark2 = p)) :mark2 => :(mark2 = p))
eval( eval(
BioCore.ReaderHelper.generate_index_function( BioGenerics.ReaderHelper.generate_index_function(
MetaInfo, MetaInfo,
sam_metainfo_machine, sam_metainfo_machine,
:(mark1 = mark2 = offset = 0), :(mark1 = mark2 = offset = 0),
sam_metainfo_actions)) sam_metainfo_actions))
eval( eval(
BioCore.ReaderHelper.generate_readheader_function( BioGenerics.ReaderHelper.generate_readheader_function(
Reader, Reader,
MetaInfo, MetaInfo,
sam_header_machine, sam_header_machine,
:(mark1 = mark2 = offset = 0), :(mark1 = mark2 = offset = 0),
merge(sam_metainfo_actions, Dict( merge(sam_metainfo_actions, Dict(
:metainfo => quote :metainfo => quote
BioCore.ReaderHelper.resize_and_copy!(record.data, data, BioCore.ReaderHelper.upanchor!(stream):p-1) BioGenerics.ReaderHelper.resize_and_copy!(record.data, data, BioGenerics.ReaderHelper.upanchor!(stream):p-1)
record.filled = (offset+1:p-1) .- offset record.filled = (offset+1:p-1) .- offset
@assert isfilled(record) @assert isfilled(record)
push!(reader.header.metainfo, record) push!(reader.header.metainfo, record)
BioCore.ReaderHelper.ensure_margin!(stream) BioGenerics.ReaderHelper.ensure_margin!(stream)
record = MetaInfo() record = MetaInfo()
end, end,
:header => :(finish_header = true; @escape), :header => :(finish_header = true; @escape),
:countline => :(linenum += 1), :countline => :(linenum += 1),
:anchor => :(BioCore.ReaderHelper.anchor!(stream, p); offset = p - 1))), :anchor => :(BioGenerics.ReaderHelper.anchor!(stream, p); offset = p - 1))),
quote quote
if !eof(stream) if !eof(stream)
stream.position -= 1 # cancel look-ahead stream.position -= 1 # cancel look-ahead
@ -234,28 +234,28 @@ const sam_record_actions = Dict(
:record_qual => :(record.qual = (mark:p-1) .- offset), :record_qual => :(record.qual = (mark:p-1) .- offset),
:record_field => :(push!(record.fields, (mark:p-1) .- offset)), :record_field => :(push!(record.fields, (mark:p-1) .- offset)),
:record => quote :record => quote
BioCore.ReaderHelper.resize_and_copy!(record.data, data, 1:p-1) BioGenerics.ReaderHelper.resize_and_copy!(record.data, data, 1:p-1)
record.filled = (offset+1:p-1) .- offset record.filled = (offset+1:p-1) .- offset
end, end,
:anchor => :(), :anchor => :(),
:mark => :(mark = p)) :mark => :(mark = p))
eval( eval(
BioCore.ReaderHelper.generate_index_function( BioGenerics.ReaderHelper.generate_index_function(
Record, Record,
sam_record_machine, sam_record_machine,
:(mark = offset = 0), :(mark = offset = 0),
sam_record_actions)) sam_record_actions))
eval( eval(
BioCore.ReaderHelper.generate_read_function( BioGenerics.ReaderHelper.generate_read_function(
Reader, Reader,
sam_body_machine, sam_body_machine,
:(mark = offset = 0), :(mark = offset = 0),
merge(sam_record_actions, Dict( merge(sam_record_actions, Dict(
:record => quote :record => quote
BioCore.ReaderHelper.resize_and_copy!(record.data, data, BioCore.ReaderHelper.upanchor!(stream):p-1) BioGenerics.ReaderHelper.resize_and_copy!(record.data, data, BioGenerics.ReaderHelper.upanchor!(stream):p-1)
record.filled = (offset+1:p-1) .- offset record.filled = (offset+1:p-1) .- offset
found_record = true found_record = true
@escape @escape
end, end,
:countline => :(linenum += 1), :countline => :(linenum += 1),
:anchor => :(BioCore.ReaderHelper.anchor!(stream, p); offset = p - 1))))) :anchor => :(BioGenerics.ReaderHelper.anchor!(stream, p); offset = p - 1)))))

View file

@ -514,39 +514,39 @@ end
# Bio Methods # Bio Methods
# ----------- # -----------
function BioCore.isfilled(record::Record) function BioGenerics.isfilled(record::Record)
return !isempty(record.filled) return !isempty(record.filled)
end end
function BioCore.seqname(record::Record) function BioGenerics.seqname(record::Record)
return tempname(record) return tempname(record)
end end
function BioCore.hasseqname(record::Record) function BioGenerics.hasseqname(record::Record)
return hastempname(record) return hastempname(record)
end end
function BioCore.sequence(record::Record) function BioGenerics.sequence(record::Record)
return sequence(record) return sequence(record)
end end
function BioCore.hassequence(record::Record) function BioGenerics.hassequence(record::Record)
return hassequence(record) return hassequence(record)
end end
function BioCore.rightposition(record::Record) function BioGenerics.rightposition(record::Record)
return rightposition(record) return rightposition(record)
end end
function BioCore.hasrightposition(record::Record) function BioGenerics.hasrightposition(record::Record)
return hasrightposition(record) return hasrightposition(record)
end end
function BioCore.leftposition(record::Record) function BioGenerics.leftposition(record::Record)
return position(record) return position(record)
end end
function BioCore.hasleftposition(record::Record) function BioGenerics.hasleftposition(record::Record)
return hasposition(record) return hasposition(record)
end end

View file

@ -3,14 +3,14 @@
module SAM module SAM
using BioCore using BioGenerics
import Automa import Automa
import Automa.RegExp: @re_str import Automa.RegExp: @re_str
import BioAlignments import BioAlignments
import BioCore.Exceptions: missingerror import BioGenerics.Exceptions: missingerror
import BioCore.RecordHelper: unsafe_parse_decimal import BioGenerics.RecordHelper: unsafe_parse_decimal
import BioCore: isfilled, header import BioGenerics: isfilled, header
import BioSequences import BioSequences
import BufferedStreams import BufferedStreams
using Printf: @sprintf using Printf: @sprintf

View file

@ -10,7 +10,7 @@ Create a data writer of the SAM file format.
* `output`: data sink * `output`: data sink
* `header=Header()`: SAM header object * `header=Header()`: SAM header object
""" """
mutable struct Writer <: BioCore.IO.AbstractWriter mutable struct Writer <: BioGenerics.IO.AbstractWriter
stream::IO stream::IO
function Writer(output::IO, header::Header=Header()) function Writer(output::IO, header::Header=Header())
@ -20,7 +20,7 @@ mutable struct Writer <: BioCore.IO.AbstractWriter
end end
end end
function BioCore.IO.stream(writer::Writer) function BioGenerics.IO.stream(writer::Writer)
return writer.stream return writer.stream
end end

View file

@ -1,25 +1,16 @@
using Test using Test
using BioGenerics
using FormatSpecimens
using GenomicFeatures using GenomicFeatures
using XAM using XAM
import BioAlignments: Alignment, AlignmentAnchor, OP_START, OP_MATCH, OP_DELETE import BioAlignments: Alignment, AlignmentAnchor, OP_START, OP_MATCH, OP_DELETE
using FormatSpecimens
import BGZFStreams: BGZFStream import BGZFStreams: BGZFStream
import BioCore.Exceptions: MissingFieldException import BioGenerics.Exceptions: MissingFieldException
import BioSequences: @dna_str, @aa_str import BioSequences: @dna_str, @aa_str
import BioCore:
header,
isfilled,
seqname,
hasseqname,
sequence,
hassequence,
leftposition,
rightposition,
hasleftposition,
hasrightposition
# Generate a random range within `range`. # Generate a random range within `range`.
function randrange(range) function randrange(range)
x = rand(range) x = rand(range)