Skip to content

Commit 2782c2d

Browse files
committed
Increment dependency compatibilities
1 parent 52d0ce2 commit 2782c2d

File tree

5 files changed

+58
-34
lines changed

5 files changed

+58
-34
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
1717
[compat]
1818
Automa = "0.7, 0.8"
1919
BGZFStreams = "0.3"
20-
BioAlignments = "2"
20+
BioAlignments = "3"
2121
BioGenerics = "0.1"
22-
BioSequences = "2.0.4"
22+
BioSequences = "3"
2323
GenomicFeatures = "2"
2424
Indexes = "0.1"
2525
TranscodingStreams = "0.6, 0.7, 0.8, 0.9"

src/bam/record.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function Base.empty!(record::Record)
9191
record.tlen = 0
9292

9393
#Note: data will be overwritten and indexed using data_size.
94-
94+
9595
return record
9696
end
9797

@@ -436,7 +436,8 @@ function alignment(record::Record)::BioAlignments.Alignment
436436
end
437437
seqpos = 0
438438
refpos = position(record) - 1
439-
anchors = [BioAlignments.AlignmentAnchor(seqpos, refpos, BioAlignments.OP_START)]
439+
alnpos = 0
440+
anchors = [BioAlignments.AlignmentAnchor(seqpos, refpos, alnpos, BioAlignments.OP_START)]
440441
for (op, len) in zip(cigar_rle(record)...)
441442
if BioAlignments.ismatchop(op)
442443
seqpos += len
@@ -448,7 +449,8 @@ function alignment(record::Record)::BioAlignments.Alignment
448449
else
449450
error("operation $(op) is not supported")
450451
end
451-
push!(anchors, BioAlignments.AlignmentAnchor(seqpos, refpos, op))
452+
alnpos += len
453+
push!(anchors, BioAlignments.AlignmentAnchor(seqpos, refpos, alnpos, op))
452454
end
453455
return BioAlignments.Alignment(anchors)
454456
end
@@ -504,12 +506,7 @@ function hastemplength(record::Record)
504506
return isfilled(record)
505507
end
506508

507-
"""
508-
sequence(record::Record)::BioSequences.LongDNASeq
509-
510-
Get the segment sequence of `record`.
511-
"""
512-
function sequence(record::Record)
509+
function sequence(::Type{S}, record::Record) where S <: BioSequences.LongSequence #TODO: add optional part retrieval.
513510
checkfilled(record)
514511
seqlen = seqlength(record)
515512
if seqlen == 0
@@ -522,7 +519,16 @@ function sequence(record::Record)
522519
x = unsafe_load(src, i)
523520
data[i] = (x & 0x0f0f0f0f0f0f0f0f) << 4 | (x & 0xf0f0f0f0f0f0f0f0) >> 4
524521
end
525-
return BioSequences.LongDNASeq(data, 1:seqlen, false)
522+
return S(data, UInt64(seqlen))
523+
end
524+
525+
"""
526+
sequence(record::Record)::BioSequences.LongDNA{4}
527+
528+
Get the segment sequence of `record`.
529+
"""
530+
function sequence(record::Record) #TODO: add optional part retrieval.
531+
return sequence(BioSequences.LongDNA{4}, record)
526532
end
527533

528534
function hassequence(record::Record)

src/sam/record.jl

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,38 @@ function hastemplength(record::Record)
387387
end
388388

389389
"""
390-
sequence(record::Record)::BioSequences.LongDNASeq
391-
392-
Get the segment sequence of `record`.
393-
"""
394-
function sequence(record::Record)
395-
checkfilled(record)
396-
if ismissing(record, record.seq)
397-
# missingerror(:sequence)
398-
return nothing
399-
end
400-
seqlen = length(record.seq)
401-
ret = BioSequences.LongDNASeq(seqlen)
402-
copyto!(ret, 1, record.data, first(record.seq), seqlen)
403-
return ret
390+
sequence(::Type{S}, record::Record, [part::UnitRange{Int}])::S
391+
392+
Get the sequence of `record`.
393+
`S` can be either a subtype of `BioSequences.BioSequence` or `String`.
394+
If `part` argument is given, it returns the specified part of the sequence.
395+
!!! note
396+
This method makes a new sequence object every time.
397+
If you have a sequence already and want to fill it with the sequence
398+
data contained in a fasta record, you can use `Base.copyto!`.
399+
"""
400+
function sequence(::Type{S}, record::Record, part::UnitRange{Int}=1:lastindex(record.seq)) where S <: BioSequences.LongSequence
401+
checkfilled(record)
402+
if ismissing(record, record.seq)
403+
# missingerror(:sequence)
404+
return nothing
405+
end
406+
seqpart = record.seq[part]
407+
return S(@view(record.data[seqpart]))
408+
end
409+
410+
function sequence(::Type{String}, record::Record, part::UnitRange{Int}=1:lastindex(record.seq))
411+
checkfilled(record)
412+
return String(record.data[record.seq[part]])
413+
end
414+
415+
"""
416+
sequence(record::Record)::BioSequences.LongDNA{4}
417+
418+
Get the segment sequence of `record`.
419+
"""
420+
function sequence(record::Record, part::UnitRange{Int}=1:lastindex(record.seq))
421+
return sequence(BioSequences.LongDNA{4}, record, part)
404422
end
405423

406424
function hassequence(record::Record)

test/test_bam.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979
@test BAM.flag(record) === UInt16(16)
8080
@test BAM.cigar(record) == "27M1D73M"
8181
@test BAM.alignment(record) == Alignment([
82-
AlignmentAnchor( 0, 1, OP_START),
83-
AlignmentAnchor( 27, 28, OP_MATCH),
84-
AlignmentAnchor( 27, 29, OP_DELETE),
85-
AlignmentAnchor(100, 102, OP_MATCH)])
82+
AlignmentAnchor( 0, 1, 0, OP_START),
83+
AlignmentAnchor( 27, 28, 27, OP_MATCH),
84+
AlignmentAnchor( 27, 29, 28, OP_DELETE),
85+
AlignmentAnchor(100, 102, 101, OP_MATCH)])
8686
@test record["XG"] == 1
8787
@test record["XM"] == 5
8888
@test record["XN"] == 0

test/test_sam.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@
104104
@test SAM.flag(record) == 16
105105
@test SAM.cigar(record) == "27M1D73M"
106106
@test SAM.alignment(record) == Alignment([
107-
AlignmentAnchor( 0, 1, OP_START),
108-
AlignmentAnchor( 27, 28, OP_MATCH),
109-
AlignmentAnchor( 27, 29, OP_DELETE),
110-
AlignmentAnchor(100, 102, OP_MATCH)])
107+
AlignmentAnchor( 0, 1, 0, OP_START),
108+
AlignmentAnchor( 27, 28, 27, OP_MATCH),
109+
AlignmentAnchor( 27, 29, 28, OP_DELETE),
110+
AlignmentAnchor(100, 102, 101, OP_MATCH)])
111111
@test record["XG"] == 1
112112
@test record["XM"] == 5
113113
@test record["XN"] == 0

0 commit comments

Comments
 (0)