Fix problem with the JpredWS service. Now Jws2Client is able to test the service
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Wed, 11 Sep 2013 16:13:02 +0000 (17:13 +0100)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Wed, 11 Sep 2013 16:13:02 +0000 (17:13 +0100)
datamodel/compbio/data/sequence/Alignment.java
datamodel/compbio/data/sequence/JpredAlignment.java
webservices/compbio/ws/client/Jws2Client.java
webservices/compbio/ws/server/JpredWS.java

index 3952d25..0893082 100644 (file)
@@ -41,11 +41,10 @@ import compbio.util.annotation.Immutable;
  * \r
  */\r
 @XmlAccessorType(XmlAccessType.FIELD)\r
-@Immutable\r
 public class Alignment {\r
 \r
-       private AlignmentMetadata metadata;\r
-       private List<FastaSequence> sequences;\r
+       protected AlignmentMetadata metadata;\r
+       protected List<FastaSequence> sequences;\r
 \r
        protected Alignment() {\r
                // This has to has a default constructor for JaxB\r
index c7f612f..768ac9e 100644 (file)
@@ -43,21 +43,8 @@ import compbio.data.sequence.Alignment;
  * \r
  */\r
 @XmlAccessorType(XmlAccessType.FIELD)\r
-@Immutable\r
 public final class JpredAlignment extends Alignment{\r
 \r
-       private AlignmentMetadata metadata;\r
-       private List<FastaSequence> sequences;\r
-       \r
-       FastaSequence jnetpred;\r
-       FastaSequence JNETCONF;\r
-       FastaSequence JNETSOL25;\r
-       FastaSequence JNETSOL5;\r
-       FastaSequence JNETSOL0;\r
-       FastaSequence JNETHMM;\r
-       FastaSequence JNETPSSM;\r
-       FastaSequence JNETJURY;\r
-\r
        private JpredAlignment() {\r
                // This has to has a default constructor for JaxB\r
        }\r
@@ -67,10 +54,9 @@ public final class JpredAlignment extends Alignment{
         * @param program\r
         * @param gapchar\r
         */\r
-       public JpredAlignment(List<FastaSequence> sequences, Program program,\r
-                       char gapchar) {\r
-               DecomposeInitalJpredSeq(sequences);\r
-               this.metadata = new AlignmentMetadata(Program.CLUSTAL, gapchar);\r
+       public JpredAlignment(List<FastaSequence> sequences, Program program, char gapchar) {\r
+               this.sequences = sequences;\r
+               this.metadata = new AlignmentMetadata(Program.Jpred, gapchar);\r
        }\r
 \r
        /**\r
@@ -79,48 +65,60 @@ public final class JpredAlignment extends Alignment{
         * @param metadata\r
         */\r
        public JpredAlignment(List<FastaSequence> sequences, AlignmentMetadata metadata) {\r
-               DecomposeInitalJpredSeq(sequences);\r
+               this.sequences = sequences;\r
                this.metadata = metadata;\r
        }\r
 \r
-       /**\r
-        * \r
-        * @param sequences\r
-        */\r
-       private void DecomposeInitalJpredSeq(List<FastaSequence> sequences) {\r
+       private List<FastaSequence> getRealSeqs() {\r
                List<FastaSequence> realsequences = new ArrayList<FastaSequence>();\r
-               for (FastaSequence s : sequences) {\r
-                       if (s.getId().equals("jnetpred")) {\r
-                               this.jnetpred = s;\r
-                       } else if (s.getId().equals("JNETCONF")) {\r
-                               this.JNETCONF = s;\r
-                       } else if (s.getId().equals("JNETSOL25")) {\r
-                               this.JNETSOL25 = s;\r
-                       } else if (s.getId().equals("JNETSOL5")) {\r
-                               this.JNETSOL5 = s;\r
-                       } else if (s.getId().equals("JNETSOL0")) {\r
-                               this.JNETSOL0 = s;\r
-                       } else if (s.getId().equals("JNETHMM")) {\r
-                               this.JNETSOL0 = s;\r
-                       } else if (s.getId().equals("JNETHMM")) {\r
-                               this.JNETHMM = s;\r
-                       } else if (s.getId().equals("JNETSOL0")) {\r
-                               this.JNETPSSM = s;\r
-                       } else if (s.getId().equals("JNETHMM")) {\r
-                               this.JNETJURY = s;\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("jnetpred") || \r
+                               s.getId().equals("JNETCONF") ||\r
+                               s.getId().equals("JNETSOL25") ||\r
+                               s.getId().equals("JNETSOL5") ||\r
+                               s.getId().equals("JNETSOL0") ||\r
+                               s.getId().equals("JNETHMM") ||\r
+                               s.getId().equals("JNETHMM") ||\r
+                               s.getId().equals("JNETSOL0") ||\r
+                               s.getId().equals("JNETHMM")) {\r
+                               // do nothing;\r
                        } else {\r
                                realsequences.add(s);\r
                        }\r
                }\r
-               this.sequences = realsequences;\r
+               return realsequences;\r
        }\r
 \r
+\r
+       public List<FastaSequence> getJpredSequences() {\r
+               List<FastaSequence> realsequences = new ArrayList<FastaSequence>();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("jnetpred") || \r
+                               s.getId().equals("JNETCONF") ||\r
+                               s.getId().equals("JNETSOL25") ||\r
+                               s.getId().equals("JNETSOL5") ||\r
+                               s.getId().equals("JNETSOL0") ||\r
+                               s.getId().equals("JNETHMM") ||\r
+                               s.getId().equals("JNETHMM") ||\r
+                               s.getId().equals("JNETSOL0") ||\r
+                               s.getId().equals("JNETSOL0") ||\r
+                               s.getId().equals("QUERY")) {\r
+                               realsequences.add(s);\r
+                       }\r
+               }\r
+               return realsequences;\r
+       }\r
        /**\r
         * \r
         * @return Jpred prediction \r
         */\r
        public String getJpredPrediction() {\r
-               return this.jnetpred.getSequence();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("jnetpred")) {\r
+                         return s.getSequence();\r
+                       }\r
+               }\r
+               return new String("");\r
        }\r
 \r
        /**\r
@@ -128,7 +126,12 @@ public final class JpredAlignment extends Alignment{
         * @return Jpred JNETSOL25 line\r
         */\r
        public String getJpredSOL25() {\r
-               return this.JNETSOL25.getSequence();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("JNETSOL25")) {\r
+                         return s.getSequence();\r
+                       }\r
+               }\r
+               return new String("");\r
        }\r
 \r
        /**\r
@@ -136,64 +139,54 @@ public final class JpredAlignment extends Alignment{
         * @return Jpred JNETSOL5 line\r
         */\r
        public String getJpredSOL5() {\r
-               return this.JNETSOL5.getSequence();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("JNETSOL5")) {\r
+                         return s.getSequence();\r
+                       }\r
+               }\r
+               return new String("");\r
        }\r
        /**\r
         * \r
         * @return Jpred JNETSOL0 line\r
         */\r
        public String getJpredSOL0() {\r
-               return this.JNETSOL0.getSequence();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("JNETSOL0")) {\r
+                         return s.getSequence();\r
+                       }\r
+               }\r
+               return new String("");\r
        }\r
        /**\r
         * \r
         * @return Jpred JNETCONF line\r
         */\r
        public String getJpredJNETCONF() {\r
-               return this.JNETCONF.getSequence();\r
+               for (FastaSequence s : this.sequences) {\r
+                       if (s.getId().equals("JNETCONF")) {\r
+                         return s.getSequence();\r
+                       }\r
+               }\r
+               return new String("");\r
        }\r
+\r
        /**\r
         * \r
         * @return list of FastaSequence records\r
         */\r
+       @Override\r
        public List<FastaSequence> getSequences() {\r
-               return sequences;\r
+               return this.getRealSeqs();\r
        }\r
 \r
        /**\r
         * \r
         * @return a number of sequence in the alignment\r
         */\r
-       public int getSize() {\r
-               return this.sequences.size();\r
-       }\r
-\r
-       /**\r
-        * \r
-        * @return AlignmentMetadata object\r
-        */\r
-       public AlignmentMetadata getMetadata() {\r
-               return metadata;\r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               String sseq = "";\r
-               for (FastaSequence fs : getSequences()) {\r
-                       sseq += fs.toString() + "\n";\r
-               }\r
-               return sseq;\r
-       }\r
-\r
        @Override\r
-       public int hashCode() {\r
-               final int prime = 31;\r
-               int result = 1;\r
-               result = prime * result\r
-                               + ((metadata == null) ? 0 : metadata.hashCode());\r
-               result = prime * result\r
-                               + ((sequences == null) ? 0 : sequences.hashCode());\r
-               return result;\r
+       public int getSize() {\r
+               return this.getRealSeqs().size();\r
        }\r
 \r
        /**\r
@@ -205,10 +198,10 @@ public final class JpredAlignment extends Alignment{
                if (obj == null) {\r
                        return false;\r
                }\r
-               if (!(obj instanceof Alignment)) {\r
+               if (!(obj instanceof JpredAlignment)) {\r
                        return false;\r
                }\r
-               Alignment al = (Alignment) obj;\r
+               JpredAlignment al = (JpredAlignment) obj;\r
                if (this.getSize() != al.getSize()) {\r
                        return false;\r
                }\r
@@ -230,7 +223,6 @@ public final class JpredAlignment extends Alignment{
                                return false;\r
                        }\r
                }\r
-\r
                return true;\r
        }\r
 \r
index 0aa02c5..eac049e 100644 (file)
@@ -25,7 +25,9 @@ import static compbio.ws.client.Constraints.paramFile;
 import java.io.Closeable;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
+import java.io.FileOutputStream;\r
 import java.io.IOException;\r
+import java.io.OutputStream;\r
 import java.io.PrintWriter;\r
 import java.io.Writer;\r
 import java.net.ConnectException;\r
@@ -48,6 +50,8 @@ import compbio.data.msa.MsaWS;
 import compbio.data.msa.RegistryWS;\r
 import compbio.data.msa.SequenceAnnotation;\r
 import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.AlignmentMetadata;\r
+import compbio.data.sequence.JpredAlignment;\r
 import compbio.data.sequence.FastaSequence;\r
 import compbio.data.sequence.ScoreManager;\r
 import compbio.data.sequence.SequenceUtil;\r
@@ -100,6 +104,7 @@ public class Jws2Client {
         *            command line options\r
         * @throws IOException\r
         */\r
+       @SuppressWarnings("unchecked")\r
        <T> Jws2Client(String[] cmd) throws IOException {\r
                \r
 \r
@@ -161,17 +166,29 @@ public class Jws2Client {
                        if (outfile != null) {\r
                                writer = IOHelper.getWriter(outfile);\r
                        } else {\r
-                               // this stream is going to be closed later which is fine as std.out will not be\r
                                writer = new PrintWriter(System.out, true);\r
                        }\r
                        if (service.getServiceType() == SequenceAnnotation.class) {\r
                                ScoreManager result = analize(infile, ((SequenceAnnotation<T>) thews), preset, customOptions);\r
                                IOHelper.writeOut(writer, result);\r
+                               writer.close();\r
                        } else if (service.getServiceType() == MsaWS.class) {\r
                                Alignment alignment = align(infile, (MsaWS<T>) thews, preset, customOptions);\r
-                               IOHelper.writeOut(writer, alignment);\r
+                               if (serviceName.equalsIgnoreCase("JpredWS")) {\r
+                                       writer.close();\r
+                                       JpredAlignment jpred = new JpredAlignment(alignment.getSequences(), alignment.getMetadata());\r
+                                       if (outfile != null) {\r
+                                               FileOutputStream fout = new FileOutputStream(outfile);\r
+                                               SequenceUtil.writeFastaKeepTheStream(fout, jpred.getJpredSequences(), 60);\r
+                                               fout.close();\r
+                                       } else {\r
+                                               SequenceUtil.writeFasta(System.out, jpred.getJpredSequences());\r
+                                       }\r
+                               } else {\r
+                                       IOHelper.writeOut(writer, alignment);\r
+                                       writer.close();\r
+                               }\r
                        }\r
-                       writer.close();\r
                }\r
 \r
                if (CmdHelper.listParameters(cmd)) {\r
@@ -412,11 +429,10 @@ public class Jws2Client {
        static <T> Alignment align(File file, MsaWS<T> msaws, Preset<T> preset,\r
                        List<Option<T>> customOptions) {\r
                FileInputStream instream = null;\r
-               List<FastaSequence> fastalist = null;\r
                Alignment alignment = null;\r
                try {\r
                        instream = new FileInputStream(file);\r
-                       fastalist = SequenceUtil.readFasta(instream);\r
+                       List<FastaSequence> fastalist = SequenceUtil.readFasta(instream);\r
                        instream.close();\r
                        String jobId = null;\r
                        if (customOptions != null && preset != null) {\r
@@ -429,22 +445,18 @@ public class Jws2Client {
                        } else {\r
                                jobId = msaws.align(fastalist);\r
                        }\r
-                       System.out.println("\ncalling aligner.........");\r
-                       Thread.sleep(1000);\r
+                       System.out.println("\ncalling program.........");\r
+                       Thread.sleep(100);\r
                        alignment = msaws.getResult(jobId);\r
-\r
                } catch (IOException e) {\r
-                       System.err.println("Exception while reading the input file. "\r
-                                               + "Check that the input file contains a list of fasta formatted sequences! "\r
+                       System.err.println("Exception while reading the input file. Check that the input file is a FASTA file! "\r
                                                + "Exception details are below:");\r
                        e.printStackTrace();\r
                } catch (JobSubmissionException e) {\r
-                       System.err.println("Exception while submitting job to a web server. "\r
-                                               + "Exception details are below:");\r
+                       System.err.println("Exception while submitting job to a web server. Exception details are below:");\r
                        e.printStackTrace();\r
                } catch (ResultNotAvailableException e) {\r
-                       System.err.println("Exception while waiting for results. "\r
-                                       + "Exception details are below:");\r
+                       System.err.println("Exception while waiting for results. Exception details are below:");\r
                        e.printStackTrace();\r
                } catch (InterruptedException ignored) {\r
                        // ignore and propagate an interruption\r
index 42529fc..b23a64b 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.log4j.Logger;
 import compbio.data.msa.JABAService;\r
 import compbio.data.msa.MsaWS;\r
 import compbio.data.sequence.Alignment;\r
+import compbio.data.sequence.JpredAlignment;\r
 import compbio.data.sequence.FastaSequence;\r
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
@@ -120,7 +121,7 @@ public class JpredWS implements MsaWS<Jpred> {
                WSUtil.validateJobId(jobId);\r
                AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId);\r
                ConfiguredExecutable<Jpred> jpred = (ConfiguredExecutable<Jpred>) asyncEngine.getResults(jobId);\r
-               return jpred.getResults();\r
+               return (Alignment)jpred.getResults();\r
        }\r
 \r
        @Override\r