Skip to content

Commit

Permalink
fully functional squaremap, fixes #8 #11
Browse files Browse the repository at this point in the history
  • Loading branch information
arturhoo committed Apr 23, 2012
1 parent 7b33af7 commit 347a310
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 120 deletions.
163 changes: 54 additions & 109 deletions prot2/Matriz.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ class Matriz {
Nivel1[][] quadrados;
int x, y, w, h;
ArrayList<HeatSquare> heatSquareList;
ArrayList<SquareMap> squareMapList;
int maiorValor = 0, segundoMaiorValor = 0;
boolean exibeLog = false, exibe00 = false, mvg=false;
boolean grown = false;
Nivel1 quadradoFocado = null;
int quadradoFocadoI, quadradoFocadoJ;
int numTotalElementos;

float[] maioresValoresX;
float[] maioresValoresY;
Expand All @@ -25,6 +27,7 @@ class Matriz {
}
}
this.heatSquareList = new ArrayList<HeatSquare>();
this.squareMapList = new ArrayList<SquareMap>();
this.maioresValoresX = new float[numChave];
this.maioresValoresY = new float[numChave];
this.maioresValoresXE00 = new float[numChave];
Expand Down Expand Up @@ -108,7 +111,8 @@ class Matriz {
return this.segundoMaiorValor;
}

void drawSquareMap2() {
void drawSquareMap() {
this.squareMapList = new ArrayList<SquareMap>();
float[] maioresValoresLocaisY = new float[numChave];
float[] maioresValoresLocaisX = new float[numChave];
int countNulls = 0;
Expand Down Expand Up @@ -142,16 +146,17 @@ class Matriz {

// Desenha regiao valida
fill(cValidos);
int novoW = countNulls == 0 ? w : (int) (w - countNulls*(w/(numChave*2)));
int novoY = (int) (y+countNulls*(h/(numChave*2)));
float regiaoInvalidaUnidade = 10;
int novoW = countNulls == 0 ? w : (int) (w - countNulls*(w/(regiaoInvalidaUnidade)));
int novoY = (int) (y+countNulls*(h/(regiaoInvalidaUnidade)));
int novoH = (y+h) - novoY;
rect(x, novoY, novoW, novoH);

// Desenha limites regiao invalida
stroke(255);
for(int i=0; i<countNulls; i++) {
line(x, y+i*(w/(numChave*2)), x+w, y+i*(w/(numChave*2)));
line(x+novoW+i*(w/(numChave*2)), y, x+novoW+i*(w/(numChave*2)), y+h);
line(x, y+i*(w/(regiaoInvalidaUnidade)), x+w, y+i*(w/(regiaoInvalidaUnidade)));
line(x+novoW+i*(w/(regiaoInvalidaUnidade)), y, x+novoW+i*(w/(regiaoInvalidaUnidade)), y+h);
}


Expand All @@ -177,12 +182,19 @@ class Matriz {
numElementosAtual = numElementosAtual*2;
if(this.exibeLog) numElementosAtual = log(numElementosAtual);
if(numElementosAtual != 0.0) {
SquareMap sm = new SquareMap(x+acumulaY+((acumulaY+maioresValoresLocaisY[j]*constanteX)-(acumulaY+numElementosAtual*constanteX)),
novoY+acumulaX,
numElementosAtual*constanteX,
numElementosAtual*constanteY,
i, j);
float smx = x+acumulaY+((acumulaY+maioresValoresLocaisY[j]*constanteX)-(acumulaY+numElementosAtual*constanteX));
float smy = novoY+acumulaX;
float smw = numElementosAtual*constanteX;
float smh = numElementosAtual*constanteY;
SquareMap sm = new SquareMap(smx, smy, smw, smh, i, j);
squareMapList.add(sm);
sm.draw();
if(quadradoFocado != null && i == quadradoFocadoI && j == quadradoFocadoJ) {
strokeWeight(2);
stroke(cHighlightedSquare);
rect(smx+2, smy+2, smw-4, smh-4);
strokeWeight(1);
}
}
}
}
Expand All @@ -193,108 +205,19 @@ class Matriz {
stroke(255);
line(x, novoY+acumulaX, x+w, novoY+acumulaX);
}
}

void drawSquareMap() {
float numElementos;
float[] maioresValoresLocaisY = new float[numChave];
float[] maioresValoresLocaisX = new float[numChave];
int countNulls = 0;

// Toma conta das variaveis booleanas
for(int i=0; i<numChave; i++) {
if(exibe00) {
maioresValoresLocaisX[i] = this.mvg ? gl.maioresValoresX[i] : this.maioresValoresX[i];
maioresValoresLocaisY[i] = this.mvg ? gl.maioresValoresY[i] : this.maioresValoresY[i];

// Contando os inválidos
if(this.quadrados[numChave-1][i] == null) {
maioresValoresLocaisX[numChave-1-i] = log(gl.maioresValoresX[i]);
maioresValoresLocaisY[i] = log(gl.maioresValoresY[i]);
countNulls++;
}
} else {
maioresValoresLocaisX[i] = this.mvg ? gl.maioresValoresXE00[i] : this.maioresValoresXE00[i];
maioresValoresLocaisY[i] = this.mvg ? gl.maioresValoresYE00[i] : this.maioresValoresYE00[i];

if(this.quadrados[numChave-1][i] == null) {
maioresValoresLocaisX[numChave-1-i] = log(gl.maioresValoresXE00[i]);
maioresValoresLocaisY[i] = log(gl.maioresValoresYE00[i]);
countNulls++;
}
}

if(this.exibeLog) {
if(maioresValoresLocaisX[i] != 0.0) maioresValoresLocaisX[i] = log(maioresValoresLocaisX[i]);
// else maioresValoresLocaisX[i] = log(gl.maioresValoresX[i]);
if(maioresValoresLocaisY[i] != 0.0) maioresValoresLocaisY[i] = log(maioresValoresLocaisY[i]);
// else maioresValoresLocaisY[i] = log(gl.maioresValoresY[i]);
}
}

// Calcula fator de compensação
float constanteX, constanteY, comp = 0, altura = 0;
for(int i=0; i<numChave; i++) {
comp += maioresValoresLocaisY[i];
altura += maioresValoresLocaisX[i];
if(grown) {
drawMatrixInfoSM();
}
constanteY = h/altura;
constanteX = w/comp;

// Desenha quadrado
fill(cValidos);
stroke(0);
rect(x, y, w, h);
}

// Desenha regiao invalida
if(countNulls !=0 ) {
float acumulaX1 = 0, acumulaY1 = 0;
for(int i=0; i<countNulls; i++) {
acumulaX1 += maioresValoresLocaisX[i];
void identificaQuadradoFocadoSM() {
for(int i=squareMapList.size()-1; i>=0; i--) {
if(squareMapList.get(i).mouseOver()) {
quadradoFocadoI = squareMapList.get(i).matI;
quadradoFocadoJ = squareMapList.get(i).matJ;
quadradoFocado = quadrados[quadradoFocadoI][quadradoFocadoJ];
}
for(int i=0; i<numChave-countNulls; i++) {
acumulaY1 += maioresValoresLocaisY[i];
}
fill(cInvalidos);
noStroke();
rect(x+1, y+1, w-1, acumulaX1*constanteY-2);
rect( acumulaY1*constanteX+x+1,
y+acumulaX1*constanteY-2,
x+w-(acumulaY1*constanteX+x+1),
y+h-(y+acumulaX1*constanteY));
}

// Desenha os squaremaps
for(int i=numChave-1; i>=0; i--) {
// Calcula o deslocamento na vertical
float acumulaX = 0;
for(int k=0; k<i; k++) {
acumulaX += maioresValoresLocaisX[k];
}
acumulaX *=constanteY;
float acumulaY = 0;
for(int j=0; j<numChave; j++) {
if(!exibe00 && i==numChave-1 && j==0){
} else {
if(quadrados[i][j] != null ) {
numElementos = pow(quadrados[i][j].numElementos, 0.5);
if(this.exibeLog) numElementos = log(numElementos);
if(numElementos != 0.0) {
fill(cPallete[4], 170);
stroke(100);
rectMode(CORNER);
rect( x+acumulaY+((acumulaY+maioresValoresLocaisY[j]*constanteX)-(acumulaY+numElementos*constanteX)),
y+acumulaX,
numElementos*constanteX,
numElementos*constanteY);
}
}
}
acumulaY += maioresValoresLocaisY[j]*constanteX;
}
}

if(grown) drawMatrixInfo();
}

void preencheHeatSquareList() {
Expand Down Expand Up @@ -369,7 +292,7 @@ class Matriz {
}
}
if(grown) {
drawMatrixInfo();
drawMatrixInfoHM();
drawMatrixAxisHM();
}
}
Expand Down Expand Up @@ -400,7 +323,29 @@ class Matriz {
fill(cHistogramText);
text("Release: r" + (quadrados[4][0].ver_estudo-1) + "-" + (quadrados[4][0].ver_estudo), x+2, y-50);
text("Prefix: " + (quadrados[4][0].prefixo), x+2, y-35);
}

void drawMatrixInfoSM() {
drawMatrixInfo();
fill(cHistogramText);
int textX = x+w/2-60;
text("Antidiagonal entries", textX, y-50);
text("Super-antidiagonal entries", textX, y-35);
text("Sub-antidiagonal entries", textX, y-20);
int rectW = 100;
int rectH = 15;
int rectX = x+w-rectW;
noStroke();
fill(cAntidiagonal);
rect(rectX, y-60, rectW, rectH);
fill(cSuperAntidiagonal);
rect(rectX, y-45, rectW, rectH);
fill(cSubAntidiagonal);
rect(rectX, y-30, rectW, rectH);
}

void drawMatrixInfoHM() {
drawMatrixInfo();
noStroke();
int sw = 30, sh = 17;
int legendX = x+w-(sw*cPallete.length);
Expand Down
35 changes: 35 additions & 0 deletions prot2/SquareMap.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class SquareMap {
int x, y, w, h;
int matI, matJ;
color cFill;

SquareMap(float x, float y, float w, float h, int matI, int matJ) {
this.x = (int) (x);
this.y = (int) (y);
this.w = (int) (w);
this.h = (int) (h);
this.matI = matI;
this.matJ = matJ;
defineCor();
}

void defineCor() {
if(this.matI == numChave-1-this.matJ) this.cFill = cAntidiagonal;
else if(this.matI + this.matJ >= numChave) this.cFill = cSubAntidiagonal;
else this.cFill = cSuperAntidiagonal;
}

boolean mouseOver() {
if((mouseX > x && mouseX < x+w) &&
(mouseY > y && mouseY < y+h))
return true;
else return false;
}

void draw() {
fill(cFill);
noStroke();
rectMode(CORNER);
rect(x, y, w, h);
}
}
44 changes: 33 additions & 11 deletions prot2/prot2.pde
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ color cButtonTitleText = #000000;
color cButtonText = #5D4157;
color cButtonMouseOver = #9B568D;
color cButtonActive = #FF4E50;
color cHighlightedSquare = #FF4E50;
color cHighlightedSquare = #3F00B7;
color cHistogramText = #5D4157;
color cElipse = #FF0000;
color cSparkLine = #5D4157;
color cProteinAnt = #E6E6E6;
color cProteinNovo = #BEBEBE;
color cAntidiagonal = #FF0000;
color cSuperAntidiagonal = #FF7B00;
color cSubAntidiagonal = #FFD000;


void setup() {
Expand Down Expand Up @@ -105,7 +108,7 @@ void draw() {
} else {
if(!drawnFocada) matrizFocada.preencheHeatSquareList(); // Vai recalcular as dimensoes
if(heatMapButton.active) matrizFocada.drawHeatMap();
if(squareMapButton.active) matrizFocada.drawSquareMap2();
if(squareMapButton.active) matrizFocada.drawSquareMap();
if(matrizFocada.quadradoFocado != null) matrizFocada.quadradoFocado.drawHistogram();
if(mudancaProteinaFocada != null) mudancaProteinaFocada.drawDetail();
drawnFocada = true;
Expand Down Expand Up @@ -206,17 +209,17 @@ void preencheSuperMatriz() {
}
}
}
print("MVG: " + gl.maiorValor + " SMVG: " + gl.segundoMaiorValor + "\n");
for(int i=0; i<numChave; i++) {
print("GX: " + gl.maioresValoresX[i] + " GY: " + gl.maioresValoresY[i] + "\n");
}
// print("MVG: " + gl.maiorValor + " SMVG: " + gl.segundoMaiorValor + "\n");
// for(int i=0; i<numChave; i++) {
// print("GX: " + gl.maioresValoresX[i] + " GY: " + gl.maioresValoresY[i] + "\n");
// }
}

void posicionaSuperMatriz() {
int x = gl.smx, y = gl.smy, w = gl.smw, h = gl.smh;
int quadradoX = (int) (w-((numEstudos-1)*gl.smEspacamentoX))/numEstudos;
int quadradoY = (int) (h-((numPrefixos-1)*gl.smEspacamentoY))/numPrefixos;
print("QuadradoX :" + quadradoX + ", QuadradoY: " + quadradoY + "\n");
// print("QuadradoX :" + quadradoX + ", QuadradoY: " + quadradoY + "\n");
for(int i=0; i<numEstudos; i++) {
for(int j=0; j<numPrefixos; j++) {
superMatriz[j][i].x = x+(quadradoX+gl.smEspacamentoX)*i;
Expand Down Expand Up @@ -259,16 +262,17 @@ void drawSuperMatrizHeatMap() {
}
}
drawSuperMatrizAxis();
drawHeatMapScale();
drawHeatMapLegend();
}

void drawSuperMatrizSquareMap() {
for(int i=0; i<numEstudos; i++) {
for(int j=numPrefixos-1; j>=0; j--) {
superMatriz[j][i].drawSquareMap2();
superMatriz[j][i].drawSquareMap();
}
}
drawSuperMatrizAxis();
drawSquareMapLegend();
}

void drawSuperMatrizAxis() {
Expand Down Expand Up @@ -296,7 +300,24 @@ void drawSuperMatrizAxis() {
textAlign(LEFT);
}

void drawHeatMapScale() {
void drawSquareMapLegend() {
fill(cHistogramText);
textFont(font, 11);
text("Antidiagonal entries", gl.smx, gl.smy+gl.smh+20);
text("Super-antidiagonal entries", gl.smx, gl.smy+gl.smh+32);
text("Sub-antidiagonal entries", gl.smx, gl.smy+gl.smh+44);
int rectW = 100;
int rectH = 12;
noStroke();
fill(cAntidiagonal);
rect(gl.smx+200, gl.smy+gl.smh+12, rectW, rectH);
fill(cSuperAntidiagonal);
rect(gl.smx+200, gl.smy+gl.smh+24, rectW, rectH);
fill(cSubAntidiagonal);
rect(gl.smx+200, gl.smy+gl.smh+36, rectW, rectH);
}

void drawHeatMapLegend() {
noStroke();
int w = 20, h = 12;
for(int i=0; i<cPallete.length; i++) {
Expand Down Expand Up @@ -344,7 +365,8 @@ void mousePressed() {
}
} else {
if(matrizFocada.mouseOver()) {
matrizFocada.identificaQuadradoFocadoHM();
if(squareMapButton.active) matrizFocada.identificaQuadradoFocadoSM();
else matrizFocada.identificaQuadradoFocadoHM();
mudancaProteinaFocada = null;
}

Expand Down

0 comments on commit 347a310

Please sign in to comment.