-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor db graph code #240
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
Open
dkhofer
wants to merge
18
commits into
main
Choose a base branch
from
refactor-db-graph-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6baa1c3
Refactor graph-specific methods out of models and into new graph loca…
dkhofer 0447bc7
Migrate graph data objects to gen-core
dkhofer bf82043
Move more code
dkhofer 7c19aa5
Move more code
dkhofer bc0e5f6
Move more code
dkhofer 6df7009
Migrate some tests to new subcrate
dkhofer e54347a
Move edge tests
dkhofer ec7c34f
Migrate region code to graphs
dkhofer 2d23cc4
Remove gen-graphs dependency from sample
dkhofer 9a772fe
Remove gen-graphs dependency from edge
dkhofer f492100
Remove gen-graphs dependency from block group
dkhofer 70a081f
Migrate get_all_sequences
dkhofer f1fcc39
Move graph unit tests
dkhofer f387088
Migrate region tests
dkhofer 14e6023
Migrate derive_subgraph
dkhofer 1ea6f95
Finish it
dkhofer 5daab09
Some cleanup
dkhofer a81fb1c
Fix warning
dkhofer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| use core::fmt; | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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