|
@@ -280,7 +280,6 @@ impl VcfVariant {
|
|
|
pub fn bnd_desc(&self) -> anyhow::Result<BNDDesc> {
|
|
pub fn bnd_desc(&self) -> anyhow::Result<BNDDesc> {
|
|
|
let alt = self.alternative.to_string();
|
|
let alt = self.alternative.to_string();
|
|
|
if alt.contains('[') || alt.contains(']') {
|
|
if alt.contains('[') || alt.contains(']') {
|
|
|
- let extending_right = alt.contains('[');
|
|
|
|
|
let alt_rep = alt.replace("[", ";").replace("]", ";");
|
|
let alt_rep = alt.replace("[", ";").replace("]", ";");
|
|
|
let alt_is_joined_after = !alt_rep.starts_with(";");
|
|
let alt_is_joined_after = !alt_rep.starts_with(";");
|
|
|
let parts = alt_rep
|
|
let parts = alt_rep
|
|
@@ -334,47 +333,6 @@ impl VcfVariant {
|
|
|
added_nt,
|
|
added_nt,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // let b_sens = alt.contains('[');
|
|
|
|
|
- //
|
|
|
|
|
- // let a_sens = if b_sens {
|
|
|
|
|
- // !alt.starts_with('[')
|
|
|
|
|
- // } else {
|
|
|
|
|
- // !alt.starts_with(']')
|
|
|
|
|
- // };
|
|
|
|
|
- //
|
|
|
|
|
- // let parts: Vec<&str> = alt
|
|
|
|
|
- // .split(&['[', ']', ':'])
|
|
|
|
|
- // .filter(|v| !v.is_empty())
|
|
|
|
|
- // .collect();
|
|
|
|
|
- //
|
|
|
|
|
- // if parts.len() != 3 {
|
|
|
|
|
- // return Err(anyhow::anyhow!("Failed to parse parts: {parts:?}"));
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // let (nt, b_contig, b_position) = if a_sens {
|
|
|
|
|
- // (parts[0], parts[1], parts[2])
|
|
|
|
|
- // } else {
|
|
|
|
|
- // (parts[2], parts[0], parts[1])
|
|
|
|
|
- // };
|
|
|
|
|
- //
|
|
|
|
|
- // let added_nt = if nt.len() > 1 {
|
|
|
|
|
- // nt[1..].to_string()
|
|
|
|
|
- // } else {
|
|
|
|
|
- // nt.to_string()
|
|
|
|
|
- // };
|
|
|
|
|
- //
|
|
|
|
|
- // Ok(BNDDesc {
|
|
|
|
|
- // a_contig: self.position.contig(),
|
|
|
|
|
- // a_position: self.position.position + 1,
|
|
|
|
|
- // a_sens,
|
|
|
|
|
- // b_contig: b_contig.to_string(),
|
|
|
|
|
- // b_position: b_position
|
|
|
|
|
- // .parse()
|
|
|
|
|
- // .map_err(|e| anyhow::anyhow!("Failed to parse: {b_position}\n{e}"))?,
|
|
|
|
|
- // b_sens,
|
|
|
|
|
- // added_nt,
|
|
|
|
|
- // })
|
|
|
|
|
} else {
|
|
} else {
|
|
|
Err(anyhow::anyhow!("The alteration is not BND: {alt}"))
|
|
Err(anyhow::anyhow!("The alteration is not BND: {alt}"))
|
|
|
}
|
|
}
|
|
@@ -766,6 +724,37 @@ pub enum Format {
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
|
|
pub struct Formats(pub Vec<Format>);
|
|
pub struct Formats(pub Vec<Format>);
|
|
|
|
|
|
|
|
|
|
+impl Formats {
|
|
|
|
|
+ /// Get the tumoral alternative read depth and total depth as an Option<(u32, u32)>.
|
|
|
|
|
+ pub fn n_alt_depth(&self) -> Option<(u32, u32)> {
|
|
|
|
|
+ let mut tumor_alt_depth: Option<u32> = None;
|
|
|
|
|
+ let mut tumor_total_depth: Option<u32> = None;
|
|
|
|
|
+
|
|
|
|
|
+ for format in &self.0 {
|
|
|
|
|
+ match format {
|
|
|
|
|
+ // Tumor Allelic Depth (AD)
|
|
|
|
|
+ Format::AD(values) => {
|
|
|
|
|
+ if values.len() > 1 {
|
|
|
|
|
+ // Sum all alternative allele depths (excluding reference allele)
|
|
|
|
|
+ tumor_alt_depth = Some(values[1..].iter().sum());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // Tumor Total Depth (DP)
|
|
|
|
|
+ Format::DP(value) => {
|
|
|
|
|
+ tumor_total_depth = Some(*value);
|
|
|
|
|
+ }
|
|
|
|
|
+ _ => {}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Return a tuple (tumor_alt_depth, tumor_total_depth) if both are available
|
|
|
|
|
+ match (tumor_alt_depth, tumor_total_depth) {
|
|
|
|
|
+ (Some(alt), Some(total)) => Some((alt, total)),
|
|
|
|
|
+ _ => None,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
impl TryFrom<(&str, &str)> for Formats {
|
|
impl TryFrom<(&str, &str)> for Formats {
|
|
|
type Error = anyhow::Error;
|
|
type Error = anyhow::Error;
|
|
|
|
|
|