Skip to contents

This function reads BED files from a specified directory or file path and combines them into a single data frame. BED files use 0-based coordinate starts, while this function transforms the coordinates to 1-based during import. chromStart and thickStart are increased by 1; end positions and blockSizes are kept as they are. blockStarts become 1-based positions relative to chromStart (the first block starts at 1), as in rtracklayer::import.bed(), so the start of a block is chromStart + blockStart - 1.

Usage

read_bed(path)

Arguments

path

A character string specifying the directory containing BED files or the file path to a single BED file.

Value

A data frame combining data from the BED files.

Details

This function can read multiple BED files from a directory or a single BED file from a specified path. It adds a 'filename' column with the name of the file, and combines the data frames from all files into one.

Examples

bed_file <- tempfile(fileext = ".bed")
writeLines(c(
  "chr1\t100\t500\tgeneA\t0\t+",
  "chr1\t700\t1200\tgeneB\t0\t-"
), bed_file)

# Read a single BED file
bed_data <- read_bed(bed_file)

# Read all BED files in a directory
bed_data <- read_bed(dirname(bed_file))

unlink(bed_file)