Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmikhasenko/decaytreedataframes.jl
https://github.com/mmikhasenko/decaytreedataframes.jl
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mmikhasenko/decaytreedataframes.jl
- Owner: mmikhasenko
- Created: 2024-11-19T16:24:46.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-19T16:34:00.000Z (2 months ago)
- Last Synced: 2024-11-19T17:36:16.507Z (2 months ago)
- Language: Julia
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DecayTreeDataFrames
`DecayTreeDataFrames` is a Julia package for creating and manipulating tree structures using a linear representation of a tree. A table interface is used for the storing the information. A navigation through the tree is done by using a `Rooting` structure, that just contains row indices of the table for `left` (child 1), `right` (child 2) and `parent`, and `me` (this) nodes.
## Installation
Include the module in your project:
```julia
import Pkg
Pkg.add(url="https://github.com/mmikhasenko/DecayTreeDataFrames.jl")
```## Usage Example
Start by importing the `DecayTreeDataFrames.jl` and two more convenient packages, `Parameters.jl`, and `DataFrames.jl`.
```julia
using DecayTreeDataFrames
using Parameters
using DataFrames
```### Build a Tree
```julia
tree_structure = ((:e, (:r, :u)), (:h, :g))
logistics = build_tree(tree_structure)
df = DataFrame(; logistics)
```### Content of subsystem
For every node, one need to collect the full list of leaves. This can be done by:
```julia
df.subsystem = getproperty.(df.logistics, :info) .|> vcat
transform_from_children!(df, :subsystem) do logistics
@unpack left, right = logistics
i1, i2 = df[left, :subsystem], df[right, :subsystem]
vcat(i1, i2)
end
```### Tuple notations
Tuple notations for the node are also useful. They need to be collected from bottom to top, using `transform_from_children!` function
```julia
df.notation = getproperty.(df.logistics, :info)
transform_from_children!(df, :notation) do logistics
@unpack left, right = logistics
i1, i2 = df[left, :notation], df[right, :notation]
"($i1, $i2)"
end
```### Transition chains
For every node,
we can generate a string that shows how to arrive to this node from the root. This can be done by:
```julia
df.chain .= "0"
transform_from_parent!(df, :chain) do logistics
@unpack parent, me, left, right = logistics
df[parent, :chain] * " -> " * string(df[me, :logistics].info)
end
```The call `transform_from_parent!` does not apply the function to the root node.
While `transform_from_children!` does not apply the function to the leaves.## License
This package is released under the MIT License.