Skip to content

Conversation

mmolari
Copy link
Collaborator

@mmolari mmolari commented Aug 2, 2025

Review of #164

  • Extends BlockAnalysis to avoid recomputing edits (can be removed if not needed, the save should be minimal, it's more a matter of computing the object just once to avoid confusion...)
  • slightly corrects the logic of apply_full_reconsensus, avoiding dealing with substitutions twice.
  • minor refactors of some methods

@mmolari mmolari marked this pull request as ready for review August 4, 2025 08:38

/// Result of analyzing blocks for reconsensus operation
#[derive(Clone, Debug, Serialize, Deserialize)]
struct BlockAnalysis {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Edit to BlockAnalysis to avoid re-computing and taking decisions on separate objects

}

/// Applies full reconsensus including indels and realignment
fn apply_full_reconsensus(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this method to the Block class edit_consensus_and_realign.
Given a set of edits that method changes the block consensus and re-aligns all the sequences


/// Change a nucleotide in the consensus sequence at a specific position by applying a substitution.
/// Updates the alignment substitutions accordingly, without changing the underlying sequences.
pub fn change_consensus_nucleotide_at_pos(&mut self, s: &Sub) -> Result<(), Report> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given a substitution, it applies it to the block consensus sequence and updates all alignment edits for consistency.


/// Applies a set of edits to the block's consensus sequence and re-aligns the sequences
/// to the new consensus. Returns a new `PangraphBlock` object with the same BlockId.
pub fn edit_consensus_and_realign(self, edits: &Edit, args: &PangraphBuildArgs) -> Result<Self, Report> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given a set of edits (also indels) it applies them to the block consensus, and then re-aligns all block sequences to the new consensus.

  • I made it return a new block instead of modifying the one existing in-place, since it has to store the new sequences anyways
  • I did not parallelize the re-alignment since this should be a relatively rare operation and I don't expect it to matter much...

}

/// Updates the consensus sequence of the block and re-aligns the sequences to the new consensus.
fn update_block_consensus(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this method to the Block class edit_consensus_and_realign

// Then apply indels and realign if present
if majority_edits.has_indels() {
let consensus = block.consensus();
let new_consensus = majority_edits.apply(consensus)?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was applying substitutions twice and is now removed.

@ivan-aksamentov ivan-aksamentov merged commit dcf6c32 into refactor/reconsensus-updated Aug 4, 2025
18 checks passed
@ivan-aksamentov ivan-aksamentov deleted the review/reconsensus-updated branch August 4, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants