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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ jobs:
- name: cargo format
uses: actions-rust-lang/rustfmt@v1

rust_check_default_features:
name: Rust check with default features
runs-on: ubuntu-latest
needs: ["rust_check", "rust_format"]

strategy:
fail-fast: true

steps:
- uses: actions/checkout@v3

- name: Install toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: cargo check
run: cargo check --bins --tests

rust_lint:
name: Rust lint
runs-on: ubuntu-latest
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ members = [
"generic_a_star",
"seed_chain",
"lib_tsalign",
"tsalign",
"lib_tsshow",
"tsalign",

# Bindings
"python_bindings",
Expand All @@ -28,4 +28,4 @@ log = "0.4.27"
num-traits = "0.2.19"

[profile.release]
debug = true
debug = true
2 changes: 1 addition & 1 deletion generic_a_star/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "generic_a_star"
description = "A generic implementation of the A* algorithm"
version = "0.15.0"
version = "0.18.0"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions lib_tsalign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "lib_tsalign"
description = "A sequence-to-sequence aligner that accounts for template switches"
license.workspace = true
authors = ["Sebastian Schmidt <sebastian.schmidt@helsinki.fi>"]
version = "0.15.0"
version = "0.18.0"
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
Expand All @@ -26,8 +26,8 @@ thiserror = "2.0.3"
num-traits.workspace = true
serde = { workspace = true, features = ["derive"], optional = true }
noisy_float = { version = "0.2.0" }
generic_a_star = { version = "0.15.0", path = "../generic_a_star" }
generic_a_star = { version = "0.18.0", path = "../generic_a_star" }
log.workspace = true
seed_chain = { version = "0.15.0", path = "../seed_chain" }
seed_chain = { version = "0.18.0", path = "../seed_chain" }
deterministic_default_hasher = "0.14.2"
extend_map = "0.14.3"
12 changes: 6 additions & 6 deletions lib_tsalign/src/a_star_aligner/alignment_geometry.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::{fmt::Display, ops::Range};

use serde::Deserialize;

#[derive(Debug, Clone, Eq, PartialEq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub struct AlignmentRange {
offset: AlignmentCoordinates,
limit: AlignmentCoordinates,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub struct AlignmentCoordinates {
reference: usize,
query: usize,
Expand Down
33 changes: 16 additions & 17 deletions lib_tsalign/src/a_star_aligner/configurable_a_star_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use compact_genome::{
},
};
use generic_a_star::cost::U64Cost;
use serde::Deserialize;

use crate::{
a_star_aligner::{
Expand Down Expand Up @@ -53,13 +52,9 @@ use super::{
},
};

// TODO to be discussed
// TODO more ergonomic way to only adjust some cost values ...
/// Default costs for a star alignment, given in the custom `.tsa` format
const DEFAULT_COSTS: &str = include_str!("../../../sample_tsa_config/config.tsa");

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case", default)]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub struct Config {
pub alphabet: InputAlphabet,
pub reference_name: String,
Expand All @@ -86,7 +81,7 @@ impl Default for Config {
alphabet: InputAlphabet::DnaN,
reference_name: "reference".to_owned(),
query_name: "query".to_owned(),
costs: DEFAULT_COSTS.to_owned(),
costs: TemplateSwitchConfig::<DnaAlphabetOrN, U64Cost>::default().to_string(),
node_ord_strategy: NodeOrdStrategySelector::AntiDiagonal,
min_length_strategy: MinLengthStrategySelector::Lookahead,
chaining_strategy: ChainingStrategySelector::None,
Expand All @@ -98,8 +93,9 @@ impl Default for Config {
}
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum InputAlphabet {
Dna,
DnaN,
Expand All @@ -109,22 +105,25 @@ pub enum InputAlphabet {
RnaIupac,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum NodeOrdStrategySelector {
CostOnly,
AntiDiagonal,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum MinLengthStrategySelector {
None,
Lookahead,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case")]
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum ChainingStrategySelector {
None,
PrecomputeOnly,
Expand Down
82 changes: 82 additions & 0 deletions lib_tsalign/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use compact_genome::interface::alphabet::Alphabet;
use generic_a_star::cost::AStarCost;
use num_traits::{Bounded, bounds::UpperBounded};

use crate::{
Expand Down Expand Up @@ -178,3 +179,84 @@ impl<AlphabetType: Alphabet, Cost: Clone> Clone for TemplateSwitchConfig<Alphabe
}
}
}

impl<AlphabetType: Alphabet, Cost: AStarCost> Default for TemplateSwitchConfig<AlphabetType, Cost> {
fn default() -> Self {
Self {
left_flank_length: 0,
right_flank_length: 0,
min_length: 5,
base_cost: BaseCost {
rrf: 4.into(),
rqf: 4.into(),
qrf: 4.into(),
qqf: 4.into(),
rrr: 3.into(),
rqr: 2.into(),
qrr: 2.into(),
qqr: 3.into(),
},
primary_edit_costs: GapAffineAlignmentCostTable::new_base_agnostic(
"Primary Edit Costs",
0.into(),
2.into(),
3.into(),
1.into(),
),
secondary_forward_edit_costs: GapAffineAlignmentCostTable::new_base_agnostic(
"Secondary Forward Edit Costs",
0.into(),
2.into(),
3.into(),
1.into(),
),
secondary_reverse_edit_costs: GapAffineAlignmentCostTable::new_base_agnostic(
"Secondary Reverse Edit Costs",
0.into(),
2.into(),
3.into(),
1.into(),
),
left_flank_edit_costs: GapAffineAlignmentCostTable::new_base_agnostic(
"Left Flank Edit Costs",
0.into(),
2.into(),
3.into(),
1.into(),
),
right_flank_edit_costs: GapAffineAlignmentCostTable::new_base_agnostic(
"Right Flank Edit Costs",
0.into(),
2.into(),
3.into(),
1.into(),
),
offset_costs: CostFunction::try_from(vec![
(isize::MIN, Cost::max_value()),
(-100, 0.into()),
(101, Cost::max_value()),
])
.unwrap(),
length_costs: CostFunction::try_from(vec![(0, Cost::max_value()), (5, 0.into())])
.unwrap(),
length_difference_costs: CostFunction::try_from(vec![
(isize::MIN, Cost::max_value()),
(-100, 0.into()),
(101, Cost::max_value()),
])
.unwrap(),
forward_anti_primary_gap_costs: CostFunction::try_from(vec![
(isize::MIN, Cost::max_value()),
(-100, 0.into()),
(101, Cost::max_value()),
])
.unwrap(),
reverse_anti_primary_gap_costs: CostFunction::try_from(vec![
(isize::MIN, Cost::max_value()),
(-100, 0.into()),
(101, Cost::max_value()),
])
.unwrap(),
}
}
}
58 changes: 58 additions & 0 deletions lib_tsalign/src/config/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,61 @@ pub fn parse_inf_value<Output: FromStr + Bounded>(input: &str) -> IResult<&str,
Ok((&input[length..], result))
}
}

impl<AlphabetType: Alphabet, Cost: AStarCost> std::fmt::Display
for TemplateSwitchConfig<AlphabetType, Cost>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "# Limits")?;
writeln!(f, "left_flank_length = {}", self.left_flank_length)?;
writeln!(f, "right_flank_length = {}", self.right_flank_length)?;

writeln!(f, "# Base Cost")?;
writeln!(f, "rrf_cost = {}", self.base_cost.rrf)?;
writeln!(f, "rqf_cost = {}", self.base_cost.rqf)?;
writeln!(f, "qrf_cost = {}", self.base_cost.qrf)?;
writeln!(f, "qqf_cost = {}", self.base_cost.qqf)?;
writeln!(f, "rrr_cost = {}", self.base_cost.rrr)?;
writeln!(f, "rqr_cost = {}", self.base_cost.rqr)?;
writeln!(f, "qrr_cost = {}", self.base_cost.qrr)?;
writeln!(f, "qqr_cost = {}", self.base_cost.qqr)?;

writeln!(f, "# Jump Costs")?;
writeln!(f, "Offset")?;
writeln!(f, "{}", self.offset_costs)?;
writeln!(f, "Length")?;
writeln!(f, "{}", self.length_costs)?;
writeln!(f, "LengthDifference")?;
writeln!(f, "{}", self.length_difference_costs)?;
writeln!(f, "ForwardAntiPrimaryGap")?;
writeln!(f, "{}", self.forward_anti_primary_gap_costs)?;
writeln!(f, "ReverseAntiPrimaryGap")?;
writeln!(f, "{}", self.reverse_anti_primary_gap_costs)?;

writeln!(f, "{}", self.primary_edit_costs)?;
writeln!(f, "{}", self.secondary_forward_edit_costs)?;
writeln!(f, "{}", self.secondary_reverse_edit_costs)?;
writeln!(f, "{}", self.left_flank_edit_costs)?;
writeln!(f, "{}", self.right_flank_edit_costs)?;

Ok(())
}
}

#[cfg(test)]
mod tests {
use compact_genome::implementation::alphabets::dna_alphabet_or_n::DnaAlphabetOrN;
use generic_a_star::cost::U64Cost;

use crate::config::TemplateSwitchConfig;

#[test]
fn display() {
let config = TemplateSwitchConfig::<DnaAlphabetOrN, U64Cost>::default();
let string = config.to_string();
assert_eq!(
config,
TemplateSwitchConfig::read_plain(string.as_bytes()).unwrap()
);
}
}
Loading