xrefs retrieved from Uniprot
[jalview.git] / src / jalview / io / AlignFile.java
index ae8e0d0..2ad32f0 100755 (executable)
@@ -34,8 +34,18 @@ public abstract class AlignFile
 {
   int noSeqs = 0;
   int maxLength = 0;
+  /**
+   * Sequences to be added to form a new alignment.
+   */
   protected Vector seqs;
+  /**
+   * annotation to be added to generated alignment object
+   */
   protected Vector annotations;
+  /**
+   * Properties to be added to generated alignment object
+   */
+  protected Hashtable properties;
   long start;
   long end;
   boolean jvSuffix = true;
@@ -61,7 +71,17 @@ public abstract class AlignFile
 
     parse();
   }
-
+  /**
+   * Attempt to read from the position where some other parsing process left off.
+   * @param source
+   * @throws IOException
+   */
+  public AlignFile(FileParse source) throws IOException
+  {
+    super(source);
+    initData();
+    parse();
+  }
   /**
    * Return the seqs Vector
    */
@@ -84,9 +104,15 @@ public abstract class AlignFile
 
     return s;
   }
-
+  /**
+   * called by AppletFormatAdapter to generate
+   * an annotated alignment, rather than bare
+   * sequences.
+   * @param al
+   */
   public void addAnnotations(Alignment al)
   {
+    addProperties(al);
     for (int i = 0; i < annotations.size(); i++)
     {
       al.addAnnotation(
@@ -95,7 +121,54 @@ public abstract class AlignFile
     }
 
   }
-
+  /**
+   * Add any additional information extracted
+   * from the file to the alignment properties.
+   * @note implicitly called by addAnnotations()
+   * @param al
+   */
+  public void addProperties(Alignment al)
+  {
+    if (properties!=null && properties.size()>0)
+    {
+      Enumeration keys = properties.keys();
+      Enumeration vals = properties.elements();
+      while (keys.hasMoreElements())
+      {
+        al.setProperty(keys.nextElement(), vals.nextElement());
+      }
+    }
+  }
+  /**
+   * Store a non-null key-value pair in a hashtable used to set alignment properties
+   * note: null keys will raise an error, null values will result in the key/value pair being silently ignored.
+   * @param key - non-null key object
+   * @param value - non-null value
+   */
+  protected void setAlignmentProperty(Object key, Object value)
+  {
+    if (key==null)
+    {
+      throw new Error("Implementation error: Cannot have null alignment property key.");
+    }
+    if (value==null)
+    {
+      return; // null properties are ignored.
+    }
+    if (properties==null)
+    {
+      properties = new Hashtable();
+    }
+    properties.put(key, value);
+  }
+  protected Object getAlignmentProperty(Object key)
+  {
+    if (properties!=null && key!=null)
+    {
+      return properties.get(key);
+    }
+    return null;
+  }
   /**
    * Initialise objects to store sequence data in.
    */
@@ -170,5 +243,27 @@ public abstract class AlignFile
   {
     return seq.getDisplayId(jvSuffix);
   }
+  /**
+   * vector of String[] treeName, newickString pairs
+   */
+  Vector newickStrings=null;
+
+  protected void addNewickTree(String treeName, String newickString)
+  {
+    if (newickStrings == null)
+    {
+      newickStrings = new Vector();
+    }
+    newickStrings.addElement(new String[] { treeName, newickString});
+  }
+
+  protected int getTreeCount()
+  {
+    if (newickStrings==null)
+    {
+      return 0;
+    }
+    return newickStrings.size();
+  }
 
 }