From: Jim Procter Date: Sat, 23 Apr 2016 17:37:04 +0000 (+0100) Subject: JAL-2075 fix: use AlignmentView.getVisibleContigs and SeqCigar.findPosition to locate... X-Git-Tag: Release_2_10_0~249^2~7^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4a621265c074df3b90126a453bed7a0e7bed02c6;p=jalview.git JAL-2075 fix: use AlignmentView.getVisibleContigs and SeqCigar.findPosition to locate aligned features --- diff --git a/src/jalview/analysis/scoremodels/FeatureScoreModel.java b/src/jalview/analysis/scoremodels/FeatureScoreModel.java index 1ca3342..7c81912 100644 --- a/src/jalview/analysis/scoremodels/FeatureScoreModel.java +++ b/src/jalview/analysis/scoremodels/FeatureScoreModel.java @@ -23,9 +23,8 @@ package jalview.analysis.scoremodels; import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.AlignmentView; +import jalview.datamodel.SeqCigar; import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.util.Comparison; import java.util.ArrayList; import java.util.Hashtable; @@ -48,13 +47,10 @@ public class FeatureScoreModel implements ScoreModelI, ViewBasedAnalysisI { int nofeats = 0; List dft = fr.getDisplayedFeatureTypes(); - nofeats = dft.size(); - - SequenceI[] sequenceString = seqData.getVisibleAlignment( - Comparison.GapChars.charAt(0)).getSequencesArray(); - int noseqs = sequenceString.length; - int cpwidth = seqData.getWidth(); + SeqCigar[] seqs = seqData.getSequences(); + int noseqs = seqs.length; + int cpwidth = 0;// = seqData.getWidth(); float[][] distance = new float[noseqs][noseqs]; if (nofeats == 0) { @@ -67,54 +63,64 @@ public class FeatureScoreModel implements ScoreModelI, ViewBasedAnalysisI } return distance; } - float max = 0; - for (int cpos = 0; cpos < cpwidth; cpos++) + // need to get real position for view position + int[] viscont = seqData.getVisibleContigs(); + for (int vc = 0; vc < viscont.length; vc += 2) { - // get visible features at cpos under view's display settings and compare - // them - List> sfap = new ArrayList>(); - for (int i = 0; i < noseqs; i++) - { - Hashtable types = new Hashtable(); - List sfs = fr.findFeaturesAtRes(sequenceString[i], - sequenceString[i].findPosition(cpos)); - for (SequenceFeature sf : sfs) - { - types.put(sf.getType(), sf); - } - sfap.add(types); - } - for (int i = 0; i < (noseqs - 1); i++) + + for (int cpos = viscont[vc]; cpos <= viscont[vc + 1]; cpos++) { - if (cpos == 0) - { - distance[i][i] = 0f; - } - for (int j = i + 1; j < noseqs; j++) + cpwidth++; + // get visible features at cpos under view's display settings and + // compare them + List> sfap = new ArrayList>(); + for (int i = 0; i < noseqs; i++) { - int sfcommon = 0; - // compare the two lists of features... - Hashtable fi = sfap.get(i), fk, fj = sfap - .get(j); - if (fi.size() > fj.size()) + Hashtable types = new Hashtable(); + int spos = seqs[i].findPosition(cpos); + if (spos != -1) { - fk = fj; + List sfs = fr.findFeaturesAtRes( + seqs[i].getRefSeq(), spos); + for (SequenceFeature sf : sfs) + { + types.put(sf.getType(), sf); + } } - else + sfap.add(types); + } + for (int i = 0; i < (noseqs - 1); i++) + { + if (cpos == 0) { - fk = fi; - fi = fj; + distance[i][i] = 0f; } - for (String k : fi.keySet()) + for (int j = i + 1; j < noseqs; j++) { - SequenceFeature sfj = fk.get(k); - if (sfj != null) + int sfcommon = 0; + // compare the two lists of features... + Hashtable fi = sfap.get(i), fk, fj = sfap + .get(j); + if (fi.size() > fj.size()) + { + fk = fj; + } + else + { + fk = fi; + fi = fj; + } + for (String k : fi.keySet()) { - sfcommon++; + SequenceFeature sfj = fk.get(k); + if (sfj != null) + { + sfcommon++; + } } + distance[i][j] += (fi.size() + fk.size() - 2f * sfcommon); + distance[j][i] += distance[i][j]; } - distance[i][j] += (fi.size() + fk.size() - 2f * sfcommon); - distance[j][i] += distance[i][j]; } } }