From 060ad1f51e43f436b1f3cec891353af845b5ed79 Mon Sep 17 00:00:00 2001 From: Renia Correya Date: Wed, 12 Jun 2024 14:54:28 +0100 Subject: [PATCH] JAL-4426 Fix when multiple secondary structure annotations are present for a sequence --- src/jalview/analysis/AAFrequency.java | 50 ++++++++++++-------- src/jalview/datamodel/Profile.java | 15 +++++- src/jalview/datamodel/ProfileI.java | 2 + .../workers/SecondaryStructureConsensusThread.java | 2 +- test/jalview/renderer/ResidueShaderTest.java | 7 +++ 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/jalview/analysis/AAFrequency.java b/src/jalview/analysis/AAFrequency.java index a979c45..9c5ab5f 100755 --- a/src/jalview/analysis/AAFrequency.java +++ b/src/jalview/analysis/AAFrequency.java @@ -235,6 +235,8 @@ public class AAFrequency int seqCount = sequences.length; + int seqWithSSCount = 0; + ProfileI[] result = new ProfileI[width]; for (int column = start; column < end; column++) @@ -256,35 +258,37 @@ public class AAFrequency char c = sequences[row].getCharAt(column); List annots = AlignmentUtils.getAlignmentAnnotationForSource(sequences[row], source); if(annots!=null) { - for(AlignmentAnnotation aa:annots) { - if(aa!=null) { - ssCount++; - } - - if (sequences[row].getLength() > column && !Comparison.isGap(c) && aa !=null) - { - - int seqPosition = sequences[row].findPosition(column); + seqWithSSCount++; + for(AlignmentAnnotation aa:annots) { + if(aa!=null) { + ssCount++; + } - char ss = AlignmentUtils.findSSAnnotationForGivenSeqposition( - aa, seqPosition); - if(ss == '*') { - continue; - } - ssCounts.add(ss); - } - else if(Comparison.isGap(c) && aa!=null) { - ssCounts.addGap(); + if (sequences[row].getLength() > column && !Comparison.isGap(c) && aa !=null) + { + + int seqPosition = sequences[row].findPosition(column); + + char ss = AlignmentUtils.findSSAnnotationForGivenSeqposition( + aa, seqPosition); + if(ss == '*') { + continue; + } + ssCounts.add(ss); + } + else if(Comparison.isGap(c) && aa!=null) { + ssCounts.addGap(); + } } } } - } int maxSSCount = ssCounts.getModalCount(); String maxSS = ssCounts.getSSForCount(maxSSCount); int gapCount = ssCounts.getGapCount(); ProfileI profile = new Profile(maxSS, ssCount, gapCount, - maxSSCount); + maxSSCount, seqWithSSCount); + if (saveFullProfile) { @@ -421,7 +425,11 @@ public class AAFrequency ssConsensus.annotations[i] = null; return; } - + + if(ssConsensus.getNoOfSequencesIncluded()<0) { + ssConsensus.setNoOfSequencesIncluded(profile.getSeqWithSSCount()); + } + final int dp = getPercentageDp(nseq); float value = profile.getSSPercentageIdentity(ignoreGaps); diff --git a/src/jalview/datamodel/Profile.java b/src/jalview/datamodel/Profile.java index 35f1429..bc87204 100644 --- a/src/jalview/datamodel/Profile.java +++ b/src/jalview/datamodel/Profile.java @@ -34,6 +34,8 @@ public class Profile implements ProfileI private ResidueCount counts; private SecondaryStructureCount ssCounts; + + private int seqWithSSCount = -1; /* * the number of sequences (gapped or not) in the profile @@ -81,12 +83,13 @@ public class Profile implements ProfileI this.modalResidue = modalRes; } - public Profile(String modalSS, int ssCount, int gaps, int maxSSCount) + public Profile(String modalSS, int ssCount, int gaps, int maxSSCount, int seqWithSSCount) { this.height = ssCount; this.gapped = gaps; this.maxSSCount = maxSSCount; this.modalSS = modalSS; + this.setSeqWithSSCount(seqWithSSCount); } /* (non-Javadoc) @@ -216,4 +219,14 @@ public class Profile implements ProfileI { return height - gapped; } + + public int getSeqWithSSCount() + { + return seqWithSSCount; + } + + public void setSeqWithSSCount(int seqWithSSCount) + { + this.seqWithSSCount = seqWithSSCount; + } } diff --git a/src/jalview/datamodel/ProfileI.java b/src/jalview/datamodel/ProfileI.java index 511095e..9046f23 100644 --- a/src/jalview/datamodel/ProfileI.java +++ b/src/jalview/datamodel/ProfileI.java @@ -57,6 +57,8 @@ public interface ProfileI * @return */ public abstract int getHeight(); + + public abstract int getSeqWithSSCount(); /** * Returns the number of sequences in the profile which had a gap character diff --git a/src/jalview/workers/SecondaryStructureConsensusThread.java b/src/jalview/workers/SecondaryStructureConsensusThread.java index 62d29f0..bd4b78c 100644 --- a/src/jalview/workers/SecondaryStructureConsensusThread.java +++ b/src/jalview/workers/SecondaryStructureConsensusThread.java @@ -250,7 +250,7 @@ public class SecondaryStructureConsensusThread extends AlignCalcWorker && ssConsensusProfile != null) { if(ssConsensusProfile.get(0)!=null) - ssConsensus.setNoOfSequencesIncluded(ssConsensusProfile.get(0).getHeight()); + ssConsensus.setNoOfSequencesIncluded(ssConsensusProfile.get(0).getSeqWithSSCount()); deriveSSConsensus(ssConsensus, ssConsensusProfile); AlignmentAnnotation gap = getGapAnnotation(); if (gap != null) diff --git a/test/jalview/renderer/ResidueShaderTest.java b/test/jalview/renderer/ResidueShaderTest.java index 081272a..9ff93e1 100644 --- a/test/jalview/renderer/ResidueShaderTest.java +++ b/test/jalview/renderer/ResidueShaderTest.java @@ -375,6 +375,13 @@ public class ResidueShaderTest // TODO Auto-generated method stub return null; } + + @Override + public int getSeqWithSSCount() + { + // TODO Auto-generated method stub + return 0; + } }; } -- 1.7.10.2