Skip to content

Commit c7c55bd

Browse files
committed
Merge branch 'hotfix/v2.1.1'
2 parents 41a5926 + df4ada7 commit c7c55bd

7 files changed

Lines changed: 36 additions & 40 deletions

File tree

c/bam_access.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ rg_info_t **bam_access_parse_header(bam_hdr_t *head, int *grps_size, stats_rd_t
129129
(*grp_stats)[j][0]->divergent= 0;
130130
(*grp_stats)[j][0]->mapped_bases= 0;
131131
(*grp_stats)[j][0]->proper= 0;
132+
(*grp_stats)[j][0]->mapped_pairs= 0;
133+
(*grp_stats)[j][0]->inter_chr_pairs= 0;
132134
(*grp_stats)[j][0]->inserts = kh_init(ins);
133135
(*grp_stats)[j][1] = (stats_rd_t *)malloc(sizeof(stats_rd_t));//Setup read two stats store
134136
check_mem((*grp_stats)[j][1]);
@@ -207,13 +209,9 @@ int bam_access_process_reads(htsFile *input, bam_hdr_t *head, rg_info_t **grps,
207209
uint32_t nm_val = bam_aux2i(nm);
208210
if(nm_val>0){
209211
(*grp_stats)[rg_index][read]->divergent += nm_val;
210-
(*grp_stats)[rg_index][read]->mapped_bases += bam_access_get_mapped_base_count_from_cigar(b);
211-
}else{
212-
(*grp_stats)[rg_index][read]->mapped_bases += (bam_endpos(b) - b->core.pos) + 1;
213212
}
214-
}else{
215-
(*grp_stats)[rg_index][read]->mapped_bases += bam_access_get_mapped_base_count_from_cigar(b);
216213
}
214+
(*grp_stats)[rg_index][read]->mapped_bases += bam_access_get_mapped_base_count_from_cigar(b);
217215

218216
// stats that only assess read 1
219217
if(b->core.flag & BAM_FREAD1) {

c/c_tests/02_bam_access_tests.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,31 @@ char *exp_platform_unit_2 = "5085_6";
6363
uint32_t exp_rd_length = 20;
6464
uint64_t exp_rg1_rd1_tot_count = 7;
6565
uint64_t exp_rg1_rd2_tot_count = 3;
66-
uint64_t exp_rg2_rd1_tot_count = 3;
67-
uint64_t exp_rg2_rd2_tot_count = 3;
66+
uint64_t exp_rg2_rd1_tot_count = 4;
67+
uint64_t exp_rg2_rd2_tot_count = 4;
6868
uint64_t exp_rg1_rd1_dups = 4;
6969
uint64_t exp_rg1_rd2_dups = 0;
7070
uint64_t exp_rg2_rd1_dups = 0;
7171
uint64_t exp_rg2_rd2_dups = 0;
7272
uint64_t exp_rg1_rd1_gc = 63;
7373
uint64_t exp_rg1_rd2_gc = 27;
74-
uint64_t exp_rg2_rd1_gc = 27;
75-
uint64_t exp_rg2_rd2_gc = 27;
74+
uint64_t exp_rg2_rd1_gc = 71;
75+
uint64_t exp_rg2_rd2_gc = 74;
7676
uint64_t exp_rg1_rd1_umap = 1;
7777
uint64_t exp_rg1_rd2_umap = 1;
7878
uint64_t exp_rg2_rd1_umap = 2;
7979
uint64_t exp_rg2_rd2_umap = 2;
8080
uint64_t exp_rg1_rd1_divergent = 30;
8181
uint64_t exp_rg1_rd2_divergent = 18;
82-
uint64_t exp_rg2_rd1_divergent = 11;
82+
uint64_t exp_rg2_rd1_divergent = 12;
8383
uint64_t exp_rg2_rd2_divergent = 12;
8484
uint64_t exp_rg1_rd1_mapped_bases = 115;
8585
uint64_t exp_rg1_rd2_mapped_bases = 37;
86-
uint64_t exp_rg2_rd1_mapped_bases = 20;
87-
uint64_t exp_rg2_rd2_mapped_bases = 20;
86+
uint64_t exp_rg2_rd1_mapped_bases = 95;
87+
uint64_t exp_rg2_rd2_mapped_bases = 95;
8888
uint64_t exp_rg1_rd1_proper = 6;
8989
uint64_t exp_rg1_rd2_proper = 0;
90-
uint64_t exp_rg2_rd1_proper = 1;
90+
uint64_t exp_rg2_rd1_proper = 2;
9191
uint64_t exp_rg2_rd2_proper = 0;
9292

9393
char err[100];
@@ -338,22 +338,22 @@ char *test_bam_access_process_reads_rna(){ // rna flag in this method includes s
338338
}
339339
//Duplicate reads 1
340340
if(grp_stats[1][0]->dups!=exp_rg2_rd1_dups){
341-
sprintf(err,"RG 1, read_1 duplicate count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd1_dups,grp_stats[1][0]->dups);
341+
sprintf(err,"RG 2, read_1 duplicate count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd1_dups,grp_stats[1][0]->dups);
342342
return err;
343343
}
344344
//Duplicate reads 2
345345
if(grp_stats[1][1]->dups!=exp_rg2_rd2_dups){
346-
sprintf(err,"RG 1, read_2 duplicate count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd2_dups,grp_stats[1][1]->dups);
346+
sprintf(err,"RG 2, read_2 duplicate count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd2_dups,grp_stats[1][1]->dups);
347347
return err;
348348
}
349349
//GC 1
350350
if(grp_stats[1][0]->gc!=exp_rg2_rd1_gc){
351-
sprintf(err,"RG 1, read_1 gc count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd1_gc,grp_stats[1][0]->gc);
351+
sprintf(err,"RG 2, read_1 gc count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd1_gc,grp_stats[1][0]->gc);
352352
return err;
353353
}
354354
//GC 2
355355
if(grp_stats[1][1]->gc!=exp_rg2_rd2_gc){
356-
sprintf(err,"RG 1, read_2 gc count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd2_gc,grp_stats[1][1]->gc);
356+
sprintf(err,"RG 2, read_2 gc count incorrect. Expected %"PRIu64" but got %"PRIu64"\n",exp_rg2_rd2_gc,grp_stats[1][1]->gc);
357357
return err;
358358
}
359359
//Unmapped 1

lib/PCAP/Bam/Stats.pm

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,11 @@ sub _process_reads {
210210
if(defined $nm) {
211211
if($nm > 0) {
212212
$rg_ref->{'total_divergent_bases_'.$read} += $nm;
213-
my @increments = $a->cigar_str =~ m/([[:digit:]]+)[IMX=]/g;
214-
$rg_ref->{'total_mapped_bases_'.$read} += sum0 @increments;
215213
}
216-
else {
217-
$rg_ref->{'total_mapped_bases_'.$read} += ($a->calend - $a->pos) + 1;
218-
}
219-
}
220-
else {
221-
my @increments = $a->cigar_str =~ m/([[:digit:]]+)[IMX=]/g;
222-
$rg_ref->{'total_mapped_bases_'.$read} += sum0 @increments;
223214
}
215+
my @increments = $a->cigar_str =~ m/([[:digit:]]+)[IMX=]/g;
216+
$rg_ref->{'total_mapped_bases_'.$read} += sum0 @increments;
217+
224218
# calculate mapped seq from cigar
225219

226220
# stats that only assess read 1

t/data/Stats.bam

246 Bytes
Binary file not shown.

t/data/Stats.bam.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bam_filename sample platform platform_unit library readgroup read_length_r1 read_length_r2 #_mapped_bases #_mapped_bases_r1 #_mapped_bases_r2 #_divergent_bases #_divergent_bases_r1 #_divergent_bases_r2 #_total_reads #_total_reads_r1 #_total_reads_r2 #_mapped_reads #_mapped_reads_r1 #_mapped_reads_r2 #_mapped_reads_properly_paired #_gc_bases_r1 #_gc_bases_r2 mean_insert_size insert_size_sd median_insert_size #_duplicate_reads #_mapped_pairs #_inter_chr_pairs
22
Stats.bam PD1234a GAII 5178_6 PD1234a 140546_1054 29976 20 20 152 115 37 48 30 18 10 7 3 8 6 2 6 63 27 195.833 119.388 125.000 4 6 0
3-
Stats.bam PD1234a GAII 5085_6 PD1234a 140546_1054 29978 20 20 40 20 20 23 11 12 6 3 3 2 1 1 1 27 27 100.000 0.000 100.000 0 1 0
3+
Stats.bam PD1234a GAII 5085_6 PD1234a 140546_1054 29978 20 20 190 95 95 24 12 12 8 4 4 4 2 2 2 71 74 545.500 445.500 545.500 0 2 0
44
Stats.bam PD1234a GAII 5086_6 PD1234a 140546_1054 29979 20 20 120 60 60 0 0 0 6 3 3 6 3 3 1 27 27 100.000 0.000 100.000 0 3 1

t/data/Stats.c.bam.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bam_filename sample platform platform_unit library readgroup read_length_r1 read_length_r2 #_mapped_bases #_mapped_bases_r1 #_mapped_bases_r2 #_divergent_bases #_divergent_bases_r1 #_divergent_bases_r2 #_total_reads #_total_reads_r1 #_total_reads_r2 #_mapped_reads #_mapped_reads_r1 #_mapped_reads_r2 #_mapped_reads_properly_paired #_gc_bases_r1 #_gc_bases_r2 mean_insert_size insert_size_sd median_insert_size #_duplicate_reads #_mapped_pairs #_inter_chr_pairs
22
Stats.bam PD1234a GAII 5178_6 PD1234a 140546_1054 29976 20 20 152 115 37 48 30 18 10 7 3 8 6 2 6 63 27 195.833 119.387 125.000 4 6 0
3-
Stats.bam PD1234a GAII 5085_6 PD1234a 140546_1054 29978 20 20 40 20 20 23 11 12 6 3 3 2 1 1 1 27 27 100.000 0.000 100.000 0 1 0
3+
Stats.bam PD1234a GAII 5085_6 PD1234a 140546_1054 29978 20 20 190 95 95 24 12 12 8 4 4 4 2 2 2 71 74 545.500 445.500 545.500 0 2 0
44
Stats.bam PD1234a GAII 5086_6 PD1234a 140546_1054 29979 20 20 120 60 60 0 0 0 6 3 3 6 3 3 1 27 27 100.000 0.000 100.000 0 3 1

t/pcapBamStats.t

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ subtest 'Object funcions' => sub {
121121
subtest 'calc_frac_' => sub {
122122
my $test_obj = _create_test_object();
123123

124-
is(sprintf('%.4f',$test_obj->calc_frac_properly_paired()),'0.6154','calc_frac_properly_paired');
125-
is(sprintf('%.4f',$test_obj->calc_frac_unmapped()),'0.2727','calc_frac_unmapped');
126-
is(sprintf('%.4f',$test_obj->calc_frac_duplicate_reads()),'0.1818','calc_frac_duplicate_reads');
124+
is(sprintf('%.4f',$test_obj->calc_frac_properly_paired()),'0.6429','calc_frac_properly_paired');
125+
is(sprintf('%.4f',$test_obj->calc_frac_unmapped()),'0.2500','calc_frac_unmapped');
126+
is(sprintf('%.4f',$test_obj->calc_frac_duplicate_reads()),'0.1667','calc_frac_duplicate_reads');
127127
};
128128

129129
subtest 'med_insert_size' => sub {
@@ -135,39 +135,39 @@ subtest 'Object funcions' => sub {
135135
subtest 'mean_insert_size' => sub {
136136
my $test_obj = _create_test_object();
137137

138-
is(sprintf('%.4f',$test_obj->mean_insert_size()),'171.8750','mean_insert_size');
138+
is(sprintf('%.4f',$test_obj->mean_insert_size()),'262.8889','mean_insert_size');
139139
};
140140

141141
subtest 'properly_mapped_ratio' => sub {
142142
my $test_obj = _create_test_object();
143-
is(sprintf('%.4f',$test_obj->properly_mapped_ratio()),'0.6154','properly_mapped_ratio');
143+
is(sprintf('%.4f',$test_obj->properly_mapped_ratio()),'0.6429','properly_mapped_ratio');
144144
};
145145

146146
subtest '_count_' => sub {
147147
my $test_obj = _create_test_object();
148148

149-
is($test_obj->count_total_reads(1),13,'count_total_reads read1');
150-
is($test_obj->count_total_reads(2),9,'count_total_reads read2');
149+
is($test_obj->count_total_reads(1),14,'count_total_reads read1');
150+
is($test_obj->count_total_reads(2),10,'count_total_reads read2');
151151

152-
is($test_obj->count_properly_paired(),8,'count_properly_paired');
152+
is($test_obj->count_properly_paired(),9,'count_properly_paired');
153153

154154
is($test_obj->count_unmapped(1),3,'count_unmapped read1');
155155
is($test_obj->count_unmapped(2),3,'count_unmapped read2');
156156

157157
is($test_obj->count_duplicate_reads(1),4,'count_duplicate_reads read1');
158158
is($test_obj->count_duplicate_reads(2),0,'count_duplicate_reads read2');
159159

160-
is($test_obj->count_total_mapped_bases(1),195,'count_total_mapped_bases read1');
161-
is($test_obj->count_total_mapped_bases(2),117,'count_total_mapped_bases read2');
160+
is($test_obj->count_total_mapped_bases(1),270,'count_total_mapped_bases read1');
161+
is($test_obj->count_total_mapped_bases(2),192,'count_total_mapped_bases read2');
162162

163-
is($test_obj->count_total_divergent_bases(1),41,'count_total_divergent_bases read1');
163+
is($test_obj->count_total_divergent_bases(1),42,'count_total_divergent_bases read1');
164164
is($test_obj->count_total_divergent_bases(2),30,'count_total_divergent_bases read2');
165165
};
166166

167167
subtest 'cal_insert_size_sd' => sub {
168168
my $test_obj = _create_test_object();
169169

170-
is(sprintf('%.4f',$test_obj->cal_insert_size_sd()),'111.4096','cal_insert_size_sd');
170+
is(sprintf('%.4f',$test_obj->cal_insert_size_sd()),'278.0310','cal_insert_size_sd');
171171
};
172172

173173
};
@@ -285,3 +285,7 @@ IL29_5086:6:35:17751:10873 129 1 9993 0 20M = 9993 -100 CTCTTCCGATCTTTAGGGTT ;?;
285285
# non-proper, inter-chr
286286
IL29_5086:6:35:17751:10874 65 1 9993 0 20M X 9993 0 CTCTTCCGATCTTTAGGGTT ;?;??>>>>F<BBDEBEEFF RG:Z:29979
287287
IL29_5086:6:35:17751:10874 129 X 9993 0 20M 1 9993 0 CTCTTCCGATCTTTAGGGTT ;?;??>>>>F<BBDEBEEFF RG:Z:29979
288+
289+
## Checks that mapped bases don't get corrupt when padding values are introduced, normally RNA issue:
290+
HS20_13617:3:1315:4901:63745 163 1 12670 255 52M761N23M = 13586 991 GACGACGGCCGACTTGGATCACACTCTTGTGAGTGTCCCCAGTGTTGCAGAGGCAGCTGCACCACTGCCTGGCGC CCCFFFFFHHHHHJJJJJJJJJJJJJJJIGIHJDHGIJJJIJGHIIIJHHHHFFFFDEEEDDDDDDDDDDDDDDB NH:i:1 HI:i:1 NM:i:0 MD:Z:75 AS:i:146 XS:A:+ RG:Z:29978
291+
HS20_13617:3:1315:4901:63745 83 1 13586 255 75M = 12670 -991 ACCCAGGAGAGTGTGGAGTCCAGAGTGATGCCAGGACCCAGGCACAGGCATTAGTGCCCGTTGGAGAAAACAGGG EFFFFFHHHHHJIJJJJIJIJJJJJJJIJJIJJJHHIJJJJIGGIJJJJJJJJJJJJJJJJJHHHHHFFFFFCCC NH:i:1 HI:i:1 NM:i:1 MD:Z:27T47 AS:i:146 XS:A:+ RG:Z:29978

0 commit comments

Comments
 (0)