refactored to use jalview.analysis.Finder for searching alignment.
[jalview.git] / src / jalview / gui / AlignViewport.java
index b275611..be7f8f4 100755 (executable)
@@ -112,6 +112,17 @@ public class AlignViewport
     Stack historyList = new Stack();
     Stack redoList = new Stack();
 
+    Hashtable sequenceColours;
+
+    int thresholdTextColour = 0;
+    Color textColour = Color.black;
+    Color textColour2 = Color.white;
+
+    boolean rightAlignIds = false;
+
+    Hashtable hiddenRepSequences;
+
+
     /**
      * Creates a new AlignViewport object.
      *
@@ -149,6 +160,8 @@ public class AlignViewport
       showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
       showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
 
+      rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
+
       autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
 
       padGaps = Cache.getDefault("PAD_GAPS", true);
@@ -306,7 +319,7 @@ public class AlignViewport
             cons.findQuality();
           }
 
-          String sequence = cons.getConsSequence().getSequence();
+          char [] sequence = cons.getConsSequence().getSequence();
           float minR;
           float minG;
           float minB;
@@ -341,7 +354,7 @@ public class AlignViewport
           {
             float value = 0;
 
-            c = sequence.charAt(i);
+            c = sequence[i];
 
             if (Character.isDigit(c))
               value = (int) (c - '0');
@@ -1251,6 +1264,33 @@ public class AlignViewport
       hasHiddenColumns = true;
     }
 
+    public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
+    {
+      int sSize = sg.getSize();
+      if(sSize < 2)
+        return;
+
+      if(hiddenRepSequences==null)
+        hiddenRepSequences = new Hashtable();
+
+       hiddenRepSequences.put(repSequence, sg);
+
+      //Hide all sequences except the repSequence
+      SequenceI [] seqs = new SequenceI[sSize-1];
+      int index = 0;
+      for(int i=0; i<sSize; i++)
+        if(sg.getSequenceAt(i)!=repSequence)
+        {
+          if(index==sSize-1)
+            return;
+
+          seqs[index++] = sg.getSequenceAt(i);
+        }
+
+      hideSequence(seqs);
+
+    }
+
     public void hideAllSelectedSeqs()
     {
       if (selectionGroup == null)
@@ -1268,8 +1308,9 @@ public class AlignViewport
       if(seq!=null)
       {
         for (int i = 0; i < seq.length; i++)
+        {
           alignment.getHiddenSequences().hideSequence(seq[i]);
-
+        }
         hasHiddenRows = true;
         firePropertyChange("alignment", null, alignment.getSequences());
       }
@@ -1277,7 +1318,8 @@ public class AlignViewport
 
     public void showSequence(int index)
     {
-      Vector tmp = alignment.getHiddenSequences().showSequence(index);
+      Vector tmp = alignment.getHiddenSequences().showSequence(index
+          , hiddenRepSequences);
       if(tmp.size()>0)
       {
         if(selectionGroup==null)
@@ -1321,7 +1363,7 @@ public class AlignViewport
           selectionGroup = new SequenceGroup();
           selectionGroup.setEndRes(alignment.getWidth()-1);
         }
-        Vector tmp = alignment.getHiddenSequences().showAll();
+        Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
         for(int t=0; t<tmp.size(); t++)
         {
           selectionGroup.addSequence(
@@ -1330,23 +1372,26 @@ public class AlignViewport
         }
         firePropertyChange("alignment", null, alignment.getSequences());
         hasHiddenRows = false;
+        hiddenRepSequences = null;
       }
     }
 
+
+
     public void invertColumnSelection()
     {
-      int column;
       for(int i=0; i<alignment.getWidth(); i++)
       {
-        column = i;
-
-        if(colSel.contains(column))
-          colSel.removeElement(column);
+        if(colSel.contains(i))
+          colSel.removeElement(i);
         else
-          colSel.addElement(column);
-
+        {
+          if (!hasHiddenColumns || colSel.isVisible(i))
+          {
+            colSel.addElement(i);
+          }
+        }
       }
-
     }
 
     public int adjustForHiddenSeqs(int alignmentIndex)
@@ -1387,7 +1432,7 @@ public class AlignViewport
       int start = 0, end = 0;
       if(selectedRegionOnly && selectionGroup!=null)
       {
-        iSize = selectionGroup.getSize(false);
+        iSize = selectionGroup.getSize();
         seqs = selectionGroup.getSequencesInOrder(alignment);
         start = selectionGroup.getStartRes();
         end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
@@ -1482,7 +1527,7 @@ public class AlignViewport
       int start = 0, end = 0;
       if(selectedRegionOnly && selectionGroup!=null)
       {
-        iSize = selectionGroup.getSize(false);
+        iSize = selectionGroup.getSize();
         seqs = selectionGroup.getSequencesInOrder(alignment);
         start = selectionGroup.getStartRes();
         end = selectionGroup.getEndRes()+1;
@@ -1500,7 +1545,7 @@ public class AlignViewport
       } else {
         for(i=0; i<iSize; i++)
         {
-          selection[i] = seqs[i].getSequence(start, end);
+          selection[i] = seqs[i].getSequenceAsString(start, end);
         }
 
       }
@@ -1592,12 +1637,31 @@ public class AlignViewport
         if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)
         {
           ((ClustalxColourScheme)sg.cs).resetClustalX(
-              sg.getSequences(true), sg.getWidth());
+              sg.getSequences(hiddenRepSequences), sg.getWidth());
         }
         sg.recalcConservation();
       }
     }
 
 
+    public Color getSequenceColour(SequenceI seq)
+    {
+      if(sequenceColours==null || !sequenceColours.containsKey(seq))
+        return Color.white;
+      else
+        return (Color)sequenceColours.get(seq);
+    }
+
+    public void setSequenceColour(SequenceI seq, Color col)
+    {
+      if(sequenceColours==null)
+        sequenceColours = new Hashtable();
+
+      if(col == null)
+        sequenceColours.remove(seq);
+      else
+        sequenceColours.put(seq, col);
+    }
+
 
 }