@@ -35,6 +35,7 @@ DEALINGS IN THE SOFTWARE. */
35
35
#include <assert.h>
36
36
#include <signal.h>
37
37
#include <inttypes.h>
38
+ #include <math.h>
38
39
39
40
// Suppress deprecation message for cigar_tab, which we initialise
40
41
#include "htslib/hts_defs.h"
@@ -4155,14 +4156,16 @@ struct __bam_plp_t {
4155
4156
void * data ;
4156
4157
olap_hash_t * overlaps ;
4157
4158
4158
- uint32_t depth [MAX_AHEAD ];
4159
- uint64_t last_depth_pos ;
4160
- double depth_pos_fract ;
4161
-
4162
4159
// For notification of creation and destruction events
4163
4160
// and associated client-owned pointer.
4164
4161
int (* plp_construct )(void * data , const bam1_t * b , bam_pileup_cd * cd );
4165
4162
int (* plp_destruct )(void * data , const bam1_t * b , bam_pileup_cd * cd );
4163
+
4164
+ // Field used for automatic depth reduction
4165
+ uint32_t depth [MAX_AHEAD ]; // circular depth buffer from b->core.pos on.
4166
+ uint64_t last_depth_pos ; // array filed out to this pos
4167
+ uint64_t max_depth_pos ; // >= max depth up to this pos
4168
+ double depth_pos_fract ; // (Simple method)
4166
4169
};
4167
4170
4168
4171
bam_plp_t bam_plp_init (bam_plp_auto_f func , void * data )
@@ -4519,10 +4522,12 @@ int bam_plp_push(bam_plp_t iter, const bam1_t *b)
4519
4522
return 0 ;
4520
4523
} else if (iter -> depth_pos_fract > 0
4521
4524
&& iter -> tid == b -> core .tid
4522
- && iter -> pos == b -> core . pos ) {
4525
+ && b -> core . pos - iter -> pos < 10 ) {
4523
4526
// Removal from depth somewhere else along read
4524
4527
endpos = bam_endpos (b );
4525
4528
uint32_t len = (uint32_t )(endpos - b -> core .pos - 1 );
4529
+
4530
+ #if 1
4526
4531
len = len * iter -> depth_pos_fract + 0.4999 ;
4527
4532
if (b -> core .pos + len < iter -> last_depth_pos
4528
4533
&& iter -> depth [(b -> core .pos + len )%MAX_AHEAD ] > iter -> maxcnt ) {
@@ -4532,6 +4537,28 @@ int bam_plp_push(bam_plp_t iter, const bam1_t *b)
4532
4537
overlap_remove (iter , b );
4533
4538
return 0 ;
4534
4539
}
4540
+ #else
4541
+ len = len * iter -> depth_pos_fract + 0.4999 ;
4542
+ if (len >= MAX_AHEAD ) len = MAX_AHEAD - 1 ;
4543
+ int64_t pos_delta = (b -> core .pos + len ) - iter -> max_depth_pos - 1 ;
4544
+ int last_depth = endpos > iter -> last_depth_pos
4545
+ ? 0
4546
+ : iter -> depth [(iter -> last_depth_pos - 1 )%MAX_AHEAD ];
4547
+ int pos_depth = iter -> depth [b -> core .pos % MAX_AHEAD ];
4548
+
4549
+ #ifndef MIN
4550
+ #define MIN (a ,b ) ((a)<(b)?(a):(b))
4551
+ #endif
4552
+
4553
+ if (drand48 () >
4554
+ //(double)h / 0xffffffff >
4555
+ MIN (1.0 , pow ((double )pos_delta / (len + .01 ), 2 ))
4556
+ * MIN (1.0 , pow ((1 - (last_depth + .1 )/iter -> maxcnt ), 2 ))
4557
+ * MIN (1.0 , pow ((iter -> maxcnt + .1 )/pos_depth , 2 )) * 2 ) {
4558
+ overlap_remove (iter , b );
4559
+ return 0 ;
4560
+ }
4561
+ #endif
4535
4562
4536
4563
// Zero newly observed iter depth elemtns.
4537
4564
uint64_t end_clipped = endpos , p ;
@@ -4547,8 +4574,11 @@ int bam_plp_push(bam_plp_t iter, const bam1_t *b)
4547
4574
}
4548
4575
4549
4576
// Increment depth
4550
- for (p = b -> core .pos ; p < end_clipped ; p ++ )
4551
- iter -> depth [p % MAX_AHEAD ]++ ;
4577
+ for (p = b -> core .pos ; p < end_clipped ; p ++ ) {
4578
+ if (++ iter -> depth [p % MAX_AHEAD ] >= iter -> maxcnt )
4579
+ if (iter -> max_depth_pos < p )
4580
+ iter -> max_depth_pos = p ;
4581
+ }
4552
4582
}
4553
4583
if (bam_copy1 (& iter -> tail -> b , b ) == NULL )
4554
4584
return -1 ;
0 commit comments