Skip to content
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

Fix warnings #85

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/exports/gfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn export_gfa(
let boundary_edges = Edge::boundary_edges_from_sequences(&blocks);
edges.extend(boundary_edges.clone());

let (mut graph, edges_by_node_pair) = Edge::build_graph(&edges, &blocks);
let (mut graph, _edges_by_node_pair) = Edge::build_graph(&edges, &blocks);

BlockGroup::prune_graph(&mut graph);

Expand Down
8 changes: 2 additions & 6 deletions src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use std::collections::{HashMap, HashSet, VecDeque};
use std::collections::{HashSet, VecDeque};
use std::fmt::Debug;
use std::hash::Hash;
use std::iter::from_fn;

use crate::models::strand::Strand;
use petgraph::graphmap::DiGraphMap;
use petgraph::prelude::EdgeRef;
use petgraph::visit::{
GraphBase, GraphRef, IntoEdgeReferences, IntoEdges, IntoNeighbors, IntoNeighborsDirected,
NodeCount,
};
use petgraph::visit::{GraphRef, IntoEdges, IntoNeighbors, IntoNeighborsDirected, NodeCount};
use petgraph::Direction;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
Expand Down
10 changes: 5 additions & 5 deletions src/models/accession.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ impl Accession {
) -> Accession {
match Accession::create(conn, name, path_id, parent_accession_id) {
Ok(accession) => accession,
Err(rusqlite::Error::SqliteFailure(err, details)) => {
Err(rusqlite::Error::SqliteFailure(err, _details)) => {
if err.code == rusqlite::ErrorCode::ConstraintViolation {
let mut existing_id: i64;
let existing_id: i64;
if let Some(id) = parent_accession_id {
existing_id = conn.query_row("select id from accessions where name = ?1 and path_id = ?2 and parent_accession_id = ?3;", params_from_iter(vec![Value::from(name.to_string()), Value::from(path_id), Value::from(id)]), |row| row.get(0)).unwrap();
} else {
Expand Down Expand Up @@ -157,7 +157,7 @@ impl AccessionEdge {
row.get(0)
}) {
Ok(res) => res,
Err(rusqlite::Error::SqliteFailure(err, details)) => {
Err(rusqlite::Error::SqliteFailure(_err, _details)) => {
conn.query_row("select id from accession_edges where source_node_id = ?1 source_coordinate = ?2 source_strand = ?3 target_node_id = ?4 target_coordinate = ?5 target_strand = ?6 chromosome_index = ?7", params_from_iter(&placeholders), |row| {
row.get(0)
}).unwrap()
Expand Down Expand Up @@ -326,9 +326,9 @@ mod tests {
#[test]
fn test_accession_create_query() {
let conn = &get_connection(None);
let (bg, path) = setup_block_group(conn);
let (_bg, path) = setup_block_group(conn);
let accession = Accession::create(conn, "test", path.id, None).unwrap();
let accession_2 = Accession::create(conn, "test2", path.id, None).unwrap();
let _accession_2 = Accession::create(conn, "test2", path.id, None).unwrap();
assert_eq!(
Accession::query(
conn,
Expand Down
23 changes: 11 additions & 12 deletions src/models/block_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use interavl::IntervalTree as IT2;
use intervaltree::IntervalTree;
use itertools::Itertools;
use petgraph::graphmap::DiGraphMap;
use petgraph::visit::Bfs;
use petgraph::Direction;
use rusqlite::{params_from_iter, types::Value as SQLValue, Connection};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -882,7 +881,7 @@ mod tests {
);

Sample::create(conn, "sample2");
let bg2 =
let _bg2 =
BlockGroup::get_or_create_sample_block_group(conn, "test", "sample2", "chr1", None)
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -1765,7 +1764,7 @@ mod tests {
fn test_blockgroup_interval_tree() {
let conn = &get_connection(None);
let (block_group_id, path) = setup_block_group(conn);
let new_sample = Sample::create(conn, "child");
let _new_sample = Sample::create(conn, "child");
let new_bg_id =
BlockGroup::get_or_create_sample_block_group(conn, "test", "child", "chr1", None)
.unwrap();
Expand Down Expand Up @@ -1942,8 +1941,8 @@ mod tests {
#[test]
fn test_changes_against_derivative_blockgroups() {
let conn = &get_connection(None);
let (block_group_id, path) = setup_block_group(conn);
let new_sample = Sample::create(conn, "child");
let (_block_group_id, _path) = setup_block_group(conn);
let _new_sample = Sample::create(conn, "child");
let new_bg_id =
BlockGroup::get_or_create_sample_block_group(conn, "test", "child", "chr1", None)
.unwrap();
Expand Down Expand Up @@ -1987,7 +1986,7 @@ mod tests {
);

// Now, we make a change against another descendant
let new_sample = Sample::create(conn, "grandchild");
let _new_sample = Sample::create(conn, "grandchild");
let gc_bg_id = BlockGroup::get_or_create_sample_block_group(
conn,
"test",
Expand Down Expand Up @@ -2037,8 +2036,8 @@ mod tests {
// This test ensures that if we have heterozygous changes that do not introduce frameshifts,
// we can modify regions downstream of them.
let conn = &get_connection(None);
let (block_group_id, path) = setup_block_group(conn);
let new_sample = Sample::create(conn, "child");
let (_block_group_id, _path) = setup_block_group(conn);
let _new_sample = Sample::create(conn, "child");
let new_bg_id =
BlockGroup::get_or_create_sample_block_group(conn, "test", "child", "chr1", None)
.unwrap();
Expand Down Expand Up @@ -2085,7 +2084,7 @@ mod tests {
);

// Now, we make a change against another descendant
let new_sample = Sample::create(conn, "grandchild");
let _new_sample = Sample::create(conn, "grandchild");
let gc_bg_id = BlockGroup::get_or_create_sample_block_group(
conn,
"test",
Expand Down Expand Up @@ -2147,8 +2146,8 @@ mod tests {
fn test_prohibits_out_of_frame_changes_against_derivative_diploid_blockgroups() {
// This test ensures that we do not allow ambiguous changes by coordinates
let conn = &get_connection(None);
let (block_group_id, path) = setup_block_group(conn);
let new_sample = Sample::create(conn, "child");
let (_block_group_id, _path) = setup_block_group(conn);
let _new_sample = Sample::create(conn, "child");
let new_bg_id =
BlockGroup::get_or_create_sample_block_group(conn, "test", "child", "chr1", None)
.unwrap();
Expand Down Expand Up @@ -2197,7 +2196,7 @@ mod tests {
);

// Now, we make a change against another descendant and get an error
let new_sample = Sample::create(conn, "grandchild");
let _new_sample = Sample::create(conn, "grandchild");
let gc_bg_id = BlockGroup::get_or_create_sample_block_group(
conn,
"test",
Expand Down
6 changes: 3 additions & 3 deletions src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ pub fn save_graph(graph: &DiGraphMap<GraphNode, GraphEdge>, path: &str) {
use petgraph::dot::{Config, Dot};
use std::fs::File;
let mut file = File::create(path).unwrap();
file.write_all(
let _ = file.write_all(
format!(
"{dot:?}",
dot = Dot::with_attr_getters(
&graph,
&[Config::NodeNoLabel, Config::EdgeNoLabel],
&|_, (_, _, edge_weight)| format!("label = \"{}\"", edge_weight.chromosome_index),
&|_, (node, weight)| format!(
&|_, (node, _weight)| format!(
"label = \"{}[{}-{}]\"",
node.node_id, node.sequence_start, node.sequence_end
),
Expand All @@ -191,8 +191,8 @@ where

pub fn get_sample_bg<'a>(conn: &Connection, sample_name: impl Into<Option<&'a str>>) -> BlockGroup {
let sample_name = sample_name.into();
let mut query = "";
let mut placeholders = vec![];
let query;
if let Some(name) = sample_name {
query = "select * from block_groups where sample_name = ?1";
placeholders.push(Value::from(name.to_string()));
Expand Down
13 changes: 6 additions & 7 deletions src/updates/vcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use noodles::vcf::variant::record::info::field::Value as InfoValue;
use noodles::vcf::variant::record::samples::series::value::genotype::Phasing;
use noodles::vcf::variant::record::samples::series::Value;
use noodles::vcf::variant::record::samples::Sample as NoodlesSample;
use noodles::vcf::variant::record::{AlternateBases, ReferenceBases};
use noodles::vcf::variant::record::AlternateBases;
use noodles::vcf::variant::Record;
use rusqlite::{session, types::Value as SQLValue, Connection};

Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn update_with_vcf<'a>(
let seq_name: String = record.reference_sequence_name().to_string();
let ref_seq = record.reference_bases();
// this converts the coordinates to be zero based, start inclusive, end exclusive
let mut ref_end = record.variant_end(&header).unwrap().get() as i64;
let ref_end = record.variant_end(&header).unwrap().get() as i64;
let alt_bases = record.alternate_bases();
let alt_alleles: Vec<_> = alt_bases.iter().collect::<io::Result<_>>().unwrap();
let mut vcf_entries = vec![];
Expand All @@ -238,7 +238,7 @@ pub fn update_with_vcf<'a>(
};

if !fixed_sample.is_empty() && !genotype.is_empty() {
let mut sample_bg_id = BlockGroupCache::lookup(
let sample_bg_id = BlockGroupCache::lookup(
&mut block_group_cache,
collection_name,
&fixed_sample,
Expand All @@ -251,7 +251,7 @@ pub fn update_with_vcf<'a>(
if let Some(gt) = genotype {
let allele_accession = accession_name
.clone()
.filter(|name| gt.allele as i32 == accession_allele);
.filter(|_| gt.allele as i32 == accession_allele);
let mut ref_start = (record.variant_start().unwrap().unwrap().get() - 1) as i64;
if gt.allele != 0 {
let mut alt_seq = alt_alleles[chromosome_index - 1];
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn update_with_vcf<'a>(
}
} else {
for (sample_index, sample) in record.samples().iter().enumerate() {
let mut sample_bg_id = BlockGroupCache::lookup(
let sample_bg_id = BlockGroupCache::lookup(
&mut block_group_cache,
collection_name,
&sample_names[sample_index],
Expand All @@ -320,7 +320,7 @@ pub fn update_with_vcf<'a>(
if let Some(allele) = allele {
let allele_accession = accession_name
.clone()
.filter(|name| allele as i32 == accession_allele);
.filter(|_| allele as i32 == accession_allele);
if allele != 0 {
let mut alt_seq = alt_alleles[allele - 1];
if alt_seq != "*" && alt_seq.len() < ref_seq.len() {
Expand Down Expand Up @@ -459,7 +459,6 @@ mod tests {
// Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*;
use crate::imports::fasta::import_fasta;
use crate::imports::gfa::import_gfa;
use crate::models::accession::Accession;
use crate::models::node::Node;
use crate::models::operations::setup_db;
Expand Down