| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.io; |
| 22 |
|
|
| 23 |
|
import jalview.analysis.AlignSeq; |
| 24 |
|
import jalview.datamodel.AlignmentI; |
| 25 |
|
import jalview.datamodel.DBRefEntry; |
| 26 |
|
import jalview.datamodel.Sequence; |
| 27 |
|
import jalview.gui.AlignmentPanel; |
| 28 |
|
import jalview.gui.CutAndPasteTransfer; |
| 29 |
|
import jalview.gui.Desktop; |
| 30 |
|
import jalview.gui.JvOptionPane; |
| 31 |
|
import jalview.util.MessageManager; |
| 32 |
|
|
| 33 |
|
import java.util.ArrayList; |
| 34 |
|
import java.util.Enumeration; |
| 35 |
|
import java.util.List; |
| 36 |
|
import java.util.StringTokenizer; |
| 37 |
|
import java.util.Vector; |
| 38 |
|
|
| 39 |
|
import javax.swing.ImageIcon; |
| 40 |
|
|
| 41 |
|
import uk.ac.ebi.www.Data; |
| 42 |
|
import uk.ac.ebi.www.InputParams; |
| 43 |
|
import uk.ac.ebi.www.WSFile; |
| 44 |
|
import uk.ac.ebi.www.WSWUBlast; |
| 45 |
|
import uk.ac.ebi.www.WSWUBlastService; |
| 46 |
|
import uk.ac.ebi.www.WSWUBlastServiceLocator; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@author |
| 52 |
|
@version |
| 53 |
|
|
| |
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 15 |
Complexity Density: 0.31 |
|
| 54 |
|
public class WSWUBlastClient |
| 55 |
|
{ |
| 56 |
|
AlignmentPanel ap; |
| 57 |
|
|
| 58 |
|
AlignmentI al; |
| 59 |
|
|
| 60 |
|
CutAndPasteTransfer output = new CutAndPasteTransfer(); |
| 61 |
|
|
| 62 |
|
int jobsRunning = 0; |
| 63 |
|
|
| 64 |
|
Vector suggestedIds = new Vector(); |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@param |
| 70 |
|
|
| 71 |
|
@param |
| 72 |
|
|
| 73 |
|
|
| |
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 74 |
0 |
public WSWUBlastClient(AlignmentPanel ap, AlignmentI al, ArrayList ids)... |
| 75 |
|
{ |
| 76 |
0 |
this.ap = ap; |
| 77 |
0 |
this.al = al; |
| 78 |
0 |
output.setText( |
| 79 |
|
MessageManager.getString("label.wswublast_client_credits")); |
| 80 |
|
|
| 81 |
0 |
Desktop.addInternalFrame(output, MessageManager.getString( |
| 82 |
|
"label.blasting_for_unidentified_sequence"), 800, 300); |
| 83 |
|
|
| 84 |
0 |
for (int i = 0; i < ids.size(); i++) |
| 85 |
|
{ |
| 86 |
0 |
Sequence sequence = (Sequence) ids.get(i); |
| 87 |
0 |
jalview.bin.Console.outPrintln(sequence.getName()); |
| 88 |
|
|
| 89 |
0 |
BlastThread thread = new BlastThread(sequence); |
| 90 |
0 |
thread.start(); |
| 91 |
0 |
jobsRunning++; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
0 |
ImageTwirler thread = new ImageTwirler(); |
| 95 |
0 |
thread.start(); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
@param |
| 102 |
|
|
| 103 |
|
@param |
| 104 |
|
|
| 105 |
|
|
| |
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 6 |
Complexity Density: 0.29 |
|
| 106 |
0 |
void parseResult(Sequence seq, String res)... |
| 107 |
|
{ |
| 108 |
0 |
StringTokenizer st = new StringTokenizer(res, "\n"); |
| 109 |
0 |
String data; |
| 110 |
0 |
String id2; |
| 111 |
0 |
int maxFound = 90; |
| 112 |
0 |
StringBuffer buffer = new StringBuffer("\n\n" + seq.getName() + " :"); |
| 113 |
|
|
| 114 |
0 |
while (st.hasMoreTokens()) |
| 115 |
|
{ |
| 116 |
0 |
data = st.nextToken(); |
| 117 |
|
|
| 118 |
0 |
if (data.indexOf(">UNIPROT") > -1) |
| 119 |
|
{ |
| 120 |
0 |
int index = data.indexOf(">UNIPROT") + 9; |
| 121 |
0 |
id2 = data.substring(index, data.indexOf(" ", index)); |
| 122 |
|
|
| 123 |
0 |
boolean identitiesFound = false; |
| 124 |
0 |
while (!identitiesFound) |
| 125 |
|
{ |
| 126 |
0 |
data = st.nextToken(); |
| 127 |
|
|
| 128 |
0 |
if (data.indexOf("Identities") > -1) |
| 129 |
|
{ |
| 130 |
0 |
identitiesFound = true; |
| 131 |
|
|
| 132 |
0 |
int value = Integer.parseInt(data |
| 133 |
|
.substring(data.indexOf("(") + 1, data.indexOf("%"))); |
| 134 |
|
|
| 135 |
0 |
if (value >= maxFound) |
| 136 |
|
{ |
| 137 |
0 |
maxFound = value; |
| 138 |
0 |
buffer.append(" " + id2 + " " + value + "%; "); |
| 139 |
0 |
suggestedIds.addElement(new Object[] { seq, id2 }); |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
|
| 146 |
0 |
output.appendText(buffer.toString()); |
| 147 |
|
} |
| 148 |
|
|
| |
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
| 149 |
0 |
void updateIds()... |
| 150 |
|
{ |
| 151 |
|
|
| 152 |
|
|
| 153 |
0 |
int reply = JvOptionPane.showConfirmDialog(Desktop.desktop, |
| 154 |
|
"Automatically update suggested ids?", |
| 155 |
|
"Auto replace sequence ids", JvOptionPane.YES_NO_OPTION); |
| 156 |
|
|
| 157 |
0 |
if (reply == JvOptionPane.YES_OPTION) |
| 158 |
|
{ |
| 159 |
0 |
Enumeration keys = suggestedIds.elements(); |
| 160 |
0 |
while (keys.hasMoreElements()) |
| 161 |
|
{ |
| 162 |
0 |
Object[] object = (Object[]) keys.nextElement(); |
| 163 |
|
|
| 164 |
0 |
Sequence oldseq = (Sequence) object[0]; |
| 165 |
|
|
| 166 |
0 |
oldseq.setName(object[1].toString()); |
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
0 |
for (int i = 0; i < al.getHeight(); i++) |
| 171 |
|
{ |
| 172 |
0 |
if (al.getSequenceAt(i).getDatasetSequence() == oldseq) |
| 173 |
|
{ |
| 174 |
0 |
al.getSequenceAt(i).setName(oldseq.getName()); |
| 175 |
0 |
break; |
| 176 |
|
} |
| 177 |
|
} |
| 178 |
|
|
| 179 |
0 |
List<DBRefEntry> entries = oldseq.getDBRefs(); |
| 180 |
|
|
| 181 |
0 |
if (entries != null && entries.size() > 0) |
| 182 |
|
{ |
| 183 |
0 |
oldseq.addDBRef(new jalview.datamodel.DBRefEntry( |
| 184 |
|
jalview.datamodel.DBRefSource.UNIPROT, "0", |
| 185 |
|
entries.get(0).getAccessionId())); |
| 186 |
|
} |
| 187 |
|
} |
| 188 |
|
} |
| 189 |
0 |
ap.paintAlignment(true, false); |
| 190 |
|
|
| 191 |
|
} |
| 192 |
|
|
| |
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.5 |
|
| 193 |
|
class ImageTwirler extends Thread |
| 194 |
|
{ |
| 195 |
|
ImageIcon[] imageIcon; |
| 196 |
|
|
| 197 |
|
int imageIndex = 0; |
| 198 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 199 |
0 |
public ImageTwirler()... |
| 200 |
|
{ |
| 201 |
0 |
imageIcon = new ImageIcon[9]; |
| 202 |
|
|
| 203 |
0 |
for (int i = 0; i < 9; i++) |
| 204 |
|
{ |
| 205 |
0 |
java.net.URL url = getClass() |
| 206 |
|
.getResource("/images/dna" + (i + 1) + ".gif"); |
| 207 |
|
|
| 208 |
0 |
if (url != null) |
| 209 |
|
{ |
| 210 |
0 |
imageIcon[i] = new ImageIcon(url); |
| 211 |
|
} |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 215 |
0 |
@Override... |
| 216 |
|
public void run() |
| 217 |
|
{ |
| 218 |
0 |
while (jobsRunning > 0) |
| 219 |
|
{ |
| 220 |
0 |
try |
| 221 |
|
{ |
| 222 |
0 |
Thread.sleep(100); |
| 223 |
0 |
imageIndex++; |
| 224 |
0 |
imageIndex %= 9; |
| 225 |
0 |
output.setFrameIcon(imageIcon[imageIndex]); |
| 226 |
0 |
output.setTitle(MessageManager.formatMessage( |
| 227 |
|
"label.blasting_for_unidentified_sequence_jobs_running", |
| 228 |
|
new String[] |
| 229 |
|
{ Integer.valueOf(jobsRunning).toString() })); |
| 230 |
|
} catch (Exception ex) |
| 231 |
|
{ |
| 232 |
|
} |
| 233 |
|
} |
| 234 |
|
|
| 235 |
0 |
if (jobsRunning == 0) |
| 236 |
|
{ |
| 237 |
0 |
updateIds(); |
| 238 |
|
} |
| 239 |
|
} |
| 240 |
|
} |
| 241 |
|
|
| |
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 7 |
Complexity Density: 0.19 |
|
| 242 |
|
class BlastThread extends Thread |
| 243 |
|
{ |
| 244 |
|
Sequence sequence; |
| 245 |
|
|
| 246 |
|
String jobid; |
| 247 |
|
|
| 248 |
|
boolean jobComplete = false; |
| 249 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 250 |
0 |
BlastThread(Sequence sequence)... |
| 251 |
|
{ |
| 252 |
0 |
jalview.bin.Console.outPrintln("blasting for: " + sequence.getName()); |
| 253 |
0 |
this.sequence = sequence; |
| 254 |
|
} |
| 255 |
|
|
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
| 256 |
0 |
@Override... |
| 257 |
|
public void run() |
| 258 |
|
{ |
| 259 |
0 |
StartJob(); |
| 260 |
|
|
| 261 |
0 |
while (!jobComplete) |
| 262 |
|
{ |
| 263 |
0 |
try |
| 264 |
|
{ |
| 265 |
0 |
WSWUBlastService service = new WSWUBlastServiceLocator(); |
| 266 |
0 |
WSWUBlast wublast = service.getWSWUBlast(); |
| 267 |
0 |
WSFile[] results = wublast.getResults(jobid); |
| 268 |
|
|
| 269 |
0 |
if (results != null) |
| 270 |
|
{ |
| 271 |
0 |
String result = new String(wublast.poll(jobid, "tooloutput")); |
| 272 |
0 |
parseResult(sequence, result); |
| 273 |
0 |
jobComplete = true; |
| 274 |
0 |
jobsRunning--; |
| 275 |
|
} |
| 276 |
|
else |
| 277 |
|
{ |
| 278 |
0 |
Thread.sleep(10000); |
| 279 |
0 |
jalview.bin.Console.outPrintln("WSWuBlastClient: I'm alive " |
| 280 |
|
+ sequence.getName() + " " + jobid); |
| 281 |
|
} |
| 282 |
|
} catch (Exception ex) |
| 283 |
|
{ |
| 284 |
|
} |
| 285 |
|
} |
| 286 |
|
} |
| 287 |
|
|
| |
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 2 |
Complexity Density: 0.09 |
|
| 288 |
0 |
void StartJob()... |
| 289 |
|
{ |
| 290 |
0 |
InputParams params = new InputParams(); |
| 291 |
|
|
| 292 |
0 |
params.setProgram("blastp"); |
| 293 |
0 |
params.setDatabase("uniprot"); |
| 294 |
0 |
params.setMatrix("pam10"); |
| 295 |
|
|
| 296 |
0 |
params.setNumal(5); |
| 297 |
0 |
params.setSensitivity("low"); |
| 298 |
0 |
params.setSort("totalscore"); |
| 299 |
0 |
params.setOutformat("txt"); |
| 300 |
0 |
params.setAsync(true); |
| 301 |
|
|
| 302 |
0 |
try |
| 303 |
|
{ |
| 304 |
0 |
Data inputs[] = new Data[1]; |
| 305 |
0 |
Data input = new Data(); |
| 306 |
0 |
input.setType("sequence"); |
| 307 |
0 |
input.setContent(AlignSeq.extractGaps("-. ", |
| 308 |
|
sequence.getSequenceAsString())); |
| 309 |
0 |
inputs[0] = input; |
| 310 |
|
|
| 311 |
0 |
WSWUBlastService service = new WSWUBlastServiceLocator(); |
| 312 |
0 |
WSWUBlast wublast = service.getWSWUBlast(); |
| 313 |
0 |
jobid = wublast.runWUBlast(params, inputs); |
| 314 |
|
} catch (Exception exp) |
| 315 |
|
{ |
| 316 |
0 |
jobComplete = true; |
| 317 |
0 |
jobsRunning--; |
| 318 |
0 |
jalview.bin.Console |
| 319 |
|
.errPrintln("WSWUBlastClient error:\n" + exp.toString()); |
| 320 |
0 |
exp.printStackTrace(); |
| 321 |
|
} |
| 322 |
|
} |
| 323 |
|
} |
| 324 |
|
} |