Skip to content

Commit

Permalink
feat(graph): implement graph analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
cauliyang committed Nov 10, 2023
1 parent b5871e1 commit 1c1d155
Show file tree
Hide file tree
Showing 9 changed files with 557 additions and 75 deletions.
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ documentation = "https://github.com/cauliyang/rboss"
license = "MIT"
description = "Rust Bioinformatics Toolbox"
keywords = ["Bioinformatics", "Graph", "Toolbox"]
categories = ["Bioinformatics"]
categories = ["command-line-interface"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[profile.dev.package."*"]
Expand Down Expand Up @@ -53,11 +53,12 @@ noodles-fasta = "0.30"
noodles-fastq = "0.9"
noodles-sam = "0.46"

petgraph = "0.6"
regex = "1.10"
serde_json = "1.0"
petgraph = { version = "0.6", features = ["serde-1"] }
regex = { version = "1.10" }
serde = { version = "1.0" }
serde_json = { version = "1.0" }

walkdir = "2.4"
walkdir = { version = "2.4" }

# standard crate data is left out
[dev-dependencies]
Expand Down
1 change: 0 additions & 1 deletion src/fa2fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::path::Path;

pub fn fa2fq<P: AsRef<Path>>(input: P) -> Result<()> {
let mut reader = fasta::reader::Builder.build_from_path(input)?;

let mut writer = fastq::Writer::new(std::io::stdout());

for result in reader.records() {
Expand Down
31 changes: 31 additions & 0 deletions src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
use anyhow::Result;
use clap::Args;
use clap::ValueHint;
use std::io::BufWriter;
use std::io::Write;
use std::path::PathBuf;

mod analysis;
mod data;
mod load;

use analysis::GraphAnalysis;
use log::warn;

#[derive(Args, Debug)]
pub struct GraphArgs {
/// Graph input file
#[arg(value_hint = ValueHint::FilePath)]
input: PathBuf,
}

pub fn analyze_nlgraph(args: &GraphArgs) -> Result<()> {
let mut nlgraph = load::load_cygraph_from_file(&args.input)?;

if !nlgraph.is_weakly_connected() {
warn!("Graph is weakly connected");
return Ok(());
}

if nlgraph.is_cyclic_directed() {
warn!("Graph is cyclic");
return Ok(());
}

nlgraph.node_degree();
nlgraph.degree_centrality();
nlgraph.closeness_centrality();
nlgraph.local_clustering_coefficient();

let stdout = std::io::stdout().lock();
let mut handle = BufWriter::new(stdout); // optional: wrap that handle in a buffer
writeln!(handle, "{}", nlgraph.to_cyjson())?;

Ok(())
}
Loading

0 comments on commit 1c1d155

Please sign in to comment.