Commit 7b1a3466 authored by Aurelien Brionne's avatar Aurelien Brionne
Browse files

bioconductor code styl update

parent 3c44818b
Package: GenomeFeatures
Version: 1.0.0
Version: 1.0
Title: Multiple genomic features annotations
Author: Aurelien Brionne [aut, cre]
Maintainer: Aurelien Brionne <aurelien.brionne@inra.fr>
......@@ -24,7 +24,7 @@ Suggests: htmltools,
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
License: GPL-3
URL: https://forgemia.inra.fr/aurelien.brionne/GenomeFeatures
BugReports: https://forgemia.inra.fr/aurelien.brionne/GenomeFeatures/issues
RoxygenNote: 6.1.1
......
This diff is collapsed.
......@@ -8,44 +8,34 @@
#' @export
GFF_att<-function(...,att.list=c("GeneID","Name","gene")){
#################
# Data loading
Data<-data.table::data.table(...)
#################
# extract attributes in table
Dat=base::lapply(att.list,function(y){
#################
# substitute
if(y=="ID"){
#################
# particular case
tmp<-base::gsub("ID=","",Data$att)
}else{
#################
# remove annotation before
tmp<-base::gsub(base::paste(".*",y,"[:=]",sep=""),"",Data$att)
}
#################
# remove annotation after
base::gsub("[;,].+","",tmp)
})
#################
# create data.table
require(data.table)
Dat=base::do.call("data.table",Dat)
#################
# add header
names(Dat)<-base::gsub(":|=","",att.list)
#################
# results table
return(data.table::data.table(Data,Dat))
# Data loading
Data<-data.table(...)
# extract attributes in table
Dat=lapply(att.list,function(y){
# substitute
if(y=="ID"){
# particular case
tmp<-gsub("ID=","",Data$att)
}else{
# remove annotation before
tmp<-gsub(paste(".*",y,"[:=]",sep=""),"",Data$att)
}
# remove annotation after
gsub("[;,].+","",tmp)
})
# create data.table
Dat=do.call("data.table",Dat)
# add header
names(Dat)<-gsub(":|=","",att.list)
# results table
return(data.table(Data,Dat))
}
......@@ -7,26 +7,33 @@
#' @return a \code{\link[plotly]{plot_ly}} object.
#' @include overlapped_genome_features.R
#' @examples
#' ###################
#' # display bar plot
#' GenomeFeatures::Plot(features_overlaps,"bar")
#' # display bar plot
#' Plot(features_overlaps,"bar")
#'
#' ###################
#' # display bar plot
#' GenomeFeatures::Plot(features_overlaps,"line")
#' # display bar plot
#' Plot(features_overlaps,"line")
#' @name Plot
#' @rdname Plot-methods
#' @exportMethod Plot
setGeneric(name="Plot",def=function(object,type){standardGeneric("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) {
setMethod(
"Plot",
signature="overlapped_genome_features",
definition=function(object,type) {
###################
# display graphs
base::switch(type,
bar=methods::slot(object,"distribution")$bar_plot,
line=methods::slot(object,"distribution")$lines_plot
)
})
# display graphs
switch(
type,
bar=slot(object,"distribution")$bar_plot,
line=slot(object,"distribution")$lines_plot
)
}
)
......@@ -7,19 +7,26 @@
#' @return a \code{\link[data.table]{data.table}} object.
#' @include overlapped_genome_features.R
#' @examples
#' ###################
# # extract the annotation table
#' annot<-GenomeFeatures::Table(features_overlaps)
#' # extract the annotation table
#' annot<-Table(features_overlaps)
#' @name Table
#' @rdname Table-methods
#' @exportMethod Table
setGeneric(name="Table",def=function(object){standardGeneric("Table")})
setGeneric(
name="Table",
def=function(object){
standardGeneric("Table")
}
)
#' @rdname Table-methods
#' @aliases Table
setMethod("Table",signature="overlapped_genome_features",definition=function(object){
setMethod(
"Table",
signature="overlapped_genome_features",
definition=function(object){
###################
# display the table
methods::slot(object,"annotation")
})
# display the table
slot(object,"annotation")
}
)
This diff is collapsed.
#' @title genome_features class object definition.
#' @description This class is invoked by \code{\link{build_genome_features}} method in order to store for each features
#' a \code{\link[base]{list}} with \code{\link[GenomicRanges]{GRanges}} and \code{\link[data.table]{data.table}} elements.
#' @importFrom methods setClass
#' @import data.table
#' @importFrom data.table data.table .N rbindlist
#' @slot metadata a \code{\link[base]{list}} with provided txdb \code{\link[AnnotationDbi]{metadata}}.
#' @slot promoter a \code{\link[base]{list}} with \code{\link[GenomicRanges]{GRanges}} and \code{\link[data.table]{data.table}} elements.
#' @slot UTR5 a \code{\link[base]{list}} with \code{\link[GenomicRanges]{GRanges}} and \code{\link[data.table]{data.table}} elements.
......@@ -12,8 +10,6 @@
#' @slot UTR3 a \code{\link[base]{list}} with \code{\link[GenomicRanges]{GRanges}} and \code{\link[data.table]{data.table}} elements.
#' @slot downstream a \code{\link[base]{list}} with \code{\link[GenomicRanges]{GRanges}} and \code{\link[data.table]{data.table}} elements.
#' @slot gff a \code{\link[data.table]{data.table}} with the gff.
###################
# define genome_features class
setClass("genome_features",
slots=c(
metadata="list",
......@@ -28,63 +24,57 @@ setClass("genome_features",
)
)
#' @importFrom methods setMethod
setMethod("show", "genome_features",function(object) {
#' @aliases genome_features
setMethod(
"show",
"genome_features",
function(object){
###################
# print short report
base::cat(
base::paste(
"genome_features class object for",
methods::slot(object,"metadata")[[1]]["Organism","value",with=FALSE,on="name"],
"species"
),
sep="\n"
)
# print short report
cat(
paste(
"genome_features class object for",
slot(object,"metadata")[[1]]["Organism","value",with=FALSE,on="name"],
"species"
),
sep="\n"
)
###################
# slots names
slots<-methods::slotNames(object)
# slots names
slots<-slotNames(object)
###################
# extract the number of ranges available by slot
Data<-base::lapply(slots[-base::c(1,base::length(slots))],function(x){
# extract the number of ranges available by slot
Data<-lapply(slots[-c(1,length(slots))],function(x){
###################
# buil a data.table
data.table::data.table(
feature=x,
count=base::length(methods::slot(object,x)$GRanges)
)
})
# build a data.table
data.table(
feature=x,
count=length(slot(object,x)$GRanges)
)
})
###################
# extract gff
gene_table<-methods::slot(object,"gene_table")
# extract gff
gene_table<-slot(object,"gene_table")
###################
# count genes
genes<-base::length(base::unique(gene_table$gene_id))
# count genes
genes<-length(unique(gene_table$gene_id))
###################
# count
gene_table<-gene_table[,.N,by="type"]
# count
gene_table<-gene_table[,.N,by="type"]
###################
# chaneg header
base::names(gene_table)<-base::c("feature","count")
# modify header
names(gene_table)<-c("feature","count")
###################
# bind results
Data<-data.table::rbindlist(
base::c(
base::list(data.table::data.table(feature="gene",count=genes)),
Data,
base::list(gene_table)
)
)
# bind results
Data<-rbindlist(
c(
list(data.table(feature="gene",count=genes)),
Data,
list(gene_table)
)
)
###################
# print the table
base::print(Data)
})
# print the table
print(Data)
}
)
This diff is collapsed.
......@@ -2,67 +2,60 @@
#' @description This class is invoked by \code{\link{genome_features_overlaps}} method in order to store
#' the genomic coordinates annotation \code{\link[data.table]{data.table}}, and features distribution
#' \code{\link[data.table]{data.table}} and \code{\link[plotly]{plot_ly}}.
#' @importFrom methods setClass
#' @import data.table
#' @importFrom data.table dcast
#' @slot annotation a \code{\link[data.table]{data.table}}.
#' @slot distribution a \code{\link[base]{list}} with \code{\link[data.table]{data.table}} and \code{\link[plotly]{plot_ly}} elements.
###################
# define genome_features class
setClass("overlapped_genome_features",
slots=c(
annotation="data.table",
distribution="list"
)
setClass(
"overlapped_genome_features",
slots=c(
annotation="data.table",
distribution="list"
)
)
#' @importFrom methods setMethod
setMethod("show", "overlapped_genome_features",function(object) {
#' @aliases overlapped_genome_features
setMethod(
"show",
"overlapped_genome_features",
function(object){
###################
# print short report
base::cat(
"overlapped_genome_features class object\n",
"-unique gene count by feature type:",
sep="\n")
# print short report
cat(
"overlapped_genome_features class object\n",
"-unique gene count by feature type:",
sep="\n"
)
###################
# extract annotations
Data<-methods::slot(object,"annotation")
# extract annotations
Data<-slot(object,"annotation")
###################
# count unique genes match by feature type
Data<-base::unique(Data[!base::is.na(type),.(condition,feature_type,type,gene_id)])
# count unique genes match by feature type
Data<-unique(Data[!is.na(type),.(condition,feature_type,type,gene_id)])
###################
# count
Data<-data.table::dcast(
Data,
condition~feature_type,
value.var="gene_id",
fun=length
)
# count
Data<-dcast(
Data,
condition~feature_type,
value.var="gene_id",
fun=length
)
###################
# print the table
base::print(Data)
# print the table
print(Data)
###################
# print short report
base::cat("\n-features count (transcript level):",sep="\n")
# print short report
cat("\n-features count (transcript level):",sep="\n")
###################
# extract distributions
Data<-methods::slot(object,"distribution")
# extract distributions
Data<-slot(object,"distribution")
###################
# display features count
base::print(Data$features_count)
# display features count
print(Data$features_count)
###################
# print short report
base::cat("\n-features frequency (transcript level):",sep="\n")
# print short report
cat("\n-features frequency (transcript level):",sep="\n")
###################
# display features frequency
base::print(Data$features_frequency)
})
# display features frequency
print(Data$features_frequency)
}
)
#' @title Read peakfile
#' @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
......@@ -8,33 +8,30 @@
#' @details This function read peaks coordinates file (bed file) and store the results in a \code{\link[GenomicRanges]{GRanges}} object.
#' @return a \code{\link[GenomicRanges]{GRanges}} object.
#' @examples
#' ###################
#' # read peak file (package sample from NCBI)
#' peaks<-GenomeFeatures::readPeakFile(
#' base::system.file(
#' "extdata/data/input/A.bed",
#' package="GenomeFeatures"
#' )
#' system.file(
#' "extdata/data/input/A.bed",
#' package="GenomeFeatures"
#' )
#' )
#' @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")
)
# read the file
Data<-fread(
file,
select=c(1:4),
col.names=c("Chr","start","end","strand")
)
###################
# return GRanges object
GenomicRanges::GRanges(
seqnames=Data$Chr,
ranges=IRanges::IRanges(
start=Data$start,
end=Data$end
),
strand=Data$strand
)
# return GRanges object
GRanges(
seqnames=Data$Chr,
ranges=IRanges(
start=Data$start,
end=Data$end
),
strand=Data$strand
)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment