(* Copyright B. Waclaw 2015 *)

(* change the directory below to where the output files are. Usually it will be something like "c:\\path_to_where_you_downloaded_TumourSimulator\\test" *)
SetDirectory["path_to_data_files"];

(* these two files are necessary to generate the 3d shape. Make sure the program outputs them *)
gens=Import[FileNames["genotypes_*.dat"][[1]],"Table"];
img=Import[FileNames["2d_image_*.dat"][[1]],"Table"];
Print["Total no. of cells ",Total[Select[gens,Length[#]≥5 &][[All,5]]]]

(* this colours drivers and passengers similarly to Fig. 2 from the paper *)
color=Table[0.7{1,1,1},{i,Length[gens]}];
Length[gens]
SeedRandom[1234];
Clear[FindPrevGen,RandChange]
FindPrevGen[mini_,maxi_,gen_]:=Module[{i,i1=mini,i2=maxi,n=0},While[i2≥i1,i=Floor[(i1+i2)/2];If[gens[[i,1]]==gen,Return[i]];If[gens[[i,1]]>gen,i2=i-1,i1=i+1];];i];
RandChange[c_]:=Module[{cn,q=0.2},cn={c[[1]](1-q+2q Random[]),c[[2]](1-q+2q Random[]),c[[3]](1-q+2q Random[])};0.7cn/Max[cn]];
Monitor[Do[color[[i]]=RandChange[color[[FindPrevGen[1,i,gens[[i,2]]]]]],{i,2,Length[gens]}],i]

Image[Reverse[Table[Table[If[img[[i,j]]==-1,{1,1,1},color[[img[[i,j]]+1]](img[[i,j+1]]/255.)],{j,1,Length[img[[i]]],2}],{i,Length[img]}]],ImageSize->Length[img[[1]]]]