Getting started
Introduction
This page let's you take a peek at what the package is capable of. If you want a better, more in-depth introduction to the package, take a look at the tutorials, starting from Read and Write MTGs. If you don't know what an MTG is, you can read more about starting from The MTG concept.
Installation
You must have a working Julia installation on your computer. The version of Julia should be greater than 1.3.
If you want to install Julia for the first time, you can download it frome julialang.org. If you want a little introduction on Julia + VSCode, you can check out this video.
You can install the latest stable version of MultiScaleTreeGraph.jl using this command:
]add MultiScaleTreeGraph
The ]
is used to enter the package mode in the REPL.
Example
Read a simple MTG file:
using MultiScaleTreeGraph
file = joinpath(dirname(dirname(pathof(MultiScaleTreeGraph))),"test","files","simple_plant.mtg")
mtg = read_mtg(file)
/ 1: Scene
└─ / 2: Individual
└─ / 3: Axis
└─ / 4: Internode
├─ + 5: Leaf
└─ < 6: Internode
└─ + 7: Leaf
Then you can compute new variables in the MTG using transform!
:
transform!(mtg, :Length => (x -> isnothing(x) ? nothing : x * 1000.) => :length_mm)
The design of transform!
is heavily inspired from the eponym function from DataFrame.jl
, with little tweaks for MTGs.
You can see the newly-computed attributes using descendants like so:
descendants(mtg, :length_mm)
6-element Vector{Any}:
nothing
nothing
100.0
200.0
100.0
200.0
Or by transforming your MTG into a DataFrame:
DataFrame(mtg, :length_mm)
Row | tree | id | symbol | scale | index | parent_id | link | length_mm |
---|---|---|---|---|---|---|---|---|
String? | Int64? | String? | Int64? | Int64? | Int64? | String? | Float64? | |
1 | / 1: Scene | 1 | Scene | 0 | 0 | missing | / | missing |
2 | └─ / 2: Individual | 2 | Individual | 1 | 0 | 1 | / | missing |
3 | └─ / 3: Axis | 3 | Axis | 2 | 0 | 2 | / | missing |
4 | └─ / 4: Internode | 4 | Internode | 3 | 0 | 3 | / | 100.0 |
5 | ├─ + 5: Leaf | 5 | Leaf | 3 | 0 | 4 | + | 200.0 |
6 | └─ < 6: Internode | 6 | Internode | 3 | 1 | 4 | < | 100.0 |
7 | └─ + 7: Leaf | 7 | Leaf | 3 | 0 | 6 | + | 200.0 |
Then you can write the MTG back to disk like so:
write_mtg("test.mtg",mtg)
You can also convert your MTG to a MetaGraph:
MetaGraph(mtg)
Meta graph based on a Graphs.SimpleGraphs.SimpleDiGraph{Int64} with vertex labels of type Int64, vertex metadata of type Dict{Symbol, Any}, edge metadata of type String, graph metadata given by "MTG", and default weight 1.0