imported from the old vamsas webservices datatypes and adapted for new
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 13 Jan 2006 16:35:54 +0000 (16:35 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 13 Jan 2006 16:35:54 +0000 (16:35 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@123 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/objects/utils/Seq.java

index 8d9371d..0d02041 100644 (file)
@@ -59,9 +59,10 @@ public class Seq {
    *This version resolves references to Sequence objects from AlignmentSequence
    *TODO: Define info: urn for dictionary string (could also be regex of valid characters!)
    * @param s
+        * @param dict TODO
    * @return true if a valid amino acid sequence object
         */
-       private static boolean valid_aadictionary_string(String s) {
+       private static boolean valid_aadictionary_string(String s, String dict) {
     if (s==null)
       return false;
     // validate against dictionary
@@ -70,7 +71,25 @@ public class Seq {
       String remnants = aa_repl.matcher(s).replaceAll("");
       return !remnants.matches("//S+");
   }
-  
+
+  public static Sequence newSequence(String Name, String Sequence, String Dictionary, int start, int end) {
+    //TODO: make hierarchy reflecting the SeqType object.
+    Sequence seq= new Sequence();
+     seq.setDictionary(Dictionary);
+     seq.setName(Name);
+     seq.setSequence(Sequence);
+     seq.setStart(start);
+     if (start<=end) {
+       if ((end-start)!=Sequence.length())
+         seq.setEnd(start+Sequence.length());
+     } else {
+       // reverse topology mapping. TODO: VAMSAS: decide if allowed to do start>end on Sequence object
+       if ((start-end)!=Sequence.length())
+         seq.setEnd(end+Sequence.length());
+     }
+     return seq;
+  }
+
   public static boolean is_valid_aa_seq(SequenceType s) {
     Sequence q;
     boolean validref=false;
@@ -79,9 +98,9 @@ public class Seq {
       if (q.getDictionary()!=null 
     
         && q.getDictionary().length()>0
-        || !q.getDictionary().equals("info:iubmb.org/aminoacid"))
+        || !q.getDictionary().equals(SymbolDictionary.STANDARD_AA))
         return false;
-      return valid_aadictionary_string(q.getSequence());
+      return valid_aadictionary_string(q.getSequence(), SymbolDictionary.STANDARD_AA);
     }
     
     // follow references
@@ -89,7 +108,7 @@ public class Seq {
       Object w = (((AlignmentSequence) s).getRefid());
       if (w!=null && w!=s && w instanceof SequenceType)
         return is_valid_aa_seq((SequenceType) w) 
-        && valid_aadictionary_string(((AlignmentSequence) s).getSequence());
+        && valid_aadictionary_string(((AlignmentSequence) s).getSequence(), SymbolDictionary.STANDARD_AA);
     }
     
     return false;