JAL-3210 Barebones gradle/buildship/eclipse. See README
[jalview.git] / src / jalview / io / AlignFile.java
index d36a588..cea2870 100755 (executable)
@@ -40,7 +40,8 @@ import java.util.Vector;
  * @author $author$
  * @version $Revision$
  */
-public abstract class AlignFile extends FileParse implements AlignmentFileI
+public abstract class AlignFile extends FileParse
+        implements AlignmentFileReaderI, AlignmentFileWriterI
 {
   int noSeqs = 0;
 
@@ -65,13 +66,26 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
   /**
    * Properties to be added to generated alignment object
    */
-  protected Hashtable properties;
+  private Hashtable properties;
 
   long start;
 
   long end;
 
-  private boolean parseCalled;
+  /**
+   * true if parse() has been called
+   */
+  private boolean parseCalled = false;
+
+  private boolean parseImmediately = true;
+
+  /**
+   * @return if doParse() was called at construction time
+   */
+  protected boolean isParseImmediately()
+  {
+    return parseImmediately;
+  }
 
   /**
    * Creates a new AlignFile object.
@@ -98,7 +112,7 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
    * @param sourceType
    *          What type of file to read from (File, URL, Pasted String)
    */
-  public AlignFile(String dataObject, DataSourceType sourceType)
+  public AlignFile(Object dataObject, DataSourceType sourceType)
           throws IOException
   {
     this(true, dataObject, sourceType);
@@ -116,10 +130,10 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
    *          What type of file to read from (File, URL)
    * @throws IOException
    */
-  public AlignFile(boolean parseImmediately, String dataObject,
-          DataSourceType sourceType)
-          throws IOException
+  public AlignFile(boolean parseImmediately, Object dataObject,
+          DataSourceType sourceType) throws IOException
   {
+    // BH allows File or String
     super(dataObject, sourceType);
     initData();
     if (parseImmediately)
@@ -153,6 +167,11 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
   {
     super(source);
     initData();
+
+    // stash flag in case parse needs to know if it has to autoconfigure or was
+    // configured after construction
+    this.parseImmediately = parseImmediately;
+
     if (parseImmediately)
     {
       doParse();
@@ -174,11 +193,6 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
     }
     parseCalled = true;
     parse();
-    // sets the index of each sequence in the alignment
-    for (int i = 0, c = seqs.size(); i < c; i++)
-    {
-      seqs.get(i).setIndex(i);
-    }
   }
 
   /**
@@ -281,9 +295,8 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
   {
     if (key == null)
     {
-      throw new Error(
-              MessageManager
-                      .getString("error.implementation_error_cannot_have_null_alignment"));
+      throw new Error(MessageManager.getString(
+              "error.implementation_error_cannot_have_null_alignment"));
     }
     if (value == null)
     {
@@ -370,8 +383,8 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
   }
 
   /**
-   * Creates the output id. Adds prefix Uniprot format source|id And suffix
-   * Jalview /start-end
+   * Creates the output id. Adds prefix Uniprot format source|id and optionally
+   * suffix Jalview /start-end
    * 
    * @param jvsuffix
    * 
@@ -382,6 +395,11 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
     return seq.getDisplayId(jvsuffix);
   }
 
+  String printId(SequenceI seq)
+  {
+    return printId(seq, true);
+  }
+
   /**
    * vector of String[] treeName, newickString pairs
    */
@@ -411,4 +429,8 @@ public abstract class AlignFile extends FileParse implements AlignmentFileI
     }
   }
 
+  protected void addSequence(SequenceI seq)
+  {
+    seqs.add(seq);
+  }
 }