Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate composite fitness #1008

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
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.0 * escape.value + 0.15 * binding.value,
});
}
}

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