Skip to content

script gtf_exons_bed.1.1.2.R

Converts the exon entries of a GTF file to a BED file with one line per exon.

Reads a GTF file, extracts features of type exon, and writes them to a BED file with one record per exon. The BED name (4th column) is taken from a user-selected GTF attribute (metadata column), and the BED score column is set to a constant value.

Imports the input GTF as a GRanges, filters rows where the feature type equals "exon", and checks that the requested attribute (from --name) exists in the GTF metadata. Then, assigns:

  • name = the chosen attribute value (e.g., transcript_id)
  • score = the numeric constant provided via --score

Finally, exports to BED using rtracklayer::export(format="bed").

COORDINATE CONVENTIONS

GTF is conventionally 1-based, while BED uses 0-based start coordinates. When exporting a GRanges to BED, rtracklayer::export() handles the BED coordinate requirements for the output file.

Usage

Rscript gtf_exons_bed.1.1.2.R [--help] [--verbose] [OPTIONS] --gtf <PATH> --bed <PATH>

Arguments

  • -i FILE | --gtf=FILE (required): Path to the input GTF file.
  • -o FILE | --bed=FILE (required): Path to the output BED file.

Options

  • -n STRING | --name=STRING: Attribute to be used for the 'name' (fourth) column in the BED output file (check GTF file for available options; default: 'transcript_ID').
  • -s NUM | --score=NUM: Score that should be set in each row of the output BED file (default: 0).
  • -h | --help: Show this information and die.
  • -u | --usage: Show this information and die.
  • -v | --verbose: Print log messages to STDOUT.

Dependencies

  • R version: >= 3.6.0
  • R packages:
    • optparse: >= 1.6.2
    • rtracklayer: >= 1.44.0