JAL-653 allow dummy sequences to be created if a sequence ID is not found in the...
authorJim Procter <jprocter@dundee.ac.uk>
Thu, 19 Feb 2015 15:11:12 +0000 (15:11 +0000)
committerJames Procter <jprocter@ls30857.local>
Fri, 5 Jun 2015 11:56:46 +0000 (12:56 +0100)
src/jalview/datamodel/SequenceDummy.java [new file with mode: 0644]
src/jalview/io/FeaturesFile.java

diff --git a/src/jalview/datamodel/SequenceDummy.java b/src/jalview/datamodel/SequenceDummy.java
new file mode 100644 (file)
index 0000000..80b0072
--- /dev/null
@@ -0,0 +1,9 @@
+package jalview.datamodel;
+
+public class SequenceDummy extends Sequence implements SequenceI
+{
+  public SequenceDummy(String sequenceId)
+  {
+    super(sequenceId, "THISAPLACEHOLDER");
+  }
+}
index 2001d7f..2009d9d 100755 (executable)
@@ -169,6 +169,10 @@ public class FeaturesFile extends AlignFile
     try
     {
       SequenceI seq = null;
+      /**
+       * keep track of any sequences we try to create from the data if it is a GFF3 file
+       */
+      ArrayList<SequenceI> newseqs = new ArrayList<SequenceI>();
       String type, desc, token = null;
 
       int index, start, end;
@@ -442,7 +446,7 @@ public class FeaturesFile extends AlignFile
             // Still possible this is an old Jalview file,
             // which does not have type colours at the beginning
             seqId = token = st.nextToken();
-            seq = findName(align, seqId, relaxedIdmatching);
+            seq = findName(align, seqId, relaxedIdmatching, newseqs);
             if (seq != null)
             {
               desc = st.nextToken();
@@ -551,7 +555,7 @@ public class FeaturesFile extends AlignFile
 
           if (!token.equals("ID_NOT_SPECIFIED"))
           {
-            seq = findName(align, seqId = token, relaxedIdmatching);
+            seq = findName(align, seqId = token, relaxedIdmatching, null);
             st.nextToken();
           }
           else
@@ -647,7 +651,7 @@ public class FeaturesFile extends AlignFile
   }
 
   private SequenceI findName(AlignmentI align, String seqId,
-          boolean relaxedIdMatching)
+          boolean relaxedIdMatching, List<SequenceI> newseqs)
   {
     SequenceI match = null;
     if (relaxedIdMatching)
@@ -656,16 +660,29 @@ public class FeaturesFile extends AlignFile
       {
         matcher = new SequenceIdMatcher(
                 (lastmatchedAl = align).getSequencesArray());
+        if (newseqs != null)
+        {
+          matcher.addAll(newseqs);
+        }
       }
       match = matcher.findIdMatch(seqId);
     }
     else
     {
       match = align.findName(seqId, true);
+      
+    }
+    if (match==null && newseqs!=null)
+    {
+      match = new SequenceDummy(seqId);
+      if (relaxedIdMatching)
+      {
+        matcher.addAll(Arrays.asList(new SequenceI[]
+        { match }));
+      }
     }
     return match;
   }
-
   public void parseDescriptionHTML(SequenceFeature sf, boolean removeHTML)
   {
     if (sf.getDescription() == null)