ERROR: MethodError: no method matching +(::String, ::Int64)

I am trying to learn bioinformatics with julia and was trying to write very basic script.
But i am getting an error, I am sure that I am missing a very simple concept of usage.
It will be great help, if someone can explain me.
Thanks in advance.
It is pointing error at line:
ln = ln_dna- ln_kmer + 1
but according to my logic and understanding, i cannot recognize error.

The programme is to find the the frequency of K-mers in the given sequences

function oric(dna, kmer)
count = 0
ln_dna = length(dna)
ln_kmer = length(kmer)
ln = ln_dna- ln_kmer + 1
for i in 1:ln
if dna[i:(i+ln_kmer-1)] == kmer
count += 1
end
end
println(“Number of k-mers =”, count)
end

dna = “gcgcg”
kmer = “gcg”
oric(dna, kmer)

ERROR: MethodError: no method matching +(::String, ::Int64)

Closest candidates are:
+(::Any, ::Any, ::Any, ::Any…)
@ Base operators.jl:578
+(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}
@ Base int.jl:87
+(::T, ::Integer) where T<:AbstractChar
@ Base char.jl:237

Your code runs just fine for me.

You might need to restart Julia. There could be an old function lurking around somewhere in Base.

2 Likes

Also, for this particular problem check out Strings · The Julia Language.

1 Like

Thanks, restart made it work.
Why it happen, what I can do to prevent it?

Julia’s look-up table for functions is based on the function name as well as the types of the inputs. If you ever change the argument types, both versions will exist and could cause conflicts with each other. Also if your functions are inside of a module, and you import them into Base, then changes to the module won’t be reflected in Base. This particular design decision has caused me to lose a lot of time debugging, personally.

So my recommendation when developing is to wrap your code inside of a module, then import the module, and use module.function to call the function. So for example, if your module is called A and your function is called B, I recommend doing import A; A.B(...).

You can also check whether this is happening by using the methods function on your function. So in this case, methods(oric) would have revealed more than one signature, if that was the issue.

1 Like