(*VISUALIZE:run this to visualize*)
SetDirectory[NotebookDirectory[]];
<<correlations_data
Labels={"CCs","C_ks[1]","C_ks[2]","C_ks[3]","C_ks[4]","C_ks[5]","C_ks[6]","bettis[1]","bettis[2]","bettis[3]","bettis[4]","bettis[5]","simplices[0]","simplices[1]","simplices[2]","simplices[3]","simplices[4]","simplices[5]","simplices[6]","layer","in_degree","out_degree","excitatory","simplex_containment[1]","simplex_containment[2]","simplex_containment[3]","simplex_containment[4]","simplex_containment[5]","simplex_containment[6]","internal_distance","90pce","90pc","betti_coeff","adjacency_spectrum_diff","adjacency_spectrum_small","laplacian_spectrum_diff","laplacian_spectrum_small","ext_comm_size[1]","ext_comm_size[2]","ext_comm_size[3]","ricci_curvature","ricci_curvature_within_community","euler_characteristic"};
Legends={"Layer: ","Excitatory: ","90% exc. membership: ","90% membership: "};
(*1 -> 1920x1080 screen, 2-> 2560x1440 screen*)
{Sizes,TextSize}={{{1200,500,1400,500},8},{{1600,800,1400,700},11}}[[2]];
(*width and height of boxes in grid*)
W=1;H=-.6;
(*Style and color parameters*)
pstyl={{PointSize[.011],Opacity[.5]}};
(*pstyl={ColorData[60][12],PointSize[.01],Opacity[.5]};*)
PlotPad={{45,60},{10,5}};
CorrToCol[val_]:=ColorData["TemperatureMap"][val/200.0+.5];
ColAssoc=<|20->1,23->2,31->3,32->4|>;
(*Size and cutoff parameters*)
Size=Length[Labels];Tops={100,500,1000,5000};TopNum=Length[Tops];
(*Helper function for coloring data in graphs*)
PlotSplit[V1_,V2_,t_,s_,c_]:=With[{
pairs=Partition[Riffle[V1,V2],2],
equiv=Take[First[VecDiscrete[[ColAssoc[c]]]][[#]]&/@((#+1)&/@First[VecID[[s]]]),t]},
Through[{Map[pairs[[#]]&,#]&,Map[equiv[[First[#]]]&,#]&}[Split[SortBy[Table[i,{i,1,Abs[t]-1}],equiv[[#]]&],equiv[[#1]]==equiv[[#2]]&]]]];
(*Main interactive graphic*)
DynamicModule[{corr=2,top=0,sort=3,color=20,x=3,y=21},Column[{
Row[{
Dynamic@With[{CurrCorr=If[top==0,{PearsAll,SpearAll,ConcAll}[[corr]],{{PearsTop,SpearTop,ConcTop}[[corr]],{PearsBot,SpearBot,ConcBot}[[corr]]}[[Quotient[top,TopNum,1]+1]][[Mod[top,TopNum,1]]][[sort]]]},Graphics[Join[
(*Squares,colored*)
Table[Table[{If[i==x||j==y,Blend[{CorrToCol[CurrCorr[[i]][[j]]],LightRed},.5],CorrToCol[CurrCorr[[i]][[j]]]],Rectangle[{W*i,H*j},{W*(i+1),H*(j+1)}]},{i,1,j-1}],{j,1,Size}]//Flatten,
(*Squares,text*)
Table[Table[Style[Text[NumberForm[N[CurrCorr[[i]][[j]]],{3,1}],{(i+.9)*W,(j+.5)*H},Right],FontSize->TextSize,If[i==x||j==y,Red,Gray]],{i,1,j-1}],{j,1,Size}]//Flatten,
(*Labels on left and diagonal*)
{Black},Table[Text[Labels[[i]],{.7,(i+.5)*H},Right,BaseStyle->{FontSize->TextSize}],{i,2,Size}],
Table[Text[Labels[[i]],{(i+.2)*W,(i+.5)*H},Left,BaseStyle->{FontSize->TextSize}],{i,1,Size}],
{Text["Click to sort by:",{.7,(Size+2.5)*H},Right,BaseStyle->{FontSize->TextSize}]},
{Text["Click to color by:",{.7,(Size+4)*H},Right,BaseStyle->{FontSize->TextSize}]},
(*Labels in top middle*)
{Black},Table[Text[t[[1]],{23*W,t[[2]]*H},Right,BaseStyle->{FontSize->TextSize*2,FontColor->Gray}],{t,{{"Property 1:",8.5},{"Property 2:",10},{"Sorting by:",5},{"Coloring by:",13.5}}}],
Table[Text[t[[1]],{23.3*W,t[[2]]*H},Left,BaseStyle->{FontSize->TextSize*2}],{t,{{Labels[[x]],8.5},{Labels[[y]],10},{Labels[[sort]],5},{<|20->"layer",23->"excitatory",31->"90_percent_cover_excitatory",32->"90_percent_cover"|>[color],13.5}}}],
(*Labels in right middle*)
{LightGray,Rectangle[{36.5*W,11*H},{45.5*W,26*H}]},{Gray},
Table[Text[t[[1]],{36*W,(11+1.5*t[[2]])*H},Right,BaseStyle->{FontSize->TextSize*1.2}],{t,{{"Top 100",1},{"Top 500",2},{"Top 1000",3},{"Top 5000",4},{"Everything",5},{"Bottom 5000",6},{"Bottom 1000",7},{"Bottom 500",8},{"Bottom 100",9}}}],
{Gray,Text["Pearson",{39*W,10*H},Right,BaseStyle->{FontSize->TextSize*1.2}]},
Table[Text[t[[1]],{39*W,(11+1.5*t[[2]])*H},Right,BaseStyle->{FontSize->TextSize*2,FontWeight->Bold,FontColor->CorrToCol[t[[1]]]}],{t,Join[
{PearsTop[[#]][[sort]][[x]][[y]],#}&/@{1,2,3,4},{{PearsAll[[x]][[y]],5}},{PearsBot[[10-#]][[sort]][[x]][[y]],#}&/@{6,7,8,9}]}],
{Gray,Text["Spearman",{42*W,10*H},Right,BaseStyle->{FontSize->TextSize*1.2}]},
Table[Text[t[[1]],{42*W,(11+1.5*t[[2]])*H},Right,BaseStyle->{FontSize->TextSize*2,FontWeight->Bold,FontColor->CorrToCol[t[[1]]]}],{t,Join[
{SpearTop[[#]][[sort]][[x]][[y]],#}&/@{1,2,3,4},{{SpearAll[[x]][[y]],5}},{SpearBot[[10-#]][[sort]][[x]][[y]],#}&/@{6,7,8,9}]}],
{Gray,Text["Concordance",{45.5*W,10*H},Right,BaseStyle->{FontSize->TextSize*1.2}]},
Table[Text[t[[1]],{45*W,(11+1.5*t[[2]])*H},Right,BaseStyle->{FontSize->TextSize*2,FontWeight->Bold,FontColor->CorrToCol[t[[1]]]}],{t,Join[
{ConcTop[[#]][[sort]][[x]][[y]],#}&/@{1,2,3,4},{{ConcAll[[x]][[y]],5}},{ConcBot[[10-#]][[sort]][[x]][[y]],#}&/@{6,7,8,9}]}],
(*Squares,transparent button overlay*)
Table[Table[{Opacity[0],Button[Rectangle[{W*i,H*j},{W*(i+1),H*(j+1)}],{x,y}={Quotient[#[[1]],W],Quotient[#[[2]],H]}&[MousePosition["Graphics"]]]},{i,1,j-1}],{j,1,Size}],
(*Bottom row for gray/red buttons*)
Table[{If[i==sort,Red,LightGray],Button[Rectangle[{W*i+.1,H*(Size+3)},{W*(i+1)-.1,H*(Size+2)}],sort=Quotient[#[[1]],W]&[MousePosition["Graphics"]]]},{i,1,Size}],
Table[{If[i==color,Red,LightGray],Button[Rectangle[{W*i+.1,H*(Size+4.5)},{W*(i+1)-.1,H*(Size+3.5)}],color=Quotient[#[[1]],W]&[MousePosition["Graphics"]]]},{i,{20,23,31,32}}]],
ImageSize->Sizes[[1]]]],
Column[{
Row[{
Style["Correlation: ",FontSize->TextSize*1.5],PopupMenu[Dynamic[corr],{1->Style[" Pearson ",FontSize->TextSize*1.5],2->Style[" Spearman ",FontSize->TextSize*1.5],3->Style[" Concordance ",FontSize->TextSize*1.5]}],Spacer[20],
Style["Cutoff: ",FontSize->TextSize*1.5],PopupMenu[Dynamic[top],{
1->Style[" Top 100 ",FontSize->TextSize*1.5],
2->Style[" Top 500 ",FontSize->TextSize*1.5],
3->Style[" Top 1000 ",FontSize->TextSize*1.5],
4->Style[" Top 5000 ",FontSize->TextSize*1.5],
0->Style[" None ",FontSize->TextSize*1.5],
8->Style[" Bottom 5000 ",FontSize->TextSize*1.5],
7->Style[" Bottom 1000 ",FontSize->TextSize*1.5],
6->Style[" Bottom 500 ",FontSize->TextSize*1.5],
5->Style[" Bottom 100 ",FontSize->TextSize*1.5]}]}],
Dynamic@With[{CurrVecX=Take[First[Vec[[sort]][[x]]],If[top<5,1,-1]*Tops[[Mod[top,TopNum,1]]]],CurrVecY=Take[First[Vec[[sort]][[y]]],If[top<5,1,-1]*Tops[[Mod[top,TopNum,1]]]]},
Histogram3D[Table[{CurrVecX[[k]],CurrVecY[[k]]},{k,1,Tops[[Mod[top,TopNum,1]]]}],ChartElementFunction->ChartElementDataFunction["GradientScaleCube","ColorScheme"->"NeonColors"],
Boxed->False,AxesEdge->{{-1,-1},{1,-1},{-1,-1}},AxesLabel->{Labels[[y]],Labels[[x]]},ImageSize->Sizes[[2]],SphericalRegion->True,ViewPoint->{2,-2,2}]]},
Left]},Alignment->Top],
Dynamic@With[{scat=If[top==0,
PlotSplit[Vec[[sort]][[x]]//Flatten,Vec[[sort]][[y]]//Flatten,31346,sort,color],
PlotSplit[Take[Vec[[sort]][[x]]//Flatten,If[top<5,1,-1]*Tops[[Mod[top,TopNum,1]]]],Take[Vec[[sort]][[y]]//Flatten,If[top<5,1,-1]*Tops[[Mod[top,TopNum,1]]]],If[top<5,1,-1]*Tops[[Mod[top,TopNum,1]]],sort,color]]},
Row[{
ListPlot[Join[scat[[1]],{{{,}}}],PlotRange->All,
PlotLegends->SwatchLegend[Style[#,TextSize*1.5]&/@scat[[2]],LegendMarkerSize->20,LegendMarkers->"Bubble",LegendLabel->Placed[Style[Legends[[ColAssoc[color]]],TextSize*1.5],Left],LegendLayout->"Row"],
PlotStyle->pstyl,PlotLabel->"Linear-Linear plot",AxesLabel->{Labels[[x]],Labels[[y]]},ImageSize->Sizes[[4]],AspectRatio->.6],
ListLogLinearPlot[Join[scat[[1]],{{{,}}}],PlotRange->All,
PlotLegends->SwatchLegend[Style[#,TextSize*1.5]&/@scat[[2]],LegendMarkerSize->20,LegendMarkers->"Bubble",LegendLabel->Placed[Style[Legends[[ColAssoc[color]]],TextSize*1.5],Left],LegendLayout->"Row"],
PlotStyle->pstyl,PlotLabel->"Log-Linear plot",AxesLabel->{Labels[[x]],Labels[[y]]},ImageSize->Sizes[[4]],AspectRatio->.6],
ListLogLinearPlot[Map[Reverse,Join[scat[[1]],{{{,}}}],{2}],PlotRange->All,
PlotLegends->SwatchLegend[Style[#,TextSize*1.5]&/@scat[[2]],LegendMarkerSize->20,LegendMarkers->"Bubble",LegendLabel->Placed[Style[Legends[[ColAssoc[color]]],TextSize*1.5],Left],LegendLayout->"Row"],
PlotStyle->pstyl,PlotLabel->"Log-Linear plot,axes swap",AxesLabel->{Labels[[y]],Labels[[x]]},ImageSize->Sizes[[4]],AspectRatio->.6]}
]]},Center]]