|
|
@@ -1,17 +1,37 @@
|
|
|
-use std::num::NonZeroI32;
|
|
|
-use minimap2::{Alignment, Strand, Mapping};
|
|
|
-use serde::{Serialize, Deserialize};
|
|
|
+use minimap2::{Alignment, Mapping, Strand};
|
|
|
+use serde::{Deserialize, Serialize};
|
|
|
use serde_nested_with::serde_nested;
|
|
|
+use std::num::NonZeroI32;
|
|
|
+use tokio::runtime::Builder;
|
|
|
+use anyhow::Result;
|
|
|
|
|
|
-pub async fn get_mappings(url: &str, sequence: String) -> Result<Mappings, Box<dyn std::error::Error>> {
|
|
|
+pub fn get_mappings(
|
|
|
+ url: &str,
|
|
|
+ sequence: String,
|
|
|
+) -> Result<Vec<Mapping>> {
|
|
|
+ let runtime = Builder::new_multi_thread()
|
|
|
+ .worker_threads(1)
|
|
|
+ .enable_all()
|
|
|
+ .build()?;
|
|
|
+ let res = runtime.block_on(get_mappings_async(url.to_string(), sequence))?;
|
|
|
+ // let handle = runtime.spawn(get_mappings_async(url.to_string(), sequence));
|
|
|
+ // let res = runtime.block_on(handle)??;
|
|
|
+
|
|
|
+ Ok(res)
|
|
|
+}
|
|
|
+
|
|
|
+pub async fn get_mappings_async(
|
|
|
+ url: String,
|
|
|
+ sequence: String,
|
|
|
+) -> Result<Vec<Mapping>> {
|
|
|
let client = reqwest::Client::new();
|
|
|
- let url = reqwest::Url::parse(url)?;
|
|
|
+ let url = reqwest::Url::parse(&url).unwrap();
|
|
|
|
|
|
- let response = client.post(url).body(sequence).send().await?;
|
|
|
- let response_body = response.text().await?;
|
|
|
- let mappings: Mappings = serde_json::from_str(&response_body)?;
|
|
|
+ let response = client.post(url).body(sequence).send().await.unwrap();
|
|
|
+ let response_body = response.text().await.unwrap();
|
|
|
+ let mappings: Mappings = serde_json::from_str(&response_body).unwrap();
|
|
|
|
|
|
- Ok(mappings)
|
|
|
+ Ok(mappings.inner)
|
|
|
}
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
@@ -67,15 +87,18 @@ pub struct Mappings {
|
|
|
pub inner: Vec<Mapping>,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use super::*;
|
|
|
|
|
|
- #[tokio::test]
|
|
|
- async fn it_works() {
|
|
|
- let mut mappings = get_mappings("http://localhost:4444/align", "ACCAAAACACATATTCACGGCAGCCACTCCACCCAGCACCTCaca".to_string()).await.unwrap();
|
|
|
- let mapping = mappings.inner.pop().unwrap();
|
|
|
+ #[test]
|
|
|
+ fn it_works() {
|
|
|
+ let mut mappings = get_mappings(
|
|
|
+ "http://localhost:4444/align",
|
|
|
+ "ACCAAAACACATATTCACGGCAGCCACTCCACCCAGCACCTCaca".to_string(),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
+ let mapping = mappings.pop().unwrap();
|
|
|
assert_eq!(mapping.target_name.unwrap(), "chr6".to_string());
|
|
|
}
|
|
|
}
|