Skip to content

Commit

Permalink
Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
kdyrhage committed Nov 13, 2024
1 parent 2424518 commit 15e2a0c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/GFF/GFF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using CodecZlib

import ..GenomicAnnotations: Record, Gene, AbstractGene, GeneDataView, Locus, Join, Order
import ..GenomicAnnotations: SpanLocus, ClosedSpan, Complement
import ..GenomicAnnotations: sequence, iscomplement, iscomplete, addgene!, pushproperty!, feature, index, locus, oneline
import ..GenomicAnnotations: sequence, iscomplement, iscomplete, addgene!, pushproperty!, feature, index, locus, oneline, ismultilocus
export sequence, iscomplement, iscomplete, feature, index, locus

include("reader.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/GFF/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function gffstring(gene::Gene)
end
end
end
if locus(gene) isa Union{Join, Order}
if ismultilocus(gene)
s = String(take!(buf))
res = IOBuffer()
for pos in locus(gene).loc
for pos in (locus(gene) isa Complement ? locus(gene).loc.loc : locus(gene).loc)
println(res, join([parent(gene).name,
get(gene, :source, "."),
feature(gene),
Expand Down
2 changes: 1 addition & 1 deletion src/GenomicAnnotations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using BioSequences

export GenBank, GFF, EMBL
export Gene, AbstractGene, GeneDataView
export sequence, iscomplement, iscomplete, addgene!, pushproperty!
export sequence, iscomplement, iscomplete, ismultilocus, addgene!, pushproperty!
export feature, index, locus, locus!, position

export AbstractLocus
Expand Down
10 changes: 10 additions & 0 deletions src/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ iscomplete(locus::Complement) = iscomplete(locus.loc)
iscomplete(loci::Join) = all(iscomplete, loci.loc)
iscomplete(loci::Order) = all(iscomplete, loci.loc)

"""
ismultilocus(gene::AbstractGene)
ismultilocus(loc::AbstractLocus)
Return `true` if `loc` is a `Join`, `Order`, or either wrapping in `Complement`.
"""
ismultilocus(gene::AbstractGene) = ismultilocus(locus(gene))
ismultilocus(locus::Union{SpanLocus, PointLocus}) = false
ismultilocus(locus::Union{Join, Order}) = true
ismultilocus(locus::Complement{T}) where T <: AbstractLocus = ismultilocus(locus.loc)

function appendstring(field, v::Bool)
return "\n" * join(fill(' ', 21)) * "/$field"
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ using Test
@test sequence(chr.sequence, Locus("complement(order(1..3,11..13))")) == [dna"tat", dna"ttt"]
@test sequence(chr.sequence, Locus("join(complement(1..3),complement(11..13))")) == dna"ttttat"
@test sequence(chr.sequence, Locus("order(complement(1..3),complement(11..13))")) == [dna"ttt", dna"tat"]

@test ismultilocus(Locus("join(1..3,7..9)")) == true
@test ismultilocus(Locus("order(1..3,7..9)")) == true
@test ismultilocus(Locus("complement(join(1..3,7..9))")) == true
@test ismultilocus(Locus("join(complement(1..3),complement(7..9))")) == true
@test ismultilocus(Locus("1..10")) == false
@test ismultilocus(Locus("<1..>10")) == false
@test ismultilocus(Locus("1^2")) == false
end

seq = dna"atgtccatatacaacggtatctccacctcaggtttagatctcaacaacggaaccattgccgacatgagacagttaggtatcgtcgagagttacaagctaaaacgagcagtagtcagctctgcatctgaagccgctgaagttctactaagggtggataacatcatccgtgcaagaccaagaaccgccaatagacaacatatgtaa"
Expand Down

0 comments on commit 15e2a0c

Please sign in to comment.