Read GFF Files
This function reads GFF files from a specified directory or file path and combines them into a single data frame.
Usage
read_gff(path, fields = NULL)Arguments
| Argument | Description |
|---|---|
path | A character string specifying the directory containing GFF files (.gff, .gff2, .gff3 or .gtf) or the file path to a single GFF file. |
fields | An optional vector of character strings specifying the fields to extract from the GFF files. |
Value
A data frame containing the combined data from the GFF files.
Details
This function can read multiple GFF files from a directory or a single GFF file. It processes each file, extracts the specified fields (if provided), adds a 'name' column with the filename, and combines the data frames from all files into one.
Each attribute becomes a character column. GFF3 attributes are read as key=value pairs; GTF and GFF2 attributes, rows without any =, as key "value" pairs, without the quotes. A key repeated in one row, such as tag in GTF files, keeps all its values joined with ",", as GFF3 writes several values of one key (Dbxref=GeneID:1,UniProt:P1).
The columns seqid, source, type, strand and phase are character, also when their values look like numbers (a chromosome named 1), so that the files of a directory can be combined. score is numeric; a score of "." (no score) is NA.
Examples
gff_file <- system.file("extdata", "HQ113105.1.gff3", package = "geneviewer")
# Read a single GFF file
gff_data <- read_gff(gff_file)
# Read GFF files from a directory
gff_data <- read_gff(dirname(gff_file))
# Read specific fields
gff_data <- read_gff(
gff_file,
fields = c("seqid", "type", "start", "end", "strand", "Name")
)