*/
package jalview.analysis;
-import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.DistanceScoreModelI;
import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.api.analysis.SimilarityScoreModelI;
import jalview.datamodel.AlignmentView;
import jalview.math.MatrixI;
private AlignmentView seqs;
private ScoreModelI scoreModel;
+
+ private SimilarityParamsI similarityParams;
- public PCA(AlignmentView s, ScoreModelI sm)
+ public PCA(AlignmentView s, ScoreModelI sm, SimilarityParamsI options)
{
this.seqs = s;
-
- scoreModel = sm;
+ this.similarityParams = options;
+ this.scoreModel = sm;
+
details.append("PCA calculation using " + sm.getName()
+ " sequence similarity matrix\n========\n\n");
}
MatrixI computeSimilarity(AlignmentView av)
{
MatrixI result = null;
- // TODO pass choice of params from GUI in constructo
if (scoreModel instanceof SimilarityScoreModelI)
{
result = ((SimilarityScoreModelI) scoreModel).findSimilarities(av,
- SimilarityParams.SeqSpace);
+ similarityParams);
}
else if (scoreModel instanceof DistanceScoreModelI)
{
result = ((DistanceScoreModelI) scoreModel).findDistances(av,
- SimilarityParams.SeqSpace);
+ similarityParams);
result.reverseRange(false);
}
else
*/
package jalview.appletgui;
+import jalview.analysis.scoremodels.SimilarityParams;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.ColumnSelection;
return;
}
}
- pcaModel = new PCAModel(seqstrings, seqs, nucleotide);
+ pcaModel = new PCAModel(seqstrings, seqs, nucleotide,
+ SimilarityParams.SeqSpace);
rc = new RotatableCanvas(av);
embedMenuIfNeeded(rc);
/**
* DOCUMENT ME!
*/
+ @Override
public void run()
{
// TODO progress indicator
rc.paint(rc.getGraphics());
}
+ @Override
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == inputData)
}
}
+ @Override
public void itemStateChanged(ItemEvent evt)
{
if (evt.getSource() == xCombobox)
package jalview.gui;
import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.ViewBasedAnalysisI;
import jalview.bin.Cache;
* @param s
* DOCUMENT ME!
*/
- public PCAPanel(AlignmentPanel ap)
+ public PCAPanel(AlignmentPanel alignPanel)
{
super();
- this.av = ap.av;
- this.ap = ap;
+ this.av = alignPanel.av;
+ this.ap = alignPanel;
progressBar = new ProgressBar(statusPanel, statusBar);
- boolean sameLength = true;
+ addInternalFrameListener(new InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosed(InternalFrameEvent e)
+ {
+ close_actionPerformed();
+ }
+ });
+
boolean selected = av.getSelectionGroup() != null
&& av.getSelectionGroup().getSize() > 0;
AlignmentView seqstrings = av.getAlignmentView(selected);
{
seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment());
}
- SeqCigar sq[] = seqstrings.getSequences();
- int length = sq[0].getWidth();
- for (int i = 0; i < seqs.length; i++)
- {
- if (sq[i].getWidth() != length)
- {
- sameLength = false;
- break;
- }
- }
-
- if (!sameLength)
+ // TODO can we allow PCA on unaligned data given choice of
+ // similarity measure parameters?
+ if (!checkAligned(seqstrings))
{
JvOptionPane.showMessageDialog(Desktop.desktop,
MessageManager.getString("label.pca_sequences_not_aligned"),
return;
}
- addInternalFrameListener(new InternalFrameAdapter()
- {
- @Override
- public void internalFrameClosed(InternalFrameEvent e)
- {
- close_actionPerformed();
- }
- });
-
- pcaModel = new PCAModel(seqstrings, seqs, nucleotide);
+ pcaModel = new PCAModel(seqstrings, seqs, nucleotide,
+ SimilarityParams.SeqSpace);
PaintRefresher.Register(this, av.getSequenceSetId());
- rc = new RotatableCanvas(ap);
+ rc = new RotatableCanvas(alignPanel);
this.getContentPane().add(rc, BorderLayout.CENTER);
Thread worker = new Thread(this);
worker.start();
}
/**
+ * Answers true if all sequences have the same aligned length, else false
+ *
+ * @param seqstrings
+ * @return
+ */
+ protected boolean checkAligned(AlignmentView seqstrings)
+ {
+ SeqCigar sq[] = seqstrings.getSequences();
+ int length = sq[0].getWidth();
+ boolean sameLength = true;
+ for (int i = 0; i < sq.length; i++)
+ {
+ if (sq[i].getWidth() != length)
+ {
+ sameLength = false;
+ break;
+ }
+ }
+ return sameLength;
+ }
+
+ /**
* Ensure references to potentially very large objects (the PCA matrices) are
* nulled when the frame is closed
*/
import jalview.analysis.scoremodels.ScoreModels;
import jalview.api.RotatableCanvasI;
import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.SequenceI;
import jalview.datamodel.SequencePoint;
private boolean jvCalcMode = true;
- public PCAModel(AlignmentView seqstrings2, SequenceI[] seqs2,
- boolean nucleotide2)
+ private SimilarityParamsI similarityParams;
+
+ /**
+ * Constructor given sequence data and score calculation parameter options.
+ * The initial state is to compute PCA using a default score model (BLOSUM62
+ * for peptide, DNA for nucleotide).
+ *
+ * @param seqData
+ * @param sqs
+ * @param nuc
+ * @param params
+ */
+ public PCAModel(AlignmentView seqData, SequenceI[] sqs, boolean nuc,
+ SimilarityParamsI params)
{
- seqstrings = seqstrings2;
- seqs = seqs2;
- nucleotide = nucleotide2;
+ seqstrings = seqData;
+ seqs = sqs;
+ nucleotide = nuc;
scoreModel = ScoreModels.getInstance().getDefaultModel(!nucleotide);
+ similarityParams = params;
}
public boolean isJvCalcMode()
public void run()
{
- pca = new PCA(seqstrings, scoreModel);
+ pca = new PCA(seqstrings, scoreModel, similarityParams);
pca.setJvCalcMode(jvCalcMode);
pca.run();