|
|
@@ -280,46 +280,101 @@ impl VcfVariant {
|
|
|
pub fn bnd_desc(&self) -> anyhow::Result<BNDDesc> {
|
|
|
let alt = self.alternative.to_string();
|
|
|
if alt.contains('[') || alt.contains(']') {
|
|
|
- let b_sens = alt.contains('[');
|
|
|
-
|
|
|
- let a_sens = if b_sens {
|
|
|
- !alt.starts_with('[')
|
|
|
+ let extending_right = alt.contains('[');
|
|
|
+ let alt_rep = alt.replace("[", ";").replace("]", ";");
|
|
|
+ let alt_is_joined_after = !alt_rep.starts_with(";");
|
|
|
+ let parts = alt_rep
|
|
|
+ .split(";")
|
|
|
+ .filter(|c| !c.is_empty())
|
|
|
+ .collect::<Vec<&str>>();
|
|
|
+
|
|
|
+ if alt_is_joined_after {
|
|
|
+ // a is ref b is alt
|
|
|
+ let a_sens = true;
|
|
|
+ let a_contig = self.position.contig();
|
|
|
+ let a_position = self.position.position + 1;
|
|
|
+
|
|
|
+ let added_nt = parts[0][1..].to_string();
|
|
|
+
|
|
|
+ let b_sens = alt.contains('[');
|
|
|
+ let (contig, pos) = parts[1].split_once(':').unwrap();
|
|
|
+ let b_contig = contig.to_string();
|
|
|
+ let b_position: u32 = pos.parse()?;
|
|
|
+
|
|
|
+ Ok(BNDDesc {
|
|
|
+ a_contig,
|
|
|
+ a_position,
|
|
|
+ a_sens,
|
|
|
+ b_contig,
|
|
|
+ b_position,
|
|
|
+ b_sens,
|
|
|
+ added_nt,
|
|
|
+ })
|
|
|
} 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:?}"));
|
|
|
+ // a is alt b is ref
|
|
|
+ let b_sens = true;
|
|
|
+ let b_contig = self.position.contig();
|
|
|
+ let b_position = self.position.position + 1;
|
|
|
+
|
|
|
+ let mut added_nt = parts[1].to_string();
|
|
|
+ added_nt.pop();
|
|
|
+
|
|
|
+ let a_sens = alt.contains(']');
|
|
|
+ let (contig, pos) = parts[0].split_once(':').unwrap();
|
|
|
+ let a_contig = contig.to_string();
|
|
|
+ let a_position: u32 = pos.parse()?;
|
|
|
+
|
|
|
+ Ok(BNDDesc {
|
|
|
+ a_contig,
|
|
|
+ a_position,
|
|
|
+ a_sens,
|
|
|
+ b_contig,
|
|
|
+ b_position,
|
|
|
+ b_sens,
|
|
|
+ added_nt,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- 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,
|
|
|
- })
|
|
|
+ // 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 {
|
|
|
Err(anyhow::anyhow!("The alteration is not BND: {alt}"))
|
|
|
}
|