From a4b541b4c6bacf108535c86ee1e1aa72d6f7d43a Mon Sep 17 00:00:00 2001 From: Alexander Blume Date: Fri, 19 Jul 2024 14:43:03 +0200 Subject: [PATCH] [export_tbx2bw] skip chromosomes without mapping (#193) --- scripts/export_tbx2bw.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/export_tbx2bw.R b/scripts/export_tbx2bw.R index 496f66a..0f6ddf1 100644 --- a/scripts/export_tbx2bw.R +++ b/scripts/export_tbx2bw.R @@ -118,6 +118,9 @@ methList <- lapply(SinfoList, message("Processing chromosome ",seqnames(gr),"...") + tryCatch( + { + # read directly from tabix file and process in chunks dt <- methylKit:::applyTbxByOverlap( tbxFile = filepath, @@ -136,9 +139,16 @@ methList <- lapply(SinfoList, return(GenomicRanges::makeGRangesFromDataFrame( dt,seqinfo = Sinfo, keep.extra.columns=TRUE) ) + + }, + error = function(e) { + message("Chromosome ",seqnames(gr)," failed.") + return(NULL) + }) }) -methList <- unlist(GRangesList(methList)) +# remove empty list elements +methList <- unlist(GRangesList(methList[!sapply(methList,is.null)])) rtracklayer::export.bw( object = methList, con = out_path )