Skip to content

Make AbstractInterval broadcastable #50

Description

@CiaranOMara

Expected Behavior

I have a use case where I would like to broadcast the Interval type. Below is a contrived example.

function example(i1, i2)
    return metadata(i1) * metadata(i2)
end

interval = Interval("chr1", 1:1, '.', 2)
intervals = Interval.("chr1", [1:2, 3:4, 5:6], '.', 1:3)

@test collect(1:3) .* 2 == example.(intervals, interval)

Current Behavior

However, the above example results in the following sort of unintuitive error because Interval is not broadcastable.

Got exception outside of a @test
  MethodError: no method matching iterate(::GenomicFeatures.Interval{Nothing})
  Closest candidates are:
    iterate(!Matched::Core.SimpleVector) at essentials.jl:604
    iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:604
    iterate(!Matched::ExponentialBackOff) at error.jl:214

Possible Solution / Implementation

Defining the following solves the issue.

Broadcast.broadcastable(x::IntervalTrees.AbstractInterval) = Ref(x) 

While it's possible to define this in my own local projects or elsewhere, I wonder if it would be a useful addition here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions