Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhofer committed Aug 21, 2024
1 parent a67c60f commit 3d1b48c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod sequence;
use crate::graph::all_simple_paths;
use crate::models::block::Block;
use crate::models::edge::Edge;
use crate::models::new_edge::NewEdge;
use crate::models::new_edge::{EdgeData, NewEdge};
use crate::models::path::{NewBlock, Path, PathBlock};
use crate::models::sequence::Sequence;
use crate::{get_overlap, models};
Expand Down Expand Up @@ -513,7 +513,7 @@ impl BlockGroup {
new_block: &NewBlock,
chromosome_index: i32,
phased: i32,
) -> Vec<NewEdge> {
) {
// todo:
// cases to check:
// change that is the size of a block
Expand All @@ -536,8 +536,7 @@ impl BlockGroup {

if new_block.sequence_start == new_block.sequence_end {
// Deletion
let new_edge = NewEdge {
id: 0,
let new_edge = EdgeData {
source_hash: start_block.sequence.hash.clone(),
source_coordinate: start - start_block.path_start + start_block.sequence_start,
target_hash: end_block.sequence.hash.clone(),
Expand All @@ -548,17 +547,15 @@ impl BlockGroup {
new_edges.push(new_edge);
} else {
// Insertion/replacement
let new_start_edge = NewEdge {
id: 0,
let new_start_edge = EdgeData {
source_hash: start_block.sequence.hash.clone(),
source_coordinate: start - start_block.path_start + start_block.sequence_start,
target_hash: new_block.sequence.hash.clone(),
target_coordinate: new_block.sequence_start,
chromosome_index,
phased,
};
let new_end_edge = NewEdge {
id: 0,
let new_end_edge = EdgeData {
source_hash: new_block.sequence.hash.clone(),
source_coordinate: new_block.sequence_end,
target_hash: end_block.sequence.hash.clone(),
Expand All @@ -574,8 +571,7 @@ impl BlockGroup {
// retrieve it as one node of the overall graph
if start < start_block.path_end {
let split_coordinate = start - start_block.path_start + start_block.sequence_start;
let new_split_start_edge = NewEdge {
id: 0,
let new_split_start_edge = EdgeData {
source_hash: start_block.sequence.hash.clone(),
source_coordinate: split_coordinate,
target_hash: start_block.sequence.hash.clone(),
Expand All @@ -588,8 +584,7 @@ impl BlockGroup {

if end > end_block.path_start {
let split_coordinate = end - end_block.path_start + end_block.sequence_start;
let new_split_end_edge = NewEdge {
id: 0,
let new_split_end_edge = EdgeData {
source_hash: new_block.sequence.hash.clone(),
source_coordinate: split_coordinate,
target_hash: end_block.sequence.hash.clone(),
Expand All @@ -601,8 +596,7 @@ impl BlockGroup {
new_edges.push(new_split_end_edge);
}

// TODO: bulk create-or-get of new edges
new_edges
NewEdge::bulk_create(conn, new_edges);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/new_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl NewEdge {
}
let formatted_edge_rows_to_insert = edge_rows_to_insert.join(", ");

let insert_statement = format!("INSERT OR IGNORE INTO new_edges (source_hash, source_coordinate, target_hash, target_coordinate, chromosome_index, phased) VALUES {0} RETURNING (id);", formatted_edge_rows_to_insert);
let insert_statement = format!("INSERT INTO new_edges (source_hash, source_coordinate, target_hash, target_coordinate, chromosome_index, phased) VALUES {0} RETURNING (id);", formatted_edge_rows_to_insert);
let mut stmt = conn.prepare(&insert_statement).unwrap();
let rows = stmt.query_map([], |row| row.get(0)).unwrap();
let mut edge_ids: Vec<i32> = vec![];
Expand Down

0 comments on commit 3d1b48c

Please sign in to comment.