Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch between rownames of tagMatrix and windows indexes #236

Open
lufce opened this issue May 24, 2024 · 0 comments
Open

Mismatch between rownames of tagMatrix and windows indexes #236

lufce opened this issue May 24, 2024 · 0 comments

Comments

@lufce
Copy link

lufce commented May 24, 2024

Dear Pr Guangchuang Yu,

Thank you for developing a useful library.
But, there seems to be a bug in getTagMatrix.internal function in tagMatrix.R.

# --- from Line 521
  windows <- subsetByOverlaps(windows, cov.width,
                              type="within", ignore.strand=FALSE)
  
  chr.idx <- intersect(names(peak.cov),
                       unique(as.character(seqnames(windows))))
  
  peakView <- Views(peak.cov[chr.idx], as(windows, "IntegerRangesList")[chr.idx])
  tagMatrixList <- lapply(peakView, function(x) t(viewApply(x, as.vector)))
  tagMatrix <- do.call("rbind", tagMatrixList)
  
  ## get the index of windows, that are reorganized by as(windows, "IntegerRangesList")
  idx.list <- split(1:length(windows),  as.factor(seqnames(windows)))
  idx <- do.call("c", idx.list)
  
  rownames(tagMatrix) <- idx
  tagMatrix <- tagMatrix[order(idx),]

I guess it tries to copy the indexes of windows to tagMatrix's rownames.
But, it won't work because peakView and idx.list do not have the same order of chromosome numbers.

  • peakView: $chr1, $chr2, $chr3, ...
  • idx.list: $chr1, $chr10, $chr11, ...

It'll cause to disconnect between tagMatrix index and window index.

I suggest the fixed code below, but I don't know it's the best way.

# --- from Line 521
  windows <- subsetByOverlaps(windows, cov.width,
                              type="within", ignore.strand=FALSE)
  
  chr.idx <- intersect(names(peak.cov),
                       unique(as.character(seqnames(windows))))
  
  peakView <- Views(peak.cov[chr.idx], as(windows, "IntegerRangesList")[chr.idx])
  tagMatrixList <- lapply(peakView, function(x) t(viewApply(x, as.vector)))
  tagMatrix <- do.call("rbind", tagMatrixList)
  
  ## get the index of windows, that are reorganized by as(windows, "IntegerRangesList")
  idx.list <- split(1:length(windows),  as.factor(seqnames(windows)))
  # ---modification
  # idx <- do.call("c", idx.list)
  idx = c()
  for(i in chr.idx){
    idx = c(idx, idx.list[[i]])
  }
  # --- end modification
  
  rownames(tagMatrix) <- idx
  tagMatrix <- tagMatrix[order(idx),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant