Controlled versionString vocabulary, newVamsasDocument construction methods and newAl...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Sun, 15 Jan 2006 13:17:45 +0000 (13:17 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Sun, 15 Jan 2006 13:17:45 +0000 (13:17 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@129 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/objects/utils/AppDataReference.java [new file with mode: 0644]
src/org/vamsas/objects/utils/DocumentStuff.java [new file with mode: 0644]
src/org/vamsas/objects/utils/Seq.java
src/org/vamsas/objects/utils/document/VersionEntries.java [new file with mode: 0644]

diff --git a/src/org/vamsas/objects/utils/AppDataReference.java b/src/org/vamsas/objects/utils/AppDataReference.java
new file mode 100644 (file)
index 0000000..2f1bc78
--- /dev/null
@@ -0,0 +1,13 @@
+/**
+ * 
+ */
+package org.vamsas.objects.utils;
+
+/**
+ * Form and validation for ApplicationData references in
+ * vamsas document.
+ * TODO: extend XML Schema to properly validate against the same forms required by this class
+ */
+public class AppDataReference {
+
+}
diff --git a/src/org/vamsas/objects/utils/DocumentStuff.java b/src/org/vamsas/objects/utils/DocumentStuff.java
new file mode 100644 (file)
index 0000000..6dcb19b
--- /dev/null
@@ -0,0 +1,34 @@
+package org.vamsas.objects.utils;
+
+import org.vamsas.objects.core.*;
+import org.vamsas.objects.utils.document.VersionEntries;
+
+/**
+ * various vamsas-client independent helpers 
+ * for creating and manipulating the vamsasDocument object
+ * @author jimp
+ *
+ */
+public class DocumentStuff {
+  public static VamsasDocument newVamsasDocument(VAMSAS root[], String version) {
+    return newVamsasDocument(root, ProvenanceStuff.newProvenance(
+      "AUTO:org.vamsas.DocumentStuff.newVamsasDocument", 
+      "Vamsas Document created"),
+      version);
+  }
+  public static VamsasDocument newVamsasDocument(VAMSAS root[]) {
+    return newVamsasDocument(root, ProvenanceStuff.newProvenance(
+      "AUTO:org.vamsas.DocumentStuff.newVamsasDocument", 
+      "Vamsas Document created"),
+      VersionEntries.latestVersion());
+  }
+  public static VamsasDocument newVamsasDocument(VAMSAS root[], Provenance p, String version) {
+    VamsasDocument doc = new VamsasDocument();
+    for (int r=0; r<root.length; r++) {
+      doc.addVAMSAS(root[r]);
+    }
+    doc.setProvenance(p);
+    doc.setVersion(version);
+    return doc;
+  }
+}
index 0d02041..ca83223 100644 (file)
@@ -89,7 +89,22 @@ public class Seq {
      }
      return seq;
   }
-
+  public static AlignmentSequence newAlignmentSequence(String name, String alSequence, Sequence refseq, int start, int end) {
+    if (refseq!=null) {
+      AlignmentSequence asq = new AlignmentSequence();
+      asq.setName(name);
+      asq.setSequence(alSequence);
+      asq.setRefid(refseq);
+      if (start<refseq.getStart())
+        start = refseq.getStart();
+      asq.setStart(start);
+      if (end>refseq.getEnd())
+        end = refseq.getEnd();
+      asq.setEnd(end);
+      return asq;
+    }
+    return null;
+  }
   public static boolean is_valid_aa_seq(SequenceType s) {
     Sequence q;
     boolean validref=false;
diff --git a/src/org/vamsas/objects/utils/document/VersionEntries.java b/src/org/vamsas/objects/utils/document/VersionEntries.java
new file mode 100644 (file)
index 0000000..b89288b
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * 
+ */
+package org.vamsas.objects.utils.document;
+
+import java.util.Hashtable;
+
+/**
+ *  enumerates versions for the VamsasDocument.Version string
+ *  provides version comparison methods
+ *  TODO: LATER: associate schema versions with these strings
+ */
+public class VersionEntries {
+  public static final String ALPHA_VERSION="alpha";
+  public static final String BETA_VERSION="beta";
+  protected static Hashtable versions;
+  static {
+    versions = new Hashtable();
+    // integers represent version hierarchy - 0 precedes 1
+    versions.put(ALPHA_VERSION, new Integer(0)); 
+    versions.put(BETA_VERSION, new Integer(1));
+  }
+  // TODO: LATER: decide on best pattern for enumeration classes (ie - need an ordered list of versions, and validator, plus explicit enum-strings)
+  public static boolean isVersion(String vstring) {
+    return versions.containsKey(vstring);
+  }
+  /**
+   * returns 0 if levels are equivalent, 
+   * 1 if higher is valid and higher, 
+   * 2 if lower is valid and higher
+   * -1 if both levels are invalid
+   * @param higher
+   * @param lower
+   * @return
+   */
+  public static int compare(String higher, String lower) {
+    int v_1 = versions.containsKey(higher) ? ((Integer) versions.get(higher)).intValue() : -1;
+    int v_2 = versions.containsKey(lower) ? ((Integer) versions.get(lower)).intValue() : -1;
+    int comp = v_1<v_2 ? 2 : v_1 == v_2 ? 0 : 1;
+    return (comp==0) ? (v_1!=-1 ? 0 : -1) : comp;
+  }
+  /**
+   * @return the latest version that this vamsas library supports
+   */
+  public static String latestVersion() {
+    return ALPHA_VERSION;
+  }
+
+}