JAL-653 basic GFF3 alignment import wrapper class
authorJim Procter <jprocter@issues.jalview.org>
Sun, 7 Jun 2015 18:01:45 +0000 (19:01 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 7 Jun 2015 18:01:45 +0000 (19:01 +0100)
src/jalview/io/FeaturesFile.java
src/jalview/io/Gff3File.java [new file with mode: 0644]

index d6c3c21..44af9ad 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.analysis.SequenceIdMatcher;
 import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
@@ -70,27 +71,48 @@ public class FeaturesFile extends AlignFile
   }
 
   /**
-   * Creates a new FeaturesFile object.
-   * 
    * @param inFile
-   *          DOCUMENT ME!
    * @param type
-   *          DOCUMENT ME!
-   * 
    * @throws IOException
-   *           DOCUMENT ME!
    */
   public FeaturesFile(String inFile, String type) throws IOException
   {
     super(inFile, type);
   }
 
+  /**
+   * @param source
+   * @throws IOException
+   */
   public FeaturesFile(FileParse source) throws IOException
   {
     super(source);
   }
 
   /**
+   * @param parseImmediately
+   * @param source
+   * @throws IOException
+   */
+  public FeaturesFile(boolean parseImmediately, FileParse source)
+          throws IOException
+  {
+    super(parseImmediately, source);
+  }
+
+  /**
+   * @param parseImmediately
+   * @param inFile
+   * @param type
+   * @throws IOException
+   */
+  public FeaturesFile(boolean parseImmediately, String inFile, String type)
+          throws IOException
+  {
+    super(parseImmediately, inFile, type);
+  }
+
+  /**
    * Parse GFF or sequence features file using case-independent matching,
    * discarding URLs
    * 
@@ -148,6 +170,27 @@ public class FeaturesFile extends AlignFile
     return parse(align, colours, featureLink, removeHTML, false);
   }
 
+  @Override
+  public void addAnnotations(Alignment al)
+  {
+    // TODO Auto-generated method stub
+    super.addAnnotations(al);
+  }
+
+  @Override
+  public void addProperties(Alignment al)
+  {
+    // TODO Auto-generated method stub
+    super.addProperties(al);
+  }
+
+  @Override
+  public void addSeqGroups(AlignmentI al)
+  {
+    // TODO Auto-generated method stub
+    super.addSeqGroups(al);
+  }
+
   /**
    * Parse GFF or sequence features file
    * 
diff --git a/src/jalview/io/Gff3File.java b/src/jalview/io/Gff3File.java
new file mode 100644 (file)
index 0000000..53179e0
--- /dev/null
@@ -0,0 +1,154 @@
+package jalview.io;
+
+import jalview.api.AlignViewportI;
+import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * A GFF3 File parsing wrapper for the tangled mess that is FeaturesFile.
+ * 
+ * This class implements the methods relied on by FileLoader/FormatAdapter in
+ * order to allow them to load alignments directly from GFF2 and GFF3 files that
+ * contain sequence data and alignment information.
+ * 
+ * Major issues:
+ * 
+ * 1. GFF3 files commonly include mappings between DNA, RNA and Protein - so
+ * this class needs a dataset AlignmentI context to create alignment codon
+ * mappings.
+ * 
+ * 2. A single GFF3 file can generate many distinct alignments. Support will be
+ * needed to allow several AlignmentI instances to be generated from a single
+ * file.
+ * 
+ * 
+ * @author jprocter
+ *
+ */
+public class Gff3File extends FeaturesFile
+{
+
+  /**
+   * 
+   */
+  public Gff3File()
+  {
+    super();
+  }
+
+  /**
+   * @param source
+   * @throws IOException
+   */
+  public Gff3File(FileParse source) throws IOException
+  {
+    super(source);
+  }
+
+  /**
+   * @param inFile
+   * @param type
+   * @throws IOException
+   */
+  public Gff3File(String inFile, String type) throws IOException
+  {
+    super(inFile, type);
+  }
+
+  /**
+   * @param parseImmediately
+   * @param source
+   * @throws IOException
+   */
+  public Gff3File(boolean parseImmediately, FileParse source)
+          throws IOException
+  {
+    super(parseImmediately, source);
+  }
+
+  /**
+   * @param parseImmediately
+   * @param inFile
+   * @param type
+   * @throws IOException
+   */
+  public Gff3File(boolean parseImmediately, String inFile, String type)
+          throws IOException
+  {
+    super(parseImmediately, inFile, type);
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see jalview.io.FeaturesFile#print()
+   */
+  @Override
+  public String print()
+  {
+    // TODO GFF3 writer with sensible defaults for writing alignment data
+
+    // return super.printGFFFormat(seqs, visible);
+    return ("Not yet implemented.");
+  }
+
+  AlignmentI dataset;
+
+  List<AlignmentI> alignments;
+  @Override
+  public void parse()
+  {
+    AlignViewportI av = getViewport();
+    if (av != null)
+    {
+      if (av.getAlignment() != null)
+      {
+        dataset = av.getAlignment().getDataset();
+      }
+      if (dataset == null)
+      {
+        // working in the applet context ?
+        dataset = av.getAlignment();
+      }
+    }
+    else
+    {
+      dataset = new Alignment(new SequenceI[]
+      {});
+    }
+
+    boolean parseResult = parse(dataset, null, null, false, true);
+    if (!parseResult)
+    {
+      // pass error up somehow
+    }
+    if (av != null)
+    {
+      // update viewport with the dataset data ?
+    }
+    else
+    {
+      setSeqs(dataset.getSequencesArray());
+    }
+
+  }
+
+  @Override
+  public void addProperties(Alignment al)
+  {
+    super.addProperties(al);
+    if (dataset.getCodonFrames() != null)
+    {
+      AlignmentI ds = (al.getDataset() == null) ? al : al.getDataset();
+      for (AlignedCodonFrame codons : dataset.getCodonFrames())
+      {
+        ds.addCodonFrame(codons);
+      }
+    }
+  }
+}