# show(io::IO, custom matrix) is not called?

**URL:** https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161
**Category:** General Usage
**Created:** [August 1, 2017, 8:19am UTC](https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161 "2017-08-01T08:19:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)
#### Post date: [August 1, 2017, 8:19am UTC](https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161/1 "2017-08-01T08:19:39Z")

</div>

Hi,

I’m trying to show my custom matrix type to display by overloading the `Base.show` method, but it doesn’t call the overloaded method. The following is a reproducible code:

```julia
# https://github.com/BioJulia/BioSymbols.jl
import BioSymbols: DNA

struct PWM{T,S<:Real} <: AbstractMatrix{S}
    # symbol type (DNA or RNA)
    typ::Type{T}
    # score matrix (row: symbols, column: position)
    data::Matrix{S}
end

function Base.size(pwm::PWM)
    return size(pwm.data)
end

function Base.getindex(pwm::PWM, i::Integer, j::Integer)
    return getindex(pwm.data, i, j)
end

function Base.show(io::IO, pwm::PWM{DNA})
    compact(x) = string(x ≥ 0 ? " " : "", sprint(showcompact, x))
    cells = hcat(['A', 'C', 'G', 'T'], compact.(pwm.data))
    width = maximum(length.(cells), 1)
    print(io, summary(pwm), ':')
    for i in 1:size(cells, 1)
        println(io)
        print(io, ' ', rpad(cells[i,1], width[1]+1))
        for j in 2:size(cells, 2)
            print(io, rpad(cells[i,j], width[j]+1))
        end
    end
end

```

I expect I see ACGT characters on the leftmost column:

```julia
julia> pwm = PWM(DNA, randn(4, 5)) # not overloaded?
4×5 PWM{BioSymbols.DNA,Float64}:
  2.05598 -1.48329 -0.909718 -0.915152 -0.199301
 -1.65405 0.456539 0.0655709 -1.18943 0.158246
  0.0463668 -0.647083 -0.430253 -0.251961 1.59043
 -0.333135 1.01648 -0.665186 0.922921 0.199385

julia> pwm isa PWM{DNA} # pwm is actually an object of PWM{DNA}
true

julia> show(pwm) # but this is okay
4×5 PWM{BioSymbols.DNA,Float64}:
 A 2.05598 -1.48329 -0.909718 -0.915152 -0.199301
 C -1.65405 0.456539 0.0655709 -1.18943 0.158246
 G 0.0463668 -0.647083 -0.430253 -0.251961 1.59043
 T -0.333135 1.01648 -0.665186 0.922921 0.199385

```

Is this a bug of Julia or am I missing something?

Thank you.

---

<div class="post-metadata">

### Author: ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)
#### Post date: [August 1, 2017, 8:32am UTC](https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161/2 "2017-08-01T08:32:10Z")

</div>

If my memory doesn’t fail me, the following should work

```julia
function Base.show(io::IO, ::MIME"text/plain", pwm::PWM{DNA})
    # ...
end

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 1, 2017, 11:21am UTC](https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161/3 "2017-08-01T11:21:00Z")

</div>

> [@bicycle1885](#):
>
> I’m trying to show my custom matrix type to display by overloading the Base.show method, but it doesn’t call the overloaded method.

That’s because `AbstractMatrix` has custom methods for both `show(io, x)` and `show(io, ::MIME"text/plain", x)`, and the latter is used for displaying results in the REPL.

---

<div class="post-metadata">

### Author: ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)
#### Post date: [August 1, 2017, 11:46am UTC](https://discourse.julialang.org/t/show-io-io-custom-matrix-is-not-called/5161/4 "2017-08-01T11:46:57Z")

</div>

Than you and @Evizero! That makes sense.
