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);
86 public SequenceI[] clustalW(SequenceI[] sequences) {
87 // Does the same as below but keeps initial sequence order.
88 return (this.clustalW(sequences, true));
90 public SequenceI[] clustalW(SequenceI[] sequences, boolean PreserveOrder)
93 // Simplest client call - with gumph from jemboss.server.TestPrivateServer
94 if (vamsas_server.getPublicSoapURL().startsWith("https"))
97 // System.setProperty ("javax.net.debug", "all");
98 com.sun.net.ssl.internal.ssl.Provider p =
99 new com.sun.net.ssl.internal.ssl.Provider();
100 Security.addProvider(p);
102 //have to do it this way to work with JNLP
103 URL.setURLStreamHandlerFactory( new URLStreamHandlerFactory()
105 public URLStreamHandler createURLStreamHandler(final String protocol)
107 if(protocol != null && protocol.compareTo("https") == 0)
109 return new com.sun.net.ssl.internal.www.protocol.https.Handler();
115 //location of keystore
116 System.setProperty("javax.net.ssl.trustStore",
117 "resources/client.keystore");
119 String jembossClientKeyStore = System.getProperty("user.home") +
120 "/.jembossClientKeystore";
124 new JembossJarUtil("resources/client.jar").writeByteFile(
125 "client.keystore",jembossClientKeyStore);
126 System.setProperty("javax.net.ssl.trustStore",
127 jembossClientKeyStore);
129 catch(Exception exp){}
133 Hashtable filesToMove = new Hashtable();
134 String embossCommand = "emma -sequence jalseqs.fasta -auto";
136 SequenceI[] myseq = new SequenceI[sequences.length];
137 for (int i=0; i<sequences.length; i++) {
138 myseq[i] = new Sequence(sequences[i]);
141 Hashtable namemap = uniquify(myseq);
142 // Load sequence file into hash
144 filesToMove.put("jalseqs.fasta",
145 jalview.io.FastaFile.print(myseq,124,false, false).getBytes());
147 if(vamsas_server.getUseAuth() == true)
148 if(vamsas_server.getServiceUserName() == null)
149 System.out.println("jalview.Jemboss: OOPS! Authentication required!");
151 // submit to private server
154 JembossRun thisrun = new JembossRun(embossCommand,"",
155 filesToMove,vamsas_server);
156 Hashtable h = thisrun.hash();
157 Enumeration enumerator = h.keys();
158 // Find the alignment generated and parse it
159 while (enumerator.hasMoreElements())
161 String thiskey = (String)enumerator.nextElement().toString();
162 if (thiskey.endsWith(".aln"))
164 // FormatAdapter, and IdentifyFile use a protocol string
165 // to work out what 'file' is - file/url/Alignmentasastring
166 String alfile = h.get(thiskey).toString();
167 String format = IdentifyFile.Identify(alfile, "Paste");
168 SequenceI[] alignment = null;
170 if (FormatAdapter.formats.contains(format))
171 alignment = FormatAdapter.readFile(alfile, "Paste", format);
173 System.out.println("jalview.Jemboss: Unknown format "+format+"\n");
174 if (alignment == null)
175 System.out.println("jalview.Jemboss: Couldn't read response:\n"
176 + alfile + "\n---EOF\n");
179 float[] ids = new float[alignment.length];
180 for (int i=0; i<alignment.length; i++)
181 ids[i] = (new Float(alignment[i].getName().substring(8))).floatValue();
182 jalview.util.QuickSort.sort(ids, alignment);
184 if (!deuniquify(namemap, alignment)) {
185 System.out.println("jalview.Jemboss: Warning: Some of the "
186 +"original sequence names have not been recovered!\n");
195 catch (JembossSoapException eae)
197 System.out.println("jalview.Jemboss: SOAP ERROR :"+embossCommand
200 catch (Exception e) {
201 System.out.println("jalview.Jemboss: Some other failure :\n"
202 +e.getMessage()+"\n");