Hi, I have implemented a basic immutable type with a type alias for a
vector of said type:
immutable CIGAR
OP::Operation
Size::Int
end
function CIGAR(op::Char, size::Int)
return CIGAR(Operation(op), size)
end
function convert(::Type{String}, cigar::CIGAR)
return "$(cigar.Size)$(Char(cigar.OP))"
end
function show(io::IO, cigar::CIGAR)
write(io, convert(String, cigar))
end
typealias CIGARString Vector{CIGAR}
function convert(::Type{CIGARString}, str::String)
matches = matchall(r"(\d+)(\w)", str)
cigarString = Vector{CIGAR}(length(matches))
@inbounds for i in 1:length(matches)
m = matches[i]
cigarString[i] = CIGAR(m[end], parse(Int, m[1:end-1]))
end
return cigarString
end
macro cigar_str(str)
return CIGARString(str)
end
I also want to define a show method for the alias CIGARString, so as it is
converted to a string that can be used with a show method:
function convert(::Type{String}, cigarString::CIGARString)
outString = ""
for cigar in cigarString
outString *= String(cigar)
end
return outString
end
function show(io::IO, cigarstr::CIGARString)
write(io, convert(String, cigarstr))
end
However the output a see on the REPL is:
*3-element Array{Bio.Align.CIGAR,1}:*
* 5M*
* 5N*
* 5M*
So, rather than the show method for CIGARString being called, the show
method for CIGAR is being called repeatedly for every element in the
CIGARString vector. How do I get Julia to use the show method I want for
CIGARString?
Thanks.