/// Finds aminoacid substitutions and deletions in query peptides relative to reference peptides, in all genes
///
/// ## Precondition
/// Nucleotide sequences and peptides are required to be stripped from insertions
Finds aminoacid substitutions and deletions in query peptides relative to reference peptides, in all genes
Finds aminoacid substitutions and deletions in query peptides relative to reference peptides in all genes
pub fn find_aa_changes(
  ref_seq: &[Nuc],
  qry_seq: &[Nuc],
  ref_peptides: &TranslationMap,
  translations: &[Translation],
  alignment_range: &Range,
  gene_map: &GeneMap,
) -> Result<FindAaChangesOutput, Report> {
  let mut changes = translations
    .iter()
    .map(
      |Translation {
         gene_name,
         seq,
         insertions,
         frame_shifts,
       }|
       -> Result<FindAaChangesOutput, Report> {
        let ref_peptide = ref_peptides.get(gene_name).ok_or(make_internal_report!(
          "Reference peptide not found for gene '{gene_name}'"
        ))?;
        let gene = gene_map
          .get(gene_name)
          .ok_or(make_internal_report!("Gene '{gene_name}' not found in gene map"))?;
        Ok(find_aa_changes_for_gene(
          qry_seq,
          ref_seq,
          &ref_peptide.seq,
          seq,
          gene,
          alignment_range,
        ))
      },
    )
    .collect::<Result<Vec<FindAaChangesOutput>, Report>>()?
    .into_iter()
    .fold(FindAaChangesOutput::default(), |mut output, changes| {
      output.aa_substitutions.extend(changes.aa_substitutions);
      output.aa_deletions.extend(changes.aa_deletions);
      output
    });
  changes.aa_substitutions.sort_by_key(|sub| sub.pos);
  changes.aa_deletions.sort_by_key(|del| del.pos);
  Ok(changes)
}
pub fn find_aa_changes ( ref_seq : & [ Nuc ] , qry_seq : & [ Nuc ] , ref_peptides : & TranslationMap , translations : & [ Translation ] , alignment_range : & Range , gene_map : & GeneMap , ) -> Result < FindAaChangesOutput , Report > { let mut changes = translations . iter ( ) . map ( | Translation { gene_name , seq , insertions , frame_shifts , } | -> Result < FindAaChangesOutput , Report > { let ref_peptide = ref_peptides . get ( gene_name ) . ok_or ( make_internal_report ! ( " " ) ) ? ; let gene = gene_map . get ( gene_name ) . ok_or ( make_internal_report ! ( " " ) ) ? ; Ok ( find_aa_changes_for_gene ( qry_seq , ref_seq , & ref_peptide . seq , seq , gene , alignment_range , ) ) } , ) . collect :: < Result < Vec < FindAaChangesOutput > , Report > > ( ) ? . into_iter ( ) . fold ( FindAaChangesOutput :: default ( ) , | mut output , changes | { output . aa_substitutions . extend ( changes . aa_substitutions ) ; output . aa_deletions . extend ( changes . aa_deletions ) ; output } ) ; changes . aa_substitutions . sort_by_key ( | sub | sub . pos ) ; changes . aa_deletions . sort_by_key ( | del | del . pos ) ; Ok ( changes ) }
Finds aminoacid substitutions and deletions in query peptides relative to reference peptides, in all genes
Finds aminoacid substitutions and deletions in query peptides relative to reference peptides in all genes
ref_seq
&[Nuc]
qry_seq
&[Nuc]
ref_peptides
&TranslationMap
translations
&[Translation]
alignment_range
&Range
gene_map
&GeneMap
precondition
Nucleotide sequences and peptides are required to be stripped from insertions
Nucleotide sequences and peptides are required to be stripped from insertions