Skip to content
This repository was archived by the owner on Oct 17, 2022. It is now read-only.

Commit 3821c7c

Browse files
Fixing problem where CpG sites preceding a region, if they are on the preceding chromosome, result in extra CpG being tabulated
1 parent 2f11724 commit 3821c7c

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/analysis/roimethstat.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ load_cpg(const bool METHPIPE_FORMAT, std::ifstream &cpg_in,
252252
}
253253

254254

255+
static bool
256+
cpg_not_past_region(const GenomicRegion &region, const size_t end_pos,
257+
const GenomicRegion &cpg) {
258+
return (cpg.same_chrom(region) && cpg.get_end() <= end_pos) ||
259+
cpg.get_chrom() < region.get_chrom();
260+
}
261+
262+
255263
static void
256264
get_cpg_stats(const bool METHPIPE_FORMAT,
257265
std::ifstream &cpg_in, const GenomicRegion region,
@@ -266,17 +274,9 @@ get_cpg_stats(const bool METHPIPE_FORMAT,
266274
find_start_line(chrom, start_pos, cpg_in);
267275

268276
GenomicRegion cpg;
269-
// find_start_line not necessarily locate at the start site.
270-
// in this case the file pointer needs to be move forward,
271-
// a little bit hopefully.
272-
while (load_cpg(METHPIPE_FORMAT, cpg_in, cpg) &&
273-
(cpg.get_chrom() < chrom ||
274-
(cpg.same_chrom(region) &&
275-
cpg.get_end() < start_pos)));
276277
while (load_cpg(METHPIPE_FORMAT, cpg_in, cpg) &&
277-
(cpg.same_chrom(region) &&
278-
cpg.get_end() <= end_pos)) {
279-
if (start_pos <= cpg.get_start()) {
278+
(cpg_not_past_region(region, end_pos, cpg))) {
279+
if (start_pos <= cpg.get_start() && cpg.same_chrom(region)) {
280280
++total_cpgs;
281281
const size_t n_reads = atoi(smithlab::split(cpg.get_name(), ":").back().c_str());
282282
if (n_reads > 0) {

0 commit comments

Comments
 (0)