Skip to content

Commit

Permalink
Merge pull request #29 from ginkgobioworks/return-full-sequence-on-cr…
Browse files Browse the repository at this point in the history
…eation

Return full Sequence object when saving it
  • Loading branch information
Chris7 authored Sep 5, 2024
2 parents 794d395 + 29143a4 commit 5e5e554
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 132 deletions.
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 @@ -547,19 +547,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 @@ -570,48 +570,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 @@ -668,11 +668,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 @@ -704,12 +703,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 @@ -749,11 +746,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 @@ -790,11 +786,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 @@ -831,11 +826,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 @@ -872,11 +866,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 @@ -913,11 +906,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 @@ -954,11 +946,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 @@ -995,11 +986,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 @@ -1036,11 +1026,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 @@ -1077,12 +1066,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 @@ -1121,11 +1108,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 5e5e554

Please sign in to comment.