renamed base class for all vamsas document objects (now org.vamsas.client.Vobject)
[vamsas.git] / src / org / vamsas / objects / utils / SeqSet.java
index 294bce6..294ce43 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Created on 17-May-2005
+ * Slurped into VamsasClient object set on 12th Jan 2006
  *
  * TODO To change the template for this generated file go to
  * Window - Preferences - Java - Code Style - Code Templates
@@ -17,7 +18,7 @@ import java.util.Hashtable;
 import java.util.Vector;
 import java.util.regex.Pattern;
 
-import vamsas.objects.simple.Sequence;
+import org.vamsas.objects.core.*;
 
 /**
  * @author jimp
@@ -25,25 +26,27 @@ import vamsas.objects.simple.Sequence;
  * TODO To change the template for this generated type comment go to
  * Window - Preferences - Java - Code Style - Code Templates
  */
-public class SeqSet extends vamsas.objects.simple.SequenceSet {
+public class SeqSet {
   
-  public static void write_Fasta(OutputStream os, Sequence[] seqs) throws IOException {
+  public static void write_Fasta(OutputStream os, SequenceType[] seqs) throws IOException {
     write_Fasta(os, seqs, 80);
   }
   
-  public static void write_Fasta(OutputStream os, Sequence[] seqs, boolean width80) throws IOException {
+  public static void write_Fasta(OutputStream os, SequenceType[] seqs, boolean width80) throws IOException {
     write_Fasta(os, seqs, (width80) ? 80 : 0);
   }
   
-  public static void write_Fasta(OutputStream os, Sequence[] seqs, int width) throws IOException {
+  public static void write_Fasta(OutputStream os, SequenceType[] seqs, int width) throws IOException {
     int i, nseq = seqs.length;
     BufferedWriter fasta_out = new BufferedWriter(new OutputStreamWriter(os));
+    System.err.println("NOT FULLY IMPLEMENTED!"); // TODO: Finish adapting this method
     for (i=0; i<nseq; i++) {
-      fasta_out.write(">"+seqs[i].getId()+"\n");
+      fasta_out.write(">"+seqs[i].getName()+"\n");
       if (width<=0) {
-        fasta_out.write(seqs[i].getSeq()+"\n");
+        fasta_out.write(seqs[i].getSequence()+"\n");
       } else {
-        String tempseq = seqs[i].getSeq();
+        // TODO: adapt to SymbolDictionary labelwidths
+        String tempseq = seqs[i].getSequence();
         int j=0, k=tempseq.length();
         while (j<k) {
           int d = k-j;
@@ -71,8 +74,9 @@ public class SeqSet extends vamsas.objects.simple.SequenceSet {
     Vector seqs = new Vector();
     int nseq = 0;
     BufferedReader infasta = new BufferedReader(new InputStreamReader(os));
-    
-    /// TODO: decide on where this routine should live... current best guess is vamsas.objects.io
+    System.err.println("NOT FULLY IMPLEMENTED!"); // TODO: Finish adapting this method
+    // TODO: decide on return type - SequenceType is a partly complete vamsas Vobject - either for a dataset or alignment sequence
+    // so could go in either!
     String line;
     Sequence seq = null;
     Pattern aaMatch = Pattern.compile("[ARNDCQEGHILKMFPSTUWYV]", Pattern.CASE_INSENSITIVE);
@@ -81,7 +85,7 @@ public class SeqSet extends vamsas.objects.simple.SequenceSet {
       line = infasta.readLine();
       if (line==null || line.startsWith(">")) {
         if (seqstr!=null) 
-          seqs.add((Object) new Sequence(sname.substring(1), seqstr));
+          seqs.add((Object) Seq.newSequence(sname.substring(1), seqstr, SymbolDictionary.STANDARD_AA, 0,0));
         sname = line; // remove >
         seqstr="";
       } else { 
@@ -102,24 +106,28 @@ public class SeqSet extends vamsas.objects.simple.SequenceSet {
     return null;
   }
   
-  public static Hashtable uniquify(Sequence[] sequences) {
+  public static Hashtable uniquify(SequenceType[] sequences) {
+    System.err.println("NOT FULLY IMPLEMENTED!"); // TODO: Finish adapting this method
+    // TODO: do we need this with vamsas sequences ?
     // Generate a safely named sequence set and a hash to recover the sequence names
     Hashtable map = new Hashtable();
     for (int i = 0; i < sequences.length; i++) {
       String safename = new String("Sequence" + i);
-      map.put(safename, sequences[i].getId());
-      sequences[i].setId(safename);
+      map.put(safename, sequences[i].getName());
+      sequences[i].setName(safename);
     }
     return map;
   }
   
-  public static boolean deuniquify(Hashtable map, Sequence[] sequences) {
+  public static boolean deuniquify(Hashtable map, SequenceType[] sequences) {
+    System.err.println("NOT FULLY IMPLEMENTED!"); // TODO: Finish adapting this method
+    // TODO: do we need this with vamsas sequences ?
     // recover unsafe sequence names for a sequence set
     boolean allfound = true;
     for (int i = 0; i < sequences.length; i++) {
-      if (map.containsKey(sequences[i].getId())) {
-        String unsafename = (String) map.get(sequences[i].getId());
-        sequences[i].setId(unsafename);
+      if (map.containsKey(sequences[i].getName())) {
+        String unsafename = (String) map.get(sequences[i].getName());
+        sequences[i].setName(unsafename);
       } else {
         allfound = false;
       }