JAL-2416 allow space in score matrix name
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 17 Feb 2017 13:30:01 +0000 (13:30 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 17 Feb 2017 13:30:01 +0000 (13:30 +0000)
src/jalview/io/ScoreMatrixFile.java
test/jalview/io/ScoreMatrixFileTest.java

index d927b3f..97fe46b 100644 (file)
@@ -89,6 +89,7 @@ public class ScoreMatrixFile extends AlignFile implements
       {
         /*
          * Parse name from ScoreMatrix <name>
+         * we allow any delimiter after ScoreMatrix then take the rest of the line
          */
         if (name != null)
         {
@@ -97,14 +98,15 @@ public class ScoreMatrixFile extends AlignFile implements
                           + lineNo);
         }
         StringTokenizer nameLine = new StringTokenizer(data, DELIMITERS);
-        if (nameLine.countTokens() != 2)
+        if (nameLine.countTokens() < 2)
         {
           err = "Format error: expected 'ScoreMatrix <name>', found '"
                   + data + "' at line " + lineNo;
           throw new FileFormatException(err);
         }
-        nameLine.nextToken();
-        name = nameLine.nextToken();
+        nameLine.nextToken(); // 'ScoreMatrix'
+        name = nameLine.nextToken(); // next field
+        name = data.substring(1).substring(data.substring(1).indexOf(name));
         continue;
       }
       else if (name == null)
index 77b7282..123de6b 100644 (file)
@@ -30,7 +30,7 @@ public class ScoreMatrixFileTest
      * or tab (or combinations) as score value delimiters
      * this example includes 'guide' symbols on score rows
      */
-    String data = "ScoreMatrix MyTest\n" + "ATU tx-\n"
+    String data = "ScoreMatrix MyTest (example)\n" + "ATU tx-\n"
             + "A,1.1,1.2,1.3,1.4, 1.5, 1.6, 1.7\n"
             + "T,2.1 2.2 2.3 2.4 2.5 2.6 2.7\n"
             + "U\t3.1\t3.2\t3.3\t3.4\t3.5\t3.6\t3.7\n"
@@ -43,7 +43,7 @@ public class ScoreMatrixFileTest
     ScoreMatrix sm = parser.parseMatrix();
 
     assertNotNull(sm);
-    assertEquals(sm.getName(), "MyTest");
+    assertEquals(sm.getName(), "MyTest (example)");
     assertTrue(sm.isDNA());
     assertFalse(sm.isProtein());
     assertEquals(sm.getPairwiseScore('A', 'A'), 1.1f);