X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2Fsifts%2FSiftsClient.java;h=fe3a25b822575c8dea7c6ea1302a057276fa7c4c;hb=95b34183f11c22462b60bc5c0254d66eba1c1f19;hp=37388d3c1a18d56c580b382db224501093bb33e1;hpb=0ed5b947087f831b8673f4c4e423bd4ef2238a89;p=jalview.git diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 37388d3..fe3a25b 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -295,6 +295,7 @@ public class SiftsClient implements SiftsClientI siftsDownloadDir.mkdirs(); } // System.out.println(">> Download ftp url : " + siftsFileFTPURL); + // long now = System.currentTimeMillis(); URL url = new URL(siftsFileFTPURL); URLConnection conn = url.openConnection(); InputStream inputStream = conn.getInputStream(); @@ -308,7 +309,8 @@ public class SiftsClient implements SiftsClientI } outputStream.close(); inputStream.close(); - // System.out.println(">>> File downloaded : " + downloadedSiftsFile); +// System.out.println(">>> File downloaded : " + downloadedSiftsFile +// + " took " + (System.currentTimeMillis() - now) + "ms"); return new File(downloadedSiftsFile); } @@ -573,18 +575,8 @@ public class SiftsClient implements SiftsClientI .equalsIgnoreCase(seqCoordSys.getName()) && isAccessionMatched(cRefDb.getDbAccessionId())) { - String resNumIndexString = cRefDb.getDbResNum() - .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED) - : cRefDb.getDbResNum(); - try - { - currSeqIndex = Integer.valueOf(resNumIndexString); - } catch (NumberFormatException nfe) - { - currSeqIndex = Integer.valueOf(resNumIndexString - .split("[a-zA-Z]")[0]); - continue; - } + currSeqIndex = getLeadingIntegerValue( + cRefDb.getDbResNum(), UNASSIGNED); if (pdbRefDb != null) { break;// exit loop if pdb and uniprot are already found @@ -597,19 +589,11 @@ public class SiftsClient implements SiftsClientI } if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd()) { - int resNum; - try - { - resNum = (pdbRefDb == null) ? Integer.valueOf(residue - .getDbResNum()) : Integer.valueOf(pdbRefDb - .getDbResNum()); - } catch (NumberFormatException nfe) - { - resNum = (pdbRefDb == null) ? Integer.valueOf(residue - .getDbResNum()) : Integer.valueOf(pdbRefDb - .getDbResNum().split("[a-zA-Z]")[0]); - continue; - } + + int resNum = (pdbRefDb == null) ? getLeadingIntegerValue( + residue.getDbResNum(), UNASSIGNED) + : getLeadingIntegerValue(pdbRefDb.getDbResNum(), + UNASSIGNED); if (isResidueObserved(residue) || seqCoordSys == CoordinateSys.UNIPROT) @@ -632,6 +616,30 @@ public class SiftsClient implements SiftsClientI } /** + * Get the leading integer part of a string that begins with an integer. + * + * @param input + * - the string input to process + * @param failValue + * - value returned if unsuccessful + * @return + */ + static int getLeadingIntegerValue(String input, int failValue) + { + if (input == null) + { + return failValue; + } + String[] parts = input.split("(?=\\D)(?<=\\d)"); + if (parts != null && parts.length > 0 && parts[0].matches("[0-9]+")) + { + return Integer.valueOf(parts[0]); + } + return failValue; + } + + + /** * * @param chainId * Target chain to populate mapping of its atom positions.