From 31df3f13e3ab1ac158ec576d691fa860e9f6dd4b Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 15 Jun 2020 20:22:29 +0100 Subject: [PATCH] JAL-3628 Changed other calls to renameTo to use BackupFiles.moveFileToFile --- src/jalview/io/BackupFiles.java | 2 +- src/jalview/ws/sifts/SiftsClient.java | 62 +++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index a41af4a..1c8525b 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -773,7 +773,7 @@ public class BackupFiles return ret; } - private boolean moveFileToFile(File oldFile, File newFile) + public static boolean moveFileToFile(File oldFile, File newFile) { boolean ret = false; Path oldPath = Paths.get(oldFile.getAbsolutePath()); diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 4fb9ca9..ae58082 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -58,6 +58,7 @@ import jalview.api.SiftsClientI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceI; +import jalview.io.BackupFiles; import jalview.io.StructureFile; import jalview.schemes.ResidueProperties; import jalview.structure.StructureMapping; @@ -124,6 +125,7 @@ public class SiftsClient implements SiftsClientI private enum CoordinateSys { UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe"); + private String name; private CoordinateSys(String name) @@ -141,6 +143,7 @@ public class SiftsClient implements SiftsClientI { NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE("codeSecondaryStructure"), ANNOTATION("Annotation"); + private String code; private ResidueDetailType(String code) @@ -227,7 +230,7 @@ public class SiftsClient implements SiftsClientI SiftsSettings.getCacheThresholdInDays())) { File oldSiftsFile = new File(siftsFileName + "_old"); - siftsFile.renameTo(oldSiftsFile); + BackupFiles.moveFileToFile(siftsFile, oldSiftsFile); try { siftsFile = downloadSiftsFile(pdbId.toLowerCase()); @@ -236,7 +239,7 @@ public class SiftsClient implements SiftsClientI } catch (IOException e) { e.printStackTrace(); - oldSiftsFile.renameTo(siftsFile); + BackupFiles.moveFileToFile(oldSiftsFile, siftsFile); return new File(siftsFileName); } } @@ -301,7 +304,7 @@ public class SiftsClient implements SiftsClientI } String siftFile = pdbId + ".xml.gz"; String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile; - + /* * Download the file from URL to either * Java: directory of cached downloaded SIFTS files @@ -329,8 +332,7 @@ public class SiftsClient implements SiftsClientI URL url = new URL(siftsFileFTPURL); URLConnection conn = url.openConnection(); InputStream inputStream = conn.getInputStream(); - FileOutputStream outputStream = new FileOutputStream( - downloadTo); + FileOutputStream outputStream = new FileOutputStream(downloadTo); byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = inputStream.read(buffer)) != -1) @@ -478,7 +480,7 @@ public class SiftsClient implements SiftsClientI SequenceI seq, java.io.PrintStream os) throws SiftsException { List omitNonObserved = new ArrayList<>(); - int nonObservedShiftIndex = 0,pdbeNonObserved=0; + int nonObservedShiftIndex = 0, pdbeNonObserved = 0; // System.out.println("Generating mappings for : " + entityId); Entity entity = null; entity = getEntityById(entityId); @@ -509,7 +511,7 @@ public class SiftsClient implements SiftsClientI TreeMap resNumMap = new TreeMap(); List segments = entity.getSegment(); SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap, - omitNonObserved, nonObservedShiftIndex,pdbeNonObserved); + omitNonObserved, nonObservedShiftIndex, pdbeNonObserved); processSegments(segments, shp); try { @@ -531,18 +533,20 @@ public class SiftsClient implements SiftsClientI { throw new SiftsException("SIFTS mapping failed"); } - // also construct a mapping object between the seq-coord sys and the PDB seq's coord sys + // also construct a mapping object between the seq-coord sys and the PDB + // seq's coord sys Integer[] keys = mapping.keySet().toArray(new Integer[0]); Arrays.sort(keys); seqStart = keys[0]; seqEnd = keys[keys.length - 1]; - List from=new ArrayList<>(),to=new ArrayList<>(); - int[]_cfrom=null,_cto=null; + List from = new ArrayList<>(), to = new ArrayList<>(); + int[] _cfrom = null, _cto = null; String matchedSeq = originalSeq; - if (seqStart != UNASSIGNED) // fixme! seqStart can map to -1 for a pdb sequence that starts <-1 + if (seqStart != UNASSIGNED) // fixme! seqStart can map to -1 for a pdb + // sequence that starts <-1 { - for (int seqps:keys) + for (int seqps : keys) { int pdbpos = mapping.get(seqps)[PDBE_POS]; if (pdbpos == UNASSIGNED) @@ -550,19 +554,23 @@ public class SiftsClient implements SiftsClientI // not correct - pdbpos might be -1, but leave it for now continue; } - if (_cfrom==null || seqps!=_cfrom[1]+1) + if (_cfrom == null || seqps != _cfrom[1] + 1) { - _cfrom = new int[] { seqps,seqps}; + _cfrom = new int[] { seqps, seqps }; from.add(_cfrom); _cto = null; // discontinuity - } else { - _cfrom[1]= seqps; } - if (_cto==null || pdbpos!=1+_cto[1]) + else + { + _cfrom[1] = seqps; + } + if (_cto == null || pdbpos != 1 + _cto[1]) { - _cto = new int[] { pdbpos,pdbpos}; + _cto = new int[] { pdbpos, pdbpos }; to.add(_cto); - } else { + } + else + { _cto[1] = pdbpos; } } @@ -584,8 +592,7 @@ public class SiftsClient implements SiftsClientI ; seqFromPdbMapping = new jalview.datamodel.Mapping(null, _cto, _cfrom, - 1, - 1); + 1, 1); pdbStart = mapping.get(seqStart)[PDB_RES_POS]; pdbEnd = mapping.get(seqEnd)[PDB_RES_POS]; int orignalSeqStart = seq.getStart(); @@ -716,12 +723,12 @@ public class SiftsClient implements SiftsClientI } // if (currSeqIndex >= seq.getStart() && currSeqIndex <= seqlength) // // true - // numbering - // is - // not - // up - // to - // seq.getEnd() + // numbering + // is + // not + // up + // to + // seq.getEnd() { int resNum = (pdbRefDb == null) @@ -1061,6 +1068,7 @@ public class SiftsClient implements SiftsClientI { return pdbeNonObserved; } + public SequenceI getSeq() { return seq; -- 1.7.10.2