X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fanalysis%2Fscoremodels%2FFeatureDistanceModel.java;h=056ecdb750082e91fca85bfe28ee9154c7a44fb8;hb=9c007fa50a82b3ae0f987e6454ae17c941b63563;hp=636c19b3b545760a4d6018dddd7f43da7ee51e25;hpb=8717834368bd00d8adfa47ee099288acd34363ef;p=jalview.git diff --git a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java index 636c19b..056ecdb 100644 --- a/src/jalview/analysis/scoremodels/FeatureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/FeatureDistanceModel.java @@ -22,9 +22,8 @@ package jalview.analysis.scoremodels; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; -import jalview.api.analysis.DistanceScoreModelI; +import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; -import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.AlignmentView; import jalview.datamodel.SeqCigar; import jalview.datamodel.SequenceFeature; @@ -38,13 +37,39 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class FeatureDistanceModel implements DistanceScoreModelI, - ViewBasedAnalysisI +public class FeatureDistanceModel extends DistanceScoreModel { + private static final String NAME = "Sequence Feature Similarity"; + + private String description; + FeatureRenderer fr; + /** + * Constructor + */ + public FeatureDistanceModel() + { + } + @Override - public boolean configureFromAlignmentView(AlignmentViewPanel view) + public ScoreModelI getInstance(AlignmentViewPanel view) + { + FeatureDistanceModel instance; + try + { + instance = this.getClass().newInstance(); + instance.configureFromAlignmentView(view); + return instance; + } catch (InstantiationException | IllegalAccessException e) + { + System.err.println("Error in " + getClass().getName() + + ".getInstance(): " + e.getMessage()); + return null; + } + } + + boolean configureFromAlignmentView(AlignmentViewPanel view) { fr = view.cloneFeatureRenderer(); @@ -57,17 +82,28 @@ public class FeatureDistanceModel implements DistanceScoreModelI, * features each sequence pair has at each column, ignore feature types they * have in common, and count the rest. The totals are normalised by the number * of columns processed. + *

+ * The parameters argument provides settings for treatment of gap-residue + * aligned positions, and whether the score is over the longer or shorter of + * each pair of sequences + * + * @param seqData + * @param params */ @Override public MatrixI findDistances(AlignmentView seqData, - SimilarityParamsI options) + SimilarityParamsI params) { - List dft = fr.getDisplayedFeatureTypes(); SeqCigar[] seqs = seqData.getSequences(); int noseqs = seqs.length; int cpwidth = 0;// = seqData.getWidth(); double[][] distances = new double[noseqs][noseqs]; - if (dft.isEmpty()) + List dft = null; + if (fr != null) + { + dft = fr.getDisplayedFeatureTypes(); + } + if (dft == null || dft.isEmpty()) { return new Matrix(distances); } @@ -86,7 +122,7 @@ public class FeatureDistanceModel implements DistanceScoreModelI, cpwidth++; /* - * first pass: record features types in column for each sequence + * first record feature types in this column for each sequence */ Map> sfap = findFeatureTypesAtColumn( seqs, cpos); @@ -99,9 +135,23 @@ public class FeatureDistanceModel implements DistanceScoreModelI, { for (int j = i + 1; j < noseqs; j++) { - int seqDistance = SetUtils.countDisjunction(sfap.get(seqs[i]), - sfap.get(seqs[j])); - distances[i][j] += seqDistance; + SeqCigar sc1 = seqs[i]; + SeqCigar sc2 = seqs[j]; + Set set1 = sfap.get(sc1); + Set set2 = sfap.get(sc2); + boolean gap1 = set1 == null; + boolean gap2 = set2 == null; + + /* + * gap-gap always scores zero + * residue-residue is always scored + * include gap-residue score if params say to do so + */ + if ((!gap1 && !gap2) || params.includeGaps()) + { + int seqDistance = SetUtils.countDisjunction(set1, set2); + distances[i][j] += seqDistance; + } } } } @@ -125,8 +175,9 @@ public class FeatureDistanceModel implements DistanceScoreModelI, } /** - * Builds and returns a list (one per SeqCigar) of visible feature types at - * the given column position + * Builds and returns a map containing a (possibly empty) list (one per + * SeqCigar) of visible feature types at the given column position. The map + * has no entry for sequences which are gapped at the column position. * * @param seqs * @param columnPosition @@ -138,18 +189,18 @@ public class FeatureDistanceModel implements DistanceScoreModelI, Map> sfap = new HashMap>(); for (SeqCigar seq : seqs) { - Set types = new HashSet(); int spos = seq.findPosition(columnPosition); if (spos != -1) { + Set types = new HashSet(); List sfs = fr.findFeaturesAtRes(seq.getRefSeq(), spos); for (SequenceFeature sf : sfs) { types.add(sf.getType()); } + sfap.put(seq, types); } - sfap.put(seq, types); } return sfap; } @@ -157,7 +208,13 @@ public class FeatureDistanceModel implements DistanceScoreModelI, @Override public String getName() { - return "Sequence Feature Similarity"; + return NAME; + } + + @Override + public String getDescription() + { + return description; } @Override