Skip to content

Commit

Permalink
Merge pull request #19 from cschin/main
Browse files Browse the repository at this point in the history
refactoring the python lib
  • Loading branch information
cschin authored May 5, 2023
2 parents 0d5b135 + 2af0ef3 commit bd4efd3
Show file tree
Hide file tree
Showing 15 changed files with 447 additions and 797 deletions.
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pushd WFA2-lib
make all
popd
#pushd WFA2-lib
#make all
#popd

rustup default stable
cargo build -p pgr-db --release
Expand Down
2 changes: 1 addition & 1 deletion pgr-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgr-bin"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
authors = ["Jason Chin <cschin@infoecho.net>"]

Expand Down
6 changes: 3 additions & 3 deletions pgr-bin/src/bin/pgr-compare-cov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const VERSION_STRING: &str = env!("VERSION_STRING");
//use std::path::PathBuf;
use clap::{self, CommandFactory, Parser};

use pgr_bin::{pair_shmmrs, sequence_to_shmmrs, SeqIndexDB, ShmmrSpec};
use pgr_db::ext::{pair_shmmrs, sequence_to_shmmrs, SeqIndexDB, ShmmrSpec};
use rayon::prelude::*;
use rustc_hash::FxHashSet;
use std::{
fs::File,
io::{BufRead, BufReader, BufWriter, Write},
path::Path,
};
use rayon::prelude::*;

/// Compare SHIMMER pair count in two input sequence files
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -320,7 +320,7 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
} else {
panic!("input type has to be specified AGC or FRG backends")
};

#[cfg(not(feature = "with_agc"))]
if input_type == "FRG" {
let _ = seq_index_db.load_from_frg_index(args.frg_idx_prefix.as_ref().unwrap().clone());
Expand Down
40 changes: 32 additions & 8 deletions pgr-bin/src/bin/pgr-compare-cov2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const VERSION_STRING: &str = env!("VERSION_STRING");
//use std::path::PathBuf;
use clap::{self, CommandFactory, Parser};

use pgr_bin::{pair_shmmrs, sequence_to_shmmrs, SeqIndexDB};
use pgr_db::ext::{pair_shmmrs, sequence_to_shmmrs, SeqIndexDB};
use pgr_db::seq_db::{get_shmmr_matches_from_mmap_file, ShmmrPair};
use rayon::prelude::*;
use rustc_hash::FxHashSet;
use std::{
Expand Down Expand Up @@ -179,7 +180,32 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
}
});

let frag_map = seq_index_db.get_shmmr_map_internal().unwrap();
//let frag_map = seq_index_db.get_shmmr_map_internal().unwrap();

let get_shmmr_matches = |smps: ShmmrPair| {
#[cfg(feature = "with_agc")]
if input_type == "AGC" {
get_shmmr_matches_from_mmap_file(
&seq_index_db.agc_db.as_ref().unwrap().frag_location_map,
smps,
&seq_index_db.agc_db.as_ref().unwrap().frag_map_file,
)
} else {
get_shmmr_matches_from_mmap_file(
&seq_index_db.frg_db.as_ref().unwrap().frag_location_map,
smps,
&seq_index_db.frg_db.as_ref().unwrap().frag_map_file,
)
}
#[cfg(not(feature = "with_agc"))]
{
get_shmmr_matches_from_mmap_file(
&seq_index_db.frg_db.as_ref().unwrap().frag_location_map,
smps,
&seq_index_db.frg_db.as_ref().unwrap().frag_map_file,
)
}
};
let mut output_bedgraph_file0 = BufWriter::new(
File::create(Path::new(&prefix).with_extension("0.bedgraph"))
.expect("can't create the output file"),
Expand Down Expand Up @@ -217,7 +243,8 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
} else {
(s1, s0, p0, p1, 1_u8)
};
let (c0, c1) = if let Some(hits) = frag_map.get(&(k.0, k.1)) {
let (c0, c1) = {
let hits = get_shmmr_matches((k.0, k.1));
let mut c0 = 0_usize;
let mut c1 = 0_usize;
hits.iter().for_each(|v| {
Expand All @@ -230,8 +257,6 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
}
});
(c0, c1)
} else {
(0, 0)
};
assert!(c0 > 0);
let r = c1 as f32 / c0 as f32;
Expand Down Expand Up @@ -273,7 +298,8 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
} else {
(s1, s0, p0, p1, 1_u8)
};
let (c0, c1) = if let Some(hits) = frag_map.get(&(k.0, k.1)) {
let (c0, c1) = {
let hits = get_shmmr_matches((k.0, k.1));
let mut c0 = 0_usize;
let mut c1 = 0_usize;
hits.iter().for_each(|v| {
Expand All @@ -286,8 +312,6 @@ fn generate_bed_graph_from_sdb(args: &CmdOptions, input_type: &str) {
}
});
(c0, c1)
} else {
(0, 0)
};
assert!(c1 > 0);
let r = c0 as f32 / c1 as f32;
Expand Down
4 changes: 2 additions & 2 deletions pgr-bin/src/bin/pgr-fetch-seqs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const VERSION_STRING: &str = env!("VERSION_STRING");
use clap::{self, CommandFactory, Parser};
use pgr_bin::SeqIndexDB;
use pgr_db::ext::SeqIndexDB;
use pgr_db::fasta_io;
use std::fs::File;
use std::io::{self, BufRead, BufReader, BufWriter, Write};
Expand Down Expand Up @@ -88,7 +88,7 @@ fn main() -> Result<(), std::io::Error> {
} else {
Box::new(io::stdout())
};

region_file.lines().into_iter().for_each(|line| {
let line = line.expect("fail to get a line in the region file");
let fields = line.split('\t').collect::<Vec<&str>>();
Expand Down
2 changes: 1 addition & 1 deletion pgr-bin/src/bin/pgr-make-frgdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const VERSION_STRING: &str = env!("VERSION_STRING");
//use std::path::PathBuf;
use clap::{self, CommandFactory, Parser};

use pgr_bin::SeqIndexDB;
use pgr_db::ext::SeqIndexDB;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
Expand Down
4 changes: 2 additions & 2 deletions pgr-bin/src/bin/pgr-pbundle-decomp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const VERSION_STRING: &str = env!("VERSION_STRING");
use bincode::config;
use clap::{self, CommandFactory, Parser};
use pgr_bin::{
use pgr_db::ext::{
get_principal_bundle_decomposition, PrincipalBundlesWithId, SeqIndexDB, VertexToBundleIdMap,
};
use rustc_hash::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -200,7 +200,7 @@ fn main() -> Result<(), std::io::Error> {
usize,
usize,
PrincipalBundlesWithId,
pgr_bin::VertexToBundleIdMap,
VertexToBundleIdMap,
),
config::Configuration,
>(&s[..], config)
Expand Down
Loading

0 comments on commit bd4efd3

Please sign in to comment.