From 7f7306b8940fcfdd0540cc7ac3b12a2a9fb440f8 Mon Sep 17 00:00:00 2001 From: Doga Gulhan Date: Mon, 8 Jul 2019 15:08:38 -0400 Subject: [PATCH] fix custom reference genomes --- R/make_matrix.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/R/make_matrix.R b/R/make_matrix.R index 2b9f4c0..f661397 100644 --- a/R/make_matrix.R +++ b/R/make_matrix.R @@ -208,12 +208,16 @@ conv_snv_matrix_to_df <- function(genomes_matrix){ chrom_nums <- as.vector(GenomicRanges::seqnames(gr_context)) } - if(sum(grepl('MT', chrom_nums)) > 0){ - seq_start <- seq_start[!grepl('MT', chrom_nums)] - seq_end <- seq_end[!grepl('MT', chrom_nums)] - ref_vector <- ref_vector[!grepl('MT', chrom_nums)] - alt_vector <- alt_vector[!grepl('MT', chrom_nums)] - chrom_nums <- chrom_nums[!grepl('MT', chrom_nums)] + if(length(chrom_nums) > 0){ + inds <- unlist(lapply(chrom_nums, + function(x){ + sum(grepl(paste0(paste0('chr', c(as.character(1:22), 'X', 'Y')), collapse = '|'), x)) > 0 + })) + seq_start <- seq_start[inds] + seq_end <- seq_end[inds] + ref_vector <- ref_vector[inds] + alt_vector <- alt_vector[inds] + chrom_nums <- chrom_nums[inds] } context_seq <- VariantAnnotation::getSeq(ref_genome,