Skip to content

Commit

Permalink
Merge pull request #14 from ginkgobioworks/cleanup-august-2024
Browse files Browse the repository at this point in the history
Fix a bunch of warnings
  • Loading branch information
dkhofer authored Aug 13, 2024
2 parents 0e9fedd + 353cfbf commit 59f66a8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# our test dbs
*.db-*
*.db

# Generated by Cargo
# will have compiled files and executables
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pub struct Genotype {

pub fn parse_genotype(gt: &str) -> Vec<Option<Genotype>> {
let mut genotypes = vec![];
let mut phase = match gt.contains("/") {
let mut phase = match gt.contains('/') {
true => Phasing::Unphased,
false => Phasing::Phased,
};
for (index, entry) in gt.split_inclusive(|c| c == '|' || c == '/').enumerate() {
let mut allele;
for entry in gt.split_inclusive(|c| c == '|' || c == '/') {
let allele;
let mut phasing = Phasing::Unphased;
if entry.ends_with(['/', '|']) {
let (allele_str, phasing_str) = entry.split_at(entry.len() - 1);
Expand Down Expand Up @@ -99,7 +99,7 @@ mod tests {

#[test]
fn it_queries() {
let mut conn = get_connection();
let conn = get_connection();
let sequence_count: i32 = conn
.query_row(
"SELECT count(*) from sequence where hash = 'foo'",
Expand Down
32 changes: 13 additions & 19 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use noodles::vcf::variant::record::info::field::value::array::Values;
use petgraph::data::Build;
use petgraph::graphmap::DiGraphMap;
use petgraph::Direction;
use rusqlite::types::Value;
use rusqlite::{params_from_iter, Connection};
use sha2::{Digest, Sha256};
use std::collections::{HashMap, HashSet};
use std::fmt::*;
use std::hash::Hash;

pub mod block;
pub mod edge;
Expand Down Expand Up @@ -175,11 +172,10 @@ impl BlockGroup {
let target_id: Option<i32> = edge.get(2).unwrap();
let chrom_index = edge.get(3).unwrap();
let phased = edge.get(4).unwrap();
let mut new_edge;
if target_id.is_some() && source_id.is_some() {
let target_id = target_id.unwrap();
let source_id = source_id.unwrap();
new_edge = Edge::create(
Edge::create(
conn,
Some(*block_map.get(&source_id).unwrap_or(&source_id)),
Some(*block_map.get(&target_id).unwrap_or(&target_id)),
Expand All @@ -188,7 +184,7 @@ impl BlockGroup {
);
} else if target_id.is_some() {
let target_id = target_id.unwrap();
new_edge = Edge::create(
Edge::create(
conn,
None,
Some(*block_map.get(&target_id).unwrap_or(&target_id)),
Expand All @@ -197,7 +193,7 @@ impl BlockGroup {
);
} else if source_id.is_some() {
let source_id = source_id.unwrap();
new_edge = Edge::create(
Edge::create(
conn,
Some(*block_map.get(&source_id).unwrap_or(&source_id)),
None,
Expand Down Expand Up @@ -415,7 +411,7 @@ impl BlockGroup {
let mut previous_block: Option<&Block> = None;
for block_id in &path.blocks {
let block = blocks.get(block_id).unwrap();
let block_length = (block.end - block.start);
let block_length = block.end - block.start;
path_end += block_length;

let (contains_start, contains_end, overlap) =
Expand Down Expand Up @@ -448,7 +444,7 @@ impl BlockGroup {
if end_split_point == next_block.start {
new_edges.push((Some(new_block_id), Some(next_block.id)));
} else {
let (left_block, right_block) =
let (left_block, _right_block) =
Block::split(conn, &next_block, end_split_point, chromosome_index, phased)
.unwrap();
Block::delete(conn, next_block.id);
Expand All @@ -465,7 +461,7 @@ impl BlockGroup {
new_edges.push((Some(pb.id), Some(new_block_id)));
}
} else {
let (left_block, right_block) =
let (left_block, _right_block) =
Block::split(conn, block, split_point, chromosome_index, phased).unwrap();
Block::delete(conn, block.id);
new_edges.push((Some(left_block.id), Some(new_block_id)));
Expand All @@ -479,7 +475,7 @@ impl BlockGroup {
// the previous change ends right before this block starts, so it's an insert
new_edges.push((Some(new_block_id), Some(block.id)));
} else {
let (left_block, right_block) =
let (_left_block, right_block) =
Block::split(conn, block, split_point, chromosome_index, phased).unwrap();
Block::delete(conn, block.id);
new_edges.push((Some(new_block_id), Some(right_block.id)));
Expand Down Expand Up @@ -586,9 +582,7 @@ impl ChangeLog {
#[cfg(test)]
mod tests {
use super::*;
use crate::get_connection as get_db_connection;
use crate::migrations::run_migrations;
use std::fs;
use std::hash::Hash;

fn get_connection() -> Connection {
Expand All @@ -603,17 +597,17 @@ mod tests {
let t_seq_hash = Sequence::create(conn, "DNA", "TTTTTTTTTT", true);
let c_seq_hash = Sequence::create(conn, "DNA", "CCCCCCCCCC", true);
let g_seq_hash = Sequence::create(conn, "DNA", "GGGGGGGGGG", true);
let collection = Collection::create(conn, "test");
let _collection = Collection::create(conn, "test");
let block_group = BlockGroup::create(conn, "test", None, "hg19");
let a_block = Block::create(conn, &a_seq_hash, block_group.id, 0, 10, "+");
let t_block = Block::create(conn, &t_seq_hash, block_group.id, 0, 10, "+");
let c_block = Block::create(conn, &c_seq_hash, block_group.id, 0, 10, "+");
let g_block = Block::create(conn, &g_seq_hash, block_group.id, 0, 10, "+");
let edge_0 = Edge::create(conn, None, Some(a_block.id), 0, 0);
let edge_1 = Edge::create(conn, Some(a_block.id), Some(t_block.id), 0, 0);
let edge_2 = Edge::create(conn, Some(t_block.id), Some(c_block.id), 0, 0);
let edge_3 = Edge::create(conn, Some(c_block.id), Some(g_block.id), 0, 0);
let edge_4 = Edge::create(conn, Some(g_block.id), None, 0, 0);
let _edge_0 = Edge::create(conn, None, Some(a_block.id), 0, 0);
let _edge_1 = Edge::create(conn, Some(a_block.id), Some(t_block.id), 0, 0);
let _edge_2 = Edge::create(conn, Some(t_block.id), Some(c_block.id), 0, 0);
let _edge_3 = Edge::create(conn, Some(c_block.id), Some(g_block.id), 0, 0);
let _edge_4 = Edge::create(conn, Some(g_block.id), None, 0, 0);
let path = Path::create(
conn,
"chr1",
Expand Down
23 changes: 11 additions & 12 deletions src/models/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::models::Path;
use rusqlite::{params_from_iter, types::Value, Connection};

use crate::models::edge::{Edge, UpdatedEdge};
Expand Down Expand Up @@ -232,7 +231,7 @@ impl Block {

pub fn get_blocks(conn: &Connection, query: &str, placeholders: Vec<Value>) -> Vec<Block> {
let mut stmt = conn.prepare(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map(params_from_iter(placeholders), |row| {
Ok(Block {
id: row.get(0)?,
Expand Down Expand Up @@ -421,21 +420,21 @@ mod tests {

#[test]
fn get_sequence() {
let conn = get_connection();
let conn = &mut get_connection();
let sequence = "AAATTTCCCGGG".to_string();
let seq = Sequence::create(&conn, "DNA", &sequence, true);
let coll = Collection::create(&conn, "test");
let bg = BlockGroup::create(&conn, "test", None, "test");
let block = Block::create(&conn, &seq, bg.id, 0, 12, "+");
let seq = Sequence::create(conn, "DNA", &sequence, true);
Collection::create(conn, "test collection");
let bg = BlockGroup::create(conn, "test collection", None, "test");
let block = Block::create(conn, &seq, bg.id, 0, 12, "+");
assert_eq!(
Block::get_sequence(&conn, block.id),
(sequence, "1".to_string())
Block::get_sequence(conn, block.id),
(sequence, "+".to_string())
);

let block = Block::create(&conn, &seq, bg.id, 0, 9, "+");
let block = Block::create(conn, &seq, bg.id, 0, 9, "+");
assert_eq!(
Block::get_sequence(&conn, block.id),
("AAATTTCCC".to_string(), "1".to_string())
Block::get_sequence(conn, block.id),
("AAATTTCCC".to_string(), "+".to_string())
);
}
}
9 changes: 3 additions & 6 deletions src/models/edge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::collections::HashMap;

use crate::models::Path;
use rusqlite::types::Value;
use rusqlite::{params_from_iter, Connection};

Expand All @@ -21,8 +18,8 @@ impl Edge {
chromosome_index: i32,
phased: i32,
) -> Edge {
let mut query;
let mut id_query;
let query;
let id_query;
let mut placeholders: Vec<Value> = vec![];
if target_id.is_some() && source_id.is_some() {
query = "INSERT INTO edges (source_id, target_id, chromosome_index, phased) VALUES (?1, ?2, ?3, ?4) RETURNING *";
Expand Down Expand Up @@ -175,7 +172,7 @@ impl Edge {

pub fn get_edges(conn: &Connection, query: &str, placeholders: Vec<Value>) -> Vec<Edge> {
let mut stmt = conn.prepare_cached(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map(params_from_iter(placeholders), |row| {
Ok(Edge {
id: row.get(0)?,
Expand Down
12 changes: 5 additions & 7 deletions src/models/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use petgraph::prelude::Dfs;
use petgraph::Direction;
use rusqlite::types::Value;
use rusqlite::{params_from_iter, Connection};
use std::hash::Hash;

#[derive(Debug)]
pub struct Path {
Expand Down Expand Up @@ -94,7 +93,7 @@ impl Path {

pub fn get_paths(conn: &Connection, query: &str, placeholders: Vec<Value>) -> Vec<Path> {
let mut stmt = conn.prepare(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map(params_from_iter(placeholders), |row| {
let path_id = row.get(0).unwrap();
Ok(Path {
Expand Down Expand Up @@ -160,7 +159,7 @@ impl PathBlock {
Err(rusqlite::Error::SqliteFailure(err, details)) => {
if err.code == rusqlite::ErrorCode::ConstraintViolation {
println!("{err:?} {details:?}");
let mut query;
let query;
let mut placeholders = vec![path_id];
if let Some(s) = source_block_id {
if let Some(t) = target_block_id {
Expand Down Expand Up @@ -198,7 +197,7 @@ impl PathBlock {

pub fn query(conn: &Connection, query: &str, placeholders: Vec<Value>) -> Vec<PathBlock> {
let mut stmt = conn.prepare(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map(params_from_iter(placeholders), |row| {
Ok(PathBlock {
id: row.get(0)?,
Expand Down Expand Up @@ -241,10 +240,10 @@ impl PathBlock {
blocks
}

pub fn blocks_to_graph(conn: &Connection, path_id: i32) -> DiGraphMap<(u32), ()> {
pub fn blocks_to_graph(conn: &Connection, path_id: i32) -> DiGraphMap<u32, ()> {
let query = "SELECT source_block_id, target_block_id from path_blocks where path_id = ?1;";
let mut stmt = conn.prepare_cached(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map((path_id,), |row| {
let source_id: Option<u32> = row.get(0).unwrap();
let target_id: Option<u32> = row.get(1).unwrap();
Expand Down Expand Up @@ -272,7 +271,6 @@ impl PathBlock {

mod tests {
use rusqlite::Connection;
use std::collections::HashSet;
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/models/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Sequence {
placeholders: Vec<Value>,
) -> Vec<Sequence> {
let mut stmt = conn.prepare_cached(query).unwrap();
let mut rows = stmt
let rows = stmt
.query_map(params_from_iter(placeholders), |row| {
Ok(Sequence {
hash: row.get(0).unwrap(),
Expand Down

0 comments on commit 59f66a8

Please sign in to comment.