Merge branch 'develop' into documentation/JAL-2418_release2102
authorJim Procter <jprocter@issues.jalview.org>
Wed, 31 May 2017 20:05:39 +0000 (21:05 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 31 May 2017 20:05:39 +0000 (21:05 +0100)
15 files changed:
src/jalview/appletgui/APopupMenu.java
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/Finder.java
src/jalview/appletgui/SeqPanel.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/gui/SeqPanel.java
src/jalview/io/AppletFormatAdapter.java
src/jalview/viewmodel/AlignmentViewport.java
test/jalview/datamodel/SequenceGroupTest.java
test/jalview/ext/jmol/JmolParserTest.java
test/jalview/ext/jmol/JmolViewerTest.java
test/jalview/gui/AlignViewportTest.java
test/jalview/gui/StructureChooserTest.java
test/jalview/io/FileLoaderTest.java

index 8fd317a..77ec373 100644 (file)
@@ -65,6 +65,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -819,9 +820,9 @@ public class APopupMenu extends java.awt.PopupMenu implements
         return;
       }
 
-      int rsize = 0, gSize = sg.getSize();
-      SequenceI[] rseqs, seqs = new SequenceI[gSize];
-      SequenceFeature[] tfeatures, features = new SequenceFeature[gSize];
+      int gSize = sg.getSize();
+      List<SequenceI> seqs = new ArrayList<SequenceI>();
+      List<SequenceFeature> features = new ArrayList<SequenceFeature>();
 
       for (int i = 0; i < gSize; i++)
       {
@@ -829,25 +830,17 @@ public class APopupMenu extends java.awt.PopupMenu implements
         int end = sg.findEndRes(sg.getSequenceAt(i));
         if (start <= end)
         {
-          seqs[rsize] = sg.getSequenceAt(i);
-          features[rsize] = new SequenceFeature(null, null, null, start,
-                  end, "Jalview");
-          rsize++;
+          seqs.add(sg.getSequenceAt(i));
+          features.add(new SequenceFeature(null, null, null, start, end,
+                  "Jalview"));
         }
       }
-      rseqs = new SequenceI[rsize];
-      tfeatures = new SequenceFeature[rsize];
-      System.arraycopy(seqs, 0, rseqs, 0, rsize);
-      System.arraycopy(features, 0, tfeatures, 0, rsize);
-      features = tfeatures;
-      seqs = rseqs;
 
       if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
               features, true, ap))
       {
         ap.alignFrame.sequenceFeatures.setState(true);
         ap.av.setShowSequenceFeatures(true);
-        ;
         ap.highlightSearchResults(null);
       }
     }
index 38ecf76..3c2715f 100644 (file)
@@ -53,6 +53,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.TextEvent;
 import java.awt.event.TextListener;
 import java.util.Hashtable;
+import java.util.List;
 
 /**
  * DOCUMENT ME!
@@ -182,8 +183,8 @@ public class FeatureRenderer extends
    * @param ap
    * @return
    */
-  boolean amendFeatures(final SequenceI[] sequences,
-          final SequenceFeature[] features, boolean create,
+  boolean amendFeatures(final List<SequenceI> sequences,
+          final List<SequenceFeature> features, boolean create,
           final AlignmentPanel ap)
   {
     final Panel bigPanel = new Panel(new BorderLayout());
@@ -223,22 +224,20 @@ public class FeatureRenderer extends
 
     // /////////////////////////////////////
     // /MULTIPLE FEATURES AT SELECTED RESIDUE
-    if (!create && features.length > 1)
+    if (!create && features.size() > 1)
     {
       panel = new Panel(new GridLayout(4, 1));
       tmp = new Panel();
       tmp.add(new Label("Select Feature: "));
       overlaps = new Choice();
-      for (int i = 0; i < features.length; i++)
+      for (SequenceFeature sf : features)
       {
-        String item = features[i].getType() + "/" + features[i].getBegin()
-                + "-" + features[i].getEnd();
-
-        if (features[i].getFeatureGroup() != null)
+        String item = sf.getType() + "/" + sf.getBegin() + "-"
+                + sf.getEnd();
+        if (sf.getFeatureGroup() != null)
         {
-          item += " (" + features[i].getFeatureGroup() + ")";
+          item += " (" + sf.getFeatureGroup() + ")";
         }
-
         overlaps.addItem(item);
       }
 
@@ -253,15 +252,16 @@ public class FeatureRenderer extends
           if (index != -1)
           {
             featureIndex = index;
-            name.setText(features[index].getType());
-            description.setText(features[index].getDescription());
-            group.setText(features[index].getFeatureGroup());
-            start.setText(features[index].getBegin() + "");
-            end.setText(features[index].getEnd() + "");
+            SequenceFeature sf = features.get(index);
+            name.setText(sf.getType());
+            description.setText(sf.getDescription());
+            group.setText(sf.getFeatureGroup());
+            start.setText(sf.getBegin() + "");
+            end.setText(sf.getEnd() + "");
 
             SearchResultsI highlight = new SearchResults();
-            highlight.addResult(sequences[0], features[index].getBegin(),
-                    features[index].getEnd());
+            highlight.addResult(sequences.get(0), sf.getBegin(),
+                    sf.getEnd());
 
             ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
 
@@ -269,8 +269,8 @@ public class FeatureRenderer extends
           FeatureColourI col = getFeatureStyle(name.getText());
           if (col == null)
           {
-            Color generatedColour = ColorUtils
-                    .createColourFromName(name.getText());
+            Color generatedColour = ColorUtils.createColourFromName(name
+                    .getText());
             col = new FeatureColour(generatedColour);
           }
 
@@ -328,16 +328,17 @@ public class FeatureRenderer extends
      * if feature type has not been supplied by the caller
      * (e.g. for Amend, or create features from Find) 
      */
-    boolean useLastDefaults = features[0].getType() == null;
-    String featureType = useLastDefaults ? lastFeatureAdded : features[0]
+    SequenceFeature firstFeature = features.get(0);
+    boolean useLastDefaults = firstFeature.getType() == null;
+    String featureType = useLastDefaults ? lastFeatureAdded : firstFeature
             .getType();
     String featureGroup = useLastDefaults ? lastFeatureGroupAdded
-            : features[0].getFeatureGroup();
+            : firstFeature.getFeatureGroup();
 
     String title = create ? MessageManager
             .getString("label.create_new_sequence_features")
             : MessageManager.formatMessage("label.amend_delete_features",
-                    new String[] { sequences[0].getName() });
+                    new String[] { sequences.get(0).getName() });
 
     final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
             240);
@@ -362,9 +363,9 @@ public class FeatureRenderer extends
       });
     }
 
-    start.setText(features[0].getBegin() + "");
-    end.setText(features[0].getEnd() + "");
-    description.setText(features[0].getDescription());
+    start.setText(firstFeature.getBegin() + "");
+    end.setText(firstFeature.getEnd() + "");
+    description.setText(firstFeature.getDescription());
     // lookup (or generate) the feature colour
     FeatureColourI fcol = getFeatureStyle(name.getText());
     // simply display the feature color in a box
@@ -403,7 +404,7 @@ public class FeatureRenderer extends
 
     if (!create)
     {
-      SequenceFeature sf = features[featureIndex];
+      SequenceFeature sf = features.get(featureIndex);
       if (dialog.accept)
       {
         sf.type = enteredType;
@@ -437,7 +438,7 @@ public class FeatureRenderer extends
       }
       if (deleteFeature)
       {
-        sequences[0].deleteFeature(sf);
+        sequences.get(0).deleteFeature(sf);
         // ensure Feature Settings reflects removal of feature / group
         featuresAdded();
       }
@@ -449,14 +450,14 @@ public class FeatureRenderer extends
        */
       if (dialog.accept && name.getText().length() > 0)
       {
-        for (int i = 0; i < sequences.length; i++)
+        for (int i = 0; i < sequences.size(); i++)
         {
-          features[i].type = enteredType;
-          features[i].featureGroup = group.getText().trim();
-          features[i].description = description.getText()
+          features.get(i).type = enteredType;
+          features.get(i).featureGroup = group.getText().trim();
+          features.get(i).description = description.getText()
                   .replace('\n', ' ');
-          sequences[i].addSequenceFeature(features[i]);
-          ffile.parseDescriptionHTML(features[i], false);
+          sequences.get(i).addSequenceFeature(features.get(i));
+          ffile.parseDescriptionHTML(features.get(i), false);
         }
 
         Color newColour = colourPanel.getBackground();
index a342736..f7ebab6 100644 (file)
@@ -41,6 +41,8 @@ import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Vector;
 
 public class Finder extends Panel implements ActionListener
@@ -113,20 +115,16 @@ public class Finder extends Panel implements ActionListener
 
   public void createNewGroup_actionPerformed()
   {
-    SequenceI[] seqs = new SequenceI[searchResults.getSize()];
-    SequenceFeature[] features = new SequenceFeature[searchResults
-            .getSize()];
+    List<SequenceI> seqs = new ArrayList<SequenceI>();
+    List<SequenceFeature> features = new ArrayList<SequenceFeature>();
     String searchString = textfield.getText().trim();
 
-    int i = 0;
     for (SearchResultMatchI match : searchResults.getResults())
     {
-      seqs[i] = match.getSequence().getDatasetSequence();
-
-      features[i] = new SequenceFeature(searchString,
+      seqs.add(match.getSequence().getDatasetSequence());
+      features.add(new SequenceFeature(searchString,
               "Search Results", null, match.getStart(), match.getEnd(),
-              "Search Results");
-      i++;
+ "Search Results"));
     }
 
     if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
index 14ea222..4aa205e 100644 (file)
@@ -54,6 +54,10 @@ import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
 import java.util.Vector;
 
 public class SeqPanel extends Panel implements MouseMotionListener,
@@ -563,20 +567,23 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         av.setSelectionGroup(null);
       }
 
-      SequenceFeature[] features = findFeaturesAtRes(sequence,
-              sequence.findPosition(findRes(evt)));
+      int column = findRes(evt);
+      boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+      List<SequenceFeature> features = findFeaturesAtRes(sequence,
+              sequence.findPosition(column));
+      if (isGapped)
+      {
+        removeAdjacentFeatures(features, column + 1, sequence);
+      }
 
-      if (features != null && features.length > 0)
+      if (!features.isEmpty())
       {
         SearchResultsI highlight = new SearchResults();
-        highlight.addResult(sequence, features[0].getBegin(),
-                features[0].getEnd());
+        highlight.addResult(sequence, features.get(0).getBegin(), features
+                .get(0).getEnd());
         seqCanvas.highlightSearchResults(highlight);
-      }
-      if (features != null && features.length > 0)
-      {
         seqCanvas.getFeatureRenderer().amendFeatures(
-                new SequenceI[] { sequence }, features, false, ap);
+                Collections.singletonList(sequence), features, false, ap);
 
         seqCanvas.highlightSearchResults(null);
       }
@@ -586,13 +593,13 @@ public class SeqPanel extends Panel implements MouseMotionListener,
   @Override
   public void mouseReleased(MouseEvent evt)
   {
+    boolean didDrag = mouseDragging; // did we come here after a drag
     mouseDragging = false;
     mouseWheelPressed = false;
-    ap.paintAlignment(true);
 
     if (!editingSeqs)
     {
-      doMouseReleasedDefineMode(evt);
+      doMouseReleasedDefineMode(evt, didDrag);
       return;
     }
 
@@ -802,9 +809,11 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
 
     final char ch = sequence.getCharAt(column);
-    int respos = Comparison.isGap(ch) ? -1 : sequence.findPosition(column);
+    boolean isGapped = Comparison.isGap(ch);
+    // find residue at column (or nearest if at a gap)
+    int respos = sequence.findPosition(column);
 
-    if (ssm != null && respos != -1)
+    if (ssm != null && !isGapped)
     {
       mouseOverSequence(sequence, column, respos);
     }
@@ -813,30 +822,21 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     text.append("Sequence ").append(Integer.toString(seq + 1))
             .append(" ID: ").append(sequence.getName());
 
-    String obj = null;
-    if (respos != -1)
+    if (!isGapped)
     {
       if (av.getAlignment().isNucleotide())
       {
-        obj = ResidueProperties.nucleotideName.get(ch);
-        if (obj != null)
-        {
-          text.append(" Nucleotide: ").append(obj);
-        }
+        String base = ResidueProperties.nucleotideName.get(ch);
+        text.append(" Nucleotide: ").append(base == null ? ch : base);
       }
       else
       {
-        obj = (ch == 'x' || ch == 'X') ? "X" : ResidueProperties.aa2Triplet
+        String residue = (ch == 'x' || ch == 'X') ? "X"
+                : ResidueProperties.aa2Triplet
                 .get(String.valueOf(ch));
-        if (obj != null)
-        {
-          text.append(" Residue: ").append(obj);
-        }
-      }
-      if (obj != null)
-      {
-        text.append(" (").append(Integer.toString(respos)).append(")");
+        text.append(" Residue: ").append(residue == null ? ch : residue);
       }
+      text.append(" (").append(Integer.toString(respos)).append(")");
     }
 
     ap.alignFrame.statusBar.setText(text.toString());
@@ -864,18 +864,19 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
 
     /*
-     * add feature details to tooltip if over one or more features
+     * add feature details to tooltip, including any that straddle
+     * a gapped position
      */
-    if (respos != -1)
+    if (av.isShowSequenceFeatures())
     {
-      SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
+      List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
               sequence.findPosition(column));
-
-      int index = 0;
-      while (index < allFeatures.length)
+      if (isGapped)
+      {
+        removeAdjacentFeatures(allFeatures, column + 1, sequence);
+      }
+      for (SequenceFeature sf : allFeatures)
       {
-        SequenceFeature sf = allFeatures[index];
-
         tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
 
         if (sf.getDescription() != null)
@@ -892,8 +893,6 @@ public class SeqPanel extends Panel implements MouseMotionListener,
           }
         }
         tooltipText.append("\n");
-
-        index++;
       }
     }
 
@@ -907,9 +906,38 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
   }
 
-  SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
+  /**
+   * Removes from the list of features any that start after, or end before, the
+   * given column position. This allows us to retain only those features
+   * adjacent to a gapped position that straddle the position. Contact features
+   * that 'straddle' the position are also removed, since they are not 'at' the
+   * position.
+   * 
+   * @param features
+   * @param column
+   *          alignment column (1..)
+   * @param sequence
+   */
+  protected void removeAdjacentFeatures(List<SequenceFeature> features,
+          int column, SequenceI sequence)
   {
-    Vector tmp = new Vector();
+    // TODO should this be an AlignViewController method (shared by gui)?
+    ListIterator<SequenceFeature> it = features.listIterator();
+    while (it.hasNext())
+    {
+      SequenceFeature sf = it.next();
+      if (sf.isContactFeature()
+              || sequence.findIndex(sf.getBegin()) > column
+              || sequence.findIndex(sf.getEnd()) < column)
+      {
+        it.remove();
+      }
+    }
+  }
+
+  List<SequenceFeature> findFeaturesAtRes(SequenceI sequence, int res)
+  {
+    List<SequenceFeature> result = new ArrayList<SequenceFeature>();
     SequenceFeature[] features = sequence.getSequenceFeatures();
     if (features != null)
     {
@@ -932,15 +960,12 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         if ((features[i].getBegin() <= res)
                 && (features[i].getEnd() >= res))
         {
-          tmp.addElement(features[i]);
+          result.add(features[i]);
         }
       }
     }
 
-    features = new SequenceFeature[tmp.size()];
-    tmp.copyInto(features);
-
-    return features;
+    return result;
   }
 
   Tooltip tooltip;
@@ -1466,24 +1491,21 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     // DETECT RIGHT MOUSE BUTTON IN AWT
     if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
     {
-      SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
+      List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
               sequence.findPosition(res));
 
       Vector<String> links = null;
-      if (allFeatures != null)
+      for (SequenceFeature sf : allFeatures)
       {
-        for (int i = 0; i < allFeatures.length; i++)
+        if (sf.links != null)
         {
-          if (allFeatures[i].links != null)
+          if (links == null)
           {
-            if (links == null)
-            {
-              links = new Vector<String>();
-            }
-            for (int j = 0; j < allFeatures[i].links.size(); j++)
-            {
-              links.addElement(allFeatures[i].links.elementAt(j));
-            }
+            links = new Vector<String>();
+          }
+          for (int j = 0; j < sf.links.size(); j++)
+          {
+            links.addElement(sf.links.elementAt(j));
           }
         }
       }
@@ -1527,7 +1549,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
   }
 
-  public void doMouseReleasedDefineMode(MouseEvent evt)
+  public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
   {
     if (stretchGroup == null)
     {
@@ -1537,7 +1559,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     // but defer colourscheme update until hidden sequences are passed in
     boolean vischange = stretchGroup.recalcConservation(true);
     // here we rely on stretchGroup == av.getSelection()
-    needOverviewUpdate |= vischange && av.isSelectionDefinedGroup();
+    needOverviewUpdate |= vischange && av.isSelectionDefinedGroup()
+            && afterDrag;
     if (stretchGroup.cs != null)
     {
       stretchGroup.cs.alignmentChanged(stretchGroup,
index fcb6109..5d91b36 100755 (executable)
@@ -73,7 +73,7 @@ public class Alignment implements AlignmentI
     groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
     hiddenSequences = new HiddenSequences(this);
     hiddenCols = new HiddenColumns();
-    codonFrameList = new ArrayList<AlignedCodonFrame>();
+    codonFrameList = new ArrayList<>();
 
     nucleotide = Comparison.isNucleotide(seqs);
 
@@ -405,7 +405,7 @@ public class Alignment implements AlignmentI
   @Override
   public SequenceGroup[] findAllGroups(SequenceI s)
   {
-    ArrayList<SequenceGroup> temp = new ArrayList<SequenceGroup>();
+    ArrayList<SequenceGroup> temp = new ArrayList<>();
 
     synchronized (groups)
     {
@@ -456,7 +456,7 @@ public class Alignment implements AlignmentI
             return;
           }
         }
-        sg.setContext(this);
+        sg.setContext(this, true);
         groups.add(sg);
       }
     }
@@ -533,7 +533,7 @@ public class Alignment implements AlignmentI
       }
       for (SequenceGroup sg : groups)
       {
-        sg.setContext(null);
+        sg.setContext(null, false);
       }
       groups.clear();
     }
@@ -549,7 +549,7 @@ public class Alignment implements AlignmentI
       {
         removeAnnotationForGroup(g);
         groups.remove(g);
-        g.setContext(null);
+        g.setContext(null, false);
       }
     }
   }
@@ -1071,7 +1071,7 @@ public class Alignment implements AlignmentI
     {
       return;
     }
-    List<SequenceI> toProcess = new ArrayList<SequenceI>();
+    List<SequenceI> toProcess = new ArrayList<>();
     toProcess.add(currentSeq);
     while (toProcess.size() > 0)
     {
@@ -1124,7 +1124,7 @@ public class Alignment implements AlignmentI
       return;
     }
     // try to avoid using SequenceI.equals at this stage, it will be expensive
-    Set<SequenceI> seqs = new LinkedIdentityHashSet<SequenceI>();
+    Set<SequenceI> seqs = new LinkedIdentityHashSet<>();
 
     for (int i = 0; i < getHeight(); i++)
     {
@@ -1409,7 +1409,7 @@ public class Alignment implements AlignmentI
     {
       return null;
     }
-    List<AlignedCodonFrame> cframes = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> cframes = new ArrayList<>();
     for (AlignedCodonFrame acf : getCodonFrames())
     {
       if (acf.involvesSequence(seq))
@@ -1486,7 +1486,7 @@ public class Alignment implements AlignmentI
     if (sqs != null)
     {
       // avoid self append deadlock by
-      List<SequenceI> toappendsq = new ArrayList<SequenceI>();
+      List<SequenceI> toappendsq = new ArrayList<>();
       synchronized (sqs)
       {
         for (SequenceI addedsq : sqs)
@@ -1627,7 +1627,7 @@ public class Alignment implements AlignmentI
   @Override
   public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
   {
-    List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    List<AlignmentAnnotation> aa = new ArrayList<>();
     AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation();
     if (alignmentAnnotation != null)
     {
@@ -1648,7 +1648,7 @@ public class Alignment implements AlignmentI
   public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
           String calcId, String label)
   {
-    ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
     for (AlignmentAnnotation ann : getAlignmentAnnotation())
     {
       if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
@@ -1853,7 +1853,7 @@ public class Alignment implements AlignmentI
   @Override
   public Set<String> getSequenceNames()
   {
-    Set<String> names = new HashSet<String>();
+    Set<String> names = new HashSet<>();
     for (SequenceI seq : getSequences())
     {
       names.add(seq.getName());
index 76ad093..463b909 100755 (executable)
@@ -52,6 +52,12 @@ public class SequenceGroup implements AnnotatedCollectionI
   boolean colourText = false;
 
   /**
+   * True if the group is defined as a group on the alignment, false if it is
+   * just a selection.
+   */
+  boolean isDefined = false;
+
+  /**
    * after Olivier's non-conserved only character display
    */
   boolean showNonconserved = false;
@@ -59,7 +65,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   /**
    * group members
    */
-  private List<SequenceI> sequences = new ArrayList<SequenceI>();
+  private List<SequenceI> sequences = new ArrayList<>();
 
   /**
    * representative sequence for this group (if any)
@@ -104,13 +110,23 @@ public class SequenceGroup implements AnnotatedCollectionI
    */
   private boolean normaliseSequenceLogo;
 
-  /**
-   * @return the includeAllConsSymbols
+  /*
+   * visibility of rows or represented rows covered by group
    */
-  public boolean isShowSequenceLogo()
-  {
-    return showSequenceLogo;
-  }
+  private boolean hidereps = false;
+
+  /*
+   * visibility of columns intersecting this group
+   */
+  private boolean hidecols = false;
+
+  AlignmentAnnotation consensus = null;
+
+  AlignmentAnnotation conservation = null;
+
+  private boolean showConsensusHistogram;
+
+  private AnnotatedCollectionI context;
 
   /**
    * Creates a new SequenceGroup object.
@@ -161,7 +177,7 @@ public class SequenceGroup implements AnnotatedCollectionI
     this();
     if (seqsel != null)
     {
-      sequences = new ArrayList<SequenceI>();
+      sequences = new ArrayList<>();
       sequences.addAll(seqsel.sequences);
       if (seqsel.groupName != null)
       {
@@ -172,13 +188,17 @@ public class SequenceGroup implements AnnotatedCollectionI
       colourText = seqsel.colourText;
       startRes = seqsel.startRes;
       endRes = seqsel.endRes;
-      cs = seqsel.cs;
+      cs = new ResidueShader(seqsel.getColourScheme());
       if (seqsel.description != null)
       {
         description = new String(seqsel.description);
       }
       hidecols = seqsel.hidecols;
       hidereps = seqsel.hidereps;
+      showNonconserved = seqsel.showNonconserved;
+      showSequenceLogo = seqsel.showSequenceLogo;
+      normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
+      showConsensusHistogram = seqsel.showConsensusHistogram;
       idColour = seqsel.idColour;
       outlineColour = seqsel.outlineColour;
       seqrep = seqsel.seqrep;
@@ -195,6 +215,11 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
   }
 
+  public boolean isShowSequenceLogo()
+  {
+    return showSequenceLogo;
+  }
+
   public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
   {
     int iSize = sequences.size();
@@ -311,7 +336,7 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
     else
     {
-      List<SequenceI> allSequences = new ArrayList<SequenceI>();
+      List<SequenceI> allSequences = new ArrayList<>();
       for (SequenceI seq : sequences)
       {
         allSequences.add(seq);
@@ -951,11 +976,6 @@ public class SequenceGroup implements AnnotatedCollectionI
   }
 
   /**
-   * visibility of rows or represented rows covered by group
-   */
-  private boolean hidereps = false;
-
-  /**
    * set visibility of sequences covered by (if no sequence representative is
    * defined) or represented by this group.
    * 
@@ -977,11 +997,6 @@ public class SequenceGroup implements AnnotatedCollectionI
   }
 
   /**
-   * visibility of columns intersecting this group
-   */
-  private boolean hidecols = false;
-
-  /**
    * set intended visibility of columns covered by this group
    * 
    * @param visibility
@@ -1015,7 +1030,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   {
     SequenceGroup sgroup = new SequenceGroup(this);
     SequenceI[] insect = getSequencesInOrder(alignment);
-    sgroup.sequences = new ArrayList<SequenceI>();
+    sgroup.sequences = new ArrayList<>();
     for (int s = 0; insect != null && s < insect.length; s++)
     {
       if (map == null || map.containsKey(insect[s]))
@@ -1043,13 +1058,6 @@ public class SequenceGroup implements AnnotatedCollectionI
     this.showNonconserved = displayNonconserved;
   }
 
-  AlignmentAnnotation consensus = null, conservation = null;
-
-  /**
-   * flag indicating if consensus histogram should be rendered
-   */
-  private boolean showConsensusHistogram;
-
   /**
    * set this alignmentAnnotation object as the one used to render consensus
    * annotation
@@ -1242,7 +1250,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   {
     // TODO add in other methods like 'getAlignmentAnnotation(String label),
     // etc'
-    ArrayList<AlignmentAnnotation> annot = new ArrayList<AlignmentAnnotation>();
+    ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
     synchronized (sequences)
     {
       for (SequenceI seq : sequences)
@@ -1274,7 +1282,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   @Override
   public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
   {
-    List<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    List<AlignmentAnnotation> aa = new ArrayList<>();
     if (calcId == null)
     {
       return aa;
@@ -1293,7 +1301,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
           String calcId, String label)
   {
-    ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
+    ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
     for (AlignmentAnnotation ann : getAlignmentAnnotation())
     {
       if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
@@ -1340,12 +1348,29 @@ public class SequenceGroup implements AnnotatedCollectionI
     }
   }
 
-  private AnnotatedCollectionI context;
+  /**
+   * Sets the alignment or group context for this group, and whether it is
+   * defined as a group
+   * 
+   * @param ctx
+   *          the context for the group
+   * @param defined
+   *          whether the group is defined on the alignment or is just a
+   *          selection
+   * @throws IllegalArgumentException
+   *           if setting the context would result in a circular reference chain
+   */
+  public void setContext(AnnotatedCollectionI ctx, boolean defined)
+  {
+    setContext(ctx);
+    this.isDefined = defined;
+  }
 
   /**
    * Sets the alignment or group context for this group
    * 
    * @param ctx
+   *          the context for the group
    * @throws IllegalArgumentException
    *           if setting the context would result in a circular reference chain
    */
@@ -1375,6 +1400,11 @@ public class SequenceGroup implements AnnotatedCollectionI
     return context;
   }
 
+  public boolean isDefined()
+  {
+    return isDefined;
+  }
+
   public void setColourScheme(ColourSchemeI scheme)
   {
     if (cs == null)
index fd6232d..ef9d8b3 100644 (file)
@@ -62,6 +62,7 @@ import java.awt.event.MouseWheelListener;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.ListIterator;
 
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
@@ -564,6 +565,7 @@ public class SeqPanel extends JPanel implements MouseListener,
   @Override
   public void mouseReleased(MouseEvent evt)
   {
+    boolean didDrag = mouseDragging; // did we come here after a drag
     mouseDragging = false;
     mouseWheelPressed = false;
 
@@ -576,7 +578,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     if (!editingSeqs)
     {
-      doMouseReleasedDefineMode(evt);
+      doMouseReleasedDefineMode(evt, didDrag);
       return;
     }
 
@@ -731,8 +733,9 @@ public class SeqPanel extends JPanel implements MouseListener,
     /*
      * set status bar message, returning residue position in sequence
      */
+    boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
     final int pos = setStatusMessage(sequence, column, seq);
-    if (ssm != null && pos > -1)
+    if (ssm != null && !isGapped)
     {
       mouseOverSequence(sequence, column, pos);
     }
@@ -761,10 +764,19 @@ public class SeqPanel extends JPanel implements MouseListener,
       }
     }
 
-    if (av.isShowSequenceFeatures() && pos != -1)
+    /*
+     * add any features at the position to the tooltip; if over a gap, only
+     * add features that straddle the gap (pos may be the residue before or
+     * after the gap)
+     */
+    if (av.isShowSequenceFeatures())
     {
       List<SequenceFeature> features = ap.getFeatureRenderer()
               .findFeaturesAtRes(sequence.getDatasetSequence(), pos);
+      if (isGapped)
+      {
+        removeAdjacentFeatures(features, column + 1, sequence);
+      }
       seqARep.appendFeatures(tooltipText, pos, features,
               this.ap.getSeqPanel().seqCanvas.fr.getMinMax());
     }
@@ -789,6 +801,35 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   }
 
+  /**
+   * Removes from the list of features any that start after, or end before, the
+   * given column position. This allows us to retain only those features
+   * adjacent to a gapped position that straddle the position. Contact features
+   * that 'straddle' the position are also removed, since they are not 'at' the
+   * position.
+   * 
+   * @param features
+   * @param column
+   *          alignment column (1..)
+   * @param sequence
+   */
+  protected void removeAdjacentFeatures(List<SequenceFeature> features,
+          final int column, SequenceI sequence)
+  {
+    // TODO should this be an AlignViewController method (and reused by applet)?
+    ListIterator<SequenceFeature> it = features.listIterator();
+    while (it.hasNext())
+    {
+      SequenceFeature sf = it.next();
+      if (sf.isContactFeature()
+              || sequence.findIndex(sf.getBegin()) > column
+              || sequence.findIndex(sf.getEnd()) < column)
+      {
+        it.remove();
+      }
+    }
+  }
+
   private Point lastp = null;
 
   /*
@@ -833,9 +874,10 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   /**
    * Sets the status message in alignment panel, showing the sequence number
-   * (index) and id, residue and residue position for the given sequence and
-   * column position. Returns the calculated residue position in the sequence,
-   * or -1 for a gapped column position.
+   * (index) and id, and residue and residue position if not at a gap, for the
+   * given sequence and column position. Returns the residue position returned
+   * by Sequence.findPosition. Note this may be for the nearest adjacent residue
+   * if at a gapped position.
    * 
    * @param sequence
    *          aligned sequence object
@@ -843,7 +885,8 @@ public class SeqPanel extends JPanel implements MouseListener,
    *          alignment column
    * @param seq
    *          index of sequence in alignment
-   * @return position of column in sequence or -1 if at a gap
+   * @return sequence position of residue at column, or adjacent residue if at a
+   *         gap
    */
   int setStatusMessage(SequenceI sequence, final int column, int seq)
   {
@@ -857,36 +900,34 @@ public class SeqPanel extends JPanel implements MouseListener,
             .append(sequence.getName());
 
     String residue = null;
+
     /*
      * Try to translate the display character to residue name (null for gap).
      */
     final String displayChar = String.valueOf(sequence.getCharAt(column));
-    if (av.getAlignment().isNucleotide())
+    boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+    int pos = sequence.findPosition(column);
+
+    if (!isGapped)
     {
-      residue = ResidueProperties.nucleotideName.get(displayChar);
-      if (residue != null)
+      boolean nucleotide = av.getAlignment().isNucleotide();
+      if (nucleotide)
       {
-        text.append(" Nucleotide: ").append(residue);
+        residue = ResidueProperties.nucleotideName.get(displayChar);
       }
-    }
-    else
-    {
-      residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*"
-              .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet
-              .get(displayChar));
-      if (residue != null)
+      else
       {
-        text.append(" Residue: ").append(residue);
+        residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*"
+                .equals(displayChar) ? "STOP"
+                : ResidueProperties.aa2Triplet.get(displayChar));
       }
-    }
+      text.append(" ").append(nucleotide ? "Nucleotide" : "Residue")
+              .append(": ").append(residue == null ? displayChar : residue);
 
-    int pos = -1;
-    if (residue != null)
-    {
-      pos = sequence.findPosition(column);
       text.append(" (").append(Integer.toString(pos)).append(")");
     }
     ap.alignFrame.statusBar.setText(text.toString());
+
     return pos;
   }
 
@@ -1526,9 +1567,20 @@ public class SeqPanel extends JPanel implements MouseListener,
         av.setSelectionGroup(null);
       }
 
+      int column = findColumn(evt);
+      boolean isGapped = Comparison.isGap(sequence.getCharAt(column));
+
+      /*
+       * find features at the position (if not gapped), or straddling
+       * the position (if at a gap)
+       */
       List<SequenceFeature> features = seqCanvas.getFeatureRenderer()
               .findFeaturesAtRes(sequence.getDatasetSequence(),
-                      sequence.findPosition(findColumn(evt)));
+                      sequence.findPosition(column));
+      if (isGapped)
+      {
+        removeAdjacentFeatures(features, column, sequence);
+      }
 
       if (!features.isEmpty())
       {
@@ -1711,7 +1763,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     List<SequenceFeature> allFeatures = ap.getFeatureRenderer()
             .findFeaturesAtRes(sequence.getDatasetSequence(),
                     sequence.findPosition(res));
-    List<String> links = new ArrayList<String>();
+    List<String> links = new ArrayList<>();
     for (SequenceFeature sf : allFeatures)
     {
       if (sf.links != null)
@@ -1728,12 +1780,15 @@ public class SeqPanel extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
+   * Update the display after mouse up on a selection or group
    * 
    * @param evt
-   *          DOCUMENT ME!
+   *          mouse released event details
+   * @param afterDrag
+   *          true if this event is happening after a mouse drag (rather than a
+   *          mouse down)
    */
-  public void doMouseReleasedDefineMode(MouseEvent evt)
+  public void doMouseReleasedDefineMode(MouseEvent evt, boolean afterDrag)
   {
     if (stretchGroup == null)
     {
@@ -1742,7 +1797,8 @@ public class SeqPanel extends JPanel implements MouseListener,
     // always do this - annotation has own state
     // but defer colourscheme update until hidden sequences are passed in
     boolean vischange = stretchGroup.recalcConservation(true);
-    needOverviewUpdate |= vischange && av.isSelectionDefinedGroup();
+    needOverviewUpdate |= vischange && av.isSelectionDefinedGroup()
+            && afterDrag;
     if (stretchGroup.cs != null)
     {
       stretchGroup.cs.alignmentChanged(stretchGroup,
@@ -1996,11 +2052,13 @@ public class SeqPanel extends JPanel implements MouseListener,
         ap.getCalculationDialog().validateCalcTypes();
       }
 
-      // process further ?
-      if (!av.followSelection)
-      {
-        return;
-      }
+      return;
+    }
+
+    // process further ?
+    if (!av.followSelection)
+    {
+      return;
     }
 
     /*
index c5a80e3..907ff46 100755 (executable)
@@ -407,15 +407,26 @@ public class AppletFormatAdapter
     return null;
   }
 
-  public static DataSourceType checkProtocol(String file)
+  /**
+   * Determines the protocol (i.e DataSourceType.{FILE|PASTE|URL}) for the input
+   * data
+   *
+   * @param data
+   * @return the protocol for the input data
+   */
+  public static DataSourceType checkProtocol(String data)
   {
-    DataSourceType protocol = DataSourceType.FILE;
-    String ft = file.toLowerCase().trim();
+    DataSourceType protocol = DataSourceType.PASTE;
+    String ft = data.toLowerCase().trim();
     if (ft.indexOf("http:") == 0 || ft.indexOf("https:") == 0
             || ft.indexOf("file:") == 0)
     {
       protocol = DataSourceType.URL;
     }
+    else if (new File(data).exists())
+    {
+      protocol = DataSourceType.FILE;
+    }
     return protocol;
   }
 
index cdf0758..60cee46 100644 (file)
@@ -92,9 +92,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   FeaturesDisplayedI featuresDisplayed = null;
 
-  protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
+  protected Deque<CommandI> historyList = new ArrayDeque<>();
 
-  protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
+  protected Deque<CommandI> redoList = new ArrayDeque<>();
 
   /**
    * alignment displayed in the viewport. Please use get/setter
@@ -1113,7 +1113,6 @@ public abstract class AlignmentViewport implements AlignViewportI,
   public void setHiddenColumns(HiddenColumns hidden)
   {
     this.alignment.setHiddenColumns(hidden);
-    // this.colSel = colsel;
   }
 
   @Override
@@ -1298,7 +1297,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   protected boolean showOccupancy = true;
 
-  private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+  private Map<SequenceI, Color> sequenceColours = new HashMap<>();
 
   protected SequenceAnnotationOrder sortAnnotationsBy = null;
 
@@ -1528,7 +1527,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
     if (hiddenRepSequences == null)
     {
-      hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+      hiddenRepSequences = new Hashtable<>();
     }
 
     hiddenRepSequences.put(repSequence, sg);
@@ -1736,7 +1735,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
   @Override
   public List<int[]> getVisibleRegionBoundaries(int min, int max)
   {
-    ArrayList<int[]> regions = new ArrayList<int[]>();
+    ArrayList<int[]> regions = new ArrayList<>();
     int start = min;
     int end = max;
 
@@ -1779,7 +1778,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
   public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
           boolean selectedOnly)
   {
-    ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
+    ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
     AlignmentAnnotation[] aa;
     if ((aa = alignment.getAlignmentAnnotation()) != null)
     {
@@ -2133,7 +2132,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
     // intersect alignment annotation with alignment groups
 
     AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
-    List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
+    List<SequenceGroup> oldrfs = new ArrayList<>();
     if (aan != null)
     {
       for (int an = 0; an < aan.length; an++)
@@ -2846,8 +2845,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
         selectionIsDefinedGroup = gps.contains(selectionGroup);
       }
     }
-    return selectionGroup.getContext() == alignment
-            || selectionIsDefinedGroup;
+    return selectionGroup.isDefined() || selectionIsDefinedGroup;
   }
 
   /**
index 6e1c2db..f6d4028 100644 (file)
@@ -3,12 +3,16 @@ package jalview.datamodel;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNotSame;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 import jalview.schemes.NucleotideColourScheme;
+import jalview.schemes.PIDColourScheme;
+
+import java.awt.Color;
 
 import junit.extensions.PA;
 
@@ -121,13 +125,32 @@ public class SequenceGroupTest
     PA.setValue(sg2, "context", sg2);
     try
     {
-      sg3.setContext(sg2); // circular reference in sg2
+      sg3.setContext(sg2, false); // circular reference in sg2
       fail("Expected exception");
     } catch (IllegalArgumentException e)
     {
       // expected
       assertNull(sg3.getContext());
     }
+
+    // test isDefined setting behaviour
+    sg2 = new SequenceGroup();
+    sg1.setContext(null, false);
+    assertFalse(sg1.isDefined());
+
+    sg1.setContext(sg2, false);
+    assertFalse(sg1.isDefined());
+
+    sg1.setContext(sg2, true);
+    assertTrue(sg1.isDefined());
+
+    // setContext without defined parameter does not change isDefined
+    sg1.setContext(null);
+    assertTrue(sg1.isDefined());
+
+    sg1.setContext(null, false);
+    sg1.setContext(sg2);
+    assertFalse(sg1.isDefined());
   }
 
   @Test(groups = { "Functional" })
@@ -198,6 +221,73 @@ public class SequenceGroupTest
     assertTrue(sg2.contains(seq2, 8));
     sg2.deleteSequence(seq2, false);
     assertFalse(sg2.contains(seq2));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCopyConstructor()
+  {
+    SequenceI seq = new Sequence("seq", "ABC");
+    SequenceGroup sg = new SequenceGroup();
+    sg.addSequence(seq, false);
+    sg.setName("g1");
+    sg.setDescription("desc");
+    sg.setColourScheme(new PIDColourScheme());
+    sg.setDisplayBoxes(false);
+    sg.setDisplayText(false);
+    sg.setColourText(true);
+    sg.isDefined = true;
+    sg.setShowNonconserved(true);
+    sg.setOutlineColour(Color.red);
+    sg.setIdColour(Color.blue);
+    sg.thresholdTextColour = 1;
+    sg.textColour = Color.orange;
+    sg.textColour2 = Color.yellow;
+    sg.setIgnoreGapsConsensus(false);
+    sg.setshowSequenceLogo(true);
+    sg.setNormaliseSequenceLogo(true);
+    sg.setHidereps(true);
+    sg.setHideCols(true);
+    sg.setShowConsensusHistogram(true);
+    sg.setContext(new SequenceGroup());
+
+    SequenceGroup sg2 = new SequenceGroup(sg);
+    assertEquals(sg2.getName(), sg.getName());
+    assertEquals(sg2.getDescription(), sg.getDescription());
+    assertNotSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme());
+    assertSame(sg2.getColourScheme(), sg.getColourScheme());
+    assertEquals(sg2.getDisplayBoxes(), sg.getDisplayBoxes());
+    assertEquals(sg2.getDisplayText(), sg.getDisplayText());
+    assertEquals(sg2.getColourText(), sg.getColourText());
+    assertEquals(sg2.getShowNonconserved(), sg.getShowNonconserved());
+    assertEquals(sg2.getOutlineColour(), sg.getOutlineColour());
+    assertEquals(sg2.getIdColour(), sg.getIdColour());
+    assertEquals(sg2.thresholdTextColour, sg.thresholdTextColour);
+    assertEquals(sg2.textColour, sg.textColour);
+    assertEquals(sg2.textColour2, sg.textColour2);
+    assertEquals(sg2.getIgnoreGapsConsensus(), sg.getIgnoreGapsConsensus());
+    assertEquals(sg2.isShowSequenceLogo(), sg.isShowSequenceLogo());
+    assertEquals(sg2.isNormaliseSequenceLogo(),
+            sg.isNormaliseSequenceLogo());
+    assertEquals(sg2.isHidereps(), sg.isHidereps());
+    assertEquals(sg2.isHideCols(), sg.isHideCols());
+    assertEquals(sg2.isShowConsensusHistogram(),
+            sg.isShowConsensusHistogram());
+
+    /*
+     * copy of sequences
+     */
+    assertNotSame(sg2.getSequences(), sg.getSequences());
+    assertEquals(sg2.getSequences(), sg.getSequences());
 
+    /*
+     * isDefined should only be set true when a new group is added to
+     * an alignment, not in the copy constructor
+     */
+    assertFalse(sg2.isDefined());
+
+    /*
+     * context should be set explicitly, not by copy
+     */
+    assertNull(sg2.getContext());
   }
 }
index 131ef41..36e9b20 100644 (file)
@@ -272,7 +272,7 @@ public class JmolParserTest
      * local structure files should yield a false ID based on the filename
      */
     assertNotNull(structureData.getId());
-    assertEquals(structureData.getId(), "localstruct.pdb");
+    assertEquals(structureData.getId(), "localstruct");
     assertNotNull(structureData.getSeqs());
     /*
      * the ID is also the group for features derived from structure data 
@@ -280,7 +280,7 @@ public class JmolParserTest
     assertNotNull(structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup);
     assertEquals(
             structureData.getSeqs().get(0).getSequenceFeatures()[0].featureGroup,
-            "localstruct.pdb");
+            "localstruct");
 
   }
 }
index 4a59044..792f7ad 100644 (file)
@@ -33,7 +33,6 @@ import jalview.gui.StructureViewer;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.DataSourceType;
 
-import org.testng.Assert;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -117,56 +116,5 @@ public class JmolViewerTest
     }
   }
 
-  @Test(groups = { "Functional", "Network" })
-  public void testStructureLoadingViaURL()
-  {
-    Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
-    String inFile = "http://www.jalview.org/builds/develop/examples/3W5V.pdb";
-    AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
-            inFile, DataSourceType.URL);
-    assertTrue("Didn't read input file " + inFile, af != null);
-    for (SequenceI sq : af.getViewport().getAlignment().getSequences())
-    {
-      SequenceI dsq = sq.getDatasetSequence();
-      while (dsq.getDatasetSequence() != null)
-      {
-        dsq = dsq.getDatasetSequence();
-      }
-      if (dsq.getAllPDBEntries() != null
-              && dsq.getAllPDBEntries().size() > 0)
-      {
-        for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
-        {
-          final StructureViewer structureViewer = new StructureViewer(af
-                  .getViewport().getStructureSelectionManager());
-          structureViewer.setViewerType(ViewerType.JMOL);
-          JalviewStructureDisplayI jmolViewer = structureViewer
-                  .viewStructures(dsq.getAllPDBEntries().elementAt(q),
-                          new SequenceI[] { sq }, af.getCurrentView()
-                                  .getAlignPanel());
-          /*
-          * Wait for viewer load thread to complete
-          */
-          try
-          {
-            while (!jmolViewer.getBinding().isFinishedInit())
-            {
-              Thread.sleep(500);
-            }
-          } catch (InterruptedException e)
-          {
-          }
-          // System.out.println(">>>>>>>>>>>>>>>>> "
-          // + jmolViewer.getBinding().getPdbFile());
-          String[] expectedModelFiles = new String[] { "http://www.jalview.org/builds/develop/examples/3W5V.pdb" };
-          String[] actualModelFiles = jmolViewer.getBinding().getStructureFiles();
-          Assert.assertEqualsNoOrder(actualModelFiles, expectedModelFiles);
-          jmolViewer.closeViewer(true);
-          // todo: break here means only once through this loop?
-          break;
-        }
-        break;
-      }
-    }
-  }
+
 }
index e6c16b7..4660842 100644 (file)
@@ -160,7 +160,7 @@ public class AlignViewportTest
     acf2.addMap(s1, s1, new MapList(new int[] { 1, 4 }, new int[] { 4, 1 },
             1, 1));
 
-    List<AlignedCodonFrame> mappings = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> mappings = new ArrayList<>();
     mappings.add(acf1);
     mappings.add(acf2);
     af1.getViewport().getAlignment().setCodonFrames(mappings);
@@ -217,11 +217,11 @@ public class AlignViewportTest
     acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
         12 }, 1, 1));
 
-    List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> mappings1 = new ArrayList<>();
     mappings1.add(acf1);
     af1.getViewport().getAlignment().setCodonFrames(mappings1);
 
-    List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> mappings2 = new ArrayList<>();
     mappings2.add(acf2);
     mappings2.add(acf3);
     af2.getViewport().getAlignment().setCodonFrames(mappings2);
@@ -280,12 +280,12 @@ public class AlignViewportTest
     acf3.addMap(cs2, cs2, new MapList(new int[] { 1, 12 }, new int[] { 1,
         12 }, 1, 1));
 
-    List<AlignedCodonFrame> mappings1 = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> mappings1 = new ArrayList<>();
     mappings1.add(acf1);
     mappings1.add(acf2);
     af1.getViewport().getAlignment().setCodonFrames(mappings1);
 
-    List<AlignedCodonFrame> mappings2 = new ArrayList<AlignedCodonFrame>();
+    List<AlignedCodonFrame> mappings2 = new ArrayList<>();
     mappings2.add(acf2);
     mappings2.add(acf3);
     af2.getViewport().getAlignment().setCodonFrames(mappings2);
@@ -389,7 +389,8 @@ public class AlignViewportTest
 
   /**
    * Verify that setting the selection group has the side-effect of setting the
-   * context on the group, unless it already has one
+   * context on the group, unless it already has one, but does not change
+   * whether the group is defined or not.
    */
   @Test(groups = { "Functional" })
   public void testSetSelectionGroup()
@@ -399,13 +400,21 @@ public class AlignViewportTest
     AlignViewport av = af.getViewport();
     SequenceGroup sg1 = new SequenceGroup();
     SequenceGroup sg2 = new SequenceGroup();
+    SequenceGroup sg3 = new SequenceGroup();
 
     av.setSelectionGroup(sg1);
     assertSame(sg1.getContext(), av.getAlignment()); // context set
+    assertFalse(sg1.isDefined()); // group not defined
 
-    sg2.setContext(sg1);
+    sg2.setContext(sg1, false);
     av.setSelectionGroup(sg2);
+    assertFalse(sg2.isDefined()); // unchanged
     assertSame(sg2.getContext(), sg1); // unchanged
+
+    // create a defined group
+    sg3.setContext(av.getAlignment(), true);
+    av.setSelectionGroup(sg3);
+    assertTrue(sg3.isDefined()); // unchanged
   }
   /**
    * Verify that setting/clearing SHOW_OCCUPANCY preference adds or omits occupancy row from viewport
index c04353f..4535c93 100644 (file)
@@ -121,7 +121,7 @@ public class StructureChooserTest
     StructureChooser sc = new StructureChooser(selectedSeqs, seq, null);
     sc.populateFilterComboBox(false, false);
     int optionsSize = sc.getCmbFilterOption().getItemCount();
-    assertEquals(3, optionsSize); // if structures are not discovered then don't
+    assertEquals(2, optionsSize); // if structures are not discovered then don't
                                   // populate filter options
 
     sc.populateFilterComboBox(true, false);
index 0e21f6e..968901f 100644 (file)
@@ -14,11 +14,9 @@ public class FileLoaderTest
     fileLoader.LoadFileWaitTillLoaded(urlFile, DataSourceType.URL,
             FileFormat.PDB);
     Assert.assertNotNull(fileLoader.file);
-    // The FileLoader's file is expected to a temporary file different from the
-    // original URL.
-    Assert.assertNotEquals(urlFile, fileLoader.file);
-    // Data source type expected to be updated from DataSourceType.URL to
-    // DataSourceType.FILE
-    Assert.assertEquals(DataSourceType.FILE, fileLoader.protocol);
+    // The FileLoader's file is expected to be same as the original URL.
+    Assert.assertEquals(urlFile, fileLoader.file);
+    // Data source type expected to be DataSourceType.URL
+    Assert.assertEquals(DataSourceType.URL, fileLoader.protocol);
   }
 }