Skip to content

Commit

Permalink
Bug fix for issue #37
Browse files Browse the repository at this point in the history
Bug identified by @zyqfrog10 in the way position indices are tracked
in the internal function bumphunt(). Previously, the order of the
`chrs` vector containing chromosome names did not necessarily match
the order of the names in the cumulative index table when chrM was
included and listed last. This commit
introduces a fix by removing the `as.character` call when building
the cumulative sum table, which was reordering the names alphabetically.
It also adds a check that the order of these two items is identical,
and if not will throw an error to prevent this type of bug from
persisting.
  • Loading branch information
kdkorthauer committed Dec 6, 2019
1 parent 987ef05 commit 27b3183
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: dmrseq
Type: Package
Title: Detection and inference of differentially methylated regions
from Whole Genome Bisulfite Sequencing
Version: 1.7.0
Version: 1.7.1
Authors@R: c(person("Keegan", "Korthauer", role = c("cre", "aut"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-4565-1654")),
Expand Down
21 changes: 14 additions & 7 deletions R/helper_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,20 @@ bumphunt <- function(bs,
}

chrs <- unique(seqnames(bs))
chrlengths <- cumsum(table(as.character(seqnames(bs))))
for (j in seq_len(length(chrs)-1)) {
ch <- chrs[[j+1]]
tab$indexStart[tab$chr %in% ch] <- tab$indexStart[tab$chr %in% ch] +
chrlengths[names(chrlengths) == chrs[j]]
tab$indexEnd[tab$chr %in% ch] <- tab$indexEnd[tab$chr %in% ch] +
chrlengths[names(chrlengths) == chrs[j]]
chrlengths <- cumsum(table(seqnames(bs)))
# Add a check to make sure chr order lines up with
# cumulative sum table
if (chrs == names(chrlengths)){
for (j in seq_len(length(chrs)-1)) {
ch <- chrs[[j+1]]
tab$indexStart[tab$chr %in% ch] <- tab$indexStart[tab$chr %in% ch] +
chrlengths[names(chrlengths) == chrs[j]]
tab$indexEnd[tab$chr %in% ch] <- tab$indexEnd[tab$chr %in% ch] +
chrlengths[names(chrlengths) == chrs[j]]
}
}else{
stop("Chromosome order could not be reliably determined. ",
"Please use the 'sort' function before running dmrseq")
}
}

Expand Down

0 comments on commit 27b3183

Please sign in to comment.