JAL-891; sequence logos are available on structure conservation row
authorjanengelhardt <engelhardt87@googlemail.com>
Mon, 8 Aug 2011 10:04:57 +0000 (12:04 +0200)
committerjanengelhardt <engelhardt87@googlemail.com>
Mon, 8 Aug 2011 10:04:57 +0000 (12:04 +0200)
now; has to be adopted to base pair interaction;

Change-Id: I86cf329d794d6ff78cb4bb4c5248cadcc34b2681

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

index a5dd030..8338c9d 100644 (file)
@@ -202,7 +202,7 @@ public class StructureFrequency
    */
   public static final void calculate(SequenceI[] sequences, int start,
                  int end, Hashtable[] result, boolean profile, AlignmentAnnotation rnaStruc){
-         System.out.println("StructureFrequency.calculate");
+         //System.out.println("StructureFrequency.calculateNEW4");
          Hashtable residueHash;
          String maxResidue;
          char[] seq, struc=rnaStruc.getRNAStruc().toCharArray();
@@ -211,12 +211,7 @@ public class StructureFrequency
          int count,nonGap=0,i,bpEnd=-1,j,jSize = sequences.length;
          int[] values = new int[255];
          float percentage;
-         
-         /*for(int x=(rna.length-1); x>=0; x--){
-                 System.out.println("BP-"+((rna.length-1)-x)+" "+rna[x].getBegin()+","+rna[x].getEnd()+" "+rna[x].getFeatureGroup());
-         }*/
-         
-         
+                 
          for (i = start; i < end; i++) //foreach column
          {
                  residueHash = new Hashtable();
@@ -231,7 +226,9 @@ public class StructureFrequency
                  }
 
                  if(s != '('){
-                         values['-']++;
+                         if(s == '-'){
+                                 values['-']++;
+                         }
                  }
                  else
                  {
@@ -259,27 +256,24 @@ public class StructureFrequency
                                                  values['-']++;
                                                  continue;
                                          }
-                                         //if(s == '('){
-                                                 //bpEnd=rna[(rna.length-1-nonGap)].getEnd();
-                                                 bpEnd=findPair(rna,i);
-                                                 cEnd=seq[bpEnd];
-                                                 //System.out.println(i+","+bpEnd);
-                                                 if(checkBpType(c,cEnd)){
-                                                         values['H']++; //H means it's a helix (structured)
-                                                 }
-                                                 maxResidue="H";
-                                 //}
+                                         bpEnd=findPair(rna,i);
+                                         cEnd=seq[bpEnd];
+                                         if(checkBpType(c,cEnd)){
+                                                 values['H']++; //H means it's a helix (structured)
+                                         }
+                                         maxResidue="H";
                                  }
                          }
-                         nonGap++;
+//                       nonGap++;
                  }
                  //UPDATE this for new values
-             //if (profile)
-             //{
-            //   residueHash.put(PROFILE, new int[][]
-             //  { values, new int[]
-            //   { jSize, nongap } });
-            // }
+             if (profile)
+             {
+                 //System.out.println("profile");
+               residueHash.put(PROFILE, new int[][]
+               { values, new int[]
+               { jSize, values['H'] } });
+             }
                   
 
                  count=values['H'];
@@ -375,6 +369,7 @@ public class StructureFrequency
           boolean ignoreGapsInConsensusCalculation,
           boolean includeAllConsSymbols, char[] alphabet)
   {
+       System.out.println("StructureFrequency.completeConsensus "+includeAllConsSymbols);
     float tval, value;
     if (consensus == null || consensus.annotations == null
             || consensus.annotations.length < width)
@@ -412,8 +407,9 @@ public class StructureFrequency
         maxRes = "+";
       }
       int[][] profile = (int[][]) hconsensus[i].get(StructureFrequency.PROFILE);
-      if (profile != null && includeAllConsSymbols)
+      if (profile != null && includeAllConsSymbols) //Just responsible for the tooltip
       {
+       //System.out.println("StructureFrequency.includeAllConsSymbols");
         mouseOver = "";
         if (alphabet != null)
         {
@@ -429,6 +425,7 @@ public class StructureFrequency
         }
         else
         {
+          //System.out.println("StructureFrequency.NOTincludeAllConsSymbols");
           Object[] ca = new Object[profile[0].length];
           float[] vl = new float[profile[0].length];
           for (int c = 0; c < ca.length; c++)
@@ -472,38 +469,37 @@ public class StructureFrequency
    * @return
    */
   public static int[] extractProfile(Hashtable hconsensus,
-          boolean ignoreGapsInConsensusCalculation)
+                 boolean ignoreGapsInConsensusCalculation)
   {
-    int[] rtnval = new int[64];
-    int[][] profile = (int[][]) hconsensus.get(StructureFrequency.PROFILE);
-    if (profile == null)
-      return null;
-    Object[] ca = new Object[profile[0].length];
-    float[] vl = new float[profile[0].length];
-    for (int c = 0; c < ca.length; c++)
-    {
-      ca[c] = new char[]
-      { (char) c };
-      vl[c] = (float) profile[0][c];
-    }
-    ;
-    jalview.util.QuickSort.sort(vl, ca);
-    rtnval[0] = 1;
-    for (int c = ca.length - 1; profile[0][((char[]) ca[c])[0]] > 0; c--)
-    {
-      if (((char[]) ca[c])[0] != '-')
-      {
-        rtnval[rtnval[0]++] = ((char[]) ca[c])[0];
-        rtnval[rtnval[0]++] = (int) (((float) profile[0][((char[]) ca[c])[0]]) * 100f / (float) profile[1][ignoreGapsInConsensusCalculation ? 1
-                : 0]);
-      }
-    }
-    return rtnval;
+         //System.out.println("StructureFrequency.extractProfile");
+         int[] rtnval = new int[11];
+         int[][] profile = (int[][]) hconsensus.get(StructureFrequency.PROFILE);
+         if (profile == null)
+                 return null;
+         
+         Object[] ca = new Object[profile[0].length];
+         float[] vl = new float[profile[0].length];
+         for (int c = 0; c < ca.length; c++)
+         {
+                 ca[c] = new char[]
+                                  { (char) c };
+                 vl[c] = (float) profile[0][c];
+         }
+         ;
+         jalview.util.QuickSort.sort(vl, ca);
+         rtnval[0] = 1;
+         for (int c = ca.length - 1; profile[0][((char[]) ca[c])[0]] > 0; c--)
+         {
+                 if (((char[]) ca[c])[0] != '-')
+                 {
+                         rtnval[rtnval[0]++] = ((char[]) ca[c])[0];
+                         rtnval[rtnval[0]++] = (int) (((float) profile[0][((char[]) ca[c])[0]]) * 100f / (float) profile[1][ignoreGapsInConsensusCalculation ? 1
+                                         : 0]);
+                 }
+         }
+         return rtnval;
   }
 
-  enum base {A,T,g,C};
-  
   public static void main(String args[]){
          //Short test to see if checkBpType works
          ArrayList<String> test = new ArrayList<String>();
index 5c83277..f15d01a 100644 (file)
@@ -2299,6 +2299,10 @@ public class AlignViewport implements SelectionSource, VamsasSource
       {
         consensusThread.updateAnnotation();
       }
+      if (strucConsensusThread != null)
+      {
+        strucConsensusThread.updateAnnotation();
+      }
     }
     this.showSequenceLogo = showSequenceLogo;
   }
index 827540a..e42264d 100755 (executable)
@@ -29,6 +29,7 @@ import javax.swing.*;
 import com.stevesoft.pat.Regex;
 
 import jalview.analysis.AAFrequency;
+import jalview.analysis.StructureFrequency;
 import jalview.datamodel.*;
 import jalview.schemes.ColourSchemeI;
 
@@ -1234,7 +1235,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
             || !dc.equals(row.annotations[sCol - 1].displayCharacter);
     boolean diffdownstream=!validRes || !validEnd || row.annotations[column] == null
             || !dc.equals(row.annotations[column].displayCharacter);
-    System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
+    //System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream);
     // If a closing base pair half of the stem, display a backward arrow
     if (column > 0
             && closeparen
@@ -1536,6 +1537,12 @@ public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
       if (renderProfile && aa.annotations[column].value != 0)
       {
         int profl[] = getProfileFor(aa, column);
+        /*if(profl != null){
+               for(int i=0; i<profl.length;i++){
+                       System.out.print(profl[i]+",");
+               }
+               System.out.print("drawProfile\n");
+        }*/
         int ht = y1, htn = y2 - y1;// aa.graphHeight;
         float wdth;
         double ht2 = 0;
@@ -1569,6 +1576,7 @@ public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
                                                       // group(aa.groupRef.cs==null)
                                                       // ? av.textColour2 :
                                                       // cs.findColour(dc));
+            //System.out.println(dc[0]);
             g.drawChars(dc, 0, 1, x * av.charWidth,
                     (int) (ht + lm.getHeight()));
             // ht+=g.getFontMetrics().getAscent()-g.getFontMetrics().getDescent();
@@ -1611,6 +1619,25 @@ public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes,
         return AAFrequency.extractProfile(av.hconsensus[column],
                 av.getIgnoreGapsConsensus());
       }
+    }else{
+        if (aa.autoCalculated && aa.label.startsWith("StrucConsensus")){
+               if (aa.groupRef != null && aa.groupRef.consensusData != null
+                    && aa.groupRef.isShowSequenceLogo())
+            {
+              return StructureFrequency.extractProfile(
+                      aa.groupRef.consensusData[column],
+                      aa.groupRef.getIgnoreGapsConsensus());
+            }
+            // TODO extend annotation row to enable dynamic and static profile data to
+            // be stored
+            if (aa.groupRef == null && aa.sequenceRef == null
+                    && av.isShowSequenceLogo())
+            {
+              return StructureFrequency.extractProfile(av.hconsensus[column],
+                      av.getIgnoreGapsConsensus());
+            }
+        }
+
     }
     return null;
   }