|
|
@@ -14,7 +14,7 @@ use rayon::prelude::*;
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
-use super::variant::{AlterationCategory, ReferenceAlternative, VcfVariant};
|
|
|
+use super::variant::{AlterationCategory, Info, ReferenceAlternative, VcfVariant};
|
|
|
use crate::{
|
|
|
annotation::{
|
|
|
cosmic::Cosmic,
|
|
|
@@ -482,6 +482,57 @@ impl Variant {
|
|
|
.collect()
|
|
|
}
|
|
|
|
|
|
+ /// Returns the maximum inferred insertion length among all VCF variants.
|
|
|
+ ///
|
|
|
+ /// This method computes the insertion length from either:
|
|
|
+ /// - The `SVINSLEN` entry in the variant's `INFO` field, if present.
|
|
|
+ /// - Or, if `SVINSLEN` is not available and the variant represents a standard
|
|
|
+ /// nucleotide-to-nucleotides substitution, it estimates the insertion length as
|
|
|
+ /// `alt.len() - 1`, where `alt` is the alternative allele sequence.
|
|
|
+ ///
|
|
|
+ /// The returned value is the maximum insertion length across all variants,
|
|
|
+ /// or `None` if no valid insertion length could be determined.
|
|
|
+ ///
|
|
|
+ /// # Returns
|
|
|
+ /// * `Some(u32)` - The maximum insertion length found.
|
|
|
+ /// * `None` - If no `SVINSLEN` or inferrable insertion is available in any variant.
|
|
|
+ ///
|
|
|
+ /// # Examples
|
|
|
+ /// ```rust
|
|
|
+ /// let insertion_length = variant_set.insertion_length();
|
|
|
+ /// if let Some(len) = insertion_length {
|
|
|
+ /// println!("Max insertion length: {}", len);
|
|
|
+ /// }
|
|
|
+ /// ```
|
|
|
+ pub fn insertion_length(&self) -> Option<u32> {
|
|
|
+ self.vcf_variants
|
|
|
+ .iter()
|
|
|
+ .filter_map(|v| {
|
|
|
+ v.infos
|
|
|
+ .0
|
|
|
+ .iter()
|
|
|
+ .find_map(|i| {
|
|
|
+ if let Info::SVINSLEN(len) = i {
|
|
|
+ Some(*len)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .or_else(|| {
|
|
|
+ if let (
|
|
|
+ ReferenceAlternative::Nucleotide(_),
|
|
|
+ ReferenceAlternative::Nucleotides(nt),
|
|
|
+ ) = (&v.reference, &self.alternative)
|
|
|
+ {
|
|
|
+ Some(nt.len().saturating_sub(1) as u32)
|
|
|
+ } else {
|
|
|
+ None
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .max()
|
|
|
+ }
|
|
|
+
|
|
|
pub fn n_alt_depth(&self) -> (f64, f64) {
|
|
|
let (n_alts, depths): (Vec<u32>, Vec<u32>) = self
|
|
|
.vcf_variants
|