Merge branch 'develop' into task/JAL-2196pdbeProperties
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 6 Oct 2016 12:53:37 +0000 (13:53 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 6 Oct 2016 12:53:37 +0000 (13:53 +0100)
1  2 
src/MCview/PDBViewer.java
src/jalview/appletgui/AlignFrame.java
src/jalview/gui/Jalview2XML.java
src/jalview/io/StructureFile.java
src/jalview/ws/dbsources/Uniprot.java
test/jalview/ws/dbsources/UniprotTest.java

@@@ -128,17 -128,18 +128,17 @@@ public class PDBViewer extends JInterna
        worker.start();
      }
  
 -    if (pdbentry.getProperty() != null)
 +    String method = (String) pdbentry.getProperty("method");
 +    if (method != null)
      {
 -      if (pdbentry.getProperty().get("method") != null)
 -      {
 -        title.append(" Method: ");
 -        title.append(pdbentry.getProperty().get("method"));
 -      }
 -      if (pdbentry.getProperty().get("chains") != null)
 -      {
 -        title.append(" Chain:");
 -        title.append(pdbentry.getProperty().get("chains"));
 -      }
 +      title.append(" Method: ");
 +      title.append(method);
 +    }
 +    String ch = (String) pdbentry.getProperty("chains");
 +    if (ch != null)
 +    {
 +      title.append(" Chain:");
 +      title.append(ch);
      }
      Desktop.addInternalFrame(this, title.toString(), 400, 400);
    }
              radioItem.removeActionListener(radioItem.getActionListeners()[0]);
  
              int option = JOptionPane.showInternalConfirmDialog(
-                     jalview.gui.Desktop.desktop,
-                     MessageManager
+                     jalview.gui.Desktop.desktop, MessageManager
                              .getString("label.remove_from_default_list"),
                      MessageManager
                              .getString("label.remove_user_defined_colour"),
@@@ -102,6 -102,7 +102,6 @@@ import java.net.URLEncoder
  import java.util.Arrays;
  import java.util.Deque;
  import java.util.HashMap;
 -import java.util.Hashtable;
  import java.util.List;
  import java.util.Map;
  import java.util.StringTokenizer;
@@@ -925,11 -926,11 +925,11 @@@ public class AlignFrame extends Embmenu
      if (alignPanel.getAlignment().getAlignmentAnnotation() != null)
      {
        for (AlignmentAnnotation aa : alignPanel.getAlignment()
-             .getAlignmentAnnotation())
-     {
-       boolean visible = (aa.sequenceRef == null ? showForAlignment
-               : showForSequences);
-       aa.visible = visible;
+               .getAlignmentAnnotation())
+       {
+         boolean visible = (aa.sequenceRef == null ? showForAlignment
+                 : showForSequences);
+         aa.visible = visible;
        }
      }
      alignPanel.validateAnnotationDimensions(true);
      FeaturesFile formatter = new FeaturesFile();
      if (format.equalsIgnoreCase("Jalview"))
      {
-       features = formatter.printJalviewFormat(viewport
-               .getAlignment().getSequencesArray(),
-               getDisplayedFeatureCols());
+       features = formatter.printJalviewFormat(viewport.getAlignment()
+               .getSequencesArray(), getDisplayedFeatureCols());
      }
      else
      {
        }
        if (needtoadd)
        {
 -        // make a note of the access mode and add
 -        if (pdbentry.getProperty() == null)
 -        {
 -          pdbentry.setProperty(new Hashtable());
 -        }
 -        pdbentry.getProperty().put("protocol", protocol);
 +        pdbentry.setProperty("protocol", protocol);
          toaddpdb.addPDBId(pdbentry);
          alignPanel.getStructureSelectionManager()
                  .registerPDBEntry(pdbentry);
      if (protocol == null || protocol.trim().length() == 0
              || protocol.equals("null"))
      {
 -      protocol = (String) pdb.getProperty().get("protocol");
 +      protocol = (String) pdb.getProperty("protocol");
        if (protocol == null)
        {
          System.err.println("Couldn't work out protocol to open structure: "
@@@ -314,6 -314,7 +314,7 @@@ public class Jalview2XM
        }
        return sq;
      }
      /**
       * @return true if the forward reference was fully resolved
       */
  
    public void resolveFrefedSequences()
    {
-     Iterator<SeqFref> nextFref=frefedSequence.iterator();
-     int toresolve=frefedSequence.size();
-     int unresolved=0,failedtoresolve=0;
-     while (nextFref.hasNext()) {
+     Iterator<SeqFref> nextFref = frefedSequence.iterator();
+     int toresolve = frefedSequence.size();
+     int unresolved = 0, failedtoresolve = 0;
+     while (nextFref.hasNext())
+     {
        SeqFref ref = nextFref.next();
        if (ref.isResolvable())
        {
-         try {
+         try
+         {
            if (ref.resolve())
            {
              nextFref.remove();
-           } else {
+           }
+           else
+           {
              failedtoresolve++;
            }
-         } catch (Exception x) {
-           System.err.println("IMPLEMENTATION ERROR: Failed to resolve forward reference for sequence "+ref.getSref());
+         } catch (Exception x)
+         {
+           System.err
+                   .println("IMPLEMENTATION ERROR: Failed to resolve forward reference for sequence "
+                           + ref.getSref());
            x.printStackTrace();
            failedtoresolve++;
-         } 
-       } else {
+         }
+       }
+       else
+       {
          unresolved++;
        }
      }
-     if (unresolved>0)
+     if (unresolved > 0)
      {
        System.err.println("Jalview Project Import: There were " + unresolved
                + " forward references left unresolved on the stack.");
      }
-     if (failedtoresolve>0)
+     if (failedtoresolve > 0)
      {
        System.err.println("SERIOUS! " + failedtoresolve
                + " resolvable forward references failed to resolve.");
      JSeq jseq;
      Set<String> calcIdSet = new HashSet<String>();
      // record the set of vamsas sequence XML POJO we create.
-     HashMap<String,Sequence> vamsasSetIds = new HashMap<String,Sequence>(); 
+     HashMap<String, Sequence> vamsasSetIds = new HashMap<String, Sequence>();
      // SAVE SEQUENCES
      for (final SequenceI jds : rjal.getSequences())
      {
            if (av.isHiddenRepSequence(jds))
            {
              jalview.datamodel.SequenceI[] reps = av
-                     .getRepresentedSequences(jds)
-                     .getSequencesInOrder(rjal);
+                     .getRepresentedSequences(jds).getSequencesInOrder(rjal);
  
              for (int h = 0; h < reps.length; h++)
              {
              }
            }
  
 -          if (entry.getProperty() != null && !entry.getProperty().isEmpty())
 +          Enumeration<String> props = entry.getProperties();
 +          if (props.hasMoreElements())
            {
              PdbentryItem item = new PdbentryItem();
 -            Hashtable properties = entry.getProperty();
 -            Enumeration en2 = properties.keys();
 -            while (en2.hasMoreElements())
 +            while (props.hasMoreElements())
              {
                Property prop = new Property();
 -              String key = en2.nextElement().toString();
 +              String key = props.nextElement();
                prop.setName(key);
 -              prop.setValue(properties.get(key).toString());
 +              prop.setValue(entry.getProperty(key).toString());
                item.addProperty(prop);
              }
              pdb.addPdbentryItem(item);
            for (String featureType : renderOrder)
            {
              FeatureColourI fcol = ap.getSeqPanel().seqCanvas
-                     .getFeatureRenderer()
-                     .getFeatureStyle(featureType);
+                     .getFeatureRenderer().getFeatureStyle(featureType);
              Setting setting = new Setting();
              setting.setType(featureType);
              if (!fcol.isSimpleColour())
                setting.setAutoScale(fcol.isAutoScaled());
                setting.setThreshold(fcol.getThreshold());
                // -1 = No threshold, 0 = Below, 1 = Above
-               setting.setThreshstate(fcol.isAboveThreshold() ? 1
-                       : (fcol.isBelowThreshold() ? 0 : -1));
+               setting.setThreshstate(fcol.isAboveThreshold() ? 1 : (fcol
+                       .isBelowThreshold() ? 0 : -1));
              }
              else
              {
  
          // is groups actually supposed to be a map here ?
          Iterator<String> en = ap.getSeqPanel().seqCanvas
-                 .getFeatureRenderer()
-                 .getFeatureGroups().iterator();
+                 .getFeatureRenderer().getFeatureGroups().iterator();
          Vector<String> groupsAdded = new Vector<String>();
          while (en.hasNext())
          {
            SplitFrame sf = createSplitFrame(dnaFrame, af);
            addedToSplitFrames.add(dnaFrame);
            addedToSplitFrames.add(af);
+           dnaFrame.setMenusForViewport();
+           af.setMenusForViewport();
            if (af.viewport.isGatherViewsHere())
            {
              gatherTo.add(sf);
          Viewport view = candidate.getKey();
          Desktop.addInternalFrame(af, view.getTitle(), view.getWidth(),
                  view.getHeight());
+         af.setMenusForViewport();
          System.err.println("Failed to restore view " + view.getTitle()
                  + " to split frame");
        }
  
      List<SequenceI> hiddenSeqs = null;
  
      List<SequenceI> tmpseqs = new ArrayList<SequenceI>();
  
      boolean multipleView = false;
          if (!incompleteSeqs.containsKey(seqId))
          {
            // may not need this check, but keep it for at least 2.9,1 release
-           if (tmpSeq.getStart()!=jseqs[i].getStart() || tmpSeq.getEnd()!=jseqs[i].getEnd())
-           { 
+           if (tmpSeq.getStart() != jseqs[i].getStart()
+                   || tmpSeq.getEnd() != jseqs[i].getEnd())
+           {
              System.err
                      .println("Warning JAL-2154 regression: updating start/end for sequence "
                              + tmpSeq.toString() + " to " + jseqs[i]);
            }
-         } else {
+         }
+         else
+         {
            incompleteSeqs.remove(seqId);
          }
          if (vamsasSeq.length > vi && vamsasSeq[vi].getId().equals(seqId))
              }
              if (ids[p].getPdbentryItem() != null)
              {
 -              entry.setProperty(new Hashtable());
                for (PdbentryItem item : ids[p].getPdbentryItem())
                {
                  for (Property pr : item.getProperty())
                  {
 -                  entry.getProperty().put(pr.getName(), pr.getValue());
 +                  entry.setProperty(pr.getName(), pr.getValue());
                  }
                }
              }
          // filename
          // translation differently.
          StructureData filedat = oldFiles.get(new File(oldfilenam));
-           if (filedat == null)
-           {
-             String reformatedOldFilename = oldfilenam.replaceAll("/",
-                     "\\\\");
-             filedat = oldFiles.get(new File(reformatedOldFilename));
+         if (filedat == null)
+         {
+           String reformatedOldFilename = oldfilenam.replaceAll("/", "\\\\");
+           filedat = oldFiles.get(new File(reformatedOldFilename));
          }
          newFileLoc.append(Platform.escapeString(filedat.getFilePath()));
          pdbfilenames.add(filedat.getFilePath());
@@@ -1,3 -1,23 +1,23 @@@
+ /*
+  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+  * Copyright (C) $$Year-Rel$$ The Jalview Authors
+  * 
+  * This file is part of Jalview.
+  * 
+  * Jalview is free software: you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License 
+  * as published by the Free Software Foundation, either version 3
+  * of the License, or (at your option) any later version.
+  *  
+  * Jalview is distributed in the hope that it will be useful, but 
+  * WITHOUT ANY WARRANTY; without even the implied warranty 
+  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+  * PURPOSE.  See the GNU General Public License for more details.
+  * 
+  * You should have received a copy of the GNU General Public License
+  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+  * The Jalview Authors are detailed in the 'AUTHORS' file.
+  */
  package jalview.io;
  
  import jalview.analysis.AlignSeq;
@@@ -15,6 -35,7 +35,6 @@@ import jalview.structure.StructureImpor
  import java.awt.Color;
  import java.io.IOException;
  import java.lang.reflect.Constructor;
 -import java.util.Hashtable;
  import java.util.List;
  import java.util.Vector;
  
@@@ -76,8 -97,8 +96,8 @@@ public abstract class StructureFile ext
  
    }
  
-   public StructureFile(boolean parseImmediately, String dataObject, String type)
-           throws IOException
+   public StructureFile(boolean parseImmediately, String dataObject,
+           String type) throws IOException
    {
      super(parseImmediately, dataObject, type);
    }
    {
    }
  
 -  @SuppressWarnings("rawtypes")
    protected SequenceI postProcessChain(PDBChain chain)
    {
      SequenceI pdbSequence = chain.sequence;
      PDBEntry entry = new PDBEntry();
      entry.setId(getId());
      entry.setType(getStructureFileType());
 -    entry.setProperty(new Hashtable());
      if (chain.id != null)
      {
 -      entry.setChainCode(String.valueOf(chain.id));
 +      entry.setChainCode(chain.id);
      }
      if (inFile != null)
      {
@@@ -193,7 -193,8 +193,8 @@@ public class Uniprot extends DbSourcePr
     *          UniprotEntry
     * @return SequenceI instance created from the UniprotEntry instance
     */
-   public SequenceI uniprotEntryToSequenceI(UniprotEntry entry){
+   public SequenceI uniprotEntryToSequenceI(UniprotEntry entry)
+   {
      String id = getUniprotEntryId(entry);
      SequenceI sequence = new Sequence(id, entry.getUniprotSequence()
              .getContent());
        if ("EMBL".equals(pdb.getType()))
        {
          // look for a CDS reference and add it, too.
 -        String cdsId = (String) pdb.getProperty()
 -                .get("protein sequence ID");
 +        String cdsId = (String) pdb.getProperty("protein sequence ID");
          if (cdsId != null && cdsId.trim().length() > 0)
          {
            // remove version
          * <property type="gene ID" value="ENSG00000158828"/>
          * </dbReference> 
           */
 -        String cdsId = (String) pdb.getProperty()
 -                .get("protein sequence ID");
 +        String cdsId = (String) pdb.getProperty("protein sequence ID");
          if (cdsId != null && cdsId.trim().length() > 0)
          {
            dbr = new DBRefEntry(DBRefSource.ENSEMBL, DBRefSource.UNIPROT
@@@ -21,7 -21,6 +21,7 @@@
  package jalview.ws.dbsources;
  
  import static org.testng.AssertJUnit.assertEquals;
 +import static org.testng.AssertJUnit.assertFalse;
  import static org.testng.AssertJUnit.assertNotNull;
  import static org.testng.AssertJUnit.assertNull;
  
@@@ -118,21 -117,25 +118,21 @@@ public class UniprotTes
      PDBEntry xref = xrefs.get(0);
      assertEquals("2FSQ", xref.getId());
      assertEquals("PDB", xref.getType());
 -    assertEquals(2, xref.getProperty().size());
 -    assertEquals("X-ray", xref.getProperty().get("method"));
 -    assertEquals("1.40", xref.getProperty().get("resolution"));
 +    assertEquals("X-ray", xref.getProperty("method"));
 +    assertEquals("1.40", xref.getProperty("resolution"));
  
      xref = xrefs.get(1);
      assertEquals("2FSR", xref.getId());
      assertEquals("PDBsum", xref.getType());
 -    assertNull(xref.getProperty());
 +    assertFalse(xref.getProperties().hasMoreElements());
  
      xref = xrefs.get(2);
      assertEquals("AE007869", xref.getId());
      assertEquals("EMBL", xref.getType());
 -    assertNotNull(xref.getProperty());
      assertEquals("AAK85932.1",
 -            (String) xref.getProperty().get("protein sequence ID"));
 + xref.getProperty("protein sequence ID"));
      assertEquals("Genomic_DNA",
 -            (String) xref.getProperty().get("molecule type"));
 -    assertEquals(2, xref.getProperty().size());
 -
 + xref.getProperty("molecule type"));
    }
  
    @Test(groups = { "Functional" })
      assertEquals(6, seq.getDBRefs().length); // 2*Uniprot, PDB, PDBsum, 2*EMBL
  
    }
    /**
     * Test the method that formats the sequence id
     */
    {
      UniprotEntry entry = new Uniprot().getUniprotEntries(
              new StringReader(UNIPROT_XML)).get(0);
-   
      /*
       * recommended names concatenated with space separator
       */