More work to disorder prediction client & services.
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 8 Jun 2011 16:03:25 +0000 (16:03 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Wed, 8 Jun 2011 16:03:25 +0000 (16:03 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4236 e3abac25-378b-4346-85de-24260fe3988d

15 files changed:
TODO.txt
datamodel/compbio/data/sequence/ClustalAlignmentUtil.java
datamodel/compbio/data/sequence/Range.java
datamodel/compbio/data/sequence/Score.java
datamodel/compbio/data/sequence/ScoreManager.java
datamodel/compbio/data/sequence/SequenceUtil.java
testsrc/compbio/data/sequence/ClustalAlignmentUtilTester.java
testsrc/compbio/data/sequence/SequenceUtilTester.java
testsrc/compbio/ws/client/AAConWSClientExample.java
webservices/compbio/ws/client/AAConClient.java
webservices/compbio/ws/client/IOHelper.java
webservices/compbio/ws/client/Jws2Client.java
webservices/compbio/ws/server/AAConWS.java
webservices/compbio/ws/server/WSUtil.java
webservices/compbio/ws/server/resource/TcoffeeWS.wsdl

index 74a7d13..539954e 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -4,9 +4,6 @@ webservices - 1 week
 client - 1 week\r
 docs - 1 week\r
 \r
-make sure that aacon checks its input (must be alignment) and log errors/throws\r
-exceptions if the input is not correct or absent! \r
-\r
 Cluster stats: \r
  +cancelled should not be reported as incomplete!\r
  -Remove hyperlinks from tasks which workdirs were removed \r
index 2d1a616..2656046 100644 (file)
@@ -24,9 +24,7 @@ import java.io.FileInputStream;
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.io.InputStreamReader;\r
-import java.io.OutputStream;\r
-import java.io.OutputStreamWriter;\r
-import java.io.PrintWriter;\r
+import java.io.Writer;\r
 import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.HashMap;\r
@@ -207,12 +205,10 @@ public final class ClustalAlignmentUtil {
         * @param alignment\r
         * @throws IOException\r
         */\r
-       public static void writeClustalAlignment(final OutputStream outStream,\r
+       public static void writeClustalAlignment(final Writer out,\r
                        final Alignment alignment) throws IOException {\r
                List<FastaSequence> seqs = alignment.getSequences();\r
 \r
-               PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream));\r
-\r
                out.write("CLUSTAL\n\n\n");\r
 \r
                int max = 0;\r
@@ -249,10 +245,10 @@ public final class ClustalAlignmentUtil {
                                // display at most 30 characters in the name, keep the names\r
                                // 6 spaces away from the alignment for longest sequence names,\r
                                // and more than this for shorter names\r
-                               out.format(\r
+                               out.write(String.format(\r
                                                "%-" + maxidLength + "s" + spacer,\r
                                                (name.length() > maxNameLength ? name.substring(0,\r
-                                                               maxidLength) : name));\r
+                                                               maxidLength) : name)));\r
                                int start = i * oneLineAlignmentLength;\r
                                int end = start + oneLineAlignmentLength;\r
 \r
index 1fabc07..a22ab8c 100644 (file)
@@ -26,7 +26,7 @@ public class Range implements Comparable<Range> {
 \r
        @Override\r
        public String toString() {\r
-               return "[" + from + ", " + to + "]";\r
+               return from + "-" + to;\r
        }\r
 \r
        @Override\r
index f28bd0d..804ef8c 100644 (file)
@@ -1,13 +1,10 @@
 package compbio.data.sequence;\r
 \r
-import java.io.BufferedWriter;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
 import java.text.NumberFormat;\r
 import java.util.ArrayList;\r
 import java.util.Locale;\r
-import java.util.Set;\r
 import java.util.TreeSet;\r
 \r
 import javax.xml.bind.annotation.XmlAccessType;\r
@@ -24,7 +21,7 @@ import compbio.util.annotation.Immutable;
  */\r
 @XmlAccessorType(XmlAccessType.FIELD)\r
 @Immutable\r
-public class Score {\r
+public class Score implements Comparable<Score> {\r
 \r
        static final NumberFormat NUMBER_FORMAT = NumberFormat\r
                        .getNumberInstance(Locale.UK);\r
@@ -41,7 +38,7 @@ public class Score {
 \r
        private Score() {\r
                // JaXB default constructor\r
-               method = null;\r
+               method = "";\r
        }\r
 \r
        /**\r
@@ -193,20 +190,32 @@ public class Score {
         * @throws NullPointerException\r
         *             if the output stream is null\r
         */\r
-       public static void write(Set<Score> scores, OutputStream output)\r
+       public static void write(TreeSet<Score> scores, Writer writer)\r
                        throws IOException {\r
-               if (output == null) {\r
-                       throw new NullPointerException("OutputStream must be provided!");\r
+               if (writer == null) {\r
+                       throw new NullPointerException("Writer must be provided!");\r
                }\r
-               BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
-                               output));\r
                for (Score score : scores) {\r
                        writer.write("#" + score.method + " ");\r
-                       for (Float scoreVal : score.getScores()) {\r
+                       int count = score.ranges.size();\r
+                       for (Range range : score.ranges) {\r
+                               count--;\r
+                               writer.write(range.toString());\r
+                               if (count != 0) {\r
+                                       writer.write(", ");\r
+                               }\r
+                       }\r
+                       for (Float scoreVal : score.scores) {\r
                                writer.write(NUMBER_FORMAT.format(scoreVal) + " ");\r
                        }\r
                        writer.write("\n");\r
+                       writer.flush();\r
                }\r
                writer.flush();\r
        }\r
+\r
+       @Override\r
+       public int compareTo(Score o) {\r
+               return this.method.compareTo(o.method);\r
+       }\r
 }\r
index 7ddf894..4be41d5 100644 (file)
@@ -1,15 +1,13 @@
 package compbio.data.sequence;\r
 \r
-import java.io.BufferedWriter;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
 import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
+import java.util.TreeMap;\r
+import java.util.TreeSet;\r
 \r
 import javax.xml.bind.annotation.XmlAccessType;\r
 import javax.xml.bind.annotation.XmlAccessorType;\r
@@ -47,9 +45,9 @@ public class ScoreManager {
 \r
        public static ScoreManager newInstanceSingleScore(\r
                        Map<String, Score> seqScoresMap) {\r
-               Map<String, Set<Score>> multipleScoresMap = new HashMap<String, Set<Score>>();\r
+               Map<String, Set<Score>> multipleScoresMap = new TreeMap<String, Set<Score>>();\r
                for (Map.Entry<String, Score> seqScore : seqScoresMap.entrySet()) {\r
-                       Set<Score> scores = new HashSet<Score>();\r
+                       Set<Score> scores = new TreeSet<Score>();\r
                        scores.add(seqScore.getValue());\r
                        multipleScoresMap.put(seqScore.getKey(), scores);\r
                }\r
@@ -57,13 +55,15 @@ public class ScoreManager {
        }\r
 \r
        public static ScoreManager newInstanceSingleSequence(Set<Score> data) {\r
-               return new ScoreManager(ScoreManager.SINGLE_ENTRY_KEY, data);\r
+               return new ScoreManager(ScoreManager.SINGLE_ENTRY_KEY,\r
+                               new TreeSet(data));\r
        }\r
 \r
-       public Map<String, Set<Score>> asMap() {\r
-               Map<String, Set<Score>> seqScoresMap = new HashMap<String, Set<Score>>();\r
+       public Map<String, TreeSet<Score>> asMap() {\r
+               Map<String, TreeSet<Score>> seqScoresMap = new TreeMap<String, TreeSet<Score>>();\r
                for (ScoreHolder sch : this.seqScores) {\r
-                       Set<Score> oldValue = seqScoresMap.put(sch.id, sch.scores);\r
+                       TreeSet<Score> oldValue = seqScoresMap.put(sch.id, new TreeSet(\r
+                                       sch.scores));\r
                        if (oldValue != null) {\r
                                throw new IllegalStateException(\r
                                                "Cannot represent this ScoreManager instance "\r
@@ -98,13 +98,10 @@ public class ScoreManager {
                return null;\r
        }\r
 \r
-       public void writeOut(OutputStream outStream) throws IOException {\r
-               BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
-                               outStream));\r
+       public void writeOut(Writer outStream) throws IOException {\r
                for (ScoreHolder oneSeqScores : seqScores) {\r
                        oneSeqScores.writeOut(outStream);\r
                }\r
-               writer.flush();\r
        }\r
 \r
        @Override\r
@@ -137,7 +134,7 @@ public class ScoreManager {
        public static class ScoreHolder {\r
 \r
                public String id;\r
-               public HashSet<Score> scores;\r
+               public TreeSet<Score> scores;\r
 \r
                private ScoreHolder() {\r
                        // JAXB Default constructor should not be used otherwise\r
@@ -145,14 +142,12 @@ public class ScoreManager {
 \r
                ScoreHolder(String id, Set<Score> scores) {\r
                        this.id = id;\r
-                       this.scores = new HashSet<Score>(scores);\r
+                       this.scores = new TreeSet<Score>(scores);\r
                }\r
 \r
-               public void writeOut(OutputStream outStream) throws IOException {\r
-                       BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
-                                       outStream));\r
+               public void writeOut(Writer writer) throws IOException {\r
                        writer.write(">" + id + "\n");\r
-                       Score.write(scores, outStream);\r
+                       Score.write(scores, writer);\r
                }\r
 \r
                public Score getScoreByMethod(Enum<?> method) {\r
index 4d61d2a..e737575 100644 (file)
@@ -610,7 +610,7 @@ public final class SequenceUtil {
                         * Also possible FastaSequence fs = new FastaSequence(sequenceName,\r
                         * seqbuffer.toString());\r
                         */\r
-                       HashSet<Score> scores = new HashSet<Score>();\r
+                       Set<Score> scores = new TreeSet<Score>();\r
                        scores.add(new Score(GlobProtResult.Disorder, disorderR));\r
                        scores.add(new Score(GlobProtResult.GlobDoms, domsR));\r
                        scores.add(new Score(GlobProtResult.Dydx, dydxScore));\r
index addba28..812cd6f 100644 (file)
@@ -25,8 +25,9 @@ import static org.testng.AssertJUnit.fail;
 \r
 import java.io.FileInputStream;\r
 import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
+import java.io.FileWriter;\r
 import java.io.IOException;\r
+import java.io.Writer;\r
 \r
 import org.testng.annotations.Test;\r
 \r
@@ -34,68 +35,68 @@ import compbio.metadata.AllTestSuit;
 \r
 public class ClustalAlignmentUtilTester {\r
 \r
-    @Test()\r
-    public void testReadClustalFile() {\r
-       try {\r
-           readWriteClustal("TO1381.aln");\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
-       } catch (Exception e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
+       @Test()\r
+       public void testReadClustalFile() {\r
+               try {\r
+                       readWriteClustal("TO1381.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
        }\r
-    }\r
 \r
-    static void readWriteClustal(String fname) throws IOException,\r
-           UnknownFileFormatException {\r
-       FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
-               + fname);\r
-       Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);\r
-       assertTrue(seqAl != null);\r
-       assertTrue(seqAl.getSize() == 3);\r
-       assertNotNull(seqAl.getSequences());\r
-       assertEquals(3, seqAl.getSequences().size());\r
+       static void readWriteClustal(String fname) throws IOException,\r
+                       UnknownFileFormatException {\r
+               FileInputStream fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH\r
+                               + fname);\r
+               Alignment seqAl = ClustalAlignmentUtil.readClustalFile(fio);\r
+               assertTrue(seqAl != null);\r
+               assertTrue(seqAl.getSize() == 3);\r
+               assertNotNull(seqAl.getSequences());\r
+               assertEquals(3, seqAl.getSequences().size());\r
 \r
-       // Now try to write the alignment read\r
-       FileOutputStream os = new FileOutputStream(AllTestSuit.TEST_DATA_PATH\r
-               + fname + ".written");\r
-       ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);\r
-       fio.close();\r
-       os.close();\r
+               // Now try to write the alignment read\r
+               Writer os = new FileWriter(AllTestSuit.TEST_DATA_PATH + fname\r
+                               + ".written");\r
+               ClustalAlignmentUtil.writeClustalAlignment(os, seqAl);\r
+               fio.close();\r
+               os.close();\r
 \r
-       fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname\r
-               + ".written");\r
-       Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);\r
-       assertTrue(readseqs != null);\r
-       assertTrue(readseqs.getSize() == 3);\r
-       fio.close();\r
-    }\r
+               fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + fname\r
+                               + ".written");\r
+               Alignment readseqs = ClustalAlignmentUtil.readClustalFile(fio);\r
+               assertTrue(readseqs != null);\r
+               assertTrue(readseqs.getSize() == 3);\r
+               fio.close();\r
+       }\r
 \r
-    @Test()\r
-    public void testReadClustalFileShortNames() {\r
-       try {\r
-           readWriteClustal("TO1381s.aln");\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
-       } catch (Exception e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
+       @Test()\r
+       public void testReadClustalFileShortNames() {\r
+               try {\r
+                       readWriteClustal("TO1381s.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
        }\r
-    }\r
 \r
-    @Test()\r
-    public void testReadClustalFileLongNames() {\r
-       try {\r
-           readWriteClustal("TO1381L.aln");\r
-       } catch (FileNotFoundException e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
-       } catch (Exception e) {\r
-           e.printStackTrace();\r
-           fail(e.getMessage());\r
+       @Test()\r
+       public void testReadClustalFileLongNames() {\r
+               try {\r
+                       readWriteClustal("TO1381L.aln");\r
+               } catch (FileNotFoundException e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+                       fail(e.getMessage());\r
+               }\r
        }\r
-    }\r
 \r
 }\r
index 3e351bf..7db01ee 100644 (file)
@@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
+import java.io.PrintWriter;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
@@ -193,7 +194,8 @@ public class SequenceUtilTester {
                        Map<String, Set<Score>> aseqs = SequenceUtil.readDisembl(fio);\r
                        assertNotNull(aseqs);\r
                        assertEquals(aseqs.size(), 3);\r
-                       // System.out.println(aseqs);\r
+                       ScoreManager sman = ScoreManager.newInstance(aseqs);\r
+\r
                        for (String fs : aseqs.keySet()) {\r
                                assertTrue(" Foobar_dundeefriends Foobar dundeefriends "\r
                                                .contains(fs));\r
@@ -255,6 +257,10 @@ public class SequenceUtilTester {
                                }\r
                                assertEquals(scores.size(), 5);\r
                        }\r
+\r
+                       ScoreManager sm = ScoreManager.newInstanceSingleSequence(scores);\r
+                       sm.writeOut(new PrintWriter(System.out, true));\r
+\r
                        for (Score score : scores) {\r
 \r
                                if (score.getMethod()\r
index 307d144..23eaf36 100644 (file)
@@ -3,6 +3,8 @@ package compbio.ws.client;
 import java.io.ByteArrayInputStream;\r
 import java.io.FileNotFoundException;\r
 import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
 import java.util.List;\r
 \r
 import compbio.data.msa.SequenceAnnotation;\r
@@ -108,7 +110,9 @@ public class AAConWSClientExample {
                // }\r
 \r
                /* Output the alignment to standard out */\r
-               IOHelper.writeOut(System.out, result);\r
+               Writer writer = new PrintWriter(System.out, true);\r
+               IOHelper.writeOut(writer, result);\r
+               writer.close();\r
                // Score.write(result, System.out);\r
 \r
                /* Alternatively, you can record retrieved alignment into the file */\r
index 4619c60..3fe638e 100644 (file)
@@ -30,7 +30,8 @@ import static compbio.ws.client.Constraints.pseparator;
 import java.io.Closeable;\r
 import java.io.File;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
 import java.util.List;\r
@@ -116,13 +117,13 @@ public class AAConClient {
                if (inputFile != null) {\r
                        System.out.println("Calculating conservation...");\r
                        result = analize(inputFile, msaws, preset, customOptions);\r
-                       OutputStream outStream = null;\r
+                       Writer outStream = null;\r
                        if (outFile != null) {\r
-                               outStream = IOHelper.getOutStream(outFile);\r
+                               outStream = IOHelper.getWriter(outFile);\r
                        } else {\r
                                // this stream is going to be closed later which is fine as\r
                                // std.out will not be\r
-                               outStream = System.out;\r
+                               outStream = new PrintWriter(System.out, true);\r
                        }\r
                        writeOut(outStream, result);\r
                        // stream is closed in the method no need to close it here\r
@@ -152,17 +153,17 @@ public class AAConClient {
         * @param result\r
         *            the AACon scores to output\r
         */\r
-       static void writeOut(OutputStream outStream, ScoreManager result) {\r
+       static void writeOut(Writer writer, ScoreManager result) {\r
                try {\r
-                       result.writeOut(outStream);\r
+                       result.writeOut(writer);\r
                } catch (IOException e) {\r
                        System.err\r
                                        .println("Problems writing output file! Stack trace is below: ");\r
                        e.printStackTrace();\r
                } finally {\r
-                       if (outStream != null) {\r
+                       if (writer != null) {\r
                                try {\r
-                                       outStream.close();\r
+                                       writer.close();\r
                                } catch (IOException ignored) {\r
                                        // e.printStackTrace();\r
                                }\r
index 8fbf763..88b695a 100644 (file)
@@ -4,11 +4,10 @@ import static compbio.ws.client.Constraints.pseparator;
 \r
 import java.io.BufferedReader;\r
 import java.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
 import java.io.FileReader;\r
+import java.io.FileWriter;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
+import java.io.Writer;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
@@ -74,14 +73,9 @@ public class IOHelper {
                return params;\r
        }\r
 \r
-       static OutputStream getOutStream(File file) {\r
+       static Writer getWriter(File file) throws IOException {\r
                assert file != null && file.exists();\r
-               try {\r
-                       return new FileOutputStream(file);\r
-               } catch (FileNotFoundException e) {\r
-                       e.printStackTrace();\r
-               }\r
-               return null;\r
+               return new FileWriter(file);\r
        }\r
 \r
        /**\r
@@ -92,17 +86,17 @@ public class IOHelper {
         * @param align\r
         *            the alignment to output\r
         */\r
-       static void writeOut(OutputStream outStream, Alignment align) {\r
+       static void writeOut(Writer writer, Alignment align) {\r
                try {\r
-                       ClustalAlignmentUtil.writeClustalAlignment(outStream, align);\r
+                       ClustalAlignmentUtil.writeClustalAlignment(writer, align);\r
                } catch (IOException e) {\r
                        System.err\r
                                        .println("Problems writing output file! Stack trace is below: ");\r
                        e.printStackTrace();\r
                } finally {\r
-                       if (outStream != null) {\r
+                       if (writer != null) {\r
                                try {\r
-                                       outStream.close();\r
+                                       writer.close();\r
                                } catch (IOException ignored) {\r
                                        // e.printStackTrace();\r
                                }\r
@@ -117,17 +111,17 @@ public class IOHelper {
         * @param result\r
         *            the AACon scores to output\r
         */\r
-       static void writeOut(OutputStream outStream, ScoreManager results) {\r
+       static void writeOut(Writer writer, ScoreManager results) {\r
                try {\r
-                       results.writeOut(outStream);\r
+                       results.writeOut(writer);\r
                } catch (IOException e) {\r
                        System.err\r
                                        .println("Problems writing output file! Stack trace is below: ");\r
                        e.printStackTrace();\r
                } finally {\r
-                       if (outStream != null) {\r
+                       if (writer != null) {\r
                                try {\r
-                                       outStream.close();\r
+                                       writer.close();\r
                                } catch (IOException ignored) {\r
                                        // e.printStackTrace();\r
                                }\r
index ceb9501..f3ca471 100644 (file)
@@ -33,7 +33,8 @@ import java.io.Closeable;
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.IOException;\r
-import java.io.OutputStream;\r
+import java.io.PrintWriter;\r
+import java.io.Writer;\r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
 import java.util.Arrays;\r
@@ -151,25 +152,25 @@ public class Jws2Client {
                }\r
                Alignment alignment = null;\r
                if (inputFile != null) {\r
-                       OutputStream outStream = null;\r
+                       Writer writer = null;\r
                        if (outFile != null) {\r
-                               outStream = IOHelper.getOutStream(outFile);\r
+                               writer = IOHelper.getWriter(outFile);\r
                        } else {\r
                                // this stream is going to be closed later which is fine as\r
                                // std.out will not be\r
-                               outStream = System.out;\r
+                               writer = new PrintWriter(System.out, true);\r
                        }\r
                        if (service.getServiceType() == SequenceAnnotation.class) {\r
                                ScoreManager result = analize(inputFile,\r
                                                ((SequenceAnnotation<T>) msaws), preset, customOptions);\r
 \r
-                               IOHelper.writeOut(outStream, result);\r
+                               IOHelper.writeOut(writer, result);\r
                        } else {\r
                                alignment = align(inputFile, (MsaWS<T>) msaws, preset,\r
                                                customOptions);\r
-                               IOHelper.writeOut(outStream, alignment);\r
+                               IOHelper.writeOut(writer, alignment);\r
                        }\r
-                       outStream.close();\r
+                       writer.close();\r
                }\r
 \r
                boolean listParameters = CmdHelper.listParameters(cmd);\r
index fab12b8..1625ded 100644 (file)
@@ -123,7 +123,7 @@ public class AAConWS implements SequenceAnnotation<AACon> {
                return aaconOptions;\r
        }\r
 \r
-       String analize(List<FastaSequence> sequences,\r
+       private String analize(List<FastaSequence> sequences,\r
                        ConfiguredExecutable<AACon> confExec, Logger log, String method,\r
                        Limit<AACon> limit) throws JobSubmissionException {\r
                if (limit != null && limit.isExceeded(sequences)) {\r
@@ -140,7 +140,8 @@ public class AAConWS implements SequenceAnnotation<AACon> {
        public String analize(List<FastaSequence> sequences)\r
                        throws UnsupportedRuntimeException, LimitExceededException,\r
                        JobSubmissionException {\r
-               WSUtil.validateFastaInput(sequences);\r
+\r
+               WSUtil.validateAAConInput(sequences);\r
                ConfiguredExecutable<AACon> confAAcon = init(sequences);\r
 \r
                // set default conservation method to fastest - SHENKIN\r
@@ -155,7 +156,7 @@ public class AAConWS implements SequenceAnnotation<AACon> {
                        List<Option<AACon>> options) throws UnsupportedRuntimeException,\r
                        LimitExceededException, JobSubmissionException,\r
                        WrongParameterException {\r
-               WSUtil.validateFastaInput(sequences);\r
+               WSUtil.validateAAConInput(sequences);\r
                ConfiguredExecutable<AACon> confAACon = init(sequences);\r
                // Could not do that! Space separated values\r
                // will all be treated as keys! thus duplicates removed\r
@@ -172,7 +173,7 @@ public class AAConWS implements SequenceAnnotation<AACon> {
                        Preset<AACon> preset) throws UnsupportedRuntimeException,\r
                        LimitExceededException, JobSubmissionException,\r
                        WrongParameterException {\r
-               WSUtil.validateFastaInput(sequences);\r
+               WSUtil.validateAAConInput(sequences);\r
                if (preset == null) {\r
                        throw new WrongParameterException("Preset must be provided!");\r
                }\r
index 9895289..6f33f24 100644 (file)
@@ -52,11 +52,18 @@ public final class WSUtil {
        }\r
 \r
        public static final void validateFastaInput(List<FastaSequence> sequences)\r
-                       throws InvalidParameterException {\r
+                       throws JobSubmissionException {\r
                if (sequences == null || sequences.isEmpty()) {\r
-                       throw new InvalidParameterException(\r
+                       throw new JobSubmissionException(\r
                                        "List of fasta sequences required but not provided! ");\r
                }\r
+               for (FastaSequence fs : sequences) {\r
+                       if (fs.getLength() == 0) {\r
+                               throw new JobSubmissionException(\r
+                                               "Sequence must not be empty! Sequence: " + fs.getId()\r
+                                                               + " was empty");\r
+                       }\r
+               }\r
        }\r
 \r
        public static JobStatus getJobStatus(String jobId) {\r
@@ -111,6 +118,25 @@ public final class WSUtil {
                return oList;\r
        }\r
 \r
+       public static void validateAAConInput(List<FastaSequence> sequences)\r
+                       throws JobSubmissionException {\r
+               validateFastaInput(sequences);\r
+               int len = 0;\r
+               for (FastaSequence fs : sequences) {\r
+                       if (len == 0) {\r
+                               len = fs.getLength();\r
+                               continue;\r
+                       }\r
+                       if (fs.getLength() != len) {\r
+                               throw new JobSubmissionException(\r
+                                               "All sequences must be of the same length. Please align "\r
+                                                               + "the sequences prior to submission! The first sequence length is : "\r
+                                                               + len + " but the sequence '" + fs.getId()\r
+                                                               + "' length is " + fs.getLength());\r
+                       }\r
+               }\r
+       }\r
+\r
        /*\r
         * UNUSED\r
         * \r
index f8d2b22..1ee9039 100644 (file)
   <message name="ResultNotAvailableException">
     <part name="fault" element="tns:ResultNotAvailableException"/>
   </message>
-  <message name="presetAlign">
-    <part name="parameters" element="tns:presetAlign"/>
+  <message name="customAlign">
+    <part name="parameters" element="tns:customAlign"/>
   </message>
-  <message name="presetAlignResponse">
-    <part name="parameters" element="tns:presetAlignResponse"/>
+  <message name="customAlignResponse">
+    <part name="parameters" element="tns:customAlignResponse"/>
   </message>
   <message name="UnsupportedRuntimeException">
     <part name="fault" element="tns:UnsupportedRuntimeException"/>
   <message name="WrongParameterException">
     <part name="fault" element="tns:WrongParameterException"/>
   </message>
-  <message name="customAlign">
-    <part name="parameters" element="tns:customAlign"/>
+  <message name="presetAlign">
+    <part name="parameters" element="tns:presetAlign"/>
   </message>
-  <message name="customAlignResponse">
-    <part name="parameters" element="tns:customAlignResponse"/>
+  <message name="presetAlignResponse">
+    <part name="parameters" element="tns:presetAlignResponse"/>
   </message>
   <message name="align">
     <part name="parameters" element="tns:align"/>
       <output wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/getResultResponse" message="tns:getResultResponse"/>
       <fault message="tns:ResultNotAvailableException" name="ResultNotAvailableException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/getResult/Fault/ResultNotAvailableException"/>
     </operation>
-    <operation name="presetAlign">
-      <input wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlignRequest" message="tns:presetAlign"/>
-      <output wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlignResponse" message="tns:presetAlignResponse"/>
-      <fault message="tns:UnsupportedRuntimeException" name="UnsupportedRuntimeException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/UnsupportedRuntimeException"/>
-      <fault message="tns:LimitExceededException" name="LimitExceededException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/LimitExceededException"/>
-      <fault message="tns:JobSubmissionException" name="JobSubmissionException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/JobSubmissionException"/>
-      <fault message="tns:WrongParameterException" name="WrongParameterException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/WrongParameterException"/>
-    </operation>
     <operation name="customAlign">
       <input wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/customAlignRequest" message="tns:customAlign"/>
       <output wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/customAlignResponse" message="tns:customAlignResponse"/>
       <fault message="tns:JobSubmissionException" name="JobSubmissionException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/customAlign/Fault/JobSubmissionException"/>
       <fault message="tns:WrongParameterException" name="WrongParameterException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/customAlign/Fault/WrongParameterException"/>
     </operation>
+    <operation name="presetAlign">
+      <input wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlignRequest" message="tns:presetAlign"/>
+      <output wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlignResponse" message="tns:presetAlignResponse"/>
+      <fault message="tns:UnsupportedRuntimeException" name="UnsupportedRuntimeException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/UnsupportedRuntimeException"/>
+      <fault message="tns:LimitExceededException" name="LimitExceededException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/LimitExceededException"/>
+      <fault message="tns:JobSubmissionException" name="JobSubmissionException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/JobSubmissionException"/>
+      <fault message="tns:WrongParameterException" name="WrongParameterException" wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/presetAlign/Fault/WrongParameterException"/>
+    </operation>
     <operation name="align">
       <input wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/alignRequest" message="tns:align"/>
       <output wsam:Action="http://msa.data.compbio/01/01/2010/MsaWS/alignResponse" message="tns:alignResponse"/>
         <soap:fault name="ResultNotAvailableException" use="literal"/>
       </fault>
     </operation>
-    <operation name="presetAlign">
+    <operation name="customAlign">
       <soap:operation soapAction=""/>
       <input>
         <soap:body use="literal"/>
         <soap:fault name="WrongParameterException" use="literal"/>
       </fault>
     </operation>
-    <operation name="customAlign">
+    <operation name="presetAlign">
       <soap:operation soapAction=""/>
       <input>
         <soap:body use="literal"/>