Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,648 changes: 849 additions & 799 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ name = "gen"
path = "src/main.rs"

[workspace]
members = [".", "gen-core", "gen-models", "gen-graph", "gen-diff", "gen-tui", "gen-sugiyama", "gen-annotations", "gen-capnp-schemas"]
default-members = [".", "gen-core", "gen-models", "gen-graph", "gen-diff", "gen-capnp-schemas", "gen-annotations"]
members = [".", "gen-core", "gen-models", "gen-models/graph-tests", "gen-graph", "gen-diff", "gen-tui", "gen-sugiyama", "gen-annotations", "gen-capnp-schemas"]
default-members = [".", "gen-core", "gen-models", "gen-models/graph-tests", "gen-graph", "gen-diff", "gen-capnp-schemas", "gen-annotations"]
exclude = ["gen-python", "gen-r/src/rust"]

[features]
Expand Down Expand Up @@ -93,6 +93,7 @@ pprof = { version = "0.15.0", optional = true }
[dev-dependencies]
cargo-llvm-cov = "0.8.5"
cargo-deny = "0.19.0"
gen-models-graph-tests = { path = "gen-models/graph-tests" }
more-asserts = "0.3.1"
insta = "1.43.1"

Expand Down
3 changes: 2 additions & 1 deletion gen-annotations/src/gff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ mod tests {
preserve_edge: true,
};

BlockGroup::insert_change(conn, &change).expect("should apply AA update to child sample");
gen_graph::models::insert_change(conn, &change)
.expect("should apply AA update to child sample");

let edge_to_insert = Edge::query(
conn,
Expand Down
2 changes: 1 addition & 1 deletion gen-annotations/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ pub fn setup_test_data(conn: &GraphConnection) {
preserve_edge: false,
};

BlockGroup::insert_change(conn, &change).expect("should apply variant change");
gen_graph::models::insert_change(conn, &change).expect("should apply variant change");
}
3 changes: 2 additions & 1 deletion gen-annotations/src/translate/bed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ where
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let path = BlockGroup::get_current_path(conn, &bg.id, history_ref)?;
let graph = BlockGroup::get_graph(conn, &bg.id, history_ref)?;
let graph =
gen_graph::models::load_block_group_graph(conn, &bg.id, history_ref)?;
let mut tree = IntervalTree::default();
let mut position: i64 = 0;
for (node, strand) in project_path(&graph, &path.blocks(conn, history_ref)?) {
Expand Down
3 changes: 2 additions & 1 deletion gen-annotations/src/translate/gff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ where
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let path = BlockGroup::get_current_path(conn, &bg.id, history_ref)?;
let graph = BlockGroup::get_graph(conn, &bg.id, history_ref)?;
let graph =
gen_graph::models::load_block_group_graph(conn, &bg.id, history_ref)?;
let mut tree = IntervalTree::default();
let mut position: i64 = 0;
for (node, strand) in project_path(&graph, &path.blocks(conn, history_ref)?) {
Expand Down
1 change: 1 addition & 0 deletions gen-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gen-capnp-schemas = { path = "../gen-capnp-schemas", version = "0.2.1" }
itertools = "0.14.0"
capnp = { version = "0.24" }
noodles = { version = "0.101.0", features = ["gff"] }
petgraph = "0.6.5"
rusqlite = { package = "rusqdoltlite", version = "0.40.14", features = ["bundled", "fallible_uint"] }
serde = { version = "1.0.219", features = ["derive"] }
thiserror = "1.0"
Expand Down
101 changes: 101 additions & 0 deletions gen-core/src/graph.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use core::fmt;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These got added here as part of the refactoring, to avoid circular dependencies. I think they could get moved back to gen-models now but I don't have a strong opinion

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, guess they came from gen-graph originally, maybe better to have them here than gen-models


use petgraph::graphmap::DiGraphMap;
use serde::{Deserialize, Serialize};

use crate::{HashId, Strand};

pub type GenGraph = DiGraphMap<GraphNode, Vec<GraphEdge>>;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub struct GraphEdge {
pub edge_id: HashId,
pub source_strand: Strand,
pub target_strand: Strand,
pub chromosome_index: i64,
pub phased: i64,
pub created_on: i64,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GraphLoadBlock {
pub id: i64,
pub node_id: HashId,
pub start: i64,
pub end: i64,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GraphLoadEdge {
pub edge_id: HashId,
pub source_node_id: HashId,
pub source_coordinate: i64,
pub source_strand: Strand,
pub target_node_id: HashId,
pub target_coordinate: i64,
pub target_strand: Strand,
pub chromosome_index: i64,
pub phased: i64,
pub created_on: i64,
}

/// A contiguous slice of a stored sequence represented as a node in graph space.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub struct GraphNode {
pub node_id: HashId,
pub sequence_start: i64,
pub sequence_end: i64,
}

impl fmt::Display for GraphNode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"{}[{}-{}]",
self.node_id, self.sequence_start, self.sequence_end
)
}
}

impl GraphNode {
pub const fn length(&self) -> i64 {
self.sequence_end - self.sequence_start
}
}

/// A local sequence slice within a graph node, including its traversal orientation.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GraphNodeSlice {
pub block: GraphNode,
/// Local start offset within the block's sequence slice (`0..block.length()`).
pub start: usize,
/// Local end offset, exclusive (`start..=block.length()`).
pub end: usize,
/// 5'→3' orientation of this slice.
pub strand: Strand,
}

impl GraphNodeSlice {
pub fn full(block: GraphNode, strand: Strand) -> Self {
Self {
block,
start: 0,
end: block.length() as usize,
strand,
}
}
}

/// A cursor within a graph node.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd, Deserialize, Serialize)]
pub struct GraphNodePosition {
pub graph_node: GraphNode,
/// Distance from `sequence_start` of `graph_node`.
pub offset: i64,
}

impl GraphNodePosition {
pub const fn coordinate(&self) -> i64 {
self.graph_node.sequence_start + self.offset
}
}
5 changes: 5 additions & 0 deletions gen-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod config;
pub mod errors;
#[allow(clippy::all)]
pub mod generated;
pub mod graph;
pub mod path;
pub mod range;
pub mod region;
Expand All @@ -17,6 +18,10 @@ pub mod traits;
pub use config::Workspace;
use errors::HashError;
pub use generated::gen_core_capnp;
pub use graph::{
GenGraph, GraphEdge, GraphLoadBlock, GraphLoadEdge, GraphNode, GraphNodePosition,
GraphNodeSlice,
};
pub use path::PathBlock;
#[cfg(feature = "python-bindings")]
use pyo3::pyclass;
Expand Down
2 changes: 2 additions & 0 deletions gen-graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ license = "Apache-2.0"

[dependencies]
gen-core = { path = "../gen-core", version = "0.2.1" }
gen-models = { path = "../gen-models", version = "0.2.1" }
interavl = "0.3.0"
intervaltree = "0.2.7"
itertools = "0.14.0"
petgraph = "0.6.5"
serde = { version = "1.0.219", features = ["derive"] }
thiserror = "2.0.12"
Loading
Loading