Merge branch 'patch/JAL-4184_description_stockholm' into develop
authorJames Procter <j.procter@dundee.ac.uk>
Wed, 17 May 2023 09:58:31 +0000 (10:58 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Wed, 17 May 2023 09:58:31 +0000 (10:58 +0100)
src/jalview/io/StockholmFile.java
test/jalview/io/StockholmFileTest.java

index a3f7531..eeadcbf 100644 (file)
@@ -1048,9 +1048,18 @@ public class StockholmFile extends AlignFile
       }
     }
 
-    // output annotations
+    // output description and annotations
+
     while (i < slen && (seq = s[i]) != null)
     {
+      if (seq.getDescription()!=null)
+      {
+        // out.append("#=GR ");
+        out.append(new Format("%-" + maxid + "s").form(
+                "#=GS " + printId(seq, jvSuffix) + " DE " + seq.getDescription()));
+        out.append(newline);
+      }
+
       AlignmentAnnotation[] alAnot = seq.getAnnotation();
       if (alAnot != null)
       {
index b1995ab..6b2982d 100644 (file)
@@ -136,6 +136,28 @@ public class StockholmFileTest
             "Couldn't find Uniprot DBRef on re-imported sequence.");
 
   }
+  @Test(groups = { "Functional" })
+  public void descriptionLineOutput() throws Exception
+  {
+    // quick test that sequence description is exported & reimported
+
+    SequenceI sq = new Sequence("FER2_SPIOL", "AASSDDDFFF");
+    String expected_descr="This is a description !@&^%@£@";
+    sq.setDescription(expected_descr);
+    AppletFormatAdapter af = new AppletFormatAdapter();
+    String toStockholm = af.formatSequences(FileFormat.Stockholm,
+            new Alignment(new SequenceI[]
+            { sq }), false);
+    System.out.println(toStockholm);
+    
+    // bleh - java.util.Regex sucks
+    assertTrue(toStockholm.contains(expected_descr),"Couldn't locate expected description srting in generated Stockholm file.");
+    
+    AlignmentI fromStockholm = af.readFile(toStockholm,
+            DataSourceType.PASTE, FileFormat.Stockholm);
+    SequenceI importedSeq = fromStockholm.getSequenceAt(0);
+    assertEquals( "Description did not get reimported.",expected_descr,importedSeq.getDescription());
+  }
 
   /**
    * test alignment data in given file can be imported, exported and reimported