

plot.corrmat <- function(mat, sse=NULL,

                         helix.labels.x=NULL,
                         helix.labels.at.x=NULL,
                         helix.labels.y=NULL,
                         helix.labels.at.y=NULL,
                         
                         axis.at.x=NULL, axis.at.y=NULL,
                         axis.labels.x=NULL, axis.labels.y=NULL,
                         cex.axis=.7, cex.sse=.6,
                         
                         vlines=NULL, hlines=NULL,
                         xlab = "Residue index",
                         ylab = "Residue index (cis subunit)",
                         main = "",
                         levels = pretty( c(-1,1), 20),
                         
                         Labpalette = colorRampPalette(
                           c("blue", "white", "red"),
                           space = "Lab"),
                         ...) {

  nr <- dim(mat)[1]
  nc <- dim(mat)[2]

  filled.contour( x=1:nr, y=1:nc, z=mat, color = Labpalette,
                 levels = levels,
                 nlevels = 10,
                 xlab = xlab, ylab=ylab, main = main,

                 plot.axes={
                   axis(2, at=axis.at.y, labels=axis.labels.y, cex.axis=cex.axis);
                   axis(1, at=axis.at.x, labels=axis.labels.x, cex.axis=cex.axis);

                   abline(v=axis.at.x, lty=2, col="grey70");
                   abline(h=axis.at.y, lty=2, col="grey70");
                   
                   mtext(helix.labels.y, side=4, line=0.2, las=2,
                         at=helix.labels.at.y,
                         cex=cex.sse);
                    mtext(helix.labels.x, side=1, line=0.2, las=1,
                         at=helix.labels.at.x,
                         cex=cex.sse);

                   abline(v=vlines, lty="dashed", lwd=2);
                   abline(h=hlines, lty="dashed", lwd=2);
                   abline(v=525, lwd=3)

                   mtext(c("right trans subunit", "left trans subunit"),
                         at=c(524/2, (524/2)+524),
                         side=3, line=.7, cex=1.1);
                   
                   mtext(c("E1", "I1", "A", "I2", "E2"),
                         at=c(132/2, (132+190)/2, (190+376)/2, (376+408)/2, (408+524)/2),
                         side=3, line=-3.0, cex=1.1);
                   mtext(c("E1", "I1", "A", "I2", "E2"),
                         at=524+c(132/2, (132+190)/2, (190+376)/2, (376+408)/2, (408+524)/2),
                         side=3, line=-3.0, cex=1.1);

                   mtext(c("cis ADP", "trans ATP", "trans ATP"),
                         at=c((1048+1060)/2, (1060+1073)/2, (1073+1085)/2), 
                         side=1, line=.2, cex=cex.sse, las=2);


                 },
                 ...
                 )
}
