--- /dev/null
+package jalview.io;\r
+\r
+import org.apache.axis.client.*;\r
+import javax.xml.namespace.QName;\r
+import java.util.*;\r
+import jalview.datamodel.*;\r
+import jalview.gui.*;\r
+import javax.swing.*;\r
+\r
+public class WSWUBlastClient\r
+{\r
+ CutAndPasteTransfer cap = new CutAndPasteTransfer(false);\r
+\r
+ public WSWUBlastClient(AlignmentI al, ArrayList ids)\r
+ {\r
+ JInternalFrame frame = new JInternalFrame();\r
+ cap.formatForOutput();\r
+ frame.setContentPane(cap);\r
+ cap.setText("To display sequence features an exact Uniprot id with 100% sequence identity match must be entered."\r
+ +"\nIn order to display these features, try changing the names of your sequences to the ids suggested below.");\r
+ Desktop.addInternalFrame(frame, "BLASTing for unidentified sequences ", 800,300);\r
+\r
+ for(int i=0; i<ids.size(); i++)\r
+ {\r
+ SequenceI sequence = al.findName( ids.get(i).toString() );\r
+ StringBuffer nonGapped = new StringBuffer();\r
+ for (int n = 0; n < sequence.getSequence().length(); n++)\r
+ {\r
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(n)))\r
+ nonGapped.append(sequence.getCharAt(n));\r
+ }\r
+\r
+ BlastThread thread = new BlastThread(ids.get(i).toString(), nonGapped.toString());\r
+ thread.start();\r
+ }\r
+\r
+ }\r
+\r
+ class BlastThread extends Thread\r
+ {\r
+ String sequence;\r
+ String id;\r
+ BlastThread(String id, String sequence)\r
+ {\r
+ this.sequence = sequence;\r
+ this.id = id;\r
+ }\r
+\r
+ public void run()\r
+ {\r
+ FindUniprotIDFromUnknownSequence(id, sequence);\r
+ }\r
+ }\r
+\r
+ public void FindUniprotIDFromUnknownSequence (String id, String s)\r
+ {\r
+ HashMap params = new HashMap();\r
+ params.put("database", "uniprot");\r
+ params.put("sensitivity","low");\r
+ params.put("sort","totalscore");\r
+ params.put("matrix","pam10");\r
+ params.put("program","blastp");\r
+ params.put("alignments","5");\r
+ params.put("outformat","xml");\r
+ byte[] sequence = s.getBytes();\r
+\r
+ try {\r
+ Call call = (Call) new Service().createCall();\r
+ call.setTargetEndpointAddress (new java.net.URL("http://www.ebi.ac.uk/cgi-bin/webservices/WSWUBlast"));\r
+ call.setOperationName(new QName("WSWUBlast", "doWUBlast"));\r
+\r
+ String result = (String) call.invoke(new Object[] {params,sequence});\r
+ parseResult(id, result);\r
+ }\r
+ catch (Exception exp) {\r
+ System.err.println ("ERROR:\n" + exp.toString());\r
+ exp.printStackTrace();\r
+ }\r
+ }\r
+\r
+ void parseResult(String id1, String res)\r
+ {\r
+ StringTokenizer st = new StringTokenizer(res, "\n");\r
+ String data;\r
+ String id2;\r
+ int maxFound = 90;\r
+ StringBuffer buffer = new StringBuffer("\n\n"+id1+" :");\r
+\r
+ while( st.hasMoreTokens() )\r
+ {\r
+ data = st.nextToken();\r
+\r
+ if(data.indexOf("database=\"uniprot\" id=")>-1)\r
+ {\r
+ int index = data.indexOf("database=\"uniprot\" id=")+ 23;\r
+ id2 = data.substring( index, data.indexOf("\"", index) );\r
+ while( data.indexOf("</alignment>")==-1)\r
+ {\r
+ data = st.nextToken();\r
+ if(data.indexOf("<identity>")>-1)\r
+ {\r
+ int value = Integer.parseInt( data.substring(data.indexOf("<identity>")+10, data.indexOf("</identity>")));\r
+ if(value>=maxFound)\r
+ {\r
+ maxFound = value;\r
+ buffer.append(" "+ id2 + " " + value+"%; ");\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+\r
+ }\r
+\r
+ cap.setText(cap.getText()+buffer.toString());\r
+ }\r
+\r
+}\r