import jalview.analysis.Conservation;
import jalview.analysis.PCA;
+import jalview.analysis.PaSiMap;
import jalview.analysis.scoremodels.ScoreModels;
import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.FeatureColourI;
import jalview.gui.OOMWarning;
import jalview.gui.OverviewPanel;
import jalview.gui.PCAPanel;
+import jalview.gui.PaSiMapPanel;
import jalview.gui.PaintRefresher;
import jalview.gui.SplitFrame;
import jalview.gui.StructureViewer;
import jalview.util.matcher.Condition;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.PCAModel;
+import jalview.viewmodel.PaSiMapModel;
import jalview.viewmodel.ViewportRanges;
import jalview.viewmodel.seqfeatures.FeatureRendererModel;
import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
savePCA(panel, object);
}
}
+ if (frame instanceof PaSiMapPanel)
+ {
+ PaSiMapPanel panel = (PaSiMapPanel) frame;
+ if (panel.getAlignViewport().getAlignment() == jal)
+ {
+ savePaSiMap(panel, object);
+ }
+ }
}
}
}
/**
+ * Writes PaSiMap viewer attributes and computed values to an XML model object and
+ * adds it to the JalviewModel. Any exceptions are reported by logging.
+ * uses the functions from PCA
+ */
+ protected void savePaSiMap(PaSiMapPanel panel, JalviewModel object)
+ {
+ try
+ {
+ PcaViewer viewer = new PcaViewer();
+ viewer.setHeight(panel.getHeight());
+ viewer.setWidth(panel.getWidth());
+ viewer.setXpos(panel.getX());
+ viewer.setYpos(panel.getY());
+ viewer.setTitle(panel.getTitle());
+ PaSiMapModel pasimapModel = panel.getPasimapModel();
+ viewer.setScoreModelName(pasimapModel.getScoreModelName());
+ viewer.setXDim(panel.getSelectedDimensionIndex(X));
+ viewer.setYDim(panel.getSelectedDimensionIndex(Y));
+ viewer.setZDim(panel.getSelectedDimensionIndex(Z));
+ viewer.setBgColour(
+ panel.getRotatableCanvas().getBackgroundColour().getRGB());
+ viewer.setScaleFactor(panel.getRotatableCanvas().getScaleFactor());
+ float[] spMin = panel.getRotatableCanvas().getSeqMin();
+ SeqPointMin spmin = new SeqPointMin();
+ spmin.setXPos(spMin[0]);
+ spmin.setYPos(spMin[1]);
+ spmin.setZPos(spMin[2]);
+ viewer.setSeqPointMin(spmin);
+ float[] spMax = panel.getRotatableCanvas().getSeqMax();
+ SeqPointMax spmax = new SeqPointMax();
+ spmax.setXPos(spMax[0]);
+ spmax.setYPos(spMax[1]);
+ spmax.setZPos(spMax[2]);
+ viewer.setSeqPointMax(spmax);
+ viewer.setShowLabels(panel.getRotatableCanvas().isShowLabels());
+ viewer.setLinkToAllViews(
+ panel.getRotatableCanvas().isApplyToAllViews());
+ /*
+ SimilarityParamsI sp = pasimapModel.getSimilarityParameters();
+ viewer.setIncludeGaps(sp.includeGaps());
+ viewer.setMatchGaps(sp.matchGaps());
+ viewer.setIncludeGappedColumns(sp.includeGappedColumns());
+ viewer.setDenominateByShortestLength(sp.denominateByShortestLength());
+ */
+
+ /*
+ * sequence points on display
+ */
+ for (jalview.datamodel.SequencePoint spt : pasimapModel
+ .getSequencePoints())
+ {
+ SequencePoint point = new SequencePoint();
+ point.setSequenceRef(seqHash(spt.getSequence()));
+ point.setXPos(spt.coord.x);
+ point.setYPos(spt.coord.y);
+ point.setZPos(spt.coord.z);
+ viewer.getSequencePoint().add(point);
+ }
+
+ /*
+ * (end points of) axes on display
+ */
+ for (Point p : panel.getRotatableCanvas().getAxisEndPoints())
+ {
+
+ Axis axis = new Axis();
+ axis.setXPos(p.x);
+ axis.setYPos(p.y);
+ axis.setZPos(p.z);
+ viewer.getAxis().add(axis);
+ }
+
+ /*
+ * raw PaSiMap data (note we are not restoring PaSiMap inputs here -
+ * alignment view, score model, similarity parameters)
+ */
+ PcaDataType data = new PcaDataType();
+ viewer.setPcaData(data);
+ PaSiMap pasimap = pasimapModel.getPasimapData();
+
+ DoubleMatrix pm = new DoubleMatrix();
+ saveDoubleMatrix(pasimap.getPairwiseScores(), pm);
+ data.setPairwiseMatrix(pm);
+
+ DoubleMatrix eigenMatrix = new DoubleMatrix();
+ data.setEigenMatrix(eigenMatrix);
+ saveDoubleMatrix(pasimap.getEigenmatrix(), eigenMatrix);
+
+ object.getPcaViewer().add(viewer);
+ } catch (Throwable t)
+ {
+ Console.error("Error saving PaSiMap: " + t.getMessage());
+ }
+ }
+ /**
* Stores values from a matrix into an XML element, including (if present) the
* D or E vectors
*
{
loadTrees(jalviewModel, view, af, av, ap);
loadPCAViewers(jalviewModel, ap);
+ loadPaSiMapViewers(jalviewModel, ap);
loadPDBStructures(jprovider, jseqs, af, ap);
loadRnaViewers(jprovider, jseqs, ap);
loadOverview(view, jalviewModel.getVersion(), af);
}
/**
+ * Loads any saved PaSiMAp viewers using the function from PCA
+ *
+ * @param jms
+ * @param ap
+ */
+ protected void loadPaSiMapViewers(JalviewModel model, AlignmentPanel ap)
+ {
+ try
+ {
+ List<PcaViewer> pcaviewers = model.getPcaViewer();
+ for (PcaViewer viewer : pcaviewers)
+ {
+ String modelName = viewer.getScoreModelName();
+ /*
+ SimilarityParamsI params = new SimilarityParams(
+ viewer.isIncludeGappedColumns(), viewer.isMatchGaps(),
+ viewer.isIncludeGaps(),
+ viewer.isDenominateByShortestLength());
+ */
+
+ /*
+ * create the panel (without computing the PaSiMAp)
+ */
+ PaSiMapPanel panel = new PaSiMapPanel(ap, modelName);
+
+ panel.setTitle(viewer.getTitle());
+ panel.setBounds(new Rectangle(viewer.getXpos(), viewer.getYpos(),
+ viewer.getWidth(), viewer.getHeight()));
+
+ boolean showLabels = viewer.isShowLabels();
+ panel.setShowLabels(showLabels);
+ panel.getRotatableCanvas().setShowLabels(showLabels);
+ panel.getRotatableCanvas()
+ .setBgColour(new Color(viewer.getBgColour()));
+ panel.getRotatableCanvas()
+ .setApplyToAllViews(viewer.isLinkToAllViews());
+
+ /*
+ * load PaSiMap output data
+ */
+ ScoreModelI scoreModel = ScoreModels.getInstance()
+ .getScoreModel(modelName, ap);
+ PaSiMap pasimap = new PaSiMap(null, scoreModel, null);
+ PcaDataType pasimapData = viewer.getPcaData();
+
+ MatrixI pairwise = loadDoubleMatrix(pasimapData.getPairwiseMatrix());
+ pasimap.setPairwiseScores(pairwise);
+
+ MatrixI result = loadDoubleMatrix(pasimapData.getEigenMatrix());
+ pasimap.setEigenmatrix(result);
+
+ panel.getPasimapModel().setPaSiMap(pasimap);
+
+ /*
+ * we haven't saved the input data! (JAL-2647 to do)
+ */
+ panel.setInputData(null);
+
+ /*
+ * add the sequence points for the PCA display
+ */
+ List<jalview.datamodel.SequencePoint> seqPoints = new ArrayList<>();
+ for (SequencePoint sp : viewer.getSequencePoint())
+ {
+ String seqId = sp.getSequenceRef();
+ SequenceI seq = seqRefIds.get(seqId);
+ if (seq == null)
+ {
+ throw new IllegalStateException(
+ "Unmatched seqref for PaSiMap: " + seqId);
+ }
+ Point pt = new Point(sp.getXPos(), sp.getYPos(), sp.getZPos());
+ jalview.datamodel.SequencePoint seqPoint = new jalview.datamodel.SequencePoint(
+ seq, pt);
+ seqPoints.add(seqPoint);
+ }
+ panel.getRotatableCanvas().setPoints(seqPoints, seqPoints.size());
+
+ /*
+ * set min-max ranges and scale after setPoints (which recomputes them)
+ */
+ panel.getRotatableCanvas().setScaleFactor(viewer.getScaleFactor());
+ SeqPointMin spMin = viewer.getSeqPointMin();
+ float[] min = new float[] { spMin.getXPos(), spMin.getYPos(),
+ spMin.getZPos() };
+ SeqPointMax spMax = viewer.getSeqPointMax();
+ float[] max = new float[] { spMax.getXPos(), spMax.getYPos(),
+ spMax.getZPos() };
+ panel.getRotatableCanvas().setSeqMinMax(min, max);
+
+ // todo: hold points list in PCAModel only
+ panel.getPasimapModel().setSequencePoints(seqPoints);
+
+ panel.setSelectedDimensionIndex(viewer.getXDim(), X);
+ panel.setSelectedDimensionIndex(viewer.getYDim(), Y);
+ panel.setSelectedDimensionIndex(viewer.getZDim(), Z);
+
+ // is this duplication needed?
+ panel.setTop(seqPoints.size() - 1);
+ panel.getPasimapModel().setTop(seqPoints.size() - 1);
+
+ /*
+ * add the axes' end points for the display
+ */
+ for (int i = 0; i < 3; i++)
+ {
+ Axis axis = viewer.getAxis().get(i);
+ panel.getRotatableCanvas().getAxisEndPoints()[i] = new Point(
+ axis.getXPos(), axis.getYPos(), axis.getZPos());
+ }
+
+ Desktop.addInternalFrame(panel, MessageManager.formatMessage(
+ "label.calc_title", "PaSiMap", modelName), 475, 450);
+ }
+ } catch (Exception ex)
+ {
+ Console.error("Error loading PaSiMap: " + ex.toString());
+ }
+ }
+
+ /**
* Creates a new structure viewer window
*
* @param viewerType