Thomas 1 year ago
parent
commit
2ab0cdc199
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/lib.rs

+ 14 - 1
src/lib.rs

@@ -88,7 +88,8 @@ impl Blast {
     }
 
     pub fn to_mapping(self) -> Option<Vec<Mapping>> {
-        self.results.map(|res| res.iter().map(Mapping::from).collect())
+        self.results
+            .map(|res| res.iter().map(Mapping::from).collect())
     }
 
     pub fn to_json(self) -> anyhow::Result<String> {
@@ -216,6 +217,18 @@ impl BlastResult {
             ..s
         }
     }
+
+    pub fn to_bed(&self) -> String {
+        let info = format!("{}:{}-{}", self.subject_id, self.s_start, self.s_end);
+        [
+            self.query_id.to_string(),
+            self.q_start.to_string(),
+            self.q_end.to_string(),
+            info,
+        ]
+        .join("\t")
+        .to_string()
+    }
 }
 
 #[derive(Debug)]