Merge branch 'develop' into bug/JAL-1803_JAL-2157
authorJim Procter <jprocter@issues.jalview.org>
Wed, 7 Sep 2016 11:46:28 +0000 (12:46 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 7 Sep 2016 11:46:28 +0000 (12:46 +0100)
1  2 
src/jalview/ext/jmol/JmolParser.java
src/jalview/gui/AlignFrame.java
src/jalview/viewmodel/AlignmentViewport.java

@@@ -22,7 -22,6 +22,7 @@@ package jalview.ext.jmol
  
  import jalview.datamodel.AlignmentAnnotation;
  import jalview.datamodel.Annotation;
 +import jalview.datamodel.PDBEntry;
  import jalview.datamodel.SequenceI;
  import jalview.io.FileParse;
  import jalview.io.StructureFile;
@@@ -98,18 -97,6 +98,18 @@@ public class JmolParser extends Structu
       */
      if (jmolModel.ms.mc > 0)
      {
 +      // ideally we do this
 +      // try
 +      // {
 +      // setStructureFileType(jmolModel.evalString("show _fileType"));
 +      // } catch (Exception q)
 +      // {
 +      // }
 +      // ;
 +      // instead, we distinguish .cif from non-.cif by filename
 +      setStructureFileType(getDataName().toLowerCase().endsWith(".cif") ? PDBEntry.Type.MMCIF
 +              .toString() : "PDB");
 +
        transformJmolModelToJalview(jmolModel.ms);
      }
    }
        // diff < 5 then mark as valid and update termination Atom
        if (chainTerMap.containsKey(curAtomChId))
        {
+         if (curAtom.getResno() < chainTerMap.get(curAtomChId).getResno())
+         {
+           return false;
+         }
          if ((curAtom.getResno() - chainTerMap.get(curAtomChId).getResno()) < 5)
          {
            chainTerMap.put(curAtomChId, curAtom);
      // atom with previously terminated chain encountered
      else if (chainTerMap.containsKey(curAtomChId))
      {
+       if (curAtom.getResno() < chainTerMap.get(curAtomChId).getResno())
+       {
+         return false;
+       }
        if ((curAtom.getResno() - chainTerMap.get(curAtomChId).getResno()) < 5)
        {
          chainTerMap.put(curAtomChId, curAtom);
@@@ -32,6 -32,7 +32,6 @@@ import jalview.api.AlignViewControllerI
  import jalview.api.AlignViewportI;
  import jalview.api.AlignmentViewPanel;
  import jalview.api.FeatureSettingsControllerI;
 -import jalview.api.FeatureSettingsModelI;
  import jalview.api.SplitContainerI;
  import jalview.api.ViewStyleI;
  import jalview.api.analysis.ScoreModelI;
@@@ -53,6 -54,7 +53,6 @@@ import jalview.datamodel.AlignmentI
  import jalview.datamodel.AlignmentOrder;
  import jalview.datamodel.AlignmentView;
  import jalview.datamodel.ColumnSelection;
 -import jalview.datamodel.DBRefSource;
  import jalview.datamodel.HiddenSequences;
  import jalview.datamodel.PDBEntry;
  import jalview.datamodel.SeqCigar;
@@@ -72,6 -74,7 +72,6 @@@ import jalview.io.JalviewFileView
  import jalview.io.JnetAnnotationMaker;
  import jalview.io.NewickFile;
  import jalview.io.TCoffeeScoreFile;
 -import jalview.io.gff.SequenceOntologyI;
  import jalview.jbgui.GAlignFrame;
  import jalview.schemes.Blosum62ColourScheme;
  import jalview.schemes.BuriedColourScheme;
@@@ -91,10 -94,12 +91,10 @@@ import jalview.schemes.TaylorColourSche
  import jalview.schemes.TurnColourScheme;
  import jalview.schemes.UserColourScheme;
  import jalview.schemes.ZappoColourScheme;
 -import jalview.structure.StructureSelectionManager;
  import jalview.util.MessageManager;
  import jalview.viewmodel.AlignmentViewport;
  import jalview.ws.DBRefFetcher;
  import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
 -import jalview.ws.SequenceFetcher;
  import jalview.ws.jws1.Discoverer;
  import jalview.ws.jws2.Jws2Discoverer;
  import jalview.ws.jws2.jabaws2.Jws2Instance;
@@@ -3620,34 -3625,51 +3620,51 @@@ public class AlignFrame extends GAlignF
            @Override
            public void mousePressed(MouseEvent evt)
            {
-             if (evt.isPopupTrigger())
+             if (evt.isPopupTrigger()) // Mac
              {
-               radioItem.removeActionListener(radioItem.getActionListeners()[0]);
-               int option = JOptionPane.showInternalConfirmDialog(
-                       jalview.gui.Desktop.desktop,
-                       MessageManager
-                               .getString("label.remove_from_default_list"),
-                       MessageManager
-                               .getString("label.remove_user_defined_colour"),
-                       JOptionPane.YES_NO_OPTION);
-               if (option == JOptionPane.YES_OPTION)
-               {
-                 jalview.gui.UserDefinedColours
-                         .removeColourFromDefaults(radioItem.getText());
-                 colourMenu.remove(radioItem);
-               }
-               else
+               offerRemoval(radioItem);
+             }
+           }
+           @Override
+           public void mouseReleased(MouseEvent evt)
+           {
+             if (evt.isPopupTrigger()) // Windows
+             {
+               offerRemoval(radioItem);
+             }
+           }
+           /**
+            * @param radioItem
+            */
+           void offerRemoval(final JRadioButtonMenuItem radioItem)
+           {
+             radioItem.removeActionListener(radioItem.getActionListeners()[0]);
+             int option = JOptionPane.showInternalConfirmDialog(
+                     jalview.gui.Desktop.desktop,
+                     MessageManager
+                             .getString("label.remove_from_default_list"),
+                     MessageManager
+                             .getString("label.remove_user_defined_colour"),
+                     JOptionPane.YES_NO_OPTION);
+             if (option == JOptionPane.YES_OPTION)
+             {
+               jalview.gui.UserDefinedColours
+                       .removeColourFromDefaults(radioItem.getText());
+               colourMenu.remove(radioItem);
+             }
+             else
+             {
+               radioItem.addActionListener(new ActionListener()
                {
-                 radioItem.addActionListener(new ActionListener()
+                 @Override
+                 public void actionPerformed(ActionEvent evt)
                  {
-                   @Override
-                   public void actionPerformed(ActionEvent evt)
-                   {
-                     userDefinedColour_actionPerformed(evt);
-                   }
-                 });
-               }
+                   userDefinedColour_actionPerformed(evt);
+                 }
+               });
              }
            }
          });
    {
      SequenceI[] seqs = viewport.getAlignment().getSequencesArray();
      AlignmentI dataset = viewport.getAlignment().getDataset();
 +
 +    showProducts.removeAll();
 +    final boolean dna = viewport.getAlignment().isNucleotide();
 +
 +    if (seqs == null || seqs.length == 0)
 +    {
 +      // nothing to see here.
 +      return false;
 +    }
 +
      boolean showp = false;
      try
      {
 -      showProducts.removeAll();
 -      final boolean dna = viewport.getAlignment().isNucleotide();
 -      List<String> ptypes = (seqs == null || seqs.length == 0) ? null
 -              : new CrossRef(seqs, dataset)
 -                      .findXrefSourcesForSequences(dna);
 +      List<String> ptypes = new CrossRef(seqs, dataset)
 +              .findXrefSourcesForSequences(dna);
  
        for (final String source : ptypes)
        {
    protected void showProductsFor(final SequenceI[] sel,
            final boolean _odna, final String source)
    {
 -    Runnable foo = new Runnable()
 -    {
 -
 -      @Override
 -      public void run()
 -      {
 -        final long sttime = System.currentTimeMillis();
 -        AlignFrame.this.setProgressBar(MessageManager.formatMessage(
 -                "status.searching_for_sequences_from",
 -                new Object[] { source }), sttime);
 -        try
 -        {
 -          AlignmentI alignment = AlignFrame.this.getViewport()
 -                  .getAlignment();
 -          AlignmentI dataset = alignment.getDataset() == null ? alignment
 -                  : alignment.getDataset();
 -          boolean dna = alignment.isNucleotide();
 -          if (_odna != dna)
 -          {
 -            System.err
 -                    .println("Conflict: showProducts for alignment originally "
 -                            + "thought to be "
 -                            + (_odna ? "DNA" : "Protein")
 -                            + " now searching for "
 -                            + (dna ? "DNA" : "Protein") + " Context.");
 -          }
 -          AlignmentI xrefs = new CrossRef(sel, dataset).findXrefSequences(
 -                  source, dna);
 -          if (xrefs == null)
 -          {
 -            return;
 -          }
 -          /*
 -           * get display scheme (if any) to apply to features
 -           */
 -          FeatureSettingsModelI featureColourScheme = new SequenceFetcher()
 -                  .getFeatureColourScheme(source);
 -
 -          AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset,
 -                  xrefs);
 -          if (!dna)
 -          {
 -            xrefsAlignment = AlignmentUtils.makeCdsAlignment(
 -                    xrefsAlignment.getSequencesArray(), dataset, sel);
 -            xrefsAlignment.alignAs(alignment);
 -          }
 -
 -          /*
 -           * If we are opening a splitframe, make a copy of this alignment (sharing the same dataset
 -           * sequences). If we are DNA, drop introns and update mappings
 -           */
 -          AlignmentI copyAlignment = null;
 -
 -          if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true))
 -          {
 -            boolean copyAlignmentIsAligned = false;
 -            if (dna)
 -            {
 -              copyAlignment = AlignmentUtils.makeCdsAlignment(sel, dataset,
 -                      xrefsAlignment.getSequencesArray());
 -              if (copyAlignment.getHeight() == 0)
 -              {
 -                JOptionPane.showMessageDialog(AlignFrame.this,
 -                        MessageManager.getString("label.cant_map_cds"),
 -                        MessageManager.getString("label.operation_failed"),
 -                        JOptionPane.OK_OPTION);
 -                System.err.println("Failed to make CDS alignment");
 -              }
 -
 -              /*
 -               * pending getting Embl transcripts to 'align', 
 -               * we are only doing this for Ensembl
 -               */
 -              // TODO proper criteria for 'can align as cdna'
 -              if (DBRefSource.ENSEMBL.equalsIgnoreCase(source)
 -                      || AlignmentUtils.looksLikeEnsembl(alignment))
 -              {
 -                copyAlignment.alignAs(alignment);
 -                copyAlignmentIsAligned = true;
 -              }
 -            }
 -            else
 -            {
 -              copyAlignment = AlignmentUtils.makeCopyAlignment(sel,
 -                      xrefs.getSequencesArray(), dataset);
 -            }
 -            copyAlignment.setGapCharacter(AlignFrame.this.viewport
 -                    .getGapCharacter());
 -
 -            StructureSelectionManager ssm = StructureSelectionManager
 -                    .getStructureSelectionManager(Desktop.instance);
 -
 -            /*
 -             * register any new mappings for sequence mouseover etc
 -             * (will not duplicate any previously registered mappings)
 -             */
 -            ssm.registerMappings(dataset.getCodonFrames());
 -
 -            if (copyAlignment.getHeight() <= 0)
 -            {
 -              System.err.println("No Sequences generated for xRef type "
 -                      + source);
 -              return;
 -            }
 -            /*
 -             * align protein to dna
 -             */
 -            if (dna && copyAlignmentIsAligned)
 -            {
 -              xrefsAlignment.alignAs(copyAlignment);
 -            }
 -            else
 -            {
 -              /*
 -               * align cdna to protein - currently only if 
 -               * fetching and aligning Ensembl transcripts!
 -               */
 -              // TODO: generalise for other sources of locus/transcript/cds data
 -              if (dna && DBRefSource.ENSEMBL.equalsIgnoreCase(source))
 -              {
 -                copyAlignment.alignAs(xrefsAlignment);
 -              }
 -            }
 -          }
 -          /*
 -           * build AlignFrame(s) according to available alignment data
 -           */
 -          AlignFrame newFrame = new AlignFrame(xrefsAlignment,
 -                  DEFAULT_WIDTH, DEFAULT_HEIGHT);
 -          if (Cache.getDefault("HIDE_INTRONS", true))
 -          {
 -            newFrame.hideFeatureColumns(SequenceOntologyI.EXON, false);
 -          }
 -          String newtitle = String.format("%s %s %s",
 -                  dna ? MessageManager.getString("label.proteins")
 -                          : MessageManager.getString("label.nucleotides"),
 -                  MessageManager.getString("label.for"), getTitle());
 -          newFrame.setTitle(newtitle);
 -
 -          if (copyAlignment == null)
 -          {
 -            /*
 -             * split frame display is turned off in preferences file
 -             */
 -            Desktop.addInternalFrame(newFrame, newtitle, DEFAULT_WIDTH,
 -                    DEFAULT_HEIGHT);
 -            return; // via finally clause
 -          }
 -          AlignFrame copyThis = new AlignFrame(copyAlignment,
 -                  AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
 -          copyThis.setTitle(AlignFrame.this.getTitle());
 -
 -          boolean showSequenceFeatures = viewport.isShowSequenceFeatures();
 -          newFrame.setShowSeqFeatures(showSequenceFeatures);
 -          copyThis.setShowSeqFeatures(showSequenceFeatures);
 -          FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
 -                  .getFeatureRenderer();
 -
 -          /*
 -           * copy feature rendering settings to split frame
 -           */
 -          newFrame.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
 -                  .transferSettings(myFeatureStyling);
 -          copyThis.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()
 -                  .transferSettings(myFeatureStyling);
 -
 -          /*
 -           * apply 'database source' feature configuration
 -           * if any was found
 -           */
 -          // TODO is this the feature colouring for the original
 -          // alignment or the fetched xrefs? either could be Ensembl
 -          newFrame.getViewport().applyFeaturesStyle(featureColourScheme);
 -          copyThis.getViewport().applyFeaturesStyle(featureColourScheme);
 -
 -          SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
 -                  dna ? newFrame : copyThis);
 -          newFrame.setVisible(true);
 -          copyThis.setVisible(true);
 -          String linkedTitle = MessageManager
 -                  .getString("label.linked_view_title");
 -          Desktop.addInternalFrame(sf, linkedTitle, -1, -1);
 -          sf.adjustDivider();
 -        } catch (OutOfMemoryError e)
 -        {
 -          new OOMWarning("whilst fetching crossreferences", e);
 -        } catch (Throwable e)
 -        {
 -          Cache.log.error("Error when finding crossreferences", e);
 -        } finally
 -        {
 -          AlignFrame.this.setProgressBar(MessageManager.formatMessage(
 -                  "status.finished_searching_for_sequences_from",
 -                  new Object[] { source }), sttime);
 -        }
 -      }
 -
 -      /**
 -       * Makes an alignment containing the given sequences, and adds them to the
 -       * given dataset, which is also set as the dataset for the new alignment
 -       * 
 -       * TODO: refactor to DatasetI method
 -       * 
 -       * @param dataset
 -       * @param seqs
 -       * @return
 -       */
 -      protected AlignmentI makeCrossReferencesAlignment(AlignmentI dataset,
 -              AlignmentI seqs)
 -      {
 -        SequenceI[] sprods = new SequenceI[seqs.getHeight()];
 -        for (int s = 0; s < sprods.length; s++)
 -        {
 -          sprods[s] = (seqs.getSequenceAt(s)).deriveSequence();
 -          if (dataset.getSequences() == null
 -                  || !dataset.getSequences().contains(
 -                          sprods[s].getDatasetSequence()))
 -          {
 -            dataset.addSequence(sprods[s].getDatasetSequence());
 -          }
 -          sprods[s].updatePDBIds();
 -        }
 -        Alignment al = new Alignment(sprods);
 -        al.setDataset(dataset);
 -        return al;
 -      }
 -
 -    };
 -    Thread frunner = new Thread(foo);
 -    frunner.start();
 +    new Thread(CrossRefAction.showProductsFor(sel, _odna, source, this))
 +            .start();
    }
  
    /**
@@@ -2730,7 -2730,7 +2730,7 @@@ public abstract class AlignmentViewpor
        }
        seqMappings = MappingUtils
                .findMappingsForSequenceAndOthers(sequence, mappings,
 -                      getCodingComplement().getAlignment());
 +                      getCodingComplement().getAlignment().getSequences());
        if (!seqMappings.isEmpty())
        {
          break;
      }
    }
  
+   /**
+    * hold status of current selection group - defined on alignment or not.
+    */
+   private boolean selectionIsDefinedGroup = false;
  
+   @Override
+   public boolean isSelectionDefinedGroup()
+   {
+     if (selectionGroup == null)
+     {
+       return false;
+     }
+     if (isSelectionGroupChanged(true))
+     {
+       selectionIsDefinedGroup = false;
+       List<SequenceGroup> gps = alignment.getGroups();
+       if (gps == null || gps.size() == 0)
+       {
+         selectionIsDefinedGroup = false;
+       }
+       else
+       {
+         selectionIsDefinedGroup = gps.contains(selectionGroup);
+       }
+     }
+     return selectionGroup.getContext() == alignment
+             || selectionIsDefinedGroup;
+   }
  }