From 0c953d0077da117532d98aeb187b700fa2b72e56 Mon Sep 17 00:00:00 2001 From: Zi-Ning Choo Date: Wed, 25 Jan 2023 10:01:57 -0500 Subject: [PATCH 1/2] bug fix to handle empty bedpe input --- R/converters.R | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/R/converters.R b/R/converters.R index 189f786a..6dfb7e6a 100755 --- a/R/converters.R +++ b/R/converters.R @@ -1315,31 +1315,35 @@ read.juncs = function(rafile, } ## create GRanges/GRangesList - bp1.gr = GRanges(seqnames = all.bedpe.dt[, chr1], - ranges = IRanges(start = all.bedpe.dt[, start1], - width = 1), - strand = all.bedpe.dt[, strand1], - seqlengths = sl) - bp2.gr = GRanges(seqnames = all.bedpe.dt[, chr2], - ranges = IRanges(start = all.bedpe.dt[, start2], - width = 1), - strand = all.bedpe.dt[, strand2], - seqlengths = sl) - - grl = gUtils::grl.pivot(GRangesList(bp1.gr, bp2.gr)) - - ## add metadata using rearrangement id - if (keep.features) + grl = GRangesList() + if (all.bedpe.dt[, .N]) { - values(grl) = cbind(VariantAnnotation::info(vcf)[all.bedpe.dt$rearrangement.id,], - mcols(MatrixGenerics::rowRanges(vcf))[all.bedpe.dt$rearrangement.id,]) - } + bp1.gr = GRanges(seqnames = all.bedpe.dt[, chr1], + ranges = IRanges(start = all.bedpe.dt[, start1], + width = 1), + strand = all.bedpe.dt[, strand1], + seqlengths = sl) + bp2.gr = GRanges(seqnames = all.bedpe.dt[, chr2], + ranges = IRanges(start = all.bedpe.dt[, start2], + width = 1), + strand = all.bedpe.dt[, strand2], + seqlengths = sl) + + grl = gUtils::grl.pivot(GRangesList(bp1.gr, bp2.gr)) + + ## add metadata using rearrangement id + if (keep.features) + { + values(grl) = cbind(VariantAnnotation::info(vcf)[all.bedpe.dt$rearrangement.id,], + mcols(MatrixGenerics::rowRanges(vcf))[all.bedpe.dt$rearrangement.id,]) + } - grl = finalize.grl(grl, - seqlengths = seqlengths, - chr.convert = chr.convert, - standard.only = standard.only, - flipstrand = flipstrand) + grl = finalize.grl(grl, + seqlengths = seqlengths, + chr.convert = chr.convert, + standard.only = standard.only, + flipstrand = flipstrand) + } return(grl) } else From e3b77b57f4adbc3dc461d1f10cffe3efa1c7ab97 Mon Sep 17 00:00:00 2001 From: Zi-Ning Choo Date: Mon, 30 Jan 2023 12:13:29 -0500 Subject: [PATCH 2/2] flip strand automatically when using bedpe --- R/converters.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/converters.R b/R/converters.R index 6dfb7e6a..56d37d2a 100755 --- a/R/converters.R +++ b/R/converters.R @@ -1036,7 +1036,7 @@ read.juncs = function(rafile, seqlengths = seqlengths, chr.convert = chr.convert, standard.only = standard.only, - flipstrand = flipstrand) + flipstrand = !flipstrand) return(grl) } @@ -1067,7 +1067,7 @@ read.juncs = function(rafile, seqlengths = seqlengths, chr.convert = chr.convert, standard.only = standard.only, - flipstrand = flipstrand) + flipstrand = !flipstrand) return(grl) }