readPeakFile.R 1.15 KB
Newer Older
Aurelien Brionne's avatar
Aurelien Brionne committed
1
2
3
4
5
6
7
#' @title  Read peakfile
#' @description This function is use to  read peaks file, also known bed file, with genomic coordinates (chr, start, end, strand),
#' and to convert it in \code{\link[GenomicRanges]{GRanges}} object.
#' @importFrom data.table fread
#' @importFrom GenomicRanges GRanges
#' @importFrom IRanges IRanges
#' @param file peak file path.
Aurelien Brionne's avatar
Aurelien Brionne committed
8
#' @details This function read peaks coordinates file (bed file) and store the results in a \code{\link[GenomicRanges]{GRanges}} object.
Aurelien Brionne's avatar
Aurelien Brionne committed
9
10
11
12
13
14
#' @return a \code{\link[GenomicRanges]{GRanges}} object.
#' @examples
#' ###################
#' # read peak file (package sample from NCBI)
#' peaks<-GenomeFeatures::readPeakFile(
#'  base::system.file(
Aurelien Brionne's avatar
Aurelien Brionne committed
15
#'   "extdata/data/input/A.bed",
Aurelien Brionne's avatar
Aurelien Brionne committed
16
#'   package="GenomeFeatures"
Aurelien Brionne's avatar
Aurelien Brionne committed
17
#'  )
Aurelien Brionne's avatar
Aurelien Brionne committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#' )
#' @export
readPeakFile<-function(file){

  ###################
  # read the file
  Data<-data.table::fread(
    file,
    select=base::c(1:4),
    col.names=base::c("Chr","start","end","strand")
  )

  ###################
  # return GRanges object
  GenomicRanges::GRanges(
    seqnames=Data$Chr,
34
35
36
37
    ranges=IRanges::IRanges(
      start=Data$start,
      end=Data$end
    ),
Aurelien Brionne's avatar
Aurelien Brionne committed
38
39
40
    strand=Data$strand
  )
}