From 7374b19d2f8fdef65897d31daada53600f485113 Mon Sep 17 00:00:00 2001 From: Karl Dyrhage Date: Wed, 3 Jan 2024 10:27:06 +0100 Subject: [PATCH] Added position(gene) --- README.md | 10 ++++++++++ src/record.jl | 1 + 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index c9e6285..c199ea1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,16 @@ end chr.genes[2].locus_tag = "test123" ``` +The `Locus` of a `Gene` retrieved with `locus(gene)`. The `Locus` itself is immutable, but can be updated with `locus!(gene, newlocus)`. For simplicity, `position(gene)` is shorthand for `locus(gene).position`. +```julia +# Create a new Locus, copying all fields of the old one but shifting the position by 1 +oldloc = locus(gene) +locus!(gene, Locus(oldloc.position .+ 1, oldloc.strand, oldloc.complete_left, oldloc.complete_right, oldloc.order, oldloc.join)) + +# Access the genomic positions of all genes +position.(chr.genes) +``` + Accessing properties that haven't been stored will return missing. For this reason, it often makes more sense to use `get()` than to access the property directly. ```julia # chr.genes[2].pseudo returns missing, so this will throw an error diff --git a/src/record.jl b/src/record.jl index 2435b08..3b22066 100644 --- a/src/record.jl +++ b/src/record.jl @@ -398,6 +398,7 @@ Base.iterate(loc::Locus) = iterate(loc.position) index(g::Gene) = getfield(g, :index) locus(g::Gene) = getfield(g, :locus) +position(g::Gene) = getfield(g, :locus).position feature(g::Gene) = getfield(g, :feature) Base.parent(g::Gene) = getfield(g, :parent) function Base.parent(gs::AbstractVector{G}) where {G <: AbstractGene}