added uniquify sequence id assertion.
authorjprocter <Jim Procter>
Mon, 28 Feb 2005 10:47:32 +0000 (10:47 +0000)
committerjprocter <Jim Procter>
Mon, 28 Feb 2005 10:47:32 +0000 (10:47 +0000)
src/jalview/ws/Jemboss.java

index a5205ac..7c107c7 100755 (executable)
@@ -58,6 +58,30 @@ public class Jemboss
       props.getEmbossEnvironmentArray());
   }
   */
+    private Hashtable uniquify(SequenceI[] 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].getName());
+            sequences[i].setName(safename);
+        }
+        return map;
+    }
+
+    private boolean deuniquify(Hashtable map, SequenceI[] 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].getName())) {
+                String unsafename = (String) map.get(sequences[i].getName());
+                sequences[i].setName(unsafename);
+            } else {
+                allfound=false;
+            }
+        }
+        return allfound;
+    }
 
   public SequenceI[] clustalW(SequenceI[] sequences)
   {
@@ -104,9 +128,17 @@ public class Jemboss
 
     Hashtable filesToMove = new Hashtable();
     String embossCommand = "emma -sequence jalseqs.fasta -auto";
+    // Duplicate
+    SequenceI[] myseq = new SequenceI[sequences.length];
+    for (int i=0; i<sequences.length; i++) {
+        myseq[i] = new Sequence(sequences[i]);
+    }
+    // Uniqueify, and 
+    Hashtable namemap = uniquify(myseq);
     // Load sequence file into hash
+    
     filesToMove.put("jalseqs.fasta",
-                    jalview.io.FastaFile.print(sequences,124,false).getBytes());
+                    jalview.io.FastaFile.print(myseq,124,false).getBytes());
 
     if(vamsas_server.getUseAuth() == true)
       if(vamsas_server.getServiceUserName() == null)
@@ -138,8 +170,13 @@ public class Jemboss
           if (alignment == null)
             System.out.println("jalview.Jemboss: Couldn't read response:\n"
                                + alfile + "\n---EOF\n");
-          else
+          else {
+            if (!deuniquify(namemap, alignment)) {
+                  System.out.println("jalview.Jemboss: Warning: Some of the "
+                                     +"original sequence names have not been recovered!\n");
+            }
             return alignment;
+          }
         }
 
       }