Merge branch 'develop' into features/JAL-2393customMatrices
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 2 May 2017 08:28:30 +0000 (09:28 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 2 May 2017 08:28:30 +0000 (09:28 +0100)
examples/testdata/example_annot_file.jva
src/jalview/io/AnnotationFile.java
src/jalview/io/JSONFile.java
src/jalview/ws/sifts/SiftsClient.java
test/jalview/gui/StructureChooserTest.java
test/jalview/io/AnnotationFileIOTest.java
test/jalview/io/JSONFileTest.java
test/jalview/ws/jws2/ParameterUtilsTest.java
test/jalview/ws/sifts/SiftsClientTest.java

index 794f42b..1779247 100644 (file)
@@ -18,5 +18,5 @@ SEQUENCE_GROUP        Group_A 30      50      *
 SEQUENCE_GROUP Group_B 1       351     2-5
 SEQUENCE_GROUP Group_C 12      14      -1      seq1    seq2    seq3
 PROPERTIES     Group_A description=This is the description     colour=Helix Propensity pidThreshold=0  outlineColour=red       displayBoxes=true       displayText=false       colourText=false        textCol1=black  textCol2=black  textColThreshold=0
-PROPERTIES     Group_B outlineColour=red
+PROPERTIES     Group_B outlineColour=red       colour=None
 PROPERTIES     Group_C colour=Clustal
index 9a4071d..ef903e3 100755 (executable)
@@ -109,23 +109,24 @@ public class AnnotationFile
    */
   public class ViewDef
   {
-    public String viewname;
+    // TODO this class is not used - remove?
+    public final String viewname;
 
-    public HiddenSequences hidseqs;
+    public final HiddenSequences hidseqs;
 
-    public ColumnSelection hiddencols;
+    public final ColumnSelection hiddencols;
 
-    public Vector visibleGroups;
+    // public final Vector visibleGroups;
 
-    public Hashtable hiddenRepSeqs;
+    public final Hashtable hiddenRepSeqs;
 
-    public ViewDef(String viewname, HiddenSequences hidseqs,
-            ColumnSelection hiddencols, Hashtable hiddenRepSeqs)
+    public ViewDef(String vname, HiddenSequences hseqs,
+            ColumnSelection hcols, Hashtable hRepSeqs)
     {
-      this.viewname = viewname;
-      this.hidseqs = hidseqs;
-      this.hiddencols = hiddencols;
-      this.hiddenRepSeqs = hiddenRepSeqs;
+      this.viewname = vname;
+      this.hidseqs = hseqs;
+      this.hiddencols = hcols;
+      this.hiddenRepSeqs = hRepSeqs;
     }
   }
 
@@ -151,7 +152,7 @@ public class AnnotationFile
       }
       if (list == null)
       {
-        list = view.visibleGroups;
+        // list = view.visibleGroups;
       }
       if (cs == null)
       {
@@ -536,7 +537,7 @@ public class AnnotationFile
     return false;
   }
 
-  public void printGroups(List<SequenceGroup> list)
+  protected void printGroups(List<SequenceGroup> list)
   {
     SequenceI seqrep = null;
     for (SequenceGroup sg : list)
@@ -582,7 +583,8 @@ public class AnnotationFile
       if (sg.cs != null)
       {
         text.append("colour=");
-        text.append(sg.cs.toString());
+        text.append(ColourSchemeProperty.getColourName(sg.cs
+                .getColourScheme()));
         text.append("\t");
         if (sg.cs.getThreshold() != 0)
         {
index 583bbc0..20148b4 100644 (file)
@@ -47,6 +47,7 @@ import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
 import jalview.json.binding.biojson.v1.SequenceGrpPojo;
 import jalview.json.binding.biojson.v1.SequencePojo;
 import jalview.renderer.seqfeatures.FeatureColourFinder;
+import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.JalviewColourScheme;
 import jalview.schemes.ResidueColourScheme;
 import jalview.util.ColorUtils;
@@ -240,8 +241,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         {
           SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
           seqGrpPojo.setGroupName(seqGrp.getName());
-          seqGrpPojo.setColourScheme(seqGrp.getColourScheme()
-                  .getSchemeName());
+          seqGrpPojo.setColourScheme(ColourSchemeProperty
+                  .getColourName(seqGrp.getColourScheme()));
           seqGrpPojo.setColourText(seqGrp.getColourText());
           seqGrpPojo.setDescription(seqGrp.getDescription());
           seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
@@ -767,8 +768,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         }
       }
     }
-    globalColourScheme = (viewport.getGlobalColourScheme() == null) ? ResidueColourScheme.NONE
-            : viewport.getGlobalColourScheme().getSchemeName();
+    globalColourScheme = ColourSchemeProperty.getColourName(viewport
+            .getGlobalColourScheme());
     setDisplayedFeatures(viewport.getFeaturesDisplayed());
     showSeqFeatures = viewport.isShowSequenceFeatures();
 
index 0e9e888..2ff4a8b 100644 (file)
@@ -577,18 +577,8 @@ public class SiftsClient implements SiftsClientI
                   .equalsIgnoreCase(seqCoordSys.getName())
                   && isAccessionMatched(cRefDb.getDbAccessionId()))
           {
-            String resNumIndexString = cRefDb.getDbResNum()
-                    .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
-                    : cRefDb.getDbResNum();
-            try
-            {
-              currSeqIndex = Integer.valueOf(resNumIndexString);
-            } catch (NumberFormatException nfe)
-            {
-              currSeqIndex = Integer.valueOf(resNumIndexString
-                      .split("[a-zA-Z]")[0]);
-              continue;
-            }
+            currSeqIndex = getLeadingIntegerValue(
+                    cRefDb.getDbResNum(), UNASSIGNED);
             if (pdbRefDb != null)
             {
               break;// exit loop if pdb and uniprot are already found
@@ -601,23 +591,11 @@ public class SiftsClient implements SiftsClientI
         }
         if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
         {
-          int resNum;
-          try
-          {
-            resNum = (pdbRefDb == null) ? Integer.valueOf(residue
-                    .getDbResNum()) : Integer.valueOf(pdbRefDb
-                    .getDbResNum());
-          } catch (NumberFormatException nfe)
-          {
-            if (pdbRefDb == null || pdbRefDb.getDbResNum().equals("null"))
-            {
-              resNum = UNASSIGNED;
-              continue;
-            }
-            resNum = Integer.valueOf(pdbRefDb
-                    .getDbResNum().split("[a-zA-Z]")[0]);
-            continue;
-          }
+
+          int resNum = (pdbRefDb == null) ? getLeadingIntegerValue(
+                  residue.getDbResNum(), UNASSIGNED)
+                  : getLeadingIntegerValue(pdbRefDb.getDbResNum(),
+                          UNASSIGNED);
 
           if (isResidueObserved(residue)
                   || seqCoordSys == CoordinateSys.UNIPROT)
@@ -640,6 +618,30 @@ public class SiftsClient implements SiftsClientI
   }
 
   /**
+   * Get the leading integer part of a string that begins with an integer.
+   * 
+   * @param input
+   *          - the string input to process
+   * @param failValue
+   *          - value returned if unsuccessful
+   * @return
+   */
+  static int getLeadingIntegerValue(String input, int failValue)
+  {
+    if (input == null)
+    {
+      return failValue;
+    }
+    String[] parts = input.split("(?=\\D)(?<=\\d)");
+    if (parts != null && parts.length > 0 && parts[0].matches("[0-9]+"))
+    {
+      return Integer.valueOf(parts[0]);
+    }
+    return failValue;
+  }
+
+
+  /**
    * 
    * @param chainId
    *          Target chain to populate mapping of its atom positions.
index b7eef0f..c04353f 100644 (file)
@@ -136,7 +136,7 @@ public class StructureChooserTest
     assertEquals("Cached PDB Entries", filterOpt.getName());
   }
 
-  @Test(groups = { "Functional" })
+  @Test(groups = { "Network" })
   public void fetchStructuresInfoTest()
   {
     SequenceI[] selectedSeqs = new SequenceI[] { seq };
index 885c673..c3aa13e 100644 (file)
@@ -124,6 +124,7 @@ public class AnnotationFileIOTest
                       DataSourceType.FILE));
 
       AnnotationFile aff = new AnnotationFile();
+      // ViewDef is not used by Jalview
       ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs,
               new Hashtable());
       String anfileout = new AnnotationFile().printAnnotations(
index 4e4abe9..acde68d 100644 (file)
@@ -130,13 +130,14 @@ public class JSONFileTest
       expectedSeqs.put(seq.getName(), seq);
     }
 
-    // create and add sequence groups
-    ArrayList<SequenceI> grpSeqs = new ArrayList<SequenceI>();
+    // create and add a sequence group
+    List<SequenceI> grpSeqs = new ArrayList<SequenceI>();
     grpSeqs.add(seqs[1]);
     grpSeqs.add(seqs[2]);
     grpSeqs.add(seqs[3]);
     grpSeqs.add(seqs[4]);
-    SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
+    SequenceGroup seqGrp = new SequenceGroup(grpSeqs,
+            "JGroup:1883305585",
             null, true, true, false, 21, 29);
     ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
             "zappo", seqGrp);
@@ -340,11 +341,12 @@ public class JSONFileTest
             "Zappo colour scheme expected!");
   }
 
-  @Test(groups = { "Functional" })
   /**
-   * Test for bug JAL-2489, NPE when exporting BioJSON with global colour scheme set as 'None'
+   * Test for bug JAL-2489, NPE when exporting BioJSON with global colour
+   * scheme, and a group colour scheme, set as 'None'
    */
-  public void testBioJSONRoundTripWithGlobalColourSchemeSetAsNone()
+  @Test(groups = { "Functional" })
+  public void testBioJSONRoundTripWithColourSchemeNone()
   {
     AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
 
@@ -359,7 +361,14 @@ public class JSONFileTest
               bioJsonFile.getHiddenSequences(),
               bioJsonFile.getColumnSelection(), AlignFrame.DEFAULT_WIDTH,
               AlignFrame.DEFAULT_HEIGHT);
-      // Change colour scheme to 'None' and perform round trip
+
+      /*
+       * Create a group on the alignment;
+       * Change global and group colour scheme to 'None' and perform round trip
+       */
+      SequenceGroup sg = new SequenceGroup();
+      sg.addSequence(_alignment.getSequenceAt(0), false);
+      sg.setColourScheme(null);
       ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme(
               ResidueColourScheme.NONE, _alignment);
       alignFrame.changeColour(cs);
@@ -556,4 +565,47 @@ public class JSONFileTest
     // System.out.println(">>>>>>>>>>>>>> features matched : " + matched);
     return matched;
   }
+
+  /**
+   * Test group roundtrip with null (None) group colour scheme
+   * 
+   * @throws IOException
+   */
+  @Test(groups = { "Functional" })
+  public void testGrpParsed_colourNone() throws IOException
+  {
+    AlignmentI copy = new Alignment(testAlignment);
+    SequenceGroup sg = testAlignment.getGroups().get(0);
+    SequenceGroup copySg = new SequenceGroup(new ArrayList<SequenceI>(),
+            sg.getName(),
+            null, sg.getDisplayBoxes(), sg.getDisplayText(),
+            sg.getColourText(), sg.getStartRes(), sg.getEndRes());
+    for (SequenceI seq : sg.getSequences())
+    {
+      int seqIndex = testAlignment.findIndex(seq);
+      copySg.addSequence(copy.getSequenceAt(seqIndex), false);
+    }
+    copy.addGroup(copySg);
+
+    AlignFrame af = new AlignFrame(copy, copy.getWidth(), copy.getHeight());
+    AppletFormatAdapter formatAdapter = new AppletFormatAdapter(
+            af.alignPanel);
+    String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
+            copy, false);
+    formatAdapter = new AppletFormatAdapter();
+    AlignmentI newAlignment = formatAdapter.readFile(jsonOutput,
+            DataSourceType.PASTE, FileFormat.Json);
+
+    Assert.assertNotNull(newAlignment.getGroups());
+    for (SequenceGroup seqGrp : newAlignment.getGroups())
+    {
+      SequenceGroup expectedGrp = expectedGrps.get(seqGrp.getName());
+      AssertJUnit.assertTrue(
+              "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
+              isGroupMatched(expectedGrp, seqGrp));
+      passedCount++;
+    }
+    AssertJUnit.assertEquals("Some SequenceGroups did not pass the test",
+            TEST_GRP_HEIGHT, passedCount);
+  }
 }
index e859cb0..c0aa2ee 100644 (file)
@@ -74,7 +74,7 @@ public class ParameterUtilsTest
     disc = JalviewJabawsTestUtils.getJabawsDiscoverer();
   }
 
-  @Test(groups = { "Functional" })
+  @Test(groups = { "Network" })
   public void testWriteParameterSet() throws WrongParameterException
   {
     for (Jws2Instance service : disc.getServices())
index 7f8adc9..b92766e 100644 (file)
@@ -514,4 +514,22 @@ groups = { "Network" },
     Assert.assertNull(entityP);
 
   }
+
+  @Test(groups = { "Network" })
+  public void getLeadingIntegerFromString()
+  {
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("1234abcd", -1), 1234);
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("1234", -1),
+            1234);
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("abcd", -1), -1);
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("abcd1234", -1), -1);
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("None", -1), -1);
+    Assert.assertEquals(
+            SiftsClient.getLeadingIntegerValue("Null", -1), -1);
+  }
 }