package jalview.analysis;
import jalview.analysis.scoremodels.ScoreModels;
+import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.DistanceScoreModelI;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityScoreModelI;
{
this.sequence = sqs;
this.node = new Vector<SequenceNode>();
+ if (!(treeType.equals(NEIGHBOUR_JOINING)))
+ {
+ treeType = AVERAGE_DISTANCE;
+ }
this.type = treeType;
this.pwtype = modelType;
if (seqView != null)
sdata.addOperation(CigarArray.M, end - start + 1);
this.seqData = new AlignmentView(sdata, start);
}
- // System.err.println("Made seqData");// dbg
- if (!(treeType.equals(NEIGHBOUR_JOINING)))
- {
- treeType = AVERAGE_DISTANCE;
- }
if (sm == null && !(modelType.equals("PID")))
{
noseqs = i++;
+ // TODO pass choice of params from GUI in constructo
if (sm instanceof DistanceScoreModelI)
{
- distance = ((DistanceScoreModelI) sm).findDistances(seqData);
+ distance = ((DistanceScoreModelI) sm).findDistances(seqData,
+ SimilarityParams.Jalview);
}
else if (sm instanceof SimilarityScoreModelI)
{
/*
* compute similarity and invert it to give a distance measure
*/
- MatrixI result = ((SimilarityScoreModelI) sm)
- .findSimilarities(seqData);
+ MatrixI result = ((SimilarityScoreModelI) sm).findSimilarities(
+ seqData, SimilarityParams.Jalview);
result.reverseRange(true);
distance = result;
}
*/
package jalview.analysis;
+import jalview.analysis.scoremodels.SimilarityParams;
import jalview.api.analysis.DistanceScoreModelI;
import jalview.api.analysis.ScoreModelI;
import jalview.api.analysis.SimilarityScoreModelI;
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);
+ result = ((SimilarityScoreModelI) scoreModel).findSimilarities(av,
+ SimilarityParams.SeqSpace);
}
else if (scoreModel instanceof DistanceScoreModelI)
{
- result = ((DistanceScoreModelI) scoreModel).findDistances(av);
+ result = ((DistanceScoreModelI) scoreModel).findDistances(av,
+ SimilarityParams.SeqSpace);
result.reverseRange(false);
}
else
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.analysis.DistanceScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.api.analysis.ViewBasedAnalysisI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.SeqCigar;
* of columns processed.
*/
@Override
- public MatrixI findDistances(AlignmentView seqData)
+ public MatrixI findDistances(AlignmentView seqData,
+ SimilarityParamsI options)
{
List<String> dft = fr.getDisplayedFeatureTypes();
SeqCigar[] seqs = seqData.getSequences();
package jalview.analysis.scoremodels;
import jalview.api.analysis.DistanceScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.datamodel.AlignmentView;
import jalview.math.Matrix;
import jalview.math.MatrixI;
{
@Override
- public MatrixI findDistances(AlignmentView seqData)
+ public MatrixI findDistances(AlignmentView seqData,
+ SimilarityParamsI options)
{
String[] sequenceString = seqData
.getSequenceStrings(Comparison.GAP_SPACE);
}
@Override
- public MatrixI findSimilarities(AlignmentView seqData)
+ public MatrixI findSimilarities(AlignmentView seqData,
+ SimilarityParamsI options)
{
- // TODO reuse code in ScoreMatrix instead somehow
String[] seqs = seqData.getSequenceStrings(' ');
- return findSimilarities(seqs, SimilarityParams.Jalview);
+ return findSimilarities(seqs, options);
}
/**
protected MatrixI findSimilarities(String[] seqs,
SimilarityParamsI options)
{
+ // TODO reuse code in ScoreMatrix instead somehow
double[][] values = new double[seqs.length][];
for (int row = 0; row < seqs.length; row++)
{
import jalview.analysis.AlignSeq;
import jalview.api.analysis.DistanceScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.datamodel.AlignmentView;
import jalview.datamodel.SequenceI;
import jalview.math.Matrix;
{
@Override
- public MatrixI findDistances(AlignmentView seqData)
+ public MatrixI findDistances(AlignmentView seqData,
+ SimilarityParamsI options)
{
SequenceI[] sequenceString = seqData.getVisibleAlignment(
Comparison.GAP_SPACE).getSequencesArray();
package jalview.analysis.scoremodels;
import jalview.api.analysis.PairwiseScoreModelI;
+import jalview.api.analysis.SimilarityParamsI;
import jalview.api.analysis.SimilarityScoreModelI;
import jalview.datamodel.AlignmentView;
import jalview.math.Matrix;
* </ul>
*/
@Override
- public MatrixI findSimilarities(AlignmentView seqstrings)
+ public MatrixI findSimilarities(AlignmentView seqstrings,
+ SimilarityParamsI options)
{
char gapChar = scoreGapAsAny ? (seqstrings.isNa() ? 'N' : 'X') : ' ';
String[] seqs = seqstrings.getSequenceStrings(gapChar);
- return findSimilarities(seqs);
+ return findSimilarities(seqs, options);
}
/**
* @param seqs
* @return
*/
- protected MatrixI findSimilarities(String[] seqs)
+ protected MatrixI findSimilarities(String[] seqs,
+ SimilarityParamsI options)
{
+ // todo use options in calculation
double[][] values = new double[seqs.length][];
for (int row = 0; row < seqs.length; row++)
{
public class SimilarityParams implements SimilarityParamsI
{
+ /**
+ * Based on Jalview's Comparison.PID method, which includes gaps and counts
+ * them as matching; it counts over the length of the shorter sequence
+ */
public static final SimilarityParamsI Jalview = new SimilarityParams(
true, true, true, true);
+ /**
+ * 'SeqSpace' mode PCA calculation includes gaps but does not count them as
+ * matching; it uses the longest sequence length
+ */
+ public static final SimilarityParamsI SeqSpace = new SimilarityParams(
+ true, false, true, true);
+
+ /**
+ * as described in the Raghava-Barton paper; considers pairwise similarity
+ * only (excludes gap-gap) and does not match gaps
+ */
public static final SimilarityParamsI PID1 = new SimilarityParams(false,
false, true, false);
+ /**
+ * as described in the Raghava-Barton paper; considers pairwise similarity
+ * only (excludes gap-gap) and does not match gaps
+ */
public static final SimilarityParamsI PID2 = new SimilarityParams(false,
false, false, false);
+ /**
+ * as described in the Raghava-Barton paper; considers pairwise similarity
+ * only (excludes gap-gap) and does not match gaps
+ */
public static final SimilarityParamsI PID3 = new SimilarityParams(false,
false, false, true);
+ /**
+ * as described in the Raghava-Barton paper; considers pairwise similarity
+ * only (excludes gap-gap) and does not match gaps
+ */
public static final SimilarityParamsI PID4 = new SimilarityParams(false,
false, true, true);
/**
* A sequence distance score models, that provides a method to compute distances
- * between pairs of sequences
+ * between pairs of sequences. The options parameter provides configuration
+ * choices for how the similarity score is calculated.
*
* @author gmcarstairs
*
* measure
*
* @param seqData
+ * @param options
* @return
*/
- MatrixI findDistances(AlignmentView seqData);
+ MatrixI findDistances(AlignmentView seqData, SimilarityParamsI options);
}
/**
* Returns a similarity score for the given sequence regions, that is, a
* matrix whose value [i][j] is the similarity of sequence i to sequence j by
- * some measure
+ * some measure. The options parameter provides configuration choices for how
+ * the similarity score is calculated.
*
* @param seqData
+ * @param options
* @return
*/
- MatrixI findSimilarities(AlignmentView seqData);
+ MatrixI findSimilarities(AlignmentView seqData, SimilarityParamsI options);
}
.getAlignPanel()));
alf.selectAllSequenceMenuItem_actionPerformed(null);
- MatrixI dm = fsm
- .findDistances(alf.getViewport().getAlignmentView(
- true));
+ MatrixI dm = fsm.findDistances(
+ alf.getViewport().getAlignmentView(true),
+ SimilarityParams.Jalview);
assertEquals(dm.getValue(0, 2), 0d,
"FER1_MESCR (0) should be identical with RAPSA (2)");
assertTrue(dm.getValue(0, 1) > dm.getValue(0, 2),
assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
.getAlignPanel()));
alf.selectAllSequenceMenuItem_actionPerformed(null);
- MatrixI dm = fsm
- .findDistances(alf.getViewport().getAlignmentView(
- true));
+ MatrixI dm = fsm.findDistances(
+ alf.getViewport().getAlignmentView(true),
+ SimilarityParams.Jalview);
assertEquals(dm.getValue(0, 2), 0d,
"FER1_MESCR (0) should be identical with RAPSA (2)");
assertTrue(dm.getValue(0, 1) > dm.getValue(0, 2),
assertTrue(fsm.configureFromAlignmentView(alf.getCurrentView()
.getAlignPanel()));
alf.selectAllSequenceMenuItem_actionPerformed(null);
- MatrixI dm = fsm
- .findDistances(alf.getViewport().getAlignmentView(
- true));
+ MatrixI dm = fsm.findDistances(
+ alf.getViewport().getAlignmentView(true),
+ SimilarityParams.Jalview);
assertEquals(
dm.getValue(0, 2),
0d,
alf.selectAllSequenceMenuItem_actionPerformed(null);
MatrixI distances = fsm.findDistances(alf.getViewport()
- .getAlignmentView(true));
+ .getAlignmentView(true), SimilarityParams.Jalview);
assertEquals(distances.width(), 2);
assertEquals(distances.height(), 2);
assertEquals(distances.getValue(0, 0), 0d);
String[] seqs = new String[] { "FKL", "R D", "QIA", "GWC" };
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
- MatrixI pairwise = sm.findSimilarities(seqs);
+ MatrixI pairwise = sm.findSimilarities(seqs, SimilarityParams.Jalview);
/*
* should be NxN where N = number of sequences