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
24 * Standardise the exceptions (currently errors are output on stdout)
25 * Allow server configuration
29 import java.security.*;
33 import ext.jemboss.soap.*;
34 import jalview.datamodel.*;
40 private static ext.jemboss.JembossParams vamsas_server;
44 // Set up default jalview-jemboss server properties
46 vamsas_server = new JembossParams();
47 vamsas_server.setCurrentMode("interactive");
48 System.out.println("Jemboss Server Init\n"
49 + vamsas_server.serverDescription()
50 + "\nUser Authorisation ? "
51 + vamsas_server.getUseAuth()
55 /* public void updateServer(JembossParams props)
57 vamsas_server.updateJembossPropStrings (
58 props.getEmbossEnvironmentArray());
61 private Hashtable uniquify(SequenceI[] sequences) {
62 // Generate a safely named sequence set and a hash to recover the sequence names
63 Hashtable map = new Hashtable();
64 for (int i=0; i<sequences.length; i++) {
65 String safename = new String("Sequence"+i);
66 map.put(safename, sequences[i].getName());
67 sequences[i].setName(safename);
72 private boolean deuniquify(Hashtable map, SequenceI[] sequences) {
73 // recover unsafe sequence names for a sequence set
74 boolean allfound=true;
75 for (int i=0; i<sequences.length; i++) {
76 if (map.containsKey(sequences[i].getName())) {
77 String unsafename = (String) map.get(sequences[i].getName());
78 sequences[i].setName(unsafename);
86 public SequenceI[] clustalW(SequenceI[] sequences)
89 // Simplest client call - with gumph from jemboss.server.TestPrivateServer
90 if (vamsas_server.getPublicSoapURL().startsWith("https"))
93 // System.setProperty ("javax.net.debug", "all");
94 com.sun.net.ssl.internal.ssl.Provider p =
95 new com.sun.net.ssl.internal.ssl.Provider();
96 Security.addProvider(p);
98 //have to do it this way to work with JNLP
99 URL.setURLStreamHandlerFactory( new URLStreamHandlerFactory()
101 public URLStreamHandler createURLStreamHandler(final String protocol)
103 if(protocol != null && protocol.compareTo("https") == 0)
105 return new com.sun.net.ssl.internal.www.protocol.https.Handler();
111 //location of keystore
112 System.setProperty("javax.net.ssl.trustStore",
113 "resources/client.keystore");
115 String jembossClientKeyStore = System.getProperty("user.home") +
116 "/.jembossClientKeystore";
120 new JembossJarUtil("resources/client.jar").writeByteFile(
121 "client.keystore",jembossClientKeyStore);
122 System.setProperty("javax.net.ssl.trustStore",
123 jembossClientKeyStore);
125 catch(Exception exp){}
129 Hashtable filesToMove = new Hashtable();
130 String embossCommand = "emma -sequence jalseqs.fasta -auto";
132 SequenceI[] myseq = new SequenceI[sequences.length];
133 for (int i=0; i<sequences.length; i++) {
134 myseq[i] = new Sequence(sequences[i]);
137 Hashtable namemap = uniquify(myseq);
138 // Load sequence file into hash
140 filesToMove.put("jalseqs.fasta",
141 jalview.io.FastaFile.print(myseq,124,false).getBytes());
143 if(vamsas_server.getUseAuth() == true)
144 if(vamsas_server.getServiceUserName() == null)
145 System.out.println("jalview.Jemboss: OOPS! Authentication required!");
147 // submit to private server
150 JembossRun thisrun = new JembossRun(embossCommand,"",
151 filesToMove,vamsas_server);
152 Hashtable h = thisrun.hash();
153 Enumeration enum = h.keys();
154 // Find the alignment generated and parse it
155 while (enum.hasMoreElements())
157 String thiskey = (String)enum.nextElement().toString();
158 if (thiskey.endsWith(".aln"))
160 // FormatAdapter, and IdentifyFile use a protocol string
161 // to work out what 'file' is - file/url/Alignmentasastring
162 String alfile = h.get(thiskey).toString();
163 String format = IdentifyFile.Identify(alfile, "Paste");
164 SequenceI[] alignment = null;
166 if (FormatProperties.contains(format))
167 alignment = FormatAdapter.read(alfile, "Paste", format);
169 System.out.println("jalview.Jemboss: Unknown format "+format+"\n");
170 if (alignment == null)
171 System.out.println("jalview.Jemboss: Couldn't read response:\n"
172 + alfile + "\n---EOF\n");
174 if (!deuniquify(namemap, alignment)) {
175 System.out.println("jalview.Jemboss: Warning: Some of the "
176 +"original sequence names have not been recovered!\n");
185 catch (JembossSoapException eae)
187 System.out.println("jalview.Jemboss: SOAP ERROR :"+embossCommand
190 catch (Exception e) {
191 System.out.println("jalview.Jemboss: Some other failure :\n"
192 +e.getMessage()+"\n");