JAL-972 JAL-1084 propagate reference to local authentication provider so it can be...
[jalview.git] / src / jalview / ws / jws2 / JabawsAlignCalcWorker.java
index 7ee6e08..a11cc35 100644 (file)
@@ -20,7 +20,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.sun.xml.internal.ws.developer.ServerSideException;
 import compbio.data.msa.SequenceAnnotation;
 import compbio.data.sequence.FastaSequence;
 import compbio.data.sequence.ScoreManager;
@@ -191,20 +190,14 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
           } catch (Exception x)
           {
 
-            if (x.getCause() instanceof ServerSideException)
+            if (x.getMessage().contains(
+                    "Position in a file could not be negative!"))
             {
-              if (x.getMessage().contains("Position in a file could not be negative!"))
-              {
-                // squash index out of bounds exception- seems to happen for
-                // disorder predictors which don't (apparently) produce any
-                // progress information and JABA server throws an exception
-                // because progress length is -1.
-                stats = null;
-              }
-              else
-              {
-                throw x;
-              }
+              // squash index out of bounds exception- seems to happen for
+              // disorder predictors which don't (apparently) produce any
+              // progress information and JABA server throws an exception
+              // because progress length is -1.
+              stats = null;
             }
             else
             {
@@ -298,19 +291,20 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
   boolean nucleotidesAllowed = false;
 
   boolean proteinAllowed = false;
-  
+
   /**
    * record sequences for mapping result back to afterwards
    */
-  protected boolean bySequence=false;
+  protected boolean bySequence = false;
+
+  Map<String, SequenceI> seqNames;
 
-  Map<String,SequenceI> seqNames;
   public List<FastaSequence> getInputSequences(AlignmentI alignment)
   {
 
     if (alignment == null || alignment.getWidth() <= 0
             || alignment.getSequences() == null
-            || (alignedSeqs && !alignment.isAligned())
+//             || (alignedSeqs && !alignment.isAligned() && !submitGaps)
             || alignment.isNucleotide() ? !nucleotidesAllowed
             : !proteinAllowed)
     {
@@ -319,9 +313,10 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
     List<compbio.data.sequence.FastaSequence> seqs = new ArrayList<compbio.data.sequence.FastaSequence>();
 
     int minlen = 10;
+    int ln=-1;
     if (bySequence)
     {
-      seqNames=new HashMap<String,SequenceI>();
+      seqNames = new HashMap<String, SequenceI>();
     }
     for (SequenceI sq : ((List<SequenceI>) alignment.getSequences()))
     {
@@ -330,14 +325,41 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
       {
         String newname = SeqsetUtils.unique_name(seqs.size() + 1);
         // make new input sequence with or without gaps
-        if (seqNames!=null) {
-          seqNames.put(newname,sq);
+        if (seqNames != null)
+        {
+          seqNames.put(newname, sq);
         }
-        seqs.add(new compbio.data.sequence.FastaSequence(newname,
+        FastaSequence seq;
+        seqs.add(seq=new compbio.data.sequence.FastaSequence(newname,
                 (submitGaps) ? sq.getSequenceAsString() : AlignSeq
                         .extractGaps(jalview.util.Comparison.GapChars,
                                 sq.getSequenceAsString())));
+        if (seq.getSequence().length()>ln)
+        {
+          ln = seq.getSequence().length();
+        }
+      }
+    }
+    if (alignedSeqs && submitGaps)
+    {
+      // try real hard to return something submittable
+      // TODO: some of AAcons measures need a minimum of two or three amino acids at each position, and aacons doesn't gracefully degrade.
+      for (int p=0; p<seqs.size();p++)
+      {
+        FastaSequence sq=seqs.get(p);
+        int l=sq.getSequence().length();
+        if (l<ln)
+        {
+          char[] padded=new char[ln];
+          System.arraycopy(sq.getSequence().toCharArray(),0,padded,0,sq.getSequence().length());
+          while (l<ln)
+          {
+            padded[l++]='-';
+          }
+          seqs.set(p, new compbio.data.sequence.FastaSequence(sq.getId(), new String(padded)));
+        }
       }
+      
     }
     return seqs;
   }