BioSequences.jl icon indicating copy to clipboard operation
BioSequences.jl copied to clipboard

Remove `convert` for biosequences

Open jakobnissen opened this issue 1 year ago • 3 comments

IMO, convert should not exist for mutable types (i.e. types with object identity), because it can be called implicitly, which can lead to very weird stuff:

julia> x = dna"TAG";

julia> y = [bioseq("TAG")];

julia> push!(y, x);

julia> y[2] === x
false

jakobnissen avatar Oct 23 '24 10:10 jakobnissen

I saw the slack gripe on this. Doesn't feel like a huge loss, especially if we put in constructors that can do the conversion for us (eg it would be nice to be able to "convert" RNA to DNA, but it could just be with a dna sequence constructor)

kescobo avatar Oct 23 '24 14:10 kescobo

Yep, the idea is to use the constructor instead. For immutable types (say, biosymbols) we can keep the conversion.

jakobnissen avatar Oct 23 '24 14:10 jakobnissen

Instead of using the implicit convert method for mutable types like BioSequence, we could remove it to avoid confusion with object identity. A recommended approach is to use explicit constructors for conversion, e.g., DNASequence(rna_seq) or RNASequence(dna_seq). For immutable types like BioSymbols, keeping convert is fine since identity is not an issue.

Bano733-code avatar Nov 28 '25 05:11 Bano733-code