Skip to content

Commit

Permalink
dup.validate updates
Browse files Browse the repository at this point in the history
  • Loading branch information
piyalkarum committed Jun 3, 2024
1 parent bad1b28 commit f8403c7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/post_detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dup.validate<-function(d.detect,window.size=100, scaf.size=10000){
gg<-lapply(nm,wind,dd=d.detect)
names(gg)<-nm
means<-lapply_pb(nm,function(x,mw,gg){yy<-unlist(gg[names(gg)==x])

ll<-mw+(mw/2)
if(length(yy)>ll){
if(length(yy)>2*scaf.size){
Expand Down Expand Up @@ -71,21 +72,24 @@ dup.validate<-function(d.detect,window.size=100, scaf.size=10000){
dp<-cbind(x,dp,length(yy),sum(yy=="cnv" | yy=="deviant"),sum(yy=="non-cnv" | yy=="non-deviant"))
}

dp<-data.frame(dp)
start_positions <- seq(1, length(yy), by = scaf.size) # validate ranges start
end_positions <- pmin(start_positions + scaf.size - 1, length(yy)) # validate ranges end
dp$start<-start_positions
dp$end<-end_positions

return(dp)
},mw=window.size,gg=gg)
dup.ratio<-do.call(rbind,means)
dup.ratio[,1]<-nm
if(is.list(means)){dup.ratio<-do.call(rbind,means)}else{dup.ratio<-data.frame(means)}
#dup.ratio[,1]<-nm
dup.ratio[dup.ratio=="NaN"]<-0
colnames(dup.ratio)<-c("CHROM","cnv.ratio","CHROM.length","cnvs","non.cnvs","start","end")
# colnames(dup.ratio)<-c("CHROM","cnv.ratio","CHROM.length","cnvs","non.cnvs","start","end")
dup.ratio<-data.frame(dup.ratio[,1],dup.ratio[,3],dup.ratio[,6:7],dup.ratio[,c(2,4:5)])
colnames(dup.ratio)<-c("CHROM","Chr.length","start","end","cnv.ratio","cnvs","non.cnvs")
return(data.frame(dup.ratio))
}


#' Calculate population-wise Vst
#'
#' This function calculates Vst (variant fixation index) for populations given
Expand Down

0 comments on commit f8403c7

Please sign in to comment.