X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fws%2Fclient%2FJws2Client.java;h=eac049e3fd90259ffa8470275cf284dbb9516339;hb=4c022b67a736b6f79dbe212d73016607cf298422;hp=0aa02c59b644115f54a3138b9fe0dfea77942e19;hpb=811c3d0faf8c9c9ed2d493e1627db6bb94260e47;p=jabaws.git 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