diff --git a/R/gUtils.R b/R/gUtils.R index 4fef890..c2472e6 100644 --- a/R/gUtils.R +++ b/R/gUtils.R @@ -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 @@ -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{ diff --git a/tests/testthat/test_rangeops.R b/tests/testthat/test_rangeops.R index 4f5ca02..9ad70d2 100644 --- a/tests/testthat/test_rangeops.R +++ b/tests/testthat/test_rangeops.R @@ -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:+') }) @@ -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:-') })