Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum for trait simulation only works in global scope #68

Closed
mkborregaard opened this issue Oct 18, 2021 · 3 comments
Closed

enum for trait simulation only works in global scope #68

mkborregaard opened this issue Oct 18, 2021 · 3 comments

Comments

@mkborregaard
Copy link
Member

There seems to be something about the use of enums to model categorical traits that tries to access the Main scope, and thus fails if the code is included in a module. This code from the plotting functionality works in the repl

using Phylo, Plots
default(linecolor = :black, size = (400, 400)) # looks nicer with black lines
hummers = open(parsenewick, Phylo.path("hummingbirds.tree"))
plot(hummers, size = (400, 600), showtips = false)
using Random
@enum TemperatureTrait lowTempPref midTempPref highTempPref
tempsampler = SymmetricDiscreteTrait(hummers, TemperatureTrait, 0.4)
rand!(tempsampler, hummers)
plot(hummers, showtips = false,
        marker_group = "TemperatureTrait",
        legend = :topleft, msc = :white, treetype = :fan,
        c = [:red :blue :green], ms = 10
)

but fails if the same code is included in a module. This means that this example does not work in our docs (where it is taken from).

@richardreeve
Copy link
Member

So, the trait acquires the name of the enum, which acquires the name of the module. Trying this at the console inside a Test module, the trait is therefore called Main.Test.TemperatureTrait...

@richardreeve
Copy link
Member

richardreeve commented Oct 18, 2021

@mkborregaard - I've made a temporary(?) fix - https://docs.ecojulia.org/Phylo.jl/dev/man/plotting/ - there's an optional final argument to set the name of the trait, and I've made it "Temperature", and then used that name again in the plot with marker_group="Temperature". If it's likely that people will be creating @enums inside modules, then it may make sense to do some regex work on the name?

@mkborregaard
Copy link
Member Author

Yeah I guess people will not be doing this very often inside modules so it may not matter.
Anyway, I like the syntax with explicitly naming the trait much better actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants