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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ The costs are a piecewise constant function, where the first row is the first in
`RQQROffset` is applied to TSMs where ancestor and descendant are different, while `RRQQOffset` is applied to TSMs where ancestor and descendant are the same.
`Length` is the cost based on the length of the 2-3-alignment of the TSM.
`LengthDifference` is the cost based on the difference between the length of the 2-3-alignment and the difference between points 1 and 4.
`ForwardAntiPrimaryGap` is the cost based on the difference between points 1 and 4, specifically `SP4 - SP1`.
`ForwardAntiDescendantGap` is the cost based on the difference between points 1 and 4, specifically `SP4 - SP1`.

```txt
# Jump Costs
Expand All @@ -177,11 +177,11 @@ LengthDifference
-inf -100 101
inf 0 inf

ForwardAntiPrimaryGap
ForwardAntiDescendantGap
-inf 1
0 inf

ReverseAntiPrimaryGap
ReverseAntiDescendantGap
-inf
0
```
Expand Down Expand Up @@ -248,6 +248,7 @@ Then, create the visualisation in SVG format as follows:
```bash
tsalign show -i alignment.toml -n alignment-no-ts.toml -s alignment.svg
```

Since SVGs are not always well supported, you can also use the switch `-p` to render the visualisation also as PNG.
Note that the `-p` switch requires setting the `-s` parameter.

Expand Down
14 changes: 7 additions & 7 deletions lib_ts_chainalign/src/alignment/ts_kind.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use lib_tsalign::a_star_aligner::template_switch_distance::{
TemplateSwitchPrimary, TemplateSwitchSecondary,
TemplateSwitchAncestor, TemplateSwitchDescendant,
};

#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash)]
Expand Down Expand Up @@ -77,19 +77,19 @@ impl TsKind {
}

impl TsAncestor {
pub fn into_tsalign_secondary(self) -> TemplateSwitchSecondary {
pub fn into_tsalign_secondary(self) -> TemplateSwitchAncestor {
match self {
TsAncestor::Seq1 => TemplateSwitchSecondary::Reference,
TsAncestor::Seq2 => TemplateSwitchSecondary::Query,
TsAncestor::Seq1 => TemplateSwitchAncestor::Reference,
TsAncestor::Seq2 => TemplateSwitchAncestor::Query,
}
}
}

impl TsDescendant {
pub fn into_tsalign_primary(self) -> TemplateSwitchPrimary {
pub fn into_tsalign_primary(self) -> TemplateSwitchDescendant {
match self {
TsDescendant::Seq1 => TemplateSwitchPrimary::Reference,
TsDescendant::Seq2 => TemplateSwitchPrimary::Query,
TsDescendant::Seq1 => TemplateSwitchDescendant::Reference,
TsDescendant::Seq2 => TemplateSwitchDescendant::Query,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib_ts_chainalign/src/chain_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ fn actually_align<
TsAlignAlignmentType::TemplateSwitchEntrance {
first_offset: jump,
equal_cost_range: EqualCostRange::new_invalid(),
primary: ts_kind.descendant.into_tsalign_primary(),
secondary: ts_kind.ancestor.into_tsalign_secondary(),
descendant: ts_kind.descendant.into_tsalign_primary(),
ancestor: ts_kind.ancestor.into_tsalign_secondary(),
direction: TemplateSwitchDirection::Reverse,
},
);
Expand All @@ -423,7 +423,7 @@ fn actually_align<
tsalign_alignment.push_n(
multiplicity,
TsAlignAlignmentType::TemplateSwitchExit {
anti_primary_gap: anti_primary_gap + jump,
anti_descendant_gap: anti_primary_gap + jump,
},
)
}
Expand Down
5 changes: 4 additions & 1 deletion lib_ts_chainalign/src/costs/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ impl<AlphabetType: Alphabet, Cost: AStarCost> From<TemplateSwitchConfig<Alphabet
// tsalign costs do not support limiting this.
jump_34: isize::MIN..isize::MAX,
length_23: value.length_costs.zero_range().unwrap(),
ancestor_gap: value.reverse_anti_primary_gap_costs.zero_range().unwrap(),
ancestor_gap: value
.reverse_anti_descendant_gap_costs
.zero_range()
.unwrap(),
},
}
}
Expand Down
35 changes: 19 additions & 16 deletions lib_tsalign/src/a_star_aligner/alignment_result/alignment/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::VecDeque, iter};

use crate::a_star_aligner::{
alignment_result::alignment::Alignment,
template_switch_distance::{AlignmentType, TemplateSwitchPrimary},
template_switch_distance::{AlignmentType, TemplateSwitchDescendant},
};

#[derive(Debug, Clone)]
Expand All @@ -20,7 +20,7 @@ pub struct AlignmentStream {
pub struct AlignmentStreamCoordinates {
reference: usize,
query: usize,
template_switch_primary: Option<TemplateSwitchPrimary>,
template_switch_descendant: Option<TemplateSwitchDescendant>,
}

impl AlignmentStream {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl AlignmentStreamCoordinates {
Self {
reference: reference_offset,
query: query_offset,
template_switch_primary: None,
template_switch_descendant: None,
}
}

Expand All @@ -210,34 +210,37 @@ impl AlignmentStreamCoordinates {
| AlignmentType::PrimaryMatch
| AlignmentType::PrimaryFlankSubstitution
| AlignmentType::PrimaryFlankMatch => (1, 1),
AlignmentType::TemplateSwitchEntrance { primary, .. } => {
AlignmentType::TemplateSwitchEntrance { descendant, .. } => {
assert!(
self.template_switch_primary.is_none(),
self.template_switch_descendant.is_none(),
"Encountered template switch entrance within template switch"
);
self.template_switch_primary = Some(primary);
self.template_switch_descendant = Some(descendant);
(0, 0)
}
AlignmentType::SecondaryInsertion
| AlignmentType::SecondarySubstitution
| AlignmentType::SecondaryMatch => match self.template_switch_primary.unwrap() {
TemplateSwitchPrimary::Reference => (1, 0),
TemplateSwitchPrimary::Query => (0, 1),
| AlignmentType::SecondaryMatch => match self.template_switch_descendant.unwrap() {
TemplateSwitchDescendant::Reference => (1, 0),
TemplateSwitchDescendant::Query => (0, 1),
},
AlignmentType::TemplateSwitchExit { anti_primary_gap } => {
let Some(template_switch_primary) = self.template_switch_primary.take() else {
AlignmentType::TemplateSwitchExit {
anti_descendant_gap,
} => {
let Some(template_switch_descendant) = self.template_switch_descendant.take()
else {
panic!(
"Encountered template switch exit without first encountering a template switch entrance"
)
};
match template_switch_primary {
TemplateSwitchPrimary::Reference => {
match template_switch_descendant {
TemplateSwitchDescendant::Reference => {
self.query =
usize::try_from(self.query as isize + anti_primary_gap).unwrap()
usize::try_from(self.query as isize + anti_descendant_gap).unwrap()
}
TemplateSwitchPrimary::Query => {
TemplateSwitchDescendant::Query => {
self.reference =
usize::try_from(self.reference as isize + anti_primary_gap).unwrap()
usize::try_from(self.reference as isize + anti_descendant_gap).unwrap()
}
}
(0, 0)
Expand Down
Loading
Loading