Skip to content
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
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ flate2 = "1.0.35"
gb-io = "0.7.1"
thiserror = "1.0.69"
indicatif = "0.17.9"
html-escape = "0.2.13"

[dev-dependencies]
cargo-llvm-cov = "0.6.14"
Expand Down
11 changes: 8 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ pub static BASE_DIR: LazyLock<RwLock<PathBuf>> =
LazyLock::new(|| RwLock::new(env::current_dir().unwrap()));
}

pub fn get_operation_connection() -> Connection {
let db_path = get_gen_db_path();
pub fn get_operation_connection(db_path: impl Into<Option<PathBuf>>) -> Connection {
let db_path = db_path.into();
let path = if let Some(s) = db_path {
s
} else {
get_gen_db_path()
};
let mut conn =
Connection::open(&db_path).unwrap_or_else(|_| panic!("Error connecting to {:?}", &db_path));
Connection::open(&path).unwrap_or_else(|_| panic!("Error connecting to {:?}", &path));
run_operation_migrations(&mut conn);
conn
}
Expand Down
12 changes: 11 additions & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use petgraph::prelude::EdgeRef;
use petgraph::visit::{GraphRef, IntoEdges, IntoNeighbors, IntoNeighborsDirected, NodeCount};
use petgraph::Direction;
use std::collections::{HashMap, HashSet, VecDeque};
use std::fmt::Debug;
use std::fmt::{self, Debug};
use std::hash::Hash;
use std::iter::from_fn;

Expand All @@ -19,6 +19,16 @@ pub struct GraphNode {
pub sequence_end: i64,
}

impl fmt::Display for GraphNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}[{}-{}]",
self.node_id, self.sequence_start, self.sequence_end
)
}
}

impl GraphNode {
pub fn length(&self) -> i64 {
self.sequence_end - self.sequence_start
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod range;
#[cfg(test)]
pub mod test_helpers;
pub mod updates;
pub mod views;

use crate::migrations::run_migrations;
use noodles::vcf::variant::record::samples::series::value::genotype::Phasing;
Expand Down
42 changes: 40 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ use gen::updates::gaf::{transform_csv_to_fasta, update_with_gaf};
use gen::updates::genbank::update_with_genbank;
use gen::updates::library::update_with_library;
use gen::updates::vcf::{update_with_vcf, VcfError};
use gen::views::patch::view_patches;
use itertools::Itertools;
use noodles::core::Region;
use rusqlite::{types::Value, Connection};
use std::fmt::Debug;
use std::fs::File;
use std::io::Write;
use std::ops::Deref;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::{io, str};

#[derive(Parser)]
Expand Down Expand Up @@ -171,6 +173,16 @@ enum Commands {
#[clap(index = 1)]
patch: String,
},
/// View a patch
#[command(name = "patch-view", arg_required_else_help(true))]
PatchView {
/// The prefix to save dot files under. Defaults to patch filename
#[arg(long, short)]
prefix: Option<String>,
/// The patch file
#[clap(index = 1)]
patch: String,
},
/// Initialize a gen repository
Init {},
/// Manage and create branches
Expand Down Expand Up @@ -317,7 +329,7 @@ fn main() {
return;
}

let operation_conn = get_operation_connection();
let operation_conn = get_operation_connection(None);
if let Some(Commands::Defaults {
database,
collection,
Expand Down Expand Up @@ -774,6 +786,32 @@ fn main() {
let patches = patch::load_patches(&mut f);
patch::apply_patches(&conn, &operation_conn, &patches);
}
Some(Commands::PatchView { prefix, patch }) => {
let patch_path = Path::new(patch);
let mut f = File::open(patch_path).unwrap();
let patches = patch::load_patches(&mut f);
let diagrams = view_patches(&patches);
for (patch_hash, patch_diagrams) in diagrams.iter() {
for (bg_id, dot) in patch_diagrams.iter() {
let path = if let Some(p) = prefix {
format!("{p}_{patch_hash}_{bg_id}.dot")
} else {
format!(
"{patch_base}_{patch_hash}_{bg_id}.dot",
patch_base = patch_path
.with_extension("")
.file_name()
.unwrap()
.to_str()
.unwrap()
)
};
let mut f = File::create(path).unwrap();
f.write_all(dot.as_bytes())
.expect("Failed to write diagram");
}
}
}
None => {}
// these will never be handled by this method as we search for them earlier.
Some(Commands::Init {}) => {
Expand Down
30 changes: 29 additions & 1 deletion src/models/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub const PATH_END_NODE_ID: i64 = 2;
pub struct Node {
pub id: i64,
pub sequence_hash: String,
pub hash: Option<String>,
}

impl Query for Node {
Expand All @@ -21,6 +22,7 @@ impl Query for Node {
Node {
id: row.get(0).unwrap(),
sequence_hash: row.get(1).unwrap(),
hash: row.get(2).unwrap(),
}
}
}
Expand Down Expand Up @@ -128,6 +130,32 @@ impl Node {
}

pub fn is_terminal(node_id: i64) -> bool {
node_id == PATH_START_NODE_ID || node_id == PATH_END_NODE_ID
Node::is_start_node(node_id) || Node::is_end_node(node_id)
}

pub fn is_start_node(node_id: i64) -> bool {
node_id == PATH_START_NODE_ID
}

pub fn is_end_node(node_id: i64) -> bool {
node_id == PATH_END_NODE_ID
}

pub fn get_start_node() -> Node {
Node {
id: PATH_START_NODE_ID,
sequence_hash: "start-node-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
.to_string(),
hash: None,
}
}

pub fn get_end_node() -> Node {
Node {
id: PATH_END_NODE_ID,
sequence_hash: "end-node-zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
.to_string(),
hash: None,
}
}
}
Loading
Loading