-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new function for atac-seq + testing and comments
- Loading branch information
rochevin
committed
Aug 20, 2021
1 parent
789391c
commit 1a7d8f6
Showing
102 changed files
with
40,053 additions
and
37,997 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
#' Title | ||
#' ExtractSubSequencefromBed : Internal function for DeepG4Scan. | ||
#' | ||
#' @param x | ||
#' @param k | ||
#' @param seq.size | ||
#' @param x An object of class GRanges. | ||
#' @param k size of the sliding windows. | ||
#' @param seq.size numeric value representing the sequence size accepted by our model. Don't change it unless you want to use our function with a custom model. | ||
#' | ||
#' @return | ||
#' | ||
#' @examples | ||
#' @return A data.frame with position of subsequence and DNA sequence. | ||
ExtractSubSequence <- function(x=NULL,k = 20,seq.size = 201){ | ||
extend <- ((seq.size-1)/2) | ||
center <- seq(1,length(x),k) | ||
start <- center - extend | ||
end <- center + extend | ||
Viewseq <- Biostrings::Views(x, start=start[start>0&end<=length(x)], end=end[start>0&end<=length(x)]) | ||
sequences <- Biostrings::DNAStringSet(Viewseq) | ||
|
||
results <- cbind(as.data.frame(IRanges::ranges(Viewseq)),seq=as.character(Viewseq)) | ||
return(results) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' ExtractSubSequencefromBed : Internal function for DeepG4Scan. | ||
#' | ||
#' @param x An object of class GRanges. | ||
#' @param x.atac A SimpleRleList object containing DNA accessibility. | ||
#' @param k size of the sliding windows. | ||
#' @param GENOME a BSgenome object containing the DNA sequence of genome of interest. | ||
#' @param seq.size numeric value representing the sequence size accepted by our model. Don't change it unless you want to use our function with a custom model. | ||
#' @param nb.threads number of threads to use, default 1. | ||
#' @param use.bg a boolean. Set to \code{TRUE} you want to normalize the accessibility using a windows background of windows_bg. | ||
#' @param windows_bg numeric value who define the windows use to get background signal. | ||
#' @param treshold_bg numeric value who set the treshold signal/background. | ||
#' | ||
#' @return A data.frame with position of subsequence, DNA sequence and accessibility. | ||
#' @export | ||
#' | ||
#' @examples | ||
ExtractSubSequencefromBed <- function(x=NULL,x.atac=NULL,k = 20,GENOME=NULL,seq.size = 201,nb.threads=1,use.bg=T,windows_bg=5000,treshold_bg = 2){ | ||
extend <- ((seq.size-1)/2) | ||
windows = IRanges::slidingWindows(x, width=k,step = k) | ||
res <- mclapply(1:length(windows),function(i){ | ||
|
||
swindows <- windows[[i]] | ||
end(swindows) <- BiocGenerics::start(swindows) + extend | ||
start(swindows) <- BiocGenerics::start(swindows) - extend | ||
|
||
cov <- x.atac[[as.character(GenomeInfoDb::seqnames(x[i]))]] | ||
|
||
score <- IRanges::Views(cov, start = BiocGenerics::start(swindows), end = BiocGenerics::end(swindows)) | ||
score <- rowMeans(as.matrix(score)) | ||
score[is.na(score)] <- 0 | ||
|
||
if(use.bg){ | ||
swindows.bg <- resize(swindows,windows_bg,fix="center") | ||
score.bg <- IRanges::Views(cov, start = BiocGenerics::start(swindows.bg), end = BiocGenerics::end(swindows.bg)) | ||
score.bg <- rowMeans(as.matrix(score.bg)) | ||
score.bg[is.na(score.bg)] <- 0 | ||
my_test <- (score/score.bg)<treshold_bg | ||
score[my_test] <- 0 | ||
} | ||
results <- cbind(seqnames = as.character(seqnames(x[i])),as.data.frame(IRanges::ranges(swindows)),score=score,seq=as.character(Biostrings::getSeq(GENOME,swindows))) | ||
|
||
return(results) | ||
},mc.cores=nb.threads) | ||
|
||
return(do.call("rbind",res)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
#' Title | ||
#' getScoreBW extract DNA accessibility from WIG to BED positions. | ||
#' | ||
#' @param WIG | ||
#' @param BED | ||
#' @param WIG An object of class GRanges containing DNA accessibility. | ||
#' @param BED An object of class GRanges. | ||
#' | ||
#' @return | ||
#' @export | ||
#' @return A SimpleRleList object containing DNA accessibility. | ||
#' @export A numeric vector of DNA accessibility | ||
#' | ||
#' @examples | ||
getScoreBW <- function (WIG, BED) | ||
getScoreBW <- function (WIG, BED,forScan=F) | ||
{ | ||
res <- do.call("rbind",lapply(split(BED, droplevels(GenomeInfoDb::seqnames(BED))), function(zz) { | ||
cov <- WIG[[unique(as.character(GenomeInfoDb::seqnames(zz)))]] | ||
score <- IRanges::Views(cov, start = BiocGenerics::start(zz), end = BiocGenerics::end(zz)) | ||
return(as.matrix(score)) | ||
})) | ||
return(rowMeans(res)) | ||
if(forScan){ | ||
return(res) | ||
}else{ | ||
return(rowMeans(res)) | ||
} | ||
} |
Oops, something went wrong.