Skip to content

Commit 729ed9d

Browse files
ghulsJakob37
andauthored
Fix off by one bug when converting BAM files to d4 files. (#97)
* Fix off by one bug when converting BAM files to d4 files. Fix off by one bug when converting BAM files to d4 files. Fixes: #75 * First iteration adding d4tools create tests * Make sure the tests are in order --------- Co-authored-by: Jakob Willforss <[email protected]>
1 parent ce8a1ab commit 729ed9d

File tree

11 files changed

+78
-57
lines changed

11 files changed

+78
-57
lines changed

d4-hts/src/alignment/alignment_ext.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ impl<'a> Alignment<'a> {
2929
}
3030

3131
pub fn ref_end(&self) -> usize {
32-
self.ref_begin() + self.ref_len()
32+
// d4 uses 0-based closed interval end coordinate.
33+
self.ref_begin() + self.ref_len() - 1
3334
}
3435

3536
pub fn ref_id(&self) -> i32 {

d4-hts/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ impl<'a, R: AlignmentReader<'a>> Iterator for DepthIter<'a, R> {
5454
return None;
5555
}
5656

57-
let ret = (self.cur_chrom, self.cur_pos, self.heap.len() as u32);
58-
59-
self.cur_pos += 1;
6057

6158
while let Some((tid, left, right)) = self.next_read {
6259
if tid != self.cur_chrom {
@@ -77,6 +74,10 @@ impl<'a, R: AlignmentReader<'a>> Iterator for DepthIter<'a, R> {
7774
self.heap.pop();
7875
}
7976

77+
let ret = (self.cur_chrom, self.cur_pos, self.heap.len() as u32);
78+
79+
self.cur_pos += 1;
80+
8081
Some(ret)
8182
}
8283
}

d4tools/test/create/from-bam/output.txt

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,56 @@
55
1 10001 10002 55
66
1 10002 10003 72
77
1 10003 10004 93
8-
1 10004 10044 94
9-
1 10044 10046 93
10-
1 10046 10047 91
11-
1 10047 10048 90
12-
1 10048 10057 89
13-
1 10057 10059 88
14-
1 10059 10061 87
15-
1 10061 10062 86
16-
1 10062 10063 85
17-
1 10063 10064 83
18-
1 10064 10065 82
19-
1 10065 10068 78
20-
1 10068 10069 77
21-
1 10069 10071 75
22-
1 10071 10073 74
23-
1 10073 10074 71
24-
1 10074 10080 70
25-
1 10080 10081 69
26-
1 10081 10084 68
27-
1 10084 10085 67
28-
1 10085 10088 66
29-
1 10088 10089 65
30-
1 10089 10092 64
31-
1 10092 10094 62
32-
1 10094 10095 60
33-
1 10095 10102 59
34-
1 10102 10103 58
35-
1 10103 10104 54
36-
1 10104 10105 53
37-
1 10105 10106 52
38-
1 10106 10107 51
39-
1 10107 10109 49
40-
1 10109 10111 47
41-
1 10111 10113 42
42-
1 10113 10114 41
43-
1 10114 10120 36
44-
1 10120 10121 34
45-
1 10121 10126 31
46-
1 10126 10131 29
47-
1 10131 10132 28
48-
1 10132 10137 27
49-
1 10137 10138 25
50-
1 10138 10139 23
51-
1 10139 10142 21
52-
1 10142 10144 20
53-
1 10144 10146 17
54-
1 10146 10147 15
55-
1 10147 10148 14
56-
1 10148 10149 11
57-
1 10149 10150 4
58-
1 10150 10151 3
59-
1 10151 10158 1
60-
1 10158 20000 0
8+
1 10004 10043 94
9+
1 10043 10045 93
10+
1 10045 10046 91
11+
1 10046 10047 90
12+
1 10047 10056 89
13+
1 10056 10058 88
14+
1 10058 10060 87
15+
1 10060 10061 86
16+
1 10061 10062 85
17+
1 10062 10063 83
18+
1 10063 10064 82
19+
1 10064 10067 78
20+
1 10067 10068 77
21+
1 10068 10070 75
22+
1 10070 10072 74
23+
1 10072 10073 71
24+
1 10073 10079 70
25+
1 10079 10080 69
26+
1 10080 10083 68
27+
1 10083 10084 67
28+
1 10084 10087 66
29+
1 10087 10088 65
30+
1 10088 10091 64
31+
1 10091 10093 62
32+
1 10093 10094 60
33+
1 10094 10101 59
34+
1 10101 10102 58
35+
1 10102 10103 54
36+
1 10103 10104 53
37+
1 10104 10105 52
38+
1 10105 10106 51
39+
1 10106 10108 49
40+
1 10108 10110 47
41+
1 10110 10112 42
42+
1 10112 10113 41
43+
1 10113 10119 36
44+
1 10119 10120 34
45+
1 10120 10125 31
46+
1 10125 10130 29
47+
1 10130 10131 28
48+
1 10131 10136 27
49+
1 10136 10137 25
50+
1 10137 10138 23
51+
1 10138 10141 21
52+
1 10141 10143 20
53+
1 10143 10145 17
54+
1 10145 10146 15
55+
1 10146 10147 14
56+
1 10147 10148 11
57+
1 10148 10149 4
58+
1 10149 10150 3
59+
1 10150 10157 1
60+
1 10157 20000 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${D4TOOLS} create --mapping-qual 0 multi_reads_multi_chr.bam ${OUTDIR}/multi_reads_multi_chr.d4 && ${D4TOOLS} view ${OUTDIR}/multi_reads_multi_chr.d4
Binary file not shown.
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
chr1 0 4 2
2+
chr1 4 14 3
3+
chr1 14 18 2
4+
chr1 18 26 3
5+
chr1 26 30 2
6+
chr2 0 14 3
7+
chr2 14 15 2
8+
chr2 15 19 0
9+
chr2 19 22 1
10+
chr2 22 23 2
11+
chr2 23 25 3
12+
chr2 25 38 4
13+
chr2 38 39 3
14+
chr2 39 40 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${D4TOOLS} create --mapping-qual 0 single_read.bam ${OUTDIR}/single_read.d4 && ${D4TOOLS} view ${OUTDIR}/single_read.d4
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
chr1 0 4 0
2+
chr1 4 25 1
3+
chr1 25 30 0
96 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)