Commit 663fd8ac authored by Aurelien Brionne's avatar Aurelien Brionne
Browse files

bioconductor styling package

parent 235b21f0
Package: GenomeFeatures
Version: 1.0.0
Title: Multiple genomic features annotations
Authors@R: c(
person("Aurelien","Brionne", role=c("aut","cre"),
email="aurelien.brionne@inra.fr"))
Depends: R (>= 3.5.2)
Imports:
AnnotationDbi,
data.table,
GenomicFeatures,
GenomicRanges,
IRanges,
methods,
plotly,
rtracklayer,
UpSetR,
BiocStyle,
knitr,
rmarkdown,
remotes,
BiocManager
Description: The aim of this package is to provide a full genomic features annotation from genomic coordinates, without use an annotation priority.
VignetteBuilder: knitr
License: GPL-3
LazyData: TRUE
Author: Aurelien Brionne [aut, cre]
Maintainer: Aurelien Brionne <aurelien.brionne@inra.fr>
Depends: R (>= 3.5)
Imports:AnnotationDbi,
data.table,
GenomicFeatures,
GenomicRanges,
IRanges,
methods,
plotly,
rtracklayer,
UpSetR
Suggests: htmltools,
org.Mm.eg.db,
Rgraphviz,
BiocStyle,
knitr,
rmarkdown,
corrplot,
remotes,
BiocManager
Description: The aim of this package is to provide a full genomic features annotation from genomic coordinates, without use an annotation priority.
VignetteBuilder: knitr
License: GPL-3 + LICENCE
URL: https://forgemia.inra.fr/aurelien.brionne/GenomeFeatures
BugReports: https://forgemia.inra.fr/aurelien.brionne/GenomeFeatures/issues
RoxygenNote: 6.1.1
......@@ -37,5 +36,4 @@ Collate:
'genome_features.R'
'build_genome_features.R'
'genome_features_overlaps.R'
'onAttach.R'
'readPeakFile.R'
# Generated by roxygen2: do not edit by hand
export(GFF_att)
export(Plot)
export(Table)
export(build_genome_features)
export(genome_features_overlaps)
export(readPeakFile)
exportMethods(Plot)
exportMethods(Table)
exportMethods(build_genome_features)
exportMethods(genome_features_overlaps)
import(data.table)
import(rtracklayer)
importFrom(AnnotationDbi,as.data.frame)
importFrom(AnnotationDbi,keys)
importFrom(AnnotationDbi,metadata)
......@@ -31,11 +30,15 @@ importFrom(S4Vectors,subjectHits)
importFrom(UpSetR,upset)
importFrom(data.table,data.table)
importFrom(data.table,fread)
importFrom(grDevices,colorRampPalette)
importFrom(grDevices,png)
importFrom(methods,is)
importFrom(methods,new)
importFrom(methods,setClass)
importFrom(methods,setGeneric)
importFrom(methods,setMethod)
importFrom(methods,slot)
importFrom(methods,slotNames)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
importFrom(rtracklayer,import)
#' @title Plot overlapped_genome_features graphs.
#' @description Plot overlapped_genome_features graphs bar or line.
#' @importFrom methods slot setGeneric setMethod
#' @param object an \code{\link{overlapped_genome_features-class}} object.
#' @param type a \code{\link[base]{character}} which coulde be "bar" or "line".
#' @details This method is a simple accessor to the stored \code{\link[plotly]{plot_ly}} bar or line plots from the \code{\link{overlapped_genome_features-class}} object.
......@@ -13,15 +14,19 @@
#' ###################
#' # display bar plot
#' GenomeFeatures::Plot(features_overlaps,"line")
#' @export
#' @name Plot
#' @rdname Plot-methods
#' @exportMethod Plot
setGeneric(name="Plot",def=function(object,type){standardGeneric("Plot")})
#' @rdname Plot-methods
#' @aliases Plot
setMethod("Plot",signature="overlapped_genome_features",definition=function(object,type) {
###################
# display graphs
switch(type,
bar=object@distribution$bar_plot,
line=object@distribution$lines_plot
base::switch(type,
bar=methods::slot(object,"distribution")$bar_plot,
line=methods::slot(object,"distribution")$lines_plot
)
})
#' @title extract the annotation table.
#' @description extract the annotation table from an \code{\link{overlapped_genome_features-class}} object.
#' @importFrom methods slot setGeneric setMethod
#' @param object an \code{\link{overlapped_genome_features-class}} object.
#' @details This method is a simple accessor to the stored genomic coordinates annnotation \code{\link[data.table]{data.table}}
#' from an \code{\link{overlapped_genome_features-class}} object.
......@@ -9,12 +10,16 @@
#' ###################
# # extract the annotation table
#' annot<-GenomeFeatures::Table(features_overlaps)
#' @export
#' @name Table
#' @rdname Table-methods
#' @exportMethod Table
setGeneric(name="Table",def=function(object){standardGeneric("Table")})
#' @rdname Table-methods
#' @aliases Table
setMethod("Table",signature="overlapped_genome_features",definition=function(object){
###################
# display the table
object@annotation
methods::slot(object,"annotation")
})
......@@ -55,16 +55,20 @@
#' downstream_range=1000
#' )
#' )
#' @export
#' @name build_genome_features
#' @rdname build_genome_features-methods
#' @exportMethod build_genome_features
setGeneric(name="build_genome_features",def=function(txdb,features=base::c("promoter","UTR5","UTR3","exon","intron","cds","downstream"),
parameters=base::list(promoter_ranges=base::list(upstream=3000,downstream=500),downstream_range=1000)){standardGeneric("build_genome_features")})
setMethod("build_genome_features",definition=function(txdb,features,parameters) {
###################
# check txdb
###################
if(base::class(txdb)!="TxDb") base::stop("txdb must be a TxDb class object")
#' @rdname build_genome_features-methods
#' @aliases build_genome_features
setMethod(
"build_genome_features",
methods::signature(
txdb="TxDb"
),
definition=function(txdb,features,parameters) {
###################
# txdb ids crossref
......@@ -83,7 +87,7 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# convert TXID to character
crossref[,TXID:=base::as.character(TXID)]
crossref[,"TXID":=base::as.character(TXID)]
###################
# promoters
......@@ -103,15 +107,27 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# convert to table
promoters_DT<-data.table::data.table(AnnotationDbi::as.data.frame(promoters,row.names = NULL))[,.(tx_id,tx_name)]
promoters_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
promoters,
row.names = NULL
)
)[,base::c("tx_id","tx_name"),with=FALSE]
###################
# convert to character
promoters_DT[,tx_id:=base::as.character(tx_id)]
promoters_DT[,"tx_id":=base::as.character(promoters_DT$tx_id)]
###################
# merge with crossref
promoters_DT<-merge(promoters_DT,crossref,by.x="tx_id",by.y="TXID",sort=F,all.x=T)
promoters_DT<-merge(
promoters_DT,
crossref,
by.x="tx_id",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# rename
......@@ -119,12 +135,17 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# format feature
promoters_DT[, tx_name:=feature]
promoters_DT[,"tx_name":=feature]
###################
# format feature
promoters_DT[,`:=`(
feature=base::paste(GENEID,feature,"promoter",sep=":"),
feature=base::paste(
promoters_DT$GENEID,
promoters_DT$feature,
"promoter",
sep=":"
),
GENEID=NULL,
TXNAME=NULL
)]
......@@ -141,19 +162,35 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get downstream
downstream<- GenomicFeatures::transcripts(txdb)
downstream<-GenomicRanges::flank(downstream,parameters$downstream_range,start=F)
downstream<-GenomicRanges::flank(
downstream,
parameters$downstream_range,
start=FALSE
)
###################
# convert to table
downstream_DT<-data.table::data.table(AnnotationDbi::as.data.frame(downstream,,row.names = NULL))[,.(tx_id,tx_name)]
downstream_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
downstream,
row.names = NULL
)
)[,base::c("tx_id","tx_name"),with=FALSE]
###################
# convert to character
downstream_DT[,tx_id:=base::as.character(tx_id)]
downstream_DT[,"tx_id":=base::as.character(downstream_DT$tx_id)]
###################
# merge with crossref
downstream_DT<-merge(downstream_DT,crossref,by.x="tx_id",by.y="TXID",sort=F,all.x=T)
downstream_DT<-merge(
downstream_DT,
crossref,
by.x="tx_id",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# rename
......@@ -161,12 +198,17 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# format feature
downstream_DT[,tx_name:=feature]
downstream_DT[,"tx_name":=feature]
###################
# format feature
downstream_DT[,`:=`(
feature=base::paste(GENEID,feature,"downstream",sep=":"),
feature=base::paste(
downstream_DT$GENEID,
downstream_DT$feature,
"downstream",
sep=":"
),
GENEID=NULL,
TXNAME=NULL
)]
......@@ -182,11 +224,16 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get 5' UTR in GRangesList
UTR5<-GenomicFeatures::fiveUTRsByTranscript(txdb,use.names=F)
UTR5<-GenomicFeatures::fiveUTRsByTranscript(txdb,use.names=FALSE)
###################
# convert to table
UTR5_DT<-data.table::data.table(BiocGenerics::as.data.frame(UTR5,,row.names = NULL))[,.(group_name,exon_rank)]
UTR5_DT<-data.table::data.table(
BiocGenerics::as.data.frame(
UTR5,
row.names = NULL
)
)[,base::c("group_name","exon_rank"),with=FALSE]
###################
# convert to GRanges
......@@ -194,15 +241,30 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# merge with crossref
UTR5_DT<-merge(UTR5_DT,crossref,by.x="group_name",by.y="TXID",sort=F,all.x=T)
UTR5_DT<-merge(
UTR5_DT,
crossref,
by.x="group_name",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# format feature
UTR5_DT[,`:=`(
feature=base::paste(GENEID,":",TXNAME,":5'UTR(exon",exon_rank,")",sep=""),
feature=base::paste(
UTR5_DT$GENEID,
":",
UTR5_DT$TXNAME,
":5'UTR(exon",
UTR5_DT$exon_rank,
")",
sep=""
),
exon_rank=NULL,
GENEID=NULL,
tx_name=TXNAME,
tx_name=UTR5_DT$TXNAME,
TXNAME=NULL,
group_name=NULL
)]
......@@ -218,11 +280,16 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get 3' UTR
UTR3<-GenomicFeatures::threeUTRsByTranscript(txdb,use.names=F)
UTR3<-GenomicFeatures::threeUTRsByTranscript(txdb,use.names=FALSE)
###################
# convert to table
UTR3_DT<-data.table::data.table(AnnotationDbi::as.data.frame(UTR3,,row.names = NULL))[,.(group_name,exon_rank)]
UTR3_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
UTR3,
row.names = NULL
)
)[,base::c("group_name","exon_rank"),with=FALSE]
###################
# convert to GRanges
......@@ -230,15 +297,30 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# merge with crossref
UTR3_DT<-merge(UTR3_DT,crossref,by.x="group_name",by.y="TXID",sort=F,all.x=T)
UTR3_DT<-merge(
UTR3_DT,
crossref,
by.x="group_name",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# format feature
UTR3_DT[,`:=`(
feature=base::paste(GENEID,":",TXNAME,":3'UTR(exon",exon_rank,")",sep=""),
feature=base::paste(
UTR3_DT$GENEID,
":",
UTR3_DT$TXNAME,
":3'UTR(exon",
UTR3_DT$exon_rank,
")",
sep=""
),
exon_rank=NULL,
GENEID=NULL,
tx_name=TXNAME,
tx_name= UTR3_DT$TXNAME,
TXNAME=NULL,
group_name=NULL
)]
......@@ -254,11 +336,16 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get exons
exons<-GenomicFeatures::exonsBy(txdb,use.names=F)
exons<-GenomicFeatures::exonsBy(txdb,use.names=FALSE)
###################
# convert to table
exons_DT<-data.table::data.table(AnnotationDbi::as.data.frame(exons,row.names = NULL))[,.(group_name,exon_rank)]
exons_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
exons,
row.names = NULL
)
)[,base::c("group_name","exon_rank"),with=FALSE]
###################
# convert to GRanges
......@@ -266,23 +353,45 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# count exons by transcripts
exons_nb<-exons_DT[!base::is.na(group_name),.N,by=group_name]
exons_nb<-exons_DT[!base::is.na(group_name),.N,by="group_name"]
###################
# merge count to exons_DT
exons_DT<-merge(exons_DT,exons_nb,by="group_name",all.x=T,sort=F)
exons_DT<-merge(
exons_DT,
exons_nb,
by="group_name",
all.x=TRUE,
sort=FALSE
)
###################
# merge with crossref
exons_DT<-merge(exons_DT,crossref,by.x="group_name",by.y="TXID",sort=F,all.x=T)
exons_DT<-merge(
exons_DT,
crossref,
by.x="group_name",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# format feature
exons_DT[,`:=`(
feature=base::paste(GENEID,":",TXNAME,":exon",exon_rank,"/",N,sep=""),
feature=base::paste(
exons_DT$GENEID,
":",
exons_DT$TXNAME,
":exon",
exons_DT$exon_rank,
"/",
exons_DT$N,
sep=""
),
exon_rank=NULL,
GENEID=NULL,
tx_name=TXNAME,
tx_name= exons_DT$TXNAME,
TXNAME=NULL,
N=NULL,
group_name=NULL
......@@ -299,11 +408,16 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get introns
introns<-GenomicFeatures::intronsByTranscript(txdb,use.names=F)
introns<-GenomicFeatures::intronsByTranscript(txdb,use.names=FALSE)
###################
# convert to table
introns_DT<-data.table::data.table(AnnotationDbi::as.data.frame(introns,row.names = NULL))[,.(group_name,strand)]
introns_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
introns,
row.names = NULL
)
)[,base::c("group_name","strand"),with=FALSE]
###################
# convert to GRanges
......@@ -311,32 +425,54 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# count introns by transcripts
introns_nb<-introns_DT[!base::is.na(group_name),.N,by=group_name]
introns_nb<-introns_DT[!base::is.na(group_name),.N,by="group_name"]
###################
# merge count to introns_DT
introns_DT<-merge(introns_DT,introns_nb,by="group_name",all.x=T,sort=F)
introns_DT<-merge(
introns_DT,
introns_nb,
by="group_name",
all.x=TRUE,
sort=FALSE
)
###################
# add intron_rank
introns_DT[,intron_rank:=1:base::length(N),by=group_name]
introns_DT[,"intron_rank":=1:base::length(N),by="group_name"]
###################
# reverse intron_rank for reverse strand
introns_DT[strand=="-",intron_rank:=base::rev(intron_rank),by=group_name]
introns_DT["-","intron_rank":=base::rev(intron_rank),by="group_name",on="strand"]
###################
# merge with crossref
introns_DT<-merge(introns_DT,crossref,by.x="group_name",by.y="TXID",sort=F,all.x=T)
introns_DT<-merge(
introns_DT,
crossref,
by.x="group_name",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# format feature
introns_DT[,`:=`(
feature=base::paste(GENEID,":",TXNAME,":intron",intron_rank,"/",N,sep=""),
feature=base::paste(
introns_DT$GENEID,
":",
introns_DT$TXNAME,
":intron",
introns_DT$intron_rank,
"/",
introns_DT$N,
sep=""
),
intron_rank=NULL,
strand=NULL,
GENEID=NULL,
tx_name=TXNAME,
tx_name=introns_DT$TXNAME,
TXNAME=NULL,
N=NULL,
group_name=NULL
......@@ -353,11 +489,16 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# get exons
cds<-GenomicFeatures::cdsBy(txdb,use.names=F)
cds<-GenomicFeatures::cdsBy(txdb,use.names=FALSE)
###################
# convert to table
cds_DT<-data.table::data.table(AnnotationDbi::as.data.frame(cds,row.names = NULL))[,.(group_name,exon_rank)]
cds_DT<-data.table::data.table(
AnnotationDbi::as.data.frame(
cds,
row.names = NULL
)
)[,base::c("group_name","exon_rank"),with=FALSE]
###################
# convert to GRanges
......@@ -365,23 +506,45 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# count exons by transcripts
cds_nb<-cds_DT[!base::is.na(group_name),.N,by=group_name]
cds_nb<-cds_DT[!base::is.na(group_name),.N,by="group_name"]
###################
# merge count to exons_DT
cds_DT<-merge(cds_DT,cds_nb,by="group_name",all.x=T,sort=F)
cds_DT<-merge(
cds_DT,
cds_nb,
by="group_name",
all.x=TRUE,
sort=FALSE
)
###################
# merge with crossref
cds_DT<-merge(cds_DT,crossref,by.x="group_name",by.y="TXID",sort=F,all.x=T)
cds_DT<-merge(
cds_DT,
crossref,
by.x="group_name",
by.y="TXID",
sort=FALSE,
all.x=TRUE
)
###################
# format feature
cds_DT[,`:=`(
feature=base::paste(GENEID,":",TXNAME,":exon",exon_rank,"/",N,sep=""),
feature=base::paste(
cds_DT$GENEID,
":",
cds_DT$TXNAME,
":exon",
cds_DT$exon_rank,
"/",
cds_DT$N,
sep=""
),
exon_rank=NULL,
GENEID=NULL,
tx_name=TXNAME,
tx_name=cds_DT$TXNAME,
TXNAME=NULL,
N=NULL,
group_name=NULL
......@@ -408,7 +571,11 @@ setMethod("build_genome_features",definition=function(txdb,features,parameters)
###################
# import the GFF
utils::download.file(file,quiet=T,destfile=output)
utils::download.file(
file,