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

Xt debug #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions R/gUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1031,23 +1031,20 @@ gr.string = function(gr, add.chr = FALSE, mb = FALSE, round = 3, other.cols = c(

str = ifelse(as.logical(strand(gr)!='*'), as.character(strand(gr)), '')


## XT debug: the lastest GRanges requires an extra ":" in between end and strand
if (mb){
return(paste(sn, ':', round(start(gr)/1e6, round), '-', round(end(gr)/1e6, round), str, other.str, sep = ''))
return(paste(sn, ':', round(start(gr)/1e6, round), '-', round(end(gr)/1e6, round), ":", str, other.str, sep = ''))
}
else{
if (pretty){
return(paste(sn, ':', stringr::str_trim(format(start(gr), big.mark = ',')), '-', stringr::str_trim(format(end(gr), big.mark = ',')), str, other.str, sep = ''))
return(paste(sn, ':', stringr::str_trim(format(start(gr), big.mark = ',')), '-', stringr::str_trim(format(end(gr), big.mark = ',')), ":", str, other.str, sep = ''))
}
else{
return(paste(sn, ':', start(gr), '-', end(gr), str, other.str, sep = ''))
return(paste(sn, ':', start(gr), '-', end(gr), ":", str, other.str, sep = ''))
}
}
}




#' @name grl.reduce
#' @title grl.reduce
#' @description
Expand Down Expand Up @@ -2386,6 +2383,10 @@ seg2gr = function(segs, seqlengths = NULL, seqinfo = Seqinfo())
segs$pos1 = as.numeric(segs$pos1)
segs$pos2 = as.numeric(segs$pos2)

## only convert valid ranges
valid.ix = which(!is.na(segs$pos1) & !is.na(segs$pos2))
segs = segs[valid.ix, , drop=FALSE]

out = GRanges(seqnames = segs$chr, ranges = IRanges(segs$pos1, segs$pos2),strand = segs$strand, seqlengths = seqlengths)

} else{
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test_rangeops.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ test_that("gr.string", {
expect_that(grepl("(+|-)", gr.string(example_genes)[1]), is_true())
## check 'if (length(gr)==0){'
## add.chr
expect_equal(gr.string(example_genes, add.chr=TRUE)[1], 'chr1:69090-70008+')
expect_equal(gr.string(example_genes, add.chr=TRUE)[1], 'chr1:69090-70008:+')
## mb
expect_equal(gr.string(example_genes[1], mb = TRUE), '1:0.069-0.07+')
expect_equal(gr.string(example_genes[1], mb = TRUE), '1:0.069-0.07:+')
## round
expect_equal(gr.string(example_genes[1], round = 1, mb=TRUE), '1:0.1-0.1+')
expect_equal(gr.string(example_genes[1], round = 1, mb=TRUE), '1:0.1-0.1:+')
## other.cols
expect_equal(gr.string(example_genes[1], other.cols='name'), '1:69090-70008+ OR4F5')
expect_equal(gr.string(example_genes[1], other.cols='name'), '1:69090-70008:+ OR4F5')
## pretty
expect_equal(gr.string(example_genes, pretty=TRUE)[1], '1:69,090-70,008+')
expect_equal(gr.string(example_genes, pretty=TRUE)[1], '1:69,090-70,008:+')

})

Expand Down Expand Up @@ -387,12 +387,12 @@ test_that("grl.string", {
expect_that(nchar(names(grl.string(grl.hiC[1:5])[1])) > 0, is_true())
expect_that(grepl(",", grl.string(grl.hiC[1:5])[1]), is_true())
## check 'if (class(grl) == "GRanges"){'
expect_equal(grl.string(example_genes[1]), '1:69090-70008+')
expect_equal(grl.string(example_genes[1]), '1:69090-70008:+')
## check 'error handling'
expect_error(grl.string('foo')) ## Error: Input must be GRangesList (or GRanges, which is sent to gr.string)
## check 'else{ nm = 1:length(grl) ! 1138 }'
names(grl1) = NULL
expect_equal(as.character(grl.string(grl1[2])), '9:140100229-140100229-,19:24309057-24309057-')
expect_equal(as.character(grl.string(grl1[2])), '9:140100229-140100229:-,19:24309057-24309057:-')

})

Expand Down