Skip to content

Commit

Permalink
feat: calculate composite fitness
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Oct 3, 2022
1 parent f7d3ae8 commit cb204a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
18 changes: 16 additions & 2 deletions packages_rs/nextclade/src/analyze/phenotype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn calculate_phenotype(phenotype_data: &PhenotypeData, aa_substitutions: &[A
}

pub fn get_phenotype_attr_descs(virus_properties: &VirusProperties) -> Vec<PhenotypeAttrDesc> {
virus_properties
let mut descs = virus_properties
.phenotype_data
.as_ref()
.map_or(vec![], |phenotype_data| {
Expand All @@ -40,7 +40,21 @@ pub fn get_phenotype_attr_descs(virus_properties: &VirusProperties) -> Vec<Pheno
description: ph.description.clone(),
})
.collect_vec()
})
});

if let Some(phenotype_data) = &virus_properties.phenotype_data {
let binding = phenotype_data.iter().find(|&ph| ph.name.contains("binding"));
let escape = phenotype_data.iter().find(|&ph| ph.name.contains("escape"));
if let (Some(binding), Some(escape)) = (binding, escape) {
descs.push(PhenotypeAttrDesc {
name: "composite_fitness".to_owned(),
name_friendly: "Composite fitness".to_owned(),
description: "".to_owned(),
});
}
}

descs
}

pub fn get_phenotype_attr_keys(virus_properties: &VirusProperties) -> Vec<String> {
Expand Down
16 changes: 15 additions & 1 deletion packages_rs/nextclade/src/run/nextclade_run_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub fn nextclade_run_one(
let total_covered_nucs = total_aligned_nucs - total_missing - total_non_acgtns;
let coverage = total_covered_nucs as f64 / ref_seq.len() as f64;

let phenotype_values = virus_properties.phenotype_data.as_ref().map(|phenotype_data| {
let mut phenotype_values = virus_properties.phenotype_data.as_ref().map(|phenotype_data| {
phenotype_data
.iter()
.filter_map(|phenotype_data| {
Expand Down Expand Up @@ -183,6 +183,20 @@ pub fn nextclade_run_one(
.collect_vec()
});

if let Some(ref mut phenotype_values) = phenotype_values {
let binding = phenotype_values.iter().find(|ph| ph.name.contains("binding"));
let escape = phenotype_values.iter().find(|ph| ph.name.contains("escape"));
if let (Some(binding), Some(escape)) = (binding, escape) {
phenotype_values.push(PhenotypeValue {
name: "composite_fitness".to_owned(),
name_friendly: "Composite fitness".to_owned(),
description: "".to_owned(),
gene: binding.gene.clone(),
value: 1.2 * escape.value + 0.5 * binding.value,
});
}
}

let qc = qc_run(
&private_nuc_mutations,
&nucleotide_composition,
Expand Down

0 comments on commit cb204a0

Please sign in to comment.