From: pvtroshin Date: Wed, 9 Feb 2011 14:51:20 +0000 (+0000) Subject: DisEMBL and GlobProt web services further work X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a79900255139dc7bcab23320de2a3630f6531107;p=jabaws.git DisEMBL and GlobProt web services further work git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3727 e3abac25-378b-4346-85de-24260fe3988d --- diff --git a/datamodel/compbio/data/sequence/SequenceUtil.java b/datamodel/compbio/data/sequence/SequenceUtil.java index 754cf5f..3990f8f 100644 --- a/datamodel/compbio/data/sequence/SequenceUtil.java +++ b/datamodel/compbio/data/sequence/SequenceUtil.java @@ -30,7 +30,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Scanner; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.logging.Level; @@ -365,7 +364,7 @@ public final class SequenceUtil { infasta.close(); return seqs; } - + private static float[] convertToNumber(String[] annotValues) throws UnknownFileFormatException { float[] annotation = new float[annotValues.length]; @@ -431,7 +430,7 @@ public final class SequenceUtil { * @throws IOException * @throws UnknownFileFormatException */ - public static Map> readDisembl( + public static HashMap> readDisembl( final InputStream input) throws IOException, UnknownFileFormatException { Scanner scan = new Scanner(input); @@ -443,7 +442,7 @@ public final class SequenceUtil { + " No such line was found!"); } - Map> results = new HashMap>(); + HashMap> results = new HashMap>(); int seqCounter = 0; while (scan.hasNext()) { seqCounter++; @@ -478,7 +477,7 @@ public final class SequenceUtil { } FastaSequence fs = new FastaSequence(sequenceName, seqbuffer.toString()); - Set scores = new HashSet(); + HashSet scores = new HashSet(); scores.add(new Score(DisemblResult.COILS, coils, coilsR)); scores.add(new Score(DisemblResult.HOTLOOPS, hotloops, rem465R)); scores.add(new Score(DisemblResult.REM465, rem, loopsR)); @@ -486,7 +485,7 @@ public final class SequenceUtil { scansingle.close(); } - + scan.close(); input.close(); return results; } @@ -506,10 +505,12 @@ public final class SequenceUtil { */ private static SortedSet parseRanges(Enum resultType, String lines) { SortedSet ranges = new TreeSet(); + Scanner scan = new Scanner(lines); assert scan.hasNext(); - assert "#".equals(scan.next()); // pass delimiter # + String del = scan.next(); + assert "#".equals(del); // pass delimiter # String type = scan.next(); // pass enum name e.g. COILS assert resultType.toString().equalsIgnoreCase(type) : "Unknown result type: " + resultType.toString(); @@ -525,10 +526,10 @@ public final class SequenceUtil { return ranges; } - public static Map> removeSequences( - Map> disemblResults) { - Map> seqNameScores = new HashMap>(); - for (Map.Entry> dres : disemblResults + public static HashMap> removeSequences( + HashMap> disemblResults) { + HashMap> seqNameScores = new HashMap>(); + for (Map.Entry> dres : disemblResults .entrySet()) { seqNameScores.put(dres.getKey().getId(), dres.getValue()); } @@ -559,7 +560,7 @@ public final class SequenceUtil { * @throws IOException * @throws UnknownFileFormatException */ - public static Map> readGlobPlot( + public static HashMap> readGlobPlot( final InputStream input) throws IOException, UnknownFileFormatException { Scanner scan = new Scanner(input); @@ -571,7 +572,7 @@ public final class SequenceUtil { + " No such line was found!"); } - Map> results = new HashMap>(); + HashMap> results = new HashMap>(); int seqCounter = 0; while (scan.hasNext()) { seqCounter++; @@ -604,7 +605,7 @@ public final class SequenceUtil { } FastaSequence fs = new FastaSequence(sequenceName, seqbuffer.toString()); - Set scores = new HashSet(); + HashSet scores = new HashSet(); scores.add(new Score(GlobProtResult.Disorder, disorderR)); scores.add(new Score(GlobProtResult.GlobDoms, domsR)); scores.add(new Score(GlobProtResult.Dydx, dydxScore)); @@ -614,7 +615,7 @@ public final class SequenceUtil { scansingle.close(); } - + scan.close(); input.close(); return results; } diff --git a/runner/compbio/runner/disorder/Disembl.java b/runner/compbio/runner/disorder/Disembl.java index 83ca5d3..616b552 100644 --- a/runner/compbio/runner/disorder/Disembl.java +++ b/runner/compbio/runner/disorder/Disembl.java @@ -19,8 +19,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; -import java.util.Set; +import java.util.HashMap; +import java.util.HashSet; import org.apache.log4j.Logger; @@ -84,12 +84,13 @@ public class Disembl extends SkeletalExecutable } @SuppressWarnings("unchecked") - public Map> getResults(String workDirectory) + @Override + public HashMap> getResults(String workDirectory) throws ResultNotAvailableException { InputStream inStream = null; - Map> results = null; - // How about getting ranges? + HashMap> results = null; + try { inStream = new FileInputStream(new File(workDirectory, getOutput())); results = SequenceUtil.removeSequences(SequenceUtil @@ -108,7 +109,7 @@ public class Disembl extends SkeletalExecutable log.error(e.getMessage(), e.getCause()); throw new ResultNotAvailableException(e); } - + log.trace("DRESULTS: " + results); return results; } diff --git a/runner/compbio/runner/disorder/GlobPlot.java b/runner/compbio/runner/disorder/GlobPlot.java index 2284671..99420f5 100644 --- a/runner/compbio/runner/disorder/GlobPlot.java +++ b/runner/compbio/runner/disorder/GlobPlot.java @@ -19,8 +19,8 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; -import java.util.Set; +import java.util.HashMap; +import java.util.HashSet; import org.apache.log4j.Logger; @@ -70,11 +70,11 @@ public class GlobPlot extends SkeletalExecutable } @SuppressWarnings("unchecked") - public Map> getResults(String workDirectory) + public HashMap> getResults(String workDirectory) throws ResultNotAvailableException { InputStream inStream = null; - Map> results = null; + HashMap> results = null; // How about getting ranges? try { inStream = new FileInputStream(new File(workDirectory, getOutput())); diff --git a/testsrc/compbio/data/sequence/SequenceUtilTester.java b/testsrc/compbio/data/sequence/SequenceUtilTester.java index 7f45855..a4bf4c9 100644 --- a/testsrc/compbio/data/sequence/SequenceUtilTester.java +++ b/testsrc/compbio/data/sequence/SequenceUtilTester.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -164,11 +165,11 @@ public class SequenceUtilTester { try { fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "disembl.out"); - Map> aseqs = SequenceUtil + Map> aseqs = SequenceUtil .readDisembl(fio); assertNotNull(aseqs); assertEquals(aseqs.size(), 3); - System.out.println(aseqs); + // System.out.println(aseqs); for (FastaSequence fs : aseqs.keySet()) { assertTrue(" Foobar_dundeefriends Foobar dundeefriends " .contains(fs.getId())); @@ -217,7 +218,7 @@ public class SequenceUtilTester { try { fio = new FileInputStream(AllTestSuit.TEST_DATA_PATH + "globplot.out"); - Map> aseqs = SequenceUtil + HashMap> aseqs = SequenceUtil .readGlobPlot(fio); assertNotNull(aseqs); assertEquals(aseqs.size(), 3); @@ -232,12 +233,12 @@ public class SequenceUtilTester { assertEquals(scores.size(), 5); } for (Score score : scores) { - + if (score.getMethod() == (Enum) GlobProtResult.Disorder) { assertEquals(score.getRanges().size(), 7); assertTrue(score.getScores().isEmpty()); } - if (score.getMethod() == (Enum)GlobProtResult.Dydx) { + if (score.getMethod() == (Enum) GlobProtResult.Dydx) { assertFalse(score.getScores().isEmpty()); assertTrue(score.getRanges().isEmpty()); } diff --git a/testsrc/testdata/disembl.out b/testsrc/testdata/disembl.out index cb9301d..eaa316d 100644 --- a/testsrc/testdata/disembl.out +++ b/testsrc/testdata/disembl.out @@ -1,7 +1,7 @@ > Foobar_dundeefriends # COILS 34-41, 50-58, 83-91, 118-127, 160-169, 191-220, 243-252, 287-343, 350-391, 429-485, 497-506, 539-547 # REM465 355-368 -# HOTLOOPS +# HOTLOOPS 190-204 # RESIDUE COILS REM465 HOTLOOPS M 0.86010 0.88512 0.37094 T 0.79983 0.85864 0.44331 diff --git a/webservices/compbio/ws/client/Jws2Client.java b/webservices/compbio/ws/client/Jws2Client.java index 62aa383..1fc2a68 100644 --- a/webservices/compbio/ws/client/Jws2Client.java +++ b/webservices/compbio/ws/client/Jws2Client.java @@ -37,6 +37,7 @@ import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -160,17 +161,17 @@ public class Jws2Client { // std.out will not be outStream = System.out; } - if (service == Services.AAConWS) { + if (service.getServiceType() == SequenceAnnotation.class) { Map> result = analize(inputFile, ((SequenceAnnotation) msaws), preset, customOptions); + assert result != null && !result.values().isEmpty() : "No Result reported!"; IOHelper.writeOut(outStream, result); } else { alignment = align(inputFile, (MsaWS) msaws, preset, customOptions); IOHelper.writeOut(outStream, alignment); } - - // stream is closed in the method no need to close it here + outStream.close(); } boolean listParameters = CmdHelper.listParameters(cmd); @@ -203,12 +204,12 @@ public class Jws2Client { * @return Set the conservation scores * @throws UnknownFileFormatException */ - Map> analize(File file, + HashMap> analize(File file, SequenceAnnotation wsproxy, Preset preset, List> customOptions) { List fastalist = null; - Map> scores = null; + HashMap> scores = null; try { fastalist = SequenceUtil.openInputStream(file.getAbsolutePath()); @@ -224,8 +225,9 @@ public class Jws2Client { } else { jobId = wsproxy.analize(fastalist); } - Thread.sleep(1000); + Thread.sleep(2000); scores = wsproxy.getAnnotation(jobId); + assert scores != null && !scores.values().isEmpty() : "Scores are NULL"; } catch (IOException e) { System.err @@ -289,6 +291,10 @@ public class Jws2Client { serv = service.getService(url, V2_QUALIFIED_SERVICE_NAME); } } + if (serv == null) { + System.err.println("Could not connect to " + url); + // FIXME + } JABAService serviceIF = service.getInterface(serv); log.log(Level.FINE, "Connected successfully!"); @@ -428,7 +434,7 @@ public class Jws2Client { /** * Starts command line client, if no parameter are supported print help. Two - * parameters are required for successfull call the JWS2 host name and a + * parameters are required for successful call the JWS2 host name and a * service name. * * @param args diff --git a/webservices/compbio/ws/client/Services.java b/webservices/compbio/ws/client/Services.java index f18eadf..a0c1f56 100644 --- a/webservices/compbio/ws/client/Services.java +++ b/webservices/compbio/ws/client/Services.java @@ -32,7 +32,7 @@ import compbio.data.msa.SequenceAnnotation; * */ public enum Services { - MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS; + MafftWS, MuscleWS, ClustalWS, TcoffeeWS, ProbconsWS, AAConWS, JronnWS, DisemblWS, GlobPlotWS; public static Services getService(String servName) { servName = servName.trim().toLowerCase(); @@ -54,6 +54,15 @@ public enum Services { if (servName.equalsIgnoreCase(AAConWS.toString())) { return AAConWS; } + if (servName.equalsIgnoreCase(JronnWS.toString())) { + return JronnWS; + } + if (servName.equalsIgnoreCase(DisemblWS.toString())) { + return DisemblWS; + } + if (servName.equalsIgnoreCase(GlobPlotWS.toString())) { + return GlobPlotWS; + } return null; } @@ -62,15 +71,15 @@ public enum Services { return Service.create(url, qname); } - JABAService getInterface(Service service) { - assert service != null; - - QName portName = new QName(service.getServiceName().getNamespaceURI(), - this.toString() + "Port"); - + Class getServiceType() { switch (this) { + // deliberate leaking case AAConWS : - return service.getPort(portName, SequenceAnnotation.class); + case JronnWS : + case DisemblWS : + case GlobPlotWS : + + return SequenceAnnotation.class; // deliberate leaking case ClustalWS : @@ -78,13 +87,19 @@ public enum Services { case MuscleWS : case ProbconsWS : case TcoffeeWS : - // TODO remove - System.out.println("Qname from serv: " + portName); - - return service.getPort(portName, MsaWS.class); + return MsaWS.class; default : - throw new RuntimeException("Should never happened!"); + throw new RuntimeException("Unrecognised Web Service Type " + + this + " - Should never happened!"); } } + + JABAService getInterface(Service service) { + assert service != null; + + QName portName = new QName(service.getServiceName().getNamespaceURI(), + this.toString() + "Port"); + return service.getPort(portName, this.getServiceType()); + } } \ No newline at end of file diff --git a/webservices/compbio/ws/server/DisemblWS.java b/webservices/compbio/ws/server/DisemblWS.java index 00f3f69..061f9a6 100644 --- a/webservices/compbio/ws/server/DisemblWS.java +++ b/webservices/compbio/ws/server/DisemblWS.java @@ -61,10 +61,10 @@ public class DisemblWS implements SequenceAnnotation { throws ResultNotAvailableException { WSUtil.validateJobId(jobId); AsyncExecutor asyncEngine = Configurator.getAsyncEngine(jobId); - ConfiguredExecutable aacon = (ConfiguredExecutable) asyncEngine + ConfiguredExecutable disembl = (ConfiguredExecutable) asyncEngine .getResults(jobId); - HashMap> mas = aacon.getResults(); - log.trace(jobId + " getConservation : " + mas); + HashMap> mas = disembl.getResults(); + log.trace(jobId + " getDisorder : " + mas); return mas; }