Thomas hace 2 años
padre
commit
ad8c290ee8
Se han modificado 3 ficheros con 74 adiciones y 2 borrados
  1. 49 0
      Cargo.lock
  2. 2 0
      Cargo.toml
  3. 23 2
      src/lib.rs

+ 49 - 0
Cargo.lock

@@ -17,6 +17,23 @@ version = "1.0.80"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
 
+[[package]]
+name = "autocfg"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+
+[[package]]
+name = "average"
+version = "0.14.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d804c74bb2d66e9b7047658d21af0f1c937d7d2466410cbf1aed3b0c04048d4"
+dependencies = [
+ "easy-cast",
+ "float-ord",
+ "num-traits",
+]
+
 [[package]]
 name = "bio-types"
 version = "1.0.1"
@@ -98,6 +115,21 @@ dependencies = [
  "syn 1.0.109",
 ]
 
+[[package]]
+name = "easy-cast"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10936778145f3bea71fd9bf61332cce28c28e96a380714f7ab34838b80733fd6"
+dependencies = [
+ "libm",
+]
+
+[[package]]
+name = "float-ord"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d"
+
 [[package]]
 name = "form_urlencoded"
 version = "1.2.1"
@@ -181,6 +213,12 @@ version = "0.2.153"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
 
+[[package]]
+name = "libm"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
+
 [[package]]
 name = "libz-sys"
 version = "1.1.15"
@@ -226,6 +264,16 @@ dependencies = [
  "rustc_version",
 ]
 
+[[package]]
+name = "num-traits"
+version = "0.2.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
+dependencies = [
+ "autocfg",
+ "libm",
+]
+
 [[package]]
 name = "openssl-src"
 version = "300.2.3+3.2.1"
@@ -259,6 +307,7 @@ name = "pileup"
 version = "0.1.0"
 dependencies = [
  "anyhow",
+ "average",
  "rust-htslib",
 ]
 

+ 2 - 0
Cargo.toml

@@ -8,4 +8,6 @@ edition = "2021"
 [dependencies]
 rust-htslib = "0.46.0"
 anyhow = "^1.0.75"
+average = "0.14.1"
+
 

+ 23 - 2
src/lib.rs

@@ -1,12 +1,13 @@
-use anyhow::{Result, Ok, Context};
+use anyhow::{Context, Ok, Result};
+use rust_htslib::{bam, bam::Read};
 
+use average::Mean;
 pub fn get_hts_nt_pileup(
     bam: &mut rust_htslib::bam::IndexedReader,
     chr: &str,
     start: i32,
     with_next_ins: bool,
 ) -> Result<Vec<u8>> {
-    use rust_htslib::{bam, bam::Read};
     let stop = start + 1;
     let mut bases = Vec::new();
     bam.fetch((chr, start, stop))?;
@@ -93,3 +94,23 @@ pub fn hts_base_at(
     }
     Ok(None)
 }
+
+pub fn get_n_start(
+    bam: &mut rust_htslib::bam::IndexedReader,
+    chr: &str,
+    start: i32,
+    stop: i32,
+) -> Result<usize> {
+    bam.fetch((chr, start, stop))?;
+
+    let mut start_positions = Vec::new();
+    for read in bam.records() {
+        let record = read.context(format!("eRR"))?;
+        let rstart = record.pos() as i32;
+        if rstart >= start && rstart < stop {
+            start_positions.push(rstart);
+        }
+    }
+
+    Ok(start_positions.len())
+}