4 * <p>Title: JalviewX</p>
5 * <p>Description: Jalview Re-engineered</p>
6 * <p>Copyright: Copyright (c) 2004</p>
7 * <p>Company: Dundee University</p>
8 * @author not attributable
10 * Commenced 14th January 2005, Jim Procter
11 * Contains and depends on GPL-2 jemboss classes
12 * see http://www.rfcgr.mrc.ac.uk/Software/EMBOSS/Jemboss/index.html
17 * Jemboss webservices are implemented here as re-entrant synchronous SOAP
18 * exchanges. It is up to the user of the class whether these exchanges
19 * are executed in their own thread to effect background processing
23 * Standardise the exceptions (currently errors are output on stdout)
24 * Allow server configuration
25 * Throw away JembossParams and Jemboss dependence
26 * Generalise results to return collections of objects - alignments, trees, annotations, etc.
30 import java.security.*;
34 import ext.jemboss.soap.*;
35 import jalview.datamodel.*;
41 private static ext.jemboss.JembossParams vamsas_server;
45 // Set up default jalview-jemboss server properties
47 vamsas_server = new JembossParams();
48 vamsas_server.setCurrentMode("interactive");
49 System.out.println("Jemboss Server Init\n"
50 + vamsas_server.serverDescription()
51 + "\nUser Authorisation ? "
52 + vamsas_server.getUseAuth()
56 /* public void updateServer(JembossParams props)
58 vamsas_server.updateJembossPropStrings (
59 props.getEmbossEnvironmentArray());
62 private Hashtable uniquify(SequenceI[] sequences) {
63 // Generate a safely named sequence set and a hash to recover the sequence names
64 Hashtable map = new Hashtable();
65 for (int i=0; i<sequences.length; i++) {
66 String safename = new String("Sequence"+i);
67 map.put(safename, sequences[i].getName());
68 sequences[i].setName(safename);
73 private boolean deuniquify(Hashtable map, SequenceI[] sequences) {
74 // recover unsafe sequence names for a sequence set
75 boolean allfound=true;
76 for (int i=0; i<sequences.length; i++) {
77 if (map.containsKey(sequences[i].getName())) {
78 String unsafename = (String) map.get(sequences[i].getName());
79 sequences[i].setName(unsafename);
87 public SequenceI[] clustalW(SequenceI[] sequences)
90 // Simplest client call - with gumph from jemboss.server.TestPrivateServer
91 if (vamsas_server.getPublicSoapURL().startsWith("https"))
94 // System.setProperty ("javax.net.debug", "all");
95 com.sun.net.ssl.internal.ssl.Provider p =
96 new com.sun.net.ssl.internal.ssl.Provider();
97 Security.addProvider(p);
99 //have to do it this way to work with JNLP
100 URL.setURLStreamHandlerFactory( new URLStreamHandlerFactory()
102 public URLStreamHandler createURLStreamHandler(final String protocol)
104 if(protocol != null && protocol.compareTo("https") == 0)
106 return new com.sun.net.ssl.internal.www.protocol.https.Handler();
112 //location of keystore
113 System.setProperty("javax.net.ssl.trustStore",
114 "resources/client.keystore");
116 String jembossClientKeyStore = System.getProperty("user.home") +
117 "/.jembossClientKeystore";
121 new JembossJarUtil("resources/client.jar").writeByteFile(
122 "client.keystore",jembossClientKeyStore);
123 System.setProperty("javax.net.ssl.trustStore",
124 jembossClientKeyStore);
126 catch(Exception exp){}
130 Hashtable filesToMove = new Hashtable();
131 String embossCommand = "emma -sequence jalseqs.fasta -auto";
133 SequenceI[] myseq = new SequenceI[sequences.length];
134 for (int i=0; i<sequences.length; i++) {
135 myseq[i] = new Sequence(sequences[i]);
138 Hashtable namemap = uniquify(myseq);
139 // Load sequence file into hash
141 filesToMove.put("jalseqs.fasta",
142 jalview.io.FastaFile.print(myseq,124,false, false).getBytes());
144 if(vamsas_server.getUseAuth() == true)
145 if(vamsas_server.getServiceUserName() == null)
146 System.out.println("jalview.Jemboss: OOPS! Authentication required!");
148 // submit to private server
151 JembossRun thisrun = new JembossRun(embossCommand,"",
152 filesToMove,vamsas_server);
153 Hashtable h = thisrun.hash();
154 Enumeration enum = h.keys();
155 // Find the alignment generated and parse it
156 while (enum.hasMoreElements())
158 String thiskey = (String)enum.nextElement().toString();
159 if (thiskey.endsWith(".aln"))
161 // FormatAdapter, and IdentifyFile use a protocol string
162 // to work out what 'file' is - file/url/Alignmentasastring
163 String alfile = h.get(thiskey).toString();
164 String format = IdentifyFile.Identify(alfile, "Paste");
165 SequenceI[] alignment = null;
167 if (FormatProperties.contains(format))
168 alignment = FormatAdapter.read(alfile, "Paste", format);
170 System.out.println("jalview.Jemboss: Unknown format "+format+"\n");
171 if (alignment == null)
172 System.out.println("jalview.Jemboss: Couldn't read response:\n"
173 + alfile + "\n---EOF\n");
175 if (!deuniquify(namemap, alignment)) {
176 System.out.println("jalview.Jemboss: Warning: Some of the "
177 +"original sequence names have not been recovered!\n");
186 catch (JembossSoapException eae)
188 System.out.println("jalview.Jemboss: SOAP ERROR :"+embossCommand
191 catch (Exception e) {
192 System.out.println("jalview.Jemboss: Some other failure :\n"
193 +e.getMessage()+"\n");