diff --git a/src/GFF/GFF.jl b/src/GFF/GFF.jl index 75691bd..71a1e6e 100644 --- a/src/GFF/GFF.jl +++ b/src/GFF/GFF.jl @@ -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") diff --git a/src/GFF/writer.jl b/src/GFF/writer.jl index c40b601..bbd1d2d 100644 --- a/src/GFF/writer.jl +++ b/src/GFF/writer.jl @@ -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), diff --git a/src/GenomicAnnotations.jl b/src/GenomicAnnotations.jl index f704bdf..6a988f1 100644 --- a/src/GenomicAnnotations.jl +++ b/src/GenomicAnnotations.jl @@ -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 diff --git a/src/record.jl b/src/record.jl index f3e9c07..335bf5e 100644 --- a/src/record.jl +++ b/src/record.jl @@ -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" diff --git a/test/runtests.jl b/test/runtests.jl index 1773a68..5a2732d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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"