Skip to content

Commit

Permalink
Merge branch 'main' into changelog-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7 authored Sep 5, 2024
2 parents 5a628f3 + 5e5e554 commit 0d27601
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 140 deletions.
16 changes: 8 additions & 8 deletions migrations/01-initial/up.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE collection (
name TEXT PRIMARY KEY NOT NULL
);
) STRICT;

CREATE TABLE sample (
name TEXT PRIMARY KEY NOT NULL
);
) STRICT;

CREATE TABLE sequence (
hash TEXT PRIMARY KEY NOT NULL,
Expand All @@ -13,7 +13,7 @@ CREATE TABLE sequence (
name TEXT NOT NULL,
file_path TEXT NOT NULL,
length INTEGER NOT NULL
);
) STRICT;

CREATE TABLE block_group (
id INTEGER PRIMARY KEY NOT NULL,
Expand All @@ -22,7 +22,7 @@ CREATE TABLE block_group (
name TEXT NOT NULL,
FOREIGN KEY(collection_name) REFERENCES collection(name),
FOREIGN KEY(sample_name) REFERENCES sample(name)
);
) STRICT;
CREATE UNIQUE INDEX block_group_uidx ON block_group(collection_name, sample_name, name) WHERE sample_name is not null;
CREATE UNIQUE INDEX block_group_null_sample_uidx ON block_group(collection_name, name) WHERE sample_name is null;

Expand All @@ -31,7 +31,7 @@ CREATE TABLE path (
block_group_id INTEGER NOT NULL,
name TEXT NOT NULL,
FOREIGN KEY(block_group_id) REFERENCES block_group(id)
);
) STRICT;
CREATE UNIQUE INDEX path_uidx ON path(block_group_id, name);

CREATE TABLE change_set (
Expand Down Expand Up @@ -76,7 +76,7 @@ CREATE TABLE edges (
FOREIGN KEY(source_hash) REFERENCES sequence(hash),
FOREIGN KEY(target_hash) REFERENCES sequence(hash),
constraint chk_phased check (phased in (0, 1))
);
) STRICT;
CREATE UNIQUE INDEX edge_uidx ON edges(source_hash, source_coordinate, source_strand, target_hash, target_coordinate, target_strand, chromosome_index, phased);

CREATE TABLE path_edges (
Expand All @@ -86,7 +86,7 @@ CREATE TABLE path_edges (
edge_id INTEGER NOT NULL,
FOREIGN KEY(edge_id) REFERENCES edges(id),
FOREIGN KEY(path_id) REFERENCES path(id)
);
) STRICT;
CREATE UNIQUE INDEX path_edges_uidx ON path_edges(path_id, edge_id);

CREATE TABLE block_group_edges (
Expand All @@ -95,7 +95,7 @@ CREATE TABLE block_group_edges (
edge_id INTEGER NOT NULL,
FOREIGN KEY(block_group_id) REFERENCES block_group(id),
FOREIGN KEY(edge_id) REFERENCES edges(id)
);
) STRICT;
CREATE UNIQUE INDEX block_group_edges_uidx ON block_group_edges(block_group_id, edge_id);

INSERT INTO sequence (hash, sequence_type, sequence, name, file_path, "length") values ("start-node-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "OTHER", "start-node-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "", "", 64), ("end-node-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "OTHER", "end-node-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "", "", 64);
12 changes: 4 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn import_fasta(fasta: &String, name: &str, shallow: bool, conn: &mut Connection
.to_string();
let name = String::from_utf8(record.name().to_vec()).unwrap();
let sequence_length = record.sequence().len() as i32;
let seq_hash = if shallow {
let seq = if shallow {
Sequence::new()
.sequence_type("DNA")
.name(&name)
Expand All @@ -105,15 +105,15 @@ fn import_fasta(fasta: &String, name: &str, shallow: bool, conn: &mut Connection
Edge::PATH_START_HASH.to_string(),
0,
"+".to_string(),
seq_hash.to_string(),
seq.hash.to_string(),
0,
"+".to_string(),
0,
0,
);
let edge_out_of = Edge::create(
conn,
seq_hash.to_string(),
seq.hash.to_string(),
sequence_length,
"+".to_string(),
Edge::PATH_END_HASH.to_string(),
Expand Down Expand Up @@ -212,14 +212,10 @@ impl<'a> SequenceCache<'_> {
if let Some(found_sequence) = sequence_lookup {
found_sequence.clone()
} else {
let new_sequence_hash = Sequence::new()
let new_sequence = Sequence::new()
.sequence_type("DNA")
.sequence(&sequence)
.save(sequence_cache.conn);
let new_sequence = NewSequence::new()
.sequence_type(sequence_type)
.sequence(&sequence)
.build();

sequence_cache
.cache
Expand Down
62 changes: 24 additions & 38 deletions src/models/block_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,19 +574,19 @@ mod tests {
}

fn setup_block_group(conn: &Connection) -> (i32, Path) {
let a_seq_hash = Sequence::new()
let a_seq = Sequence::new()
.sequence_type("DNA")
.sequence("AAAAAAAAAA")
.save(conn);
let t_seq_hash = Sequence::new()
let t_seq = Sequence::new()
.sequence_type("DNA")
.sequence("TTTTTTTTTT")
.save(conn);
let c_seq_hash = Sequence::new()
let c_seq = Sequence::new()
.sequence_type("DNA")
.sequence("CCCCCCCCCC")
.save(conn);
let g_seq_hash = Sequence::new()
let g_seq = Sequence::new()
.sequence_type("DNA")
.sequence("GGGGGGGGGG")
.save(conn);
Expand All @@ -597,48 +597,48 @@ mod tests {
Edge::PATH_START_HASH.to_string(),
0,
"+".to_string(),
a_seq_hash.clone(),
a_seq.hash.clone(),
0,
"+".to_string(),
0,
0,
);
let edge1 = Edge::create(
conn,
a_seq_hash,
a_seq.hash,
10,
"+".to_string(),
t_seq_hash.clone(),
t_seq.hash.clone(),
0,
"+".to_string(),
0,
0,
);
let edge2 = Edge::create(
conn,
t_seq_hash,
t_seq.hash,
10,
"+".to_string(),
c_seq_hash.clone(),
c_seq.hash.clone(),
0,
"+".to_string(),
0,
0,
);
let edge3 = Edge::create(
conn,
c_seq_hash,
c_seq.hash,
10,
"+".to_string(),
g_seq_hash.clone(),
g_seq.hash.clone(),
0,
"+".to_string(),
0,
0,
);
let edge4 = Edge::create(
conn,
g_seq_hash,
g_seq.hash,
10,
"+".to_string(),
Edge::PATH_END_HASH.to_string(),
Expand Down Expand Up @@ -695,11 +695,10 @@ mod tests {
fn insert_and_deletion_get_all() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -731,12 +730,10 @@ mod tests {
])
);

let deletion_sequence_hash = Sequence::new()
let deletion_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("")
.save(&conn);
let deletion_sequence =
Sequence::sequence_from_hash(&conn, &deletion_sequence_hash).unwrap();
let deletion = NewBlock {
id: 0,
sequence: deletion_sequence.clone(),
Expand Down Expand Up @@ -776,11 +773,10 @@ mod tests {
fn simple_insert_get_all() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -817,11 +813,10 @@ mod tests {
fn insert_on_block_boundary_middle() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -858,11 +853,10 @@ mod tests {
fn insert_within_block() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -899,11 +893,10 @@ mod tests {
fn insert_on_block_boundary_start() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -940,11 +933,10 @@ mod tests {
fn insert_on_block_boundary_end() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -981,11 +973,10 @@ mod tests {
fn insert_across_entire_block_boundary() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -1022,11 +1013,10 @@ mod tests {
fn insert_across_two_blocks() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -1063,11 +1053,10 @@ mod tests {
fn insert_spanning_blocks() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down Expand Up @@ -1104,12 +1093,10 @@ mod tests {
fn simple_deletion() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let deletion_sequence_hash = Sequence::new()
let deletion_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("")
.save(&conn);
let deletion_sequence =
Sequence::sequence_from_hash(&conn, &deletion_sequence_hash).unwrap();
let deletion = NewBlock {
id: 0,
sequence: deletion_sequence.clone(),
Expand Down Expand Up @@ -1148,11 +1135,10 @@ mod tests {
fn doesnt_apply_same_insert_twice() {
let conn = get_connection();
let (block_group_id, path) = setup_block_group(&conn);
let insert_sequence_hash = Sequence::new()
let insert_sequence = Sequence::new()
.sequence_type("DNA")
.sequence("NNNN")
.save(&conn);
let insert_sequence = Sequence::sequence_from_hash(&conn, &insert_sequence_hash).unwrap();
let insert = NewBlock {
id: 0,
sequence: insert_sequence.clone(),
Expand Down
Loading

0 comments on commit 0d27601

Please sign in to comment.