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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/tsa_config
/*.log
/*.log
/callgrind.out.*
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ compact-genome = "12.3.0"
traitsequence = "8.1.2"
log = "0.4.27"
num-traits = "0.2.19"

[profile.release]
debug = true
28 changes: 28 additions & 0 deletions generic_a_star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,31 @@ impl<NodeIdentifier, Cost> Default for AStarResult<NodeIdentifier, Cost> {
Self::NoTarget
}
}

impl<T: AStarNode> AStarNode for Box<T> {
type Identifier = <T as AStarNode>::Identifier;

type EdgeType = <T as AStarNode>::EdgeType;

type Cost = <T as AStarNode>::Cost;

fn identifier(&self) -> &Self::Identifier {
<T as AStarNode>::identifier(self)
}

fn cost(&self) -> Self::Cost {
<T as AStarNode>::cost(self)
}

fn a_star_lower_bound(&self) -> Self::Cost {
<T as AStarNode>::a_star_lower_bound(self)
}

fn predecessor(&self) -> Option<&Self::Identifier> {
<T as AStarNode>::predecessor(self)
}

fn predecessor_edge_type(&self) -> Option<Self::EdgeType> {
<T as AStarNode>::predecessor_edge_type(self)
}
}
112 changes: 70 additions & 42 deletions lib_tsalign/src/a_star_aligner/template_switch_distance/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Context<
<Strategies as AlignmentStrategySelector>::Cost,
>>::IdentifierPrimaryExtraData,
>,
Node<Strategies>,
Box<Node<Strategies>>,
>,
pub memory: Memory<Strategies>,

Expand Down Expand Up @@ -102,10 +102,10 @@ impl<
Strategies: AlignmentStrategySelector,
> AStarContext for Context<'_, '_, SubsequenceType, Strategies>
{
type Node = Node<Strategies>;
type Node = Box<Node<Strategies>>;

fn create_root(&self) -> Self::Node {
Self::Node {
Box::new(Node {
node_data: NodeData {
identifier: Identifier::new_primary(self.range.reference_offset(), self.range.query_offset(), 0, GapType::None, <<Strategies as AlignmentStrategySelector>::PrimaryMatch as PrimaryMatchStrategy<<Strategies as AlignmentStrategySelector>::Cost>>::create_root_identifier_primary_extra_data(self)),
predecessor: None,
Expand All @@ -114,7 +114,7 @@ impl<
a_star_lower_bound: Strategies::Cost::zero(),
},
strategies: AlignmentStrategiesNodeMemory::create_root(self),
}
})
}

fn generate_successors(
Expand Down Expand Up @@ -186,12 +186,15 @@ impl<
};

if cost_increment != Strategies::Cost::max_value() {
opened_nodes_output.extend(node.generate_primary_diagonal_successor(
0,
cost_increment,
is_match,
self,
));
opened_nodes_output.extend(
node.generate_primary_diagonal_successor(
0,
cost_increment,
is_match,
self,
)
.map(Into::into),
);
}

if is_match && <<Strategies as AlignmentStrategySelector>::PrimaryMatch as PrimaryMatchStrategy<<Strategies as AlignmentStrategySelector>::Cost>>::always_generate_substitution() {
Expand All @@ -203,7 +206,8 @@ impl<
cost_increment,
false,
self,
));
)
.map(Into::into));
}
}
}
Expand Down Expand Up @@ -232,12 +236,15 @@ impl<
};

if cost_increment != Strategies::Cost::max_value() {
opened_nodes_output.extend(node.generate_primary_diagonal_successor(
flank_index + 1,
cost_increment,
is_match,
self,
));
opened_nodes_output.extend(
node.generate_primary_diagonal_successor(
flank_index + 1,
cost_increment,
is_match,
self,
)
.map(Into::into),
);
}
}
}
Expand All @@ -256,7 +263,8 @@ impl<
.primary_edit_costs
.gap_costs(r.clone(), gap_type != GapType::Deletion),
self,
),
)
.map(Into::into),
);
}

Expand All @@ -271,7 +279,8 @@ impl<
.left_flank_edit_costs
.gap_costs(r, gap_type != GapType::Deletion),
self,
),
)
.map(Into::into),
);
} else if flank_index < 0 {
opened_nodes_output.extend(
Expand All @@ -281,7 +290,8 @@ impl<
.right_flank_edit_costs
.gap_costs(r, gap_type != GapType::Deletion),
self,
),
)
.map(Into::into),
);
}
}
Expand All @@ -300,7 +310,8 @@ impl<
.primary_edit_costs
.gap_costs(q.clone(), gap_type != GapType::Insertion),
self,
),
)
.map(Into::into),
);
}

Expand All @@ -315,7 +326,8 @@ impl<
.left_flank_edit_costs
.gap_costs(q, gap_type != GapType::Insertion),
self,
),
)
.map(Into::into),
);
} else if flank_index < 0 {
opened_nodes_output.extend(
Expand All @@ -325,7 +337,8 @@ impl<
.right_flank_edit_costs
.gap_costs(q, gap_type != GapType::Insertion),
self,
),
)
.map(Into::into),
);
}
}
Expand All @@ -340,7 +353,8 @@ impl<
config.offset_costs.evaluate(&0),
&config.base_cost,
self,
),
)
.map(Into::into),
);
}
}
Expand Down Expand Up @@ -394,7 +408,8 @@ impl<
cost_increment,
template_switch_first_offset + 1,
self,
),
)
.map(Into::into),
)
}
}
Expand All @@ -421,7 +436,8 @@ impl<
cost_increment,
template_switch_first_offset - 1,
self,
),
)
.map(Into::into),
)
}
}
Expand All @@ -443,6 +459,7 @@ impl<
let secondary_root_node: Vec<_> = node
.generate_secondary_root_node(self)
.into_iter()
.map(Box::new)
.collect();
opened_nodes_output = ExtendMap::new(
opened_nodes_direct_output,
Expand Down Expand Up @@ -505,7 +522,8 @@ impl<
.match_or_substitution_cost(p.clone(), s.clone()),
p == s,
self,
),
)
.map(Into::into),
);
}

Expand Down Expand Up @@ -543,7 +561,8 @@ impl<
.secondary_edit_costs(template_switch_direction)
.gap_costs(s, gap_type != GapType::Deletion),
self,
),
)
.map(Into::into),
);
}

Expand All @@ -557,7 +576,8 @@ impl<
.secondary_edit_costs(template_switch_direction)
.gap_costs(p, gap_type != GapType::Insertion),
self,
),
)
.map(Into::into),
);
}
}
Expand All @@ -570,7 +590,8 @@ impl<
let cost_increment = length_cost + length_difference_cost;

opened_nodes_output.extend(
node.generate_initial_template_switch_exit_successor(cost_increment, self),
node.generate_initial_template_switch_exit_successor(cost_increment, self)
.map(Into::into),
)
}
}
Expand Down Expand Up @@ -613,11 +634,14 @@ impl<
assert!(new_cost >= old_cost);
let cost_increment = new_cost - old_cost;

opened_nodes_output.extend(node.generate_template_switch_exit_successor(
cost_increment,
anti_primary_gap + 1,
self,
))
opened_nodes_output.extend(
node.generate_template_switch_exit_successor(
cost_increment,
anti_primary_gap + 1,
self,
)
.map(Into::into),
)
}
}

Expand All @@ -634,11 +658,14 @@ impl<
assert!(new_cost >= old_cost);
let cost_increment = new_cost - old_cost;

opened_nodes_output.extend(node.generate_template_switch_exit_successor(
cost_increment,
anti_primary_gap - 1,
self,
))
opened_nodes_output.extend(
node.generate_template_switch_exit_successor(
cost_increment,
anti_primary_gap - 1,
self,
)
.map(Into::into),
)
}
}

Expand All @@ -652,7 +679,7 @@ impl<
node.generate_primary_reentry_successor(self, anti_primary_gap_cost)
.map(|mut node| {
node.strategies.template_switch_count.increment_count();
node
node.into()
}),
);
}
Expand Down Expand Up @@ -705,7 +732,8 @@ fn generate_output_mapper_function<
<Context<'reference, 'query, SubsequenceType, Strategies> as AStarContext>::Node,
) -> <Context<'reference, 'query, SubsequenceType, Strategies> as AStarContext>::Node {
move |node| {
<Strategies as AlignmentStrategySelector>::Chaining::apply_lower_bound(node, context)
<Strategies as AlignmentStrategySelector>::Chaining::apply_lower_bound(*node, context)
.into()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<Cost: AStarCost> TemplateSwitchLowerBoundMatrix<Cost> {
),
);
let root_xy = genome_length / 2;
a_star.initialise_with(|context| Node::new_root_at(root_xy, root_xy, context));
a_star.initialise_with(|context| Node::new_root_at(root_xy, root_xy, context).into());
previous_closed_lower_bounds.extend(closed_lower_bounds.drain());

let root_xy_isize = isize::try_from(root_xy).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ impl<Cost: AStarCost> ShortcutStrategy<Cost> for TemplateSwitchLowerBoundShortcu
Identifier::Primary { flank_index, .. }
| Identifier::PrimaryReentry { flank_index, .. } => {
if flank_index == context.config.left_flank_length {
opened_nodes_output.extend(context.memory.shortcut.iter().flat_map(|entry| {
node.generate_template_switch_shortcut_successor(
entry.x(),
entry.y(),
entry.cost(),
context,
)
}));
opened_nodes_output.extend(
context
.memory
.shortcut
.iter()
.flat_map(|entry| {
node.generate_template_switch_shortcut_successor(
entry.x(),
entry.y(),
entry.cost(),
context,
)
})
.map(Into::into),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ impl<
Strategies: AlignmentStrategySelector,
> AStarContext for TemplateSwitchMinLengthContext<'_, '_, '_, SubsequenceType, Strategies>
{
type Node = Node<Strategies>;
type Node = Box<Node<Strategies>>;

fn create_root(&self) -> Self::Node {
self.root_node.clone()
self.root_node.clone().into()
}

fn generate_successors(&mut self, node: &Self::Node, output: &mut impl Extend<Self::Node>) {
Expand Down