Thomas 1 рік тому
батько
коміт
216553e806
3 змінених файлів з 807 додано та 87 видалено
  1. 788 28
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 18 59
      src/lib.rs

Різницю між файлами не показано, бо вона завелика
+ 788 - 28
Cargo.lock


+ 1 - 0
Cargo.toml

@@ -8,6 +8,7 @@ edition = "2021"
 [dependencies]
 env_logger = "^0.10.1"
 minimap2 = { git = "https://github.com/jguhlin/minimap2-rs", features = ["htslib", "simde"]}
+aligner_client = { git = "https://git.t0m4.fr/Thomas/aligner_client.git"}
 rust-htslib = "0.46.0"
 anyhow = "1.0.75"
 log = "0.4.19"

+ 18 - 59
src/lib.rs

@@ -9,7 +9,7 @@ use std::{
     fs::{self, File},
     io::{BufReader, BufWriter, Write},
     process::{Command, Stdio},
-    thread
+    thread,
 };
 use uuid::Uuid;
 
@@ -193,6 +193,7 @@ pub fn get_ref_pos(mappings: Vec<Mapping>) -> Result<ContigRef> {
         return Ok(ContigRef::Unique(mappings.get(0).unwrap().clone()));
     } else {
         let mut grouped: VecDeque<Vec<Mapping>> = group_mappings(&mut mappings)?.into();
+        println!("{grouped:?}");
 
         if grouped.len() == 1 {
             let r = grouped.into_iter().flat_map(|e| e).collect();
@@ -223,6 +224,7 @@ pub fn get_ref_pos(mappings: Vec<Mapping>) -> Result<ContigRef> {
                 }
             }
             if first.len() == 1 && last.len() == 1 {
+                println!("bim");
                 if grouped.len() == 1 {
                     return Ok(ContigRef::ChimericTriple((
                         first.get(0).unwrap().clone(),
@@ -383,11 +385,9 @@ impl Genome {
         &mut self,
         name: String,
         sequence: &Vec<u8>,
-        aligner: &Aligner,
+        aligner: impl Fn(String) -> Result<Vec<Mapping>>,
     ) -> Result<()> {
-        let mappings = aligner
-            .map(sequence, false, false, None, None)
-            .expect("Unable to align");
+        let mappings = aligner(String::from_utf8(sequence.to_vec())?)?;
         self.add_contig(name, mappings, None, String::from_utf8(sequence.to_vec())?)?;
         Ok(())
     }
@@ -711,46 +711,11 @@ pub fn read_fasta(path: &str) -> Result<Vec<(String, Vec<u8>)>> {
 
     Ok(res)
 }
-use crossbeam_channel::{unbounded, Receiver, Sender};
 
-pub fn spawn_aligner(reference: String, mmi: Option<String>) -> (Sender<Option<Vec<u8>>>, Receiver<(Vec<u8>, Vec<Mapping>)>) {
-    println!("kkkkkkkkkk");
-    let reference = reference.clone();
-    let mmi = mmi.clone();
-    let (thread_s, out_r) = unbounded::<(Vec<u8>, Vec<Mapping>)>();
-    let (out_s, thread_r) = unbounded::<Option<Vec<u8>>>();
-
-    thread::spawn(move || {
-        println!("Thread spawned");
-        let aligner = Aligner::builder()
-            .map_ont()
-            .with_threads(8)
-            .with_cigar()
-            .with_index(reference, mmi.as_deref())
-            .expect("Unable to build index");
-
-         println!("aligner spawned");
-
-
-        loop {
-            if let std::result::Result::Ok(seq) = thread_r.recv() {
-                println!("rec");
-                match seq {
-                    Some(seq) => {
-                        let mappings = aligner
-                            .map(&seq, false, false, None, None)
-                            .expect("Unable to align");
-                        let _ = thread_s.send((seq, mappings));
-                    }
-                    None => break,
-                }
-            }
-        }
-    });
-
-    println!("Out");
-
-    return (out_s, out_r);
+pub fn dist_align(url: String) -> impl Fn(String) -> Result<Vec<Mapping>> {
+    move |sequence: String| -> Result<Vec<Mapping>> {
+        aligner_client::get_mappings(url.as_str(), sequence)
+    }
 }
 
 #[cfg(test)]
@@ -758,31 +723,25 @@ mod tests {
     use super::*;
     use test_log::test;
 
-
     #[test_log::test]
     fn it_works() -> Result<()> {
         let _ = env_logger::builder().is_test(true).try_init();
         let contig_fa = "./data_test/contig_1.fa";
-
-        let reference = "/data/ref/hs1/chm13v2.0.fa";
-        let mmi_path = "/data/ref/hs1/hs1-ont.mmi".to_string();
-        let mmi = Some("/data/ref/hs1/hs1-ont.mmi");
+        let aligner_url = "http://localhost:4444/align";
 
         let mut genome = Genome::new();
-        let (s, r) =  spawn_aligner(reference.to_string(), Some(mmi_path.to_string()));
+        let aligner = dist_align(aligner_url.to_string());
 
         let sequences = read_fasta(contig_fa)?;
         for (name, seq) in sequences {
-            println!("Sending to thread");
-            s.send(Some(seq)).unwrap();
-            // genome.add_contig_from_seq(name, &seq, &aligner)?;
+            genome.add_contig_from_seq(name, &seq, &aligner)?;
+            println!("Sending");
         }
-
-        while let std::result::Result::Ok(res) = r.recv() {
-            println!("Recived {:?}", res);
-        }
-
-        s.send(None)?;
+        genome.iter().for_each(|(n, c)| {
+            c.iter().for_each(|cont| {
+                println!("{}", cont.contig_ref);
+            });
+        });
 
         Ok(())
     }

Деякі файли не було показано, через те що забагато файлів було змінено