Skip to content

Commit

Permalink
adding fixes that handle out-of-order clones and a test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisamiller committed Dec 13, 2018
1 parent 050cbb3 commit 3da45eb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
11 changes: 8 additions & 3 deletions R/draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,14 @@ fishPlot <- function(fish,shape="polygon", vlines=NULL, col.vline="#FFFFFF99", v
#(if neither is set, bg will just be white)

##draw the clusters one at a time, being sure that parents go before children
for(parent in sort(unique(fish@parents))){
for(i in which(fish@parents==parent)){

parentsList = 0
while(length(parentsList) > 0){
parent = parentsList[[1]]
children = which(fish@parents==parent)
parentsList = parentsList[-1]
parentsList = c(parentsList, children)
numChildren = length(children)
for(i in children){
pad.left=pad
if(parent>0){
pad.left=pad*0.4
Expand Down
14 changes: 9 additions & 5 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ layoutClones <- function(fish,separate.independent.clones=FALSE){
xpos = rep(timepoint, length(fish@parents))

##starting with those with no parents, then moving through each existing parent
for(parent in sort(unique(fish@parents))){

numChildren = length(fish@parents[fish@parents==parent])
spacing = 0
parentsList = 0
while(length(parentsList) > 0){
parent = parentsList[[1]]
children = which(fish@parents == parent)
parentsList = parentsList[-1]
parentsList = c(parentsList, children)
numChildren = length(children)
spacing = 0
##start at the bottom plus half the outer space
y = fish@outer.space[timepos]/2;

Expand All @@ -54,7 +58,7 @@ layoutClones <- function(fish,separate.independent.clones=FALSE){
}

##for each clone that has this parent, get coords
for(clone in which(fish@parents==parent)){
for(clone in children){

##clone absent, don't need to add positions
if(fish@frac.table[clone,timepos] == 0){
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ A: The original visualization was put together by [Joshua McMichael](https://git

## Notes
Citation: [Visualizing tumor evolution with the fishplot package for R](https://bmcgenomics.biomedcentral.com/articles/10.1186/s12864-016-3195-z). Miller CA, McMichael J, Dang HX, Maher CA, Ding L, Ley TJ, Mardis ER, Wilson RK. BMC Genomics. doi:10.1186/s12864-016-3195-z

26 changes: 26 additions & 0 deletions tests/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,29 @@ fishPlot(fish, shape="polygon", vlab=c("Primary","Post-AI"),
cex.title=0.7, cex.vlab=0.8,ramp.angle=1, pad.left=0.3)

dev <- dev.off()

##-------------------------------------------
## test if the clones are not listed in order
## see https://github.com/chrisamiller/fishplot/pull/2
pdf("ordertest.pdf", width=8, height=5)
library(fishplot)
timepoints=c(0,30,75,150)
frac.table = matrix(
c(100, 45, 00, 00,
02, 00, 00, 00,
02, 00, 02, 01,
98, 00, 95, 40),
ncol=length(timepoints))
parents = c(0,1,1,3)

##Now just rearrange clones.
frac.table = frac.table[c(4,3,2,1),]
parents = c(2,4,4,0)

fish = createFishObject(frac.table,parents,timepoints=timepoints)
fish = layoutClones(fish)
fishPlot(fish,shape="spline",title.btm="Sample1",
cex.title=0.5, vlines=c(0,150),
vlab=c("day 0","day 150"))
dev <- dev.off()

0 comments on commit 3da45eb

Please sign in to comment.