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