Skip to content

Commit

Permalink
Update merge_windows.R
Browse files Browse the repository at this point in the history
merge only if nrow(windows) >2
  • Loading branch information
rr1859 authored Jul 22, 2018
1 parent 3c88936 commit 5131577
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions R/merge_windows.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ merge_windows = function(windows){
chr=as.character(windows[1,1])
start=windows[1,2]
end=windows[1,3]
for(i in 2:nrow(windows)){
if(as.character(windows[i,1]) == chr & windows[i,2] <= end & windows[i,2] >= start){
end=windows[i,3]
}
else{
output=rbind(output, c(chr,start, end))
chr=as.character(windows[i,1])
start=windows[i,2]
end=windows[i,3]
if(nrow(windows) > 2){
for(i in 2:nrow(windows)){
if(as.character(windows[i,1]) == chr & windows[i,2] <= end & windows[i,2] >= start){
end=windows[i,3]
}
else{
output=rbind(output, c(chr,start, end))
chr=as.character(windows[i,1])
start=windows[i,2]
end=windows[i,3]
}
}
return(data.frame(output))
} else{
return(windows)
}
return(data.frame(output))
}
}

0 comments on commit 5131577

Please sign in to comment.