1
0
Fork 0
mirror of https://github.com/MillironX/XAM.jl.git synced 2024-12-23 13:28:16 +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"
BGZFStreams = "28d598bf-9b8f-59f1-b38c-5a06b4a0f5e6"
BioAlignments = "00701ae9-d1dc-5365-b64a-a3a3ebf5695e"
BioCore = "37cfa864-2cd6-5c12-ad9e-b6597d696c81"
BioGenerics = "47718e42-2ac5-11e9-14af-e5595289c2ea"
BioSequences = "7e6ae17a-c86d-528c-b3b9-7f778a29fe59"
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
GenomicFeatures = "899a7d2d-5c61-547b-bef9-6698a8d05446"
@ -18,7 +18,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Automa = "0.7, 0.8"
BGZFStreams = "0.3"
BioAlignments = "2"
BioCore = "2"
BioGenerics = "0.1"
BioSequences = "2"
BufferedStreams = "1"
GenomicFeatures = "2"

View file

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

View file

@ -10,7 +10,7 @@ Create a data reader of the BAM file format.
* `input`: data source
* `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}
header::SAM.Header
start_offset::BGZFStreams.VirtualOffset
@ -23,7 +23,7 @@ function Base.eltype(::Type{Reader{T}}) where T
return Record
end
function BioCore.IO.stream(reader::Reader)
function BioGenerics.IO.stream(reader::Reader)
return reader.stream
end

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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