/// Finds private mutations.
///
/// Private mutations are the mutations in the query (user-provided) sequence relative to the parent node on the
/// reference tree.
///
/// We have an array of sequence mutations relative to reference and a map of node mutations relative to reference.
/// We want to find private mutations. The following cases are possible:
///
/// |   |                         Case                                 | Private | Mutation from | Mutation to  |
/// |---|--------------------------------------------------------------|---------|---------------|--------------|
/// | 1 | mutation in sequence and in node, same query character       |   no    |      N/A      |     N/A      |
/// | 2 | mutation in sequence and in node, but not the same character |   yes   |    node.qry   |   seq.qry    |
/// | 3 | mutation in sequence but not in node                         |   yes   |    seq.ref    |   seq.qry    |
/// | 4 | mutation in node, but not in sequence, aka "reversion"       |   yes   |    node.qry   |   node.ref   |
/// |   | (mutation in sequence that reverts the character to ref seq) |         |               |              |
/// | 5 | unknown in sequence, mutation in node                        |   no    |      N/A      |     N/A      |
/// | 6 | unknown in sequence, no mutation in node                     |   no    |      N/A      |     N/A      |
///
/// At this point sequence have not yet become a new node on the tree, but is described by the results of the previous
/// analysis steps.
Finds private mutations.
Private mutations are the mutations in the query (user-provided) sequence relative to the parent node on the
reference tree.

We have an array of sequence mutations relative to reference and a map of node mutations relative to reference.
We want to find private mutations. The following cases are possible.



At this point sequence have not yet become a new node on the tree, but is described by the results of the previous
analysis steps.
Finds private mutations . Private mutations are the mutations in the query ( user - provided ) sequence relative to the parent node on the reference tree . We have an array of sequence mutations relative to reference and a map of node mutations relative to reference . We want to find private mutations . The following cases are possible . At this point sequence have not yet become a new node on the tree but is described by the results of the previous analysis steps .
pub fn find_private_nuc_mutations(
  node: &AuspiceTreeNode,
  substitutions: &[NucSub],
  deletions: &[NucDel],
  missing: &[NucRange],
  alignment_range: &Range,
  ref_seq: &[Nuc],
  virus_properties: &VirusProperties,
) -> PrivateNucMutations {
  let node_mut_map = &node.tmp.mutations;
  // Remember which positions we cover while iterating sequence mutations,
  // to be able to skip them when we iterate over node mutations
  let mut seq_positions_mutated_or_deleted = BTreeSet::<usize>::new();
  // Iterate over sequence substitutions
  let non_reversion_substitutions =
    process_seq_substitutions(node_mut_map, substitutions, &mut seq_positions_mutated_or_deleted);
  // Iterate over sequence deletions
  let non_reversion_deletions =
    process_seq_deletions(node_mut_map, deletions, ref_seq, &mut seq_positions_mutated_or_deleted);
  // Iterate over node substitutions and deletions and find reversions
  let reversion_substitutions = find_reversions(
    node_mut_map,
    missing,
    alignment_range,
    ref_seq,
    &mut seq_positions_mutated_or_deleted,
  );
  let (labeled_substitutions, unlabeled_substitutions) = label_private_mutations(
    &non_reversion_substitutions,
    &virus_properties.nuc_mut_label_maps.substitution_label_map,
  );
  let mut private_substitutions = concat_to_vec(&reversion_substitutions, &non_reversion_substitutions);
  private_substitutions.sort();
  private_substitutions.dedup();
  let mut private_deletions = non_reversion_deletions;
  private_deletions.sort();
  private_deletions.dedup();
  let total_private_substitutions = private_substitutions.len();
  let total_private_deletions = private_deletions.len();
  let total_reversion_substitutions = reversion_substitutions.len();
  let total_labeled_substitutions = labeled_substitutions.len();
  let total_unlabeled_substitutions = unlabeled_substitutions.len();
  PrivateNucMutations {
    private_substitutions,
    private_deletions,
    reversion_substitutions,
    labeled_substitutions,
    unlabeled_substitutions,
    total_private_substitutions,
    total_private_deletions,
    total_reversion_substitutions,
    total_labeled_substitutions,
    total_unlabeled_substitutions,
  }
}
pub fn find_private_nuc_mutations ( node : & AuspiceTreeNode , substitutions : & [ NucSub ] , deletions : & [ NucDel ] , missing : & [ NucRange ] , alignment_range : & Range , ref_seq : & [ Nuc ] , virus_properties : & VirusProperties , ) -> PrivateNucMutations { let node_mut_map = & node . tmp . mutations ; // Remember which positions we cover while iterating sequence mutations, // to be able to skip them when we iterate over node mutations let mut seq_positions_mutated_or_deleted = BTreeSet :: < usize > :: new ( ) ; // Iterate over sequence substitutions let non_reversion_substitutions = process_seq_substitutions ( node_mut_map , substitutions , & mut seq_positions_mutated_or_deleted ) ; // Iterate over sequence deletions let non_reversion_deletions = process_seq_deletions ( node_mut_map , deletions , ref_seq , & mut seq_positions_mutated_or_deleted ) ; // Iterate over node substitutions and deletions and find reversions let reversion_substitutions = find_reversions ( node_mut_map , missing , alignment_range , ref_seq , & mut seq_positions_mutated_or_deleted , ) ; let ( labeled_substitutions , unlabeled_substitutions ) = label_private_mutations ( & non_reversion_substitutions , & virus_properties . nuc_mut_label_maps . substitution_label_map , ) ; let mut private_substitutions = concat_to_vec ( & reversion_substitutions , & non_reversion_substitutions ) ; private_substitutions . sort ( ) ; private_substitutions . dedup ( ) ; let mut private_deletions = non_reversion_deletions ; private_deletions . sort ( ) ; private_deletions . dedup ( ) ; let total_private_substitutions = private_substitutions . len ( ) ; let total_private_deletions = private_deletions . len ( ) ; let total_reversion_substitutions = reversion_substitutions . len ( ) ; let total_labeled_substitutions = labeled_substitutions . len ( ) ; let total_unlabeled_substitutions = unlabeled_substitutions . len ( ) ; PrivateNucMutations { private_substitutions , private_deletions , reversion_substitutions , labeled_substitutions , unlabeled_substitutions , total_private_substitutions , total_private_deletions , total_reversion_substitutions , total_labeled_substitutions , total_unlabeled_substitutions , } }
Finds private mutations.
Finds private mutations .
node
&AuspiceTreeNode
substitutions
&[NucSub]
deletions
&[NucDel]
missing
&[NucRange]
alignment_range
&Range
ref_seq
&[Nuc]
virus_properties
&VirusProperties