JAL-885; StructureConservation row is displayed at the bottom of the
authorjanengelhardt <engelhardt87@googlemail.com>
Sun, 31 Jul 2011 22:42:25 +0000 (00:42 +0200)
committerjanengelhardt <engelhardt87@googlemail.com>
Sun, 31 Jul 2011 22:42:25 +0000 (00:42 +0200)
AlignmentPanel; StructureFrequency class was introduced and is called
by thread in AlignViewport that is called by AlignFrame; everything is
according to Conservation-Row

Change-Id: I3753bbb5678147cbc0c9d1d6bc1a4886b0551a59

src/jalview/analysis/AAFrequency.java
src/jalview/analysis/StructureFrequency.java
src/jalview/gui/AlignViewport.java

index 16754a1..31cb7ad 100755 (executable)
@@ -85,7 +85,6 @@ public class AAFrequency
   public static final void calculate(SequenceI[] sequences, int start,
           int end, Hashtable[] result, boolean profile)
   {
-       System.out.println("AAFrequence.calculate");
     Hashtable residueHash;
     int maxCount, nongap, i, j, v, jSize = sequences.length;
     String maxResidue;
index a666bc0..29c0a0b 100644 (file)
@@ -102,6 +102,7 @@ public class StructureFrequency
       maxResidue = "";
       nongap = 0;
       values = new int[255];
+      
 
       for (j = 0; j < jSize; j++)
       {
@@ -191,83 +192,106 @@ public class StructureFrequency
    * @param rnaStruc
    */
   public static final void calculate(SequenceI[] sequences, int start,
-          int end, Hashtable[] result, boolean profile, AlignmentAnnotation rnaStruc){
-         //TODO Consider to use AlignmentAnnotation instead of structure string
+                 int end, Hashtable[] result, boolean profile, AlignmentAnnotation rnaStruc){
 
          Hashtable residueHash;
-
+         String maxResidue;
          char[] seq, struc=rnaStruc.getRNAStruc().toCharArray();
          SequenceFeature[] rna =rnaStruc._rnasecstr;
          char c,s,cEnd;
-         int count,nonGap,i,j,jSize = sequences.length;
+         int count,nonGap=0,i,bpEnd=-1,j,jSize = sequences.length;
          int[] values = new int[255];
          float percentage;
-
-
+         
          for (i = start; i < end; i++) //foreach column
-           {
-             residueHash = new Hashtable();
-             for (j = 0; j < jSize; j++) //foreach row
-             {
-               if (sequences[j]==null)
-               {
-                 System.err.println("WARNING: Consensus skipping null sequence - possible race condition.");
-                 continue;
-               }
-               seq = sequences[j].getSequence();
-               if (seq.length > i)
-               {
-                       c = seq[i];
-                       s = struc[i];
-                       nonGap=0;
-                       
-                       //standard representation for gaps in sequence and structure
-                       if (c == '.' || c == ' ')
-                   {
-                     c = '-';
-                   }
-                       if (s == '.' || s == ' ')
-                   {
-                     s = '-';
-                   }
-                       
-                       if (c == '-')
-                   {
-                     values['-']++;
-                     continue;
-                   }
-                       if(s == '-'){
-                               values['-']++;
-                               continue;
-                       }
-                       nonGap++;
-                       cEnd=seq[rna[i].getEnd()];
-                       if(checkBpType(c,cEnd)){
-                               values['H']++; //H means it's a helix (structured)
-                       }
-               }
-             }
-             /*UPDATE this for new values
+         {
+                 residueHash = new Hashtable();
+                 maxResidue="";
+                 values = new int[255];
+                 bpEnd=-1;
+
+                 s = struc[i];
+                 if (s == '.' || s == ' ')
+                 {
+                         s = '-';
+                 }
+
+                 if(s == '-'){
+                         values['-']++;
+                 }
+                 else
+                 {
+                         for (j = 0; j < jSize; j++) //foreach row
+                         {
+                                 if (sequences[j]==null)
+                                 {
+                                         System.err.println("WARNING: Consensus skipping null sequence - possible race condition.");
+                                         continue;
+                                 }
+                                 seq = sequences[j].getSequence();
+                                 
+                                 if (seq.length > i)
+                                 {
+                                         c = seq[i];
+
+                                         //standard representation for gaps in sequence and structure
+                                         if (c == '.' || c == ' ')
+                                         {
+                                                 c = '-';
+                                         }
+
+                                         if (c == '-')
+                                         {
+                                                 values['-']++;
+                                                 continue;
+                                         }
+                                         if(s == '('){
+                                                 bpEnd=rna[(rna.length-1-nonGap)].getEnd();              
+                                                 cEnd=seq[bpEnd];
+                                                 if(checkBpType(c,cEnd)){
+                                                         values['H']++; //H means it's a helix (structured)
+                                                 }
+                                         }
+                                 }
+                         }
+                         nonGap++;
+                 }
+                 /*UPDATE this for new values
              if (profile)
              {
                residueHash.put(PROFILE, new int[][]
                { values, new int[]
                { jSize, nongap } });
              }
-             */
+                  */
+
+                 count=values['H'];
+                 
+                 if (count == 0)
+                 {
+                         maxResidue = "-";
+                 }else{
+                         maxResidue="H";
+                 }
+                 
+                 residueHash.put(MAXCOUNT, new Integer(count));
+             residueHash.put(MAXRESIDUE, maxResidue);
              
-             count=values['H'];
+                 percentage = ((float) count * 100) / (float) jSize;
+                 residueHash.put(PID_GAPS, new Float(percentage));
 
-             percentage = ((float) count * 100) / (float) jSize;
-             residueHash.put(PID_GAPS, new Float(percentage));
+                 //percentage = ((float) count * 100) / (float) nongap;
+                 //residueHash.put(PID_NOGAPS, new Float(percentage));
+                 if(result[i]==null){
+                         result[i] = residueHash;
+                 }
+                 if(bpEnd>0){
+                         result[bpEnd]=residueHash;
+                 }
 
-             //percentage = ((float) count * 100) / (float) nongap;
-             //residueHash.put(PID_NOGAPS, new Float(percentage));
-             result[i] = residueHash;
-             
-           }
+         }
   }
-                       
+
         
   /**
    * Method to check if a base-pair is a canonical or a wobble bp 
@@ -370,7 +394,7 @@ public class StructureFrequency
         value = ((Float) hconsensus[i].get(StructureFrequency.PID_GAPS))
                 .floatValue();
       }
-
+      
       String maxRes = hconsensus[i].get(StructureFrequency.MAXRESIDUE).toString();
       String mouseOver = hconsensus[i].get(StructureFrequency.MAXRESIDUE) + " ";
       if (maxRes.length() > 1)
index 98cae4c..5c83277 100644 (file)
@@ -413,11 +413,20 @@ public class AlignViewport implements SelectionSource, VamsasSource
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       consensus.hasText = true;
       consensus.autoCalculated = true;
+      
+      //TODO check if this can done accordingly
+      strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
+              new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
+      strucConsensus.hasText = true;
+      strucConsensus.autoCalculated = true;
 
       if (Cache.getDefault("SHOW_IDENTITY", true))
       {
         alignment.addAnnotation(consensus);
+        //TODO: Make own if for structure
+        alignment.addAnnotation(strucConsensus);
       }
+      
     }
 
     if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
@@ -620,7 +629,7 @@ public class AlignViewport implements SelectionSource, VamsasSource
   //--------START Structure Conservation
   public void updateStrucConsensus(final AlignmentPanel ap)
   {
-    // see note in mantis : issue number 8585
+   // see note in mantis : issue number 8585
     if (strucConsensus == null || !autoCalculateStrucConsensus)
     {
       return;
@@ -640,7 +649,7 @@ public class AlignViewport implements SelectionSource, VamsasSource
 
     public void run()
     {
-      updatingStrucConsensus = true;
+         updatingStrucConsensus = true;
       while (UPDATING_STRUC_CONSENSUS)
       {
         try
@@ -676,9 +685,19 @@ public class AlignViewport implements SelectionSource, VamsasSource
         strucConsensus.annotations = new Annotation[aWidth];
 
         hStrucConsensus = new Hashtable[aWidth];
+        
+         AlignmentAnnotation[] aa = ap.av.getAlignment().getAlignmentAnnotation();
+         AlignmentAnnotation rnaStruc = null;
+         for(int i=0; i<aa.length;i++){
+                 if(aa[i].getRNAStruc() != null){
+                         rnaStruc=aa[i];
+                         break;
+                 }
+         }
+        
         AlignmentAnnotation rna = ap.av.getAlignment().getAlignmentAnnotation()[0];
         StructureFrequency.calculate(alignment.getSequencesArray(), 0,
-                alignment.getWidth(), hStrucConsensus, true, rna);
+                alignment.getWidth(), hStrucConsensus, true, rnaStruc);
         //TODO AlignmentAnnotation rnaStruc!!!
         updateAnnotation(true);
         if (globalColourScheme != null)
@@ -688,7 +707,7 @@ public class AlignViewport implements SelectionSource, VamsasSource
 
       } catch (OutOfMemoryError error)
       {
-        alignment.deleteAnnotation(consensus);
+        alignment.deleteAnnotation(strucConsensus);
 
         strucConsensus = null;
         hStrucConsensus = null;
@@ -717,10 +736,10 @@ public class AlignViewport implements SelectionSource, VamsasSource
       // TODO: make calls thread-safe, so if another thread calls this method,
       // it will either return or wait until one calculation is finished.
       if (immediate
-              || (!updatingConsensus && consensus != null && hconsensus != null))
-      {
+              || (!updatingStrucConsensus && strucConsensus != null && hStrucConsensus != null))
+      {          
         StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus, 0,
-                hStrucConsensus.length, ignoreGapsInConsensusCalculation,
+                hStrucConsensus.length, false,
                 showSequenceLogo);
       }
     }
@@ -1854,7 +1873,6 @@ public class AlignViewport implements SelectionSource, VamsasSource
     {
       updateConsensus(ap);
     }
-    
     if(autoCalculateStrucConsensus)
     {
        updateStrucConsensus(ap);