JAL-4426 Fix when multiple secondary structure annotations are present
authorRenia Correya <rcorreya001@dundee.ac.uk>
Wed, 12 Jun 2024 13:54:28 +0000 (14:54 +0100)
committerRenia Correya <rcorreya001@dundee.ac.uk>
Wed, 12 Jun 2024 13:54:28 +0000 (14:54 +0100)
for a sequence

src/jalview/analysis/AAFrequency.java
src/jalview/datamodel/Profile.java
src/jalview/datamodel/ProfileI.java
src/jalview/workers/SecondaryStructureConsensusThread.java
test/jalview/renderer/ResidueShaderTest.java

index a979c45..9c5ab5f 100755 (executable)
@@ -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<AlignmentAnnotation> 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);
index 35f1429..bc87204 100644 (file)
@@ -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;
+  }
 }
index 511095e..9046f23 100644 (file)
@@ -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
index 62d29f0..bd4b78c 100644 (file)
@@ -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)
index 081272a..9ff93e1 100644 (file)
@@ -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;
+          }
         };
       }