From 56ca8ce910e7d3e669e681aaa17f01e1ef46f839 Mon Sep 17 00:00:00 2001
From: Laurent Modolo <laurent.modolo@ens-lyon.fr>
Date: Mon, 18 Dec 2023 10:50:05 +0100
Subject: [PATCH] read.rs: fix bug leading to empty bam

---
 src/read.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/read.rs b/src/read.rs
index e6a4f92..75c3cb7 100644
--- a/src/read.rs
+++ b/src/read.rs
@@ -118,7 +118,7 @@ impl Fragments {
     pub fn next_chr(&mut self) {
         loop {
             self.get_chr();
-            if !self.check_name() {
+            if self.check_name() {
                 break;
             }
         }
@@ -141,7 +141,7 @@ impl Fragments {
         while self.chr_id < chr_id {
             self.next_chr();
         }
-        if chr_pos > self.chr_seq.len() as u32 - self.fragment_len {
+        if chr_pos > self.chr_seq.len() as u32 {
             panic!(
                 "Fragments::get_single() pos {} not present in chromosome {}:{} of size {}",
                 chr_pos,
@@ -171,7 +171,7 @@ impl Fragments {
         while self.chr_id < chr_id {
             self.next_chr();
         }
-        if chr_pos >= self.chr_seq.len() as u32 - self.fragment_len {
+        if chr_pos >= self.chr_seq.len() as u32 {
             panic!(
                 "Fragments::get() pos {} not present in chromosome {} of size {}",
                 chr_pos,
@@ -306,7 +306,7 @@ impl Read {
     /// # Return
     /// String
     fn build_name(read_number: u64, paired: bool, first: bool) -> String {
-        let mut read_name = String::from("bigwig2bam:0:0:0:");
+        let mut read_name = String::from("bigwig2bam:0:1:3:");
         read_name.push_str(&read_number.to_string());
         if paired {
             if first {
-- 
GitLab