# Install and load necessary packages
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene")
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(GenomicRanges)
library(readxl)
# Load the gene annotation database
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
# Read gene information and regions of interest from Excel file
gene_data <- read_excel("coverage.xlsx")
# Convert gene information and regions of interest data to GRanges object
regions_gr <- GRanges(
seqnames = gene_data$chromosome,
ranges = IRanges(start = gene_data$region_start, end = gene_data$region_end),
strand = "*",
region_id = gene_data$region_id, # Replace with actual column name for region ID
gene_id = gene_data$gene_id # Replace with actual column name for gene ID
)
# Extract exon information
exon_info <- exons(txdb)
# Find overlaps between regions and exons
overlap <- findOverlaps(regions_gr, exon_info)
# Extract the overlapping exons
overlapping_exons <- subjectHits(overlap)
# Calculate the width of overlapping exons
exon_widths <- width(exon_info[overlapping_exons])
# Calculate the coverage for each region
coverage <- width(coverage(overlap, weight = TRUE)) / exon_widths
----this is my code but its showing no overlaps found