| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.util; |
| 22 |
|
|
| 23 |
|
import jalview.datamodel.Sequence; |
| 24 |
|
import jalview.datamodel.SequenceI; |
| 25 |
|
|
| 26 |
|
import java.util.Hashtable; |
| 27 |
|
|
| |
|
| 0% |
Uncovered Elements: 418 (418) |
Complexity: 109 |
Complexity Density: 0.43 |
|
| 28 |
|
public class GroupUrlLink |
| 29 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 30 |
|
public class UrlStringTooLongException extends Exception |
| 31 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 32 |
0 |
public UrlStringTooLongException(int lng)... |
| 33 |
|
{ |
| 34 |
0 |
urlLength = lng; |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
public int urlLength; |
| 38 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 39 |
0 |
@Override... |
| 40 |
|
public String toString() |
| 41 |
|
{ |
| 42 |
0 |
return "Generated url is estimated to be too long (" + urlLength |
| 43 |
|
+ ")"; |
| 44 |
|
} |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
private String url_prefix, target, label; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
private String url_suffix[], separators[], regexReplace[]; |
| 65 |
|
|
| 66 |
|
private String invalidMessage = null; |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
private static String[] tokens; |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
private int[] segs; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
private String[] mtch; |
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 82 |
0 |
static... |
| 83 |
|
{ |
| 84 |
0 |
if (tokens == null) |
| 85 |
|
{ |
| 86 |
0 |
tokens = new String[] { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
public static final int SEQUENCEIDS = 1; |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
public static final int SEQUENCES = 2; |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
public static final int DATASETID = 4; |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
@param |
| 115 |
|
|
| |
|
| 0% |
Uncovered Elements: 105 (105) |
Complexity: 23 |
Complexity Density: 0.34 |
|
| 116 |
0 |
public GroupUrlLink(String link)... |
| 117 |
|
{ |
| 118 |
0 |
int sep = link.indexOf("|"); |
| 119 |
0 |
segs = new int[tokens.length]; |
| 120 |
0 |
int ntoks = 0; |
| 121 |
0 |
for (int i = 0; i < segs.length; i++) |
| 122 |
|
{ |
| 123 |
0 |
if ((segs[i] = link.indexOf("$" + tokens[i])) > -1) |
| 124 |
|
{ |
| 125 |
0 |
ntoks++; |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
|
| 129 |
0 |
if (ntoks == 0) |
| 130 |
|
{ |
| 131 |
0 |
invalidMessage = "Group URL string must contain at least one of "; |
| 132 |
0 |
for (int i = 0; i < segs.length; i++) |
| 133 |
|
{ |
| 134 |
0 |
invalidMessage += " '$" + tokens[i] + "[=/regex=/]$'"; |
| 135 |
|
} |
| 136 |
0 |
return; |
| 137 |
|
} |
| 138 |
|
|
| 139 |
0 |
int[] ptok = new int[ntoks + 1]; |
| 140 |
0 |
String[] tmtch = new String[ntoks + 1]; |
| 141 |
0 |
mtch = new String[ntoks]; |
| 142 |
0 |
for (int i = 0, t = 0; i < segs.length; i++) |
| 143 |
|
{ |
| 144 |
0 |
if (segs[i] > -1) |
| 145 |
|
{ |
| 146 |
0 |
ptok[t] = segs[i]; |
| 147 |
0 |
tmtch[t++] = tokens[i]; |
| 148 |
|
} |
| 149 |
|
} |
| 150 |
0 |
ptok[ntoks] = link.length(); |
| 151 |
0 |
tmtch[ntoks] = "$$$$$$$$$"; |
| 152 |
0 |
jalview.util.QuickSort.sort(ptok, tmtch); |
| 153 |
0 |
for (int i = 0; i < ntoks; i++) |
| 154 |
|
{ |
| 155 |
0 |
mtch[i] = tmtch[i]; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
0 |
int p = sep; |
| 171 |
|
|
| 172 |
0 |
do |
| 173 |
|
{ |
| 174 |
0 |
sep = p; |
| 175 |
0 |
p = link.indexOf("|", sep + 1); |
| 176 |
0 |
} while (p > sep && p < ptok[0]); |
| 177 |
|
|
| 178 |
|
|
| 179 |
0 |
label = link.substring(0, sep); |
| 180 |
0 |
if (label.indexOf("|") > -1) |
| 181 |
|
{ |
| 182 |
|
|
| 183 |
0 |
target = label.substring(0, label.indexOf("|")); |
| 184 |
|
} |
| 185 |
0 |
else if (label.indexOf(" ") > 2) |
| 186 |
|
{ |
| 187 |
|
|
| 188 |
0 |
target = label.substring(0, label.indexOf(" ")); |
| 189 |
|
} |
| 190 |
|
else |
| 191 |
|
{ |
| 192 |
0 |
target = label; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
0 |
url_prefix = link.substring(sep + 1, ptok[0]); |
| 196 |
0 |
url_suffix = new String[mtch.length]; |
| 197 |
0 |
regexReplace = new String[mtch.length]; |
| 198 |
|
|
| 199 |
0 |
for (int pass = 0; pass < mtch.length; pass++) |
| 200 |
|
{ |
| 201 |
0 |
int mlength = 3 + mtch[pass].length(); |
| 202 |
0 |
if (link.indexOf("$" + mtch[pass] + "=/") == ptok[pass] && (p = link |
| 203 |
|
.indexOf("/=$", ptok[pass] + mlength)) > ptok[pass] + mlength) |
| 204 |
|
{ |
| 205 |
|
|
| 206 |
0 |
if (ptok[pass + 1] < p + 3) |
| 207 |
|
{ |
| 208 |
|
|
| 209 |
|
|
| 210 |
0 |
invalidMessage = "Token regexes cannot contain other regexes (did you terminate the $" |
| 211 |
|
+ mtch[pass] + " regex with a '/=$' ?"; |
| 212 |
0 |
return; |
| 213 |
|
} |
| 214 |
0 |
url_suffix[pass] = link.substring(p + 3, ptok[pass + 1]); |
| 215 |
0 |
regexReplace[pass] = link.substring(ptok[pass] + mlength, p); |
| 216 |
0 |
try |
| 217 |
|
{ |
| 218 |
0 |
com.stevesoft.pat.Regex rg = com.stevesoft.pat.Regex |
| 219 |
|
.perlCode("/" + regexReplace[pass] + "/"); |
| 220 |
0 |
if (rg == null) |
| 221 |
|
{ |
| 222 |
0 |
invalidMessage = "Invalid Regular Expression : '" |
| 223 |
|
+ regexReplace[pass] + "'\n"; |
| 224 |
|
} |
| 225 |
|
} catch (Exception e) |
| 226 |
|
{ |
| 227 |
0 |
invalidMessage = "Invalid Regular Expression : '" |
| 228 |
|
+ regexReplace[pass] + "'\n"; |
| 229 |
|
} |
| 230 |
|
} |
| 231 |
|
else |
| 232 |
|
{ |
| 233 |
0 |
regexReplace[pass] = null; |
| 234 |
|
|
| 235 |
0 |
if ((p = link.indexOf("$" + mtch[pass] + "$")) == ptok[pass]) |
| 236 |
|
{ |
| 237 |
0 |
url_suffix[pass] = link.substring(p + mtch[pass].length() + 2, |
| 238 |
|
ptok[pass + 1]); |
| 239 |
|
} |
| 240 |
|
else |
| 241 |
|
{ |
| 242 |
0 |
invalidMessage = "Warning: invalid regex structure (after '" |
| 243 |
|
+ mtch[0] + "') for URL link : " + link; |
| 244 |
|
} |
| 245 |
|
} |
| 246 |
|
} |
| 247 |
0 |
int pass = 0; |
| 248 |
0 |
separators = new String[url_suffix.length]; |
| 249 |
0 |
String suffices = url_suffix[url_suffix.length - 1], lastsep = ","; |
| 250 |
|
|
| 251 |
0 |
while ((p = suffices.indexOf('|')) > -1) |
| 252 |
|
{ |
| 253 |
0 |
separators[pass] = suffices.substring(p + 1); |
| 254 |
0 |
if (pass == 0) |
| 255 |
|
{ |
| 256 |
|
|
| 257 |
0 |
url_suffix[url_suffix.length - 1] = suffices.substring(0, p); |
| 258 |
|
} |
| 259 |
|
else |
| 260 |
|
{ |
| 261 |
0 |
lastsep = (separators[pass - 1] = separators[pass - 1].substring(0, |
| 262 |
|
p)); |
| 263 |
|
} |
| 264 |
0 |
suffices = separators[pass]; |
| 265 |
0 |
pass++; |
| 266 |
|
} |
| 267 |
0 |
if (pass > 0) |
| 268 |
|
{ |
| 269 |
0 |
lastsep = separators[pass - 1]; |
| 270 |
|
} |
| 271 |
|
|
| 272 |
0 |
while (pass < separators.length) |
| 273 |
|
{ |
| 274 |
0 |
separators[pass++] = lastsep; |
| 275 |
|
} |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
|
| 279 |
|
@return |
| 280 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 281 |
0 |
public String getUrl_suffix()... |
| 282 |
|
{ |
| 283 |
0 |
return url_suffix[url_suffix.length - 1]; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
|
|
| 287 |
|
@return |
| 288 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 289 |
0 |
public String getUrl_prefix()... |
| 290 |
|
{ |
| 291 |
0 |
return url_prefix; |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
|
| 295 |
|
@return |
| 296 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 297 |
0 |
public String getTarget()... |
| 298 |
|
{ |
| 299 |
0 |
return target; |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
|
| 303 |
|
@return |
| 304 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 305 |
0 |
public String getLabel()... |
| 306 |
|
{ |
| 307 |
0 |
return label; |
| 308 |
|
} |
| 309 |
|
|
| 310 |
|
|
| 311 |
|
@return |
| 312 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 313 |
0 |
public String getIDRegexReplace()... |
| 314 |
|
{ |
| 315 |
0 |
return _replaceFor(tokens[0]); |
| 316 |
|
} |
| 317 |
|
|
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
| 318 |
0 |
private String _replaceFor(String token)... |
| 319 |
|
{ |
| 320 |
0 |
for (int i = 0; i < mtch.length; i++) |
| 321 |
|
{ |
| 322 |
0 |
if (segs[i] > -1 && mtch[i].equals(token)) |
| 323 |
|
{ |
| 324 |
0 |
return regexReplace[i]; |
| 325 |
|
} |
| 326 |
|
} |
| 327 |
0 |
return null; |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 331 |
|
@return |
| 332 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 333 |
0 |
public String getSeqRegexReplace()... |
| 334 |
|
{ |
| 335 |
0 |
return _replaceFor(tokens[1]); |
| 336 |
|
} |
| 337 |
|
|
| 338 |
|
|
| 339 |
|
@return |
| 340 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 341 |
0 |
public String getInvalidMessage()... |
| 342 |
|
{ |
| 343 |
0 |
return invalidMessage; |
| 344 |
|
} |
| 345 |
|
|
| 346 |
|
|
| 347 |
|
|
| 348 |
|
|
| 349 |
|
@return |
| 350 |
|
|
| 351 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 352 |
0 |
public boolean isValid()... |
| 353 |
|
{ |
| 354 |
0 |
return invalidMessage == null; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
|
|
| 359 |
|
|
| 360 |
|
@param |
| 361 |
|
|
| 362 |
|
@param |
| 363 |
|
|
| 364 |
|
@param |
| 365 |
|
|
| 366 |
|
|
| 367 |
|
|
| 368 |
|
@return |
| 369 |
|
|
| 370 |
|
|
| 371 |
|
@throws |
| 372 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 373 |
0 |
public Object[] makeUrls(String[] idstrings, String[] seqstrings,... |
| 374 |
|
String dsstring, boolean onlyIfMatches) |
| 375 |
|
throws UrlStringTooLongException |
| 376 |
|
{ |
| 377 |
0 |
Hashtable rstrings = replacementArgs(idstrings, seqstrings, dsstring); |
| 378 |
0 |
return makeUrls(rstrings, onlyIfMatches); |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
|
| 382 |
|
|
| 383 |
|
|
| 384 |
|
@param |
| 385 |
|
@param |
| 386 |
|
@param |
| 387 |
|
@return |
| 388 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 389 |
0 |
private Hashtable replacementArgs(String[] idstrings, String[] seqstrings,... |
| 390 |
|
String dsstring) |
| 391 |
|
{ |
| 392 |
0 |
Hashtable rstrings = new Hashtable(); |
| 393 |
0 |
rstrings.put(tokens[0], idstrings); |
| 394 |
0 |
rstrings.put(tokens[1], seqstrings); |
| 395 |
0 |
rstrings.put(tokens[2], new String[] { dsstring }); |
| 396 |
0 |
if (idstrings.length != seqstrings.length) |
| 397 |
|
{ |
| 398 |
0 |
throw new Error(MessageManager.getString( |
| 399 |
|
"error.idstring_seqstrings_only_one_per_sequence")); |
| 400 |
|
} |
| 401 |
0 |
return rstrings; |
| 402 |
|
} |
| 403 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 404 |
0 |
public Object[] makeUrls(Hashtable repstrings, boolean onlyIfMatches)... |
| 405 |
|
throws UrlStringTooLongException |
| 406 |
|
{ |
| 407 |
0 |
return makeUrlsIf(true, repstrings, onlyIfMatches); |
| 408 |
|
} |
| 409 |
|
|
| 410 |
|
|
| 411 |
|
|
| 412 |
|
@param |
| 413 |
|
@param |
| 414 |
|
@param |
| 415 |
|
@param |
| 416 |
|
@return |
| 417 |
|
@throws |
| 418 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 419 |
0 |
public Object[] makeUrlStubs(String[] ids, String[] seqstr, String string,... |
| 420 |
|
boolean b) throws UrlStringTooLongException |
| 421 |
|
{ |
| 422 |
0 |
Hashtable rstrings = replacementArgs(ids, seqstr, string); |
| 423 |
0 |
Object[] stubs = makeUrlsIf(false, rstrings, b); |
| 424 |
0 |
if (stubs != null) |
| 425 |
|
{ |
| 426 |
0 |
return new Object[] { stubs[0], stubs[1], rstrings, |
| 427 |
|
new boolean[] |
| 428 |
|
{ b } }; |
| 429 |
|
} |
| 430 |
|
|
| 431 |
0 |
return null; |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
|
| 435 |
|
|
| 436 |
|
|
| 437 |
|
|
| 438 |
|
@param |
| 439 |
|
@return |
| 440 |
|
@throws |
| 441 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 442 |
0 |
public String constructFrom(Object[] stubs)... |
| 443 |
|
throws UrlStringTooLongException |
| 444 |
|
{ |
| 445 |
0 |
Object[] results = makeUrlsIf(true, (Hashtable) stubs[2], |
| 446 |
|
((boolean[]) stubs[3])[0]); |
| 447 |
0 |
return ((String[]) results[3])[0]; |
| 448 |
|
} |
| 449 |
|
|
| 450 |
|
|
| 451 |
|
|
| 452 |
|
|
| 453 |
|
@param |
| 454 |
|
|
| 455 |
|
@param |
| 456 |
|
@param |
| 457 |
|
@return |
| 458 |
|
|
| 459 |
|
|
| 460 |
|
|
| 461 |
|
@throws |
| 462 |
|
|
| |
|
| 0% |
Uncovered Elements: 154 (154) |
Complexity: 42 |
Complexity Density: 0.48 |
|
| 463 |
0 |
protected Object[] makeUrlsIf(boolean createFullUrl, Hashtable repstrings,... |
| 464 |
|
boolean onlyIfMatches) throws UrlStringTooLongException |
| 465 |
|
{ |
| 466 |
0 |
int pass = 0; |
| 467 |
|
|
| 468 |
|
|
| 469 |
0 |
String[][] idseq = new String[mtch.length][]; |
| 470 |
0 |
int mins = 0, maxs = 0; |
| 471 |
0 |
for (int i = 0; i < mtch.length; i++) |
| 472 |
|
{ |
| 473 |
0 |
idseq[i] = (String[]) repstrings.get(mtch[i]); |
| 474 |
0 |
if (idseq[i].length >= 1) |
| 475 |
|
{ |
| 476 |
0 |
if (mins == 0 && idseq[i].length == 1) |
| 477 |
|
{ |
| 478 |
0 |
mins = 1; |
| 479 |
|
} |
| 480 |
0 |
if (maxs < 2) |
| 481 |
|
{ |
| 482 |
0 |
maxs = idseq[i].length; |
| 483 |
|
} |
| 484 |
|
else |
| 485 |
|
{ |
| 486 |
0 |
if (maxs != idseq[i].length) |
| 487 |
|
{ |
| 488 |
0 |
throw new Error(MessageManager.formatMessage( |
| 489 |
|
"error.cannot_have_mixed_length_replacement_vectors", |
| 490 |
|
new String[] |
| 491 |
|
{ (mtch[i]), |
| 492 |
|
Integer.valueOf(idseq[i].length).toString(), |
| 493 |
|
Integer.valueOf(maxs).toString() })); |
| 494 |
|
} |
| 495 |
|
} |
| 496 |
|
} |
| 497 |
|
else |
| 498 |
|
{ |
| 499 |
0 |
throw new Error(MessageManager.getString( |
| 500 |
|
"error.cannot_have_zero_length_vector_replacement_strings")); |
| 501 |
|
} |
| 502 |
|
} |
| 503 |
|
|
| 504 |
0 |
StringBuffer matched[] = new StringBuffer[idseq.length]; |
| 505 |
|
|
| 506 |
0 |
com.stevesoft.pat.Regex[] rgxs = new com.stevesoft.pat.Regex[matched.length]; |
| 507 |
0 |
for (pass = 0; pass < matched.length; pass++) |
| 508 |
|
{ |
| 509 |
0 |
matched[pass] = new StringBuffer(); |
| 510 |
0 |
if (regexReplace[pass] != null) |
| 511 |
|
{ |
| 512 |
0 |
rgxs[pass] = com.stevesoft.pat.Regex |
| 513 |
|
.perlCode("/" + regexReplace[pass] + "/"); |
| 514 |
|
} |
| 515 |
|
else |
| 516 |
|
{ |
| 517 |
0 |
rgxs[pass] = null; |
| 518 |
|
} |
| 519 |
|
} |
| 520 |
|
|
| 521 |
0 |
int urllength = url_prefix.length(); |
| 522 |
0 |
for (pass = 0; pass < matched.length; pass++) |
| 523 |
|
{ |
| 524 |
0 |
urllength += url_suffix[pass].length(); |
| 525 |
|
} |
| 526 |
|
|
| 527 |
|
|
| 528 |
|
|
| 529 |
|
|
| 530 |
0 |
boolean[] thismatched = new boolean[maxs]; |
| 531 |
0 |
int seqsmatched = 0; |
| 532 |
0 |
for (int sq = 0; sq < maxs; sq++) |
| 533 |
|
{ |
| 534 |
|
|
| 535 |
0 |
thismatched[sq] = false; |
| 536 |
0 |
StringBuffer[] thematches = new StringBuffer[rgxs.length]; |
| 537 |
0 |
for (pass = 0; pass < rgxs.length; pass++) |
| 538 |
|
{ |
| 539 |
0 |
thematches[pass] = new StringBuffer(); |
| 540 |
|
|
| 541 |
|
|
| 542 |
|
|
| 543 |
|
|
| 544 |
0 |
if (idseq[pass].length <= sq) |
| 545 |
|
{ |
| 546 |
|
|
| 547 |
0 |
continue; |
| 548 |
|
} |
| 549 |
0 |
if (rgxs[pass] != null) |
| 550 |
|
{ |
| 551 |
0 |
com.stevesoft.pat.Regex rg = rgxs[pass]; |
| 552 |
0 |
int rematchat = 0; |
| 553 |
|
|
| 554 |
0 |
while (rg.searchFrom(idseq[pass][sq], rematchat)) |
| 555 |
|
{ |
| 556 |
0 |
rematchat = rg.matchedTo(); |
| 557 |
0 |
thismatched[sq] |= true; |
| 558 |
0 |
urllength += rg.charsMatched(); |
| 559 |
0 |
if ((urllength + 32) > Platform.getMaxCommandLineLength()) |
| 560 |
|
{ |
| 561 |
0 |
throw new UrlStringTooLongException(urllength); |
| 562 |
|
} |
| 563 |
|
|
| 564 |
0 |
if (!createFullUrl) |
| 565 |
|
{ |
| 566 |
0 |
continue; |
| 567 |
|
} |
| 568 |
|
|
| 569 |
0 |
int ns = rg.numSubs(); |
| 570 |
0 |
if (ns == 0) |
| 571 |
|
{ |
| 572 |
0 |
thematches[pass].append(rg.stringMatched()); |
| 573 |
|
} |
| 574 |
|
|
| 575 |
|
|
| 576 |
|
|
| 577 |
|
|
| 578 |
|
|
| 579 |
|
|
| 580 |
|
|
| 581 |
|
|
| 582 |
|
|
| 583 |
|
else |
| 584 |
|
{ |
| 585 |
|
|
| 586 |
|
|
| 587 |
|
|
| 588 |
|
|
| 589 |
|
|
| 590 |
|
|
| 591 |
|
|
| 592 |
|
|
| 593 |
0 |
StringBuffer subs = new StringBuffer(); |
| 594 |
|
|
| 595 |
|
|
| 596 |
0 |
int s = 0; |
| 597 |
0 |
while (s <= ns) |
| 598 |
|
{ |
| 599 |
0 |
if (s + 1 <= ns && rg.matchedTo(s) > -1 |
| 600 |
|
&& rg.matchedTo(s + 1) > -1 |
| 601 |
|
&& rg.matchedTo(s + 1) < rg.matchedTo(s)) |
| 602 |
|
{ |
| 603 |
|
|
| 604 |
|
|
| 605 |
0 |
int r = s + 1; |
| 606 |
0 |
StringBuffer rmtch = new StringBuffer(); |
| 607 |
0 |
while (r <= ns && rg.matchedTo(r) <= rg.matchedTo(s)) |
| 608 |
|
{ |
| 609 |
0 |
if (rg.matchedFrom(r) > -1) |
| 610 |
|
{ |
| 611 |
0 |
rmtch.append(rg.stringMatched(r)); |
| 612 |
|
} |
| 613 |
0 |
r++; |
| 614 |
|
} |
| 615 |
0 |
if (rmtch.length() > 0) |
| 616 |
|
{ |
| 617 |
0 |
subs.append(rmtch); |
| 618 |
|
} |
| 619 |
0 |
s = r; |
| 620 |
|
} |
| 621 |
|
else |
| 622 |
|
{ |
| 623 |
0 |
if (rg.matchedFrom(s) > -1) |
| 624 |
|
{ |
| 625 |
0 |
subs.append(rg.stringMatched(s)); |
| 626 |
|
} |
| 627 |
0 |
s++; |
| 628 |
|
} |
| 629 |
|
} |
| 630 |
0 |
thematches[pass].append(subs); |
| 631 |
|
} |
| 632 |
|
} |
| 633 |
|
} |
| 634 |
|
else |
| 635 |
|
{ |
| 636 |
|
|
| 637 |
0 |
if (!onlyIfMatches) |
| 638 |
|
{ |
| 639 |
0 |
thismatched[sq] |= true; |
| 640 |
0 |
urllength += idseq[pass][sq].length(); |
| 641 |
0 |
if (createFullUrl) |
| 642 |
|
{ |
| 643 |
0 |
thematches[pass] = new StringBuffer(idseq[pass][sq]); |
| 644 |
|
|
| 645 |
|
|
| 646 |
|
|
| 647 |
|
|
| 648 |
|
|
| 649 |
|
|
| 650 |
|
|
| 651 |
|
|
| 652 |
|
|
| 653 |
|
|
| 654 |
|
|
| 655 |
|
} |
| 656 |
|
|
| 657 |
|
} |
| 658 |
|
} |
| 659 |
|
} |
| 660 |
|
|
| 661 |
|
|
| 662 |
|
|
| 663 |
|
|
| 664 |
0 |
if (thismatched[sq]) |
| 665 |
|
{ |
| 666 |
0 |
if (createFullUrl) |
| 667 |
|
{ |
| 668 |
0 |
for (pass = 0; pass < matched.length; pass++) |
| 669 |
|
{ |
| 670 |
0 |
if (idseq[pass].length > 1 && matched[pass].length() > 0) |
| 671 |
|
{ |
| 672 |
0 |
matched[pass].append(separators[pass]); |
| 673 |
|
} |
| 674 |
0 |
matched[pass].append(thematches[pass]); |
| 675 |
|
} |
| 676 |
|
} |
| 677 |
0 |
seqsmatched++; |
| 678 |
|
} |
| 679 |
|
} |
| 680 |
|
|
| 681 |
0 |
if (seqsmatched == 0 || (createFullUrl && matched[0].length() == 0)) |
| 682 |
|
{ |
| 683 |
|
|
| 684 |
0 |
return null; |
| 685 |
|
} |
| 686 |
|
|
| 687 |
|
|
| 688 |
0 |
if ((urllength + 32) > Platform.getMaxCommandLineLength()) |
| 689 |
|
{ |
| 690 |
0 |
throw new UrlStringTooLongException(urllength); |
| 691 |
|
} |
| 692 |
0 |
if (!createFullUrl) |
| 693 |
|
{ |
| 694 |
|
|
| 695 |
|
|
| 696 |
0 |
return new Object[] { new int[] { seqsmatched }, thismatched }; |
| 697 |
|
} |
| 698 |
|
|
| 699 |
|
|
| 700 |
0 |
StringBuffer submiturl = new StringBuffer(); |
| 701 |
0 |
submiturl.append(url_prefix); |
| 702 |
0 |
for (pass = 0; pass < matched.length; pass++) |
| 703 |
|
{ |
| 704 |
0 |
submiturl.append(matched[pass]); |
| 705 |
0 |
if (url_suffix[pass] != null) |
| 706 |
|
{ |
| 707 |
0 |
submiturl.append(url_suffix[pass]); |
| 708 |
|
} |
| 709 |
|
} |
| 710 |
|
|
| 711 |
0 |
return new Object[] { new int[] { seqsmatched }, thismatched, matched, |
| 712 |
|
new String[] |
| 713 |
|
{ submiturl.toString() } }; |
| 714 |
|
} |
| 715 |
|
|
| 716 |
|
|
| 717 |
|
|
| 718 |
|
@param |
| 719 |
|
@return |
| 720 |
|
|
| 721 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 722 |
0 |
public int getNumberInvolved(Object[] urlstub)... |
| 723 |
|
{ |
| 724 |
0 |
return ((int[]) urlstub[0])[0]; |
| 725 |
|
|
| 726 |
|
} |
| 727 |
|
|
| 728 |
|
|
| 729 |
|
|
| 730 |
|
|
| 731 |
|
|
| 732 |
|
@return |
| 733 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 734 |
0 |
public int getGroupURLType()... |
| 735 |
|
{ |
| 736 |
0 |
int r = 0; |
| 737 |
0 |
for (int pass = 0; pass < tokens.length; pass++) |
| 738 |
|
{ |
| 739 |
0 |
for (int i = 0; i < mtch.length; i++) |
| 740 |
|
{ |
| 741 |
0 |
if (mtch[i].equals(tokens[pass])) |
| 742 |
|
{ |
| 743 |
0 |
r += 1 << pass; |
| 744 |
|
} |
| 745 |
|
} |
| 746 |
|
} |
| 747 |
0 |
return r; |
| 748 |
|
} |
| 749 |
|
|
| |
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
| 750 |
0 |
@Override... |
| 751 |
|
public String toString() |
| 752 |
|
{ |
| 753 |
0 |
StringBuffer result = new StringBuffer(); |
| 754 |
0 |
result.append(label + "|" + url_prefix); |
| 755 |
0 |
int r; |
| 756 |
0 |
for (r = 0; r < url_suffix.length; r++) |
| 757 |
|
{ |
| 758 |
0 |
result.append("$"); |
| 759 |
0 |
result.append(mtch[r]); |
| 760 |
0 |
if (regexReplace[r] != null) |
| 761 |
|
{ |
| 762 |
0 |
result.append("=/"); |
| 763 |
0 |
result.append(regexReplace[r]); |
| 764 |
0 |
result.append("/="); |
| 765 |
|
} |
| 766 |
0 |
result.append("$"); |
| 767 |
0 |
result.append(url_suffix[r]); |
| 768 |
|
} |
| 769 |
0 |
for (r = 0; r < separators.length; r++) |
| 770 |
|
{ |
| 771 |
0 |
result.append("|"); |
| 772 |
0 |
result.append(separators[r]); |
| 773 |
|
} |
| 774 |
0 |
return result.toString(); |
| 775 |
|
} |
| 776 |
|
|
| 777 |
|
|
| 778 |
|
|
| 779 |
|
|
| 780 |
|
@param |
| 781 |
|
@param |
| 782 |
|
@param |
| 783 |
|
|
| |
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
| 784 |
0 |
private static void testUrls(GroupUrlLink ul, String[][] idstring,... |
| 785 |
|
Object[] url) |
| 786 |
|
{ |
| 787 |
|
|
| 788 |
0 |
if (url == null) |
| 789 |
|
{ |
| 790 |
0 |
jalview.bin.Console.outPrintln("Created NO urls."); |
| 791 |
|
} |
| 792 |
|
else |
| 793 |
|
{ |
| 794 |
0 |
jalview.bin.Console |
| 795 |
|
.outPrintln("Created a url from " + ((int[]) url[0])[0] |
| 796 |
|
+ "out of " + idstring[0].length + " sequences."); |
| 797 |
0 |
jalview.bin.Console.outPrintln("Sequences that did not match:"); |
| 798 |
0 |
for (int sq = 0; sq < idstring[0].length; sq++) |
| 799 |
|
{ |
| 800 |
0 |
if (!((boolean[]) url[1])[sq]) |
| 801 |
|
{ |
| 802 |
0 |
jalview.bin.Console.outPrintln("Seq " + sq + ": " |
| 803 |
|
+ idstring[0][sq] + "\t: " + idstring[1][sq]); |
| 804 |
|
} |
| 805 |
|
} |
| 806 |
0 |
jalview.bin.Console.outPrintln("Sequences that DID match:"); |
| 807 |
0 |
for (int sq = 0; sq < idstring[0].length; sq++) |
| 808 |
|
{ |
| 809 |
0 |
if (((boolean[]) url[1])[sq]) |
| 810 |
|
{ |
| 811 |
0 |
jalview.bin.Console.outPrintln("Seq " + sq + ": " |
| 812 |
|
+ idstring[0][sq] + "\t: " + idstring[1][sq]); |
| 813 |
|
} |
| 814 |
|
} |
| 815 |
0 |
jalview.bin.Console.outPrintln("The generated URL:"); |
| 816 |
0 |
jalview.bin.Console.outPrintln(((String[]) url[3])[0]); |
| 817 |
|
} |
| 818 |
|
} |
| 819 |
|
|
| 820 |
|
|
| 821 |
|
|
| 822 |
|
@param |
| 823 |
|
|
| 824 |
|
|
| |
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 5 |
Complexity Density: 0.21 |
|
| 825 |
0 |
public static void main(String argv[])... |
| 826 |
|
{ |
| 827 |
|
|
| 828 |
0 |
String[] links = new String[] { |
| 829 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCEIDS$&inputType=0|,", |
| 830 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=linkInDatasetFromJalview&input=$SEQUENCES$&inputType=1|,", |
| 831 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,", |
| 832 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Enfin%20Default%20Workflow&datasetName=$DATASETID$&input=$SEQUENCES$&inputType=1|,", |
| 833 |
|
"EnVision2|IDS|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=$SEQUENCEIDS$&datasetName=linkInDatasetFromJalview&input=$SEQUENCEIDS$&inputType=0|,", |
| 834 |
|
"EnVision2|Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=$SEQUENCEIDS$&datasetName=$DATASETID$&input=$SEQUENCES$&inputType=1|,", |
| 835 |
|
"EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([a-zA-Z]+)/=$&inputType=1|,", |
| 836 |
|
"EnVision2 Seqs|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/[A-Za-z]+/=$&inputType=1|," |
| 837 |
|
|
| 838 |
|
|
| 839 |
|
|
| 840 |
|
|
| 841 |
|
|
| 842 |
|
}; |
| 843 |
|
|
| 844 |
0 |
SequenceI[] seqs = new SequenceI[] { |
| 845 |
|
new Sequence("StupidLabel:gi|9234|pdb|102L|A", |
| 846 |
|
"asdiasdpasdpadpwpadasdpaspdw"), }; |
| 847 |
0 |
String[][] seqsandids = formStrings(seqs); |
| 848 |
0 |
for (int i = 0; i < links.length; i++) |
| 849 |
|
{ |
| 850 |
0 |
GroupUrlLink ul = new GroupUrlLink(links[i]); |
| 851 |
0 |
if (ul.isValid()) |
| 852 |
|
{ |
| 853 |
0 |
jalview.bin.Console.outPrintln("\n\n\n"); |
| 854 |
0 |
jalview.bin.Console.outPrintln( |
| 855 |
|
"Link " + i + " " + links[i] + " : " + ul.toString()); |
| 856 |
0 |
jalview.bin.Console.outPrintln(" pref : " + ul.getUrl_prefix()); |
| 857 |
0 |
jalview.bin.Console |
| 858 |
|
.outPrintln(" IdReplace : " + ul.getIDRegexReplace()); |
| 859 |
0 |
jalview.bin.Console |
| 860 |
|
.outPrintln(" SeqReplace : " + ul.getSeqRegexReplace()); |
| 861 |
0 |
jalview.bin.Console.outPrintln(" Suffixes : " + ul.getUrl_suffix()); |
| 862 |
|
|
| 863 |
0 |
jalview.bin.Console.outPrintln( |
| 864 |
|
"<insert input id and sequence strings here> Without onlyIfMatches:"); |
| 865 |
0 |
Object[] urls; |
| 866 |
0 |
try |
| 867 |
|
{ |
| 868 |
0 |
urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", |
| 869 |
|
false); |
| 870 |
0 |
testUrls(ul, seqsandids, urls); |
| 871 |
|
} catch (UrlStringTooLongException ex) |
| 872 |
|
{ |
| 873 |
0 |
jalview.bin.Console.outPrintln("too long exception " + ex); |
| 874 |
|
} |
| 875 |
0 |
jalview.bin.Console.outPrintln( |
| 876 |
|
"<insert input id and sequence strings here> With onlyIfMatches set:"); |
| 877 |
0 |
try |
| 878 |
|
{ |
| 879 |
0 |
urls = ul.makeUrls(seqsandids[0], seqsandids[1], "mydataset", |
| 880 |
|
true); |
| 881 |
0 |
testUrls(ul, seqsandids, urls); |
| 882 |
|
} catch (UrlStringTooLongException ex) |
| 883 |
|
{ |
| 884 |
0 |
jalview.bin.Console.outPrintln("too long exception " + ex); |
| 885 |
|
} |
| 886 |
|
} |
| 887 |
|
else |
| 888 |
|
{ |
| 889 |
0 |
jalview.bin.Console.errPrintln("Invalid URLLink : " + links[i] |
| 890 |
|
+ " : " + ul.getInvalidMessage()); |
| 891 |
|
} |
| 892 |
|
} |
| 893 |
|
} |
| 894 |
|
|
| 895 |
|
|
| 896 |
|
|
| 897 |
|
|
| 898 |
|
|
| 899 |
|
|
| 900 |
|
@param |
| 901 |
|
@return |
| 902 |
|
|
| |
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 903 |
0 |
public static String[][] formStrings(SequenceI[] seqs)... |
| 904 |
|
{ |
| 905 |
0 |
String[][] idset = new String[2][seqs.length]; |
| 906 |
0 |
for (int i = 0; i < seqs.length; i++) |
| 907 |
|
{ |
| 908 |
0 |
idset[0][i] = seqs[i].getName(); |
| 909 |
0 |
idset[1][i] = seqs[i].getSequenceAsString(); |
| 910 |
|
} |
| 911 |
0 |
return idset; |
| 912 |
|
} |
| 913 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 914 |
0 |
public void setLabel(String newlabel)... |
| 915 |
|
{ |
| 916 |
0 |
this.label = newlabel; |
| 917 |
|
} |
| 918 |
|
|
| 919 |
|
} |