From a73a304ef8081ca374f2978c59b062cc29029472 Mon Sep 17 00:00:00 2001 From: rl3328 Date: Tue, 15 Apr 2025 06:04:52 +0000 Subject: [PATCH 1/2] modify LD.R --- R/LD.R | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/R/LD.R b/R/LD.R index 6c6fc26a..7403f65a 100644 --- a/R/LD.R +++ b/R/LD.R @@ -49,11 +49,11 @@ find_intersection_rows <- function(genomic_data, region_chrom, region_start, reg # Try to find rows that cover the region start and end start_row <- genomic_data %>% - filter(chrom == region_chrom, start <= region_start, end >= region_start) %>% + filter(chrom == region_chrom, start <= region_start, end > region_start) %>% slice(1) end_row <- genomic_data %>% - filter(chrom == region_chrom, start <= region_end, end >= region_end) %>% + filter(chrom == region_chrom, start < region_end, end >= region_end) %>% arrange(desc(end)) %>% slice(1) @@ -366,8 +366,24 @@ load_LD_matrix <- function(LD_meta_file_path, region, extract_coordinates = NULL block_id = seq_along(LD_file_paths), chrom = block_chroms, size = sapply(block_variants, length), - start_idx = sapply(block_variants, function(v) min(match(v, combined_LD_variants))), - end_idx = sapply(block_variants, function(v) max(match(v, combined_LD_variants))), + start_idx = sapply(block_variants, function(v) { + matches <- match(v, combined_LD_variants) + valid_matches <- matches[is.finite(matches) & !is.na(matches)] + if(length(valid_matches) > 0) { + return(min(valid_matches)) + } else { + return(NA) + } + }), + end_idx = sapply(block_variants, function(v) { + matches <- match(v, combined_LD_variants) + valid_matches <- matches[is.finite(matches) & !is.na(matches)] + if(length(valid_matches) > 0) { + return(max(valid_matches)) + } else { + return(NA) + } + }), stringsAsFactors = FALSE ) From 3b9a5c89f82800d9ebfebdc1f4f1643ed0754f6c Mon Sep 17 00:00:00 2001 From: rl3328 Date: Tue, 15 Apr 2025 18:15:38 +0000 Subject: [PATCH 2/2] revert some unnecessary change --- R/LD.R | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/R/LD.R b/R/LD.R index 7403f65a..6350b13e 100644 --- a/R/LD.R +++ b/R/LD.R @@ -366,24 +366,8 @@ load_LD_matrix <- function(LD_meta_file_path, region, extract_coordinates = NULL block_id = seq_along(LD_file_paths), chrom = block_chroms, size = sapply(block_variants, length), - start_idx = sapply(block_variants, function(v) { - matches <- match(v, combined_LD_variants) - valid_matches <- matches[is.finite(matches) & !is.na(matches)] - if(length(valid_matches) > 0) { - return(min(valid_matches)) - } else { - return(NA) - } - }), - end_idx = sapply(block_variants, function(v) { - matches <- match(v, combined_LD_variants) - valid_matches <- matches[is.finite(matches) & !is.na(matches)] - if(length(valid_matches) > 0) { - return(max(valid_matches)) - } else { - return(NA) - } - }), + start_idx = sapply(block_variants, function(v) min(match(v, combined_LD_variants))), + end_idx = sapply(block_variants, function(v) max(match(v, combined_LD_variants))), stringsAsFactors = FALSE )