From 865633cd6ddc767e82ac3fd265ac2d9400a25198 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Tue, 28 Mar 2017 18:03:41 +0100 Subject: [PATCH] JAL-2465 bugfix and rerefactor renamed getPdbFile() method to getStructureFile() --- src/MCview/AppletPDBCanvas.java | 2 +- src/MCview/PDBCanvas.java | 2 +- src/jalview/ext/jmol/JalviewJmolBinding.java | 38 ++++++++++++++++---- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 10 +++--- src/jalview/gui/AppJmol.java | 8 ++--- src/jalview/gui/StructureViewerBase.java | 4 +-- .../javascript/MouseOverStructureListener.java | 2 +- src/jalview/structure/StructureListener.java | 2 +- .../structure/StructureSelectionManager.java | 2 +- .../structures/models/AAStructureBindingModel.java | 4 +-- .../ext/rbvi/chimera/JalviewChimeraView.java | 2 +- .../models/AAStructureBindingModelTest.java | 4 +-- 12 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 3ae0650..277b84d 100644 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -1119,7 +1119,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // //////////////////////////////// // /StructureListener @Override - public String[] getPdbFile() + public String[] getStructureFiles() { return new String[] { pdbentry.getFile() }; } diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index 08bca8c..3b47d94 100644 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -1075,7 +1075,7 @@ public class PDBCanvas extends JPanel implements MouseListener, // //////////////////////////////// // /StructureListener @Override - public String[] getPdbFile() + public String[] getStructureFiles() { return new String[] { pdbentry.getFile() }; } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 94df99a..0122802 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -164,7 +164,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel public void closeViewer() { // remove listeners for all structures in viewer - getSsm().removeStructureViewerListener(this, this.getPdbFile()); + getSsm().removeStructureViewerListener(this, this.getStructureFiles()); viewer.dispose(); lastCommand = null; viewer = null; @@ -250,7 +250,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel * get the distinct structure files modelled * (a file with multiple chains may map to multiple sequences) */ - String[] files = getPdbFile(); + String[] files = getStructureFiles(); if (!waitForFileLoad(files)) { return null; @@ -577,7 +577,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel private int getModelNum(String modelFileName) { - String[] mfn = getPdbFile(); + String[] mfn = getStructureFiles(); if (mfn == null) { return -1; @@ -601,8 +601,8 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel // //////////////////////////////// // /StructureListener - @Override - public synchronized String[] getPdbFile() + // @Override + public synchronized String[] getPdbFilex() { if (viewer == null) { @@ -667,6 +667,32 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel return modelFileNames; } + @Override + public synchronized String[] getStructureFiles() + { + List mset = new ArrayList(); + if (viewer == null) + { + return new String[0]; + } + + if (modelFileNames == null) + { + int modelCount = viewer.ms.mc; + String filePath = null; + for (int i = 0; i < modelCount; ++i) + { + filePath = viewer.ms.getModelFileName(i); + if (!mset.contains(filePath)) + { + mset.add(filePath); + } + } + modelFileNames = mset.toArray(new String[mset.size()]); + } + + return modelFileNames; + } /** * map from string to applet */ @@ -1035,7 +1061,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel chainNames = new ArrayList(); chainFile = new Hashtable(); boolean notifyLoaded = false; - String[] modelfilenames = getPdbFile(); + String[] modelfilenames = getStructureFiles(); // first check if we've lost any structures if (oldmodels != null && oldmodels.length > 0) { diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index ffce90c..daf6131 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -289,7 +289,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ public void closeViewer(boolean closeChimera) { - getSsm().removeStructureViewerListener(this, this.getPdbFile()); + getSsm().removeStructureViewerListener(this, this.getStructureFiles()); if (closeChimera) { viewer.exitChimera(); @@ -340,7 +340,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel int[] _refStructure, ColumnSelection[] _hiddenCols) { StringBuilder allComs = new StringBuilder(128); - String[] files = getPdbFile(); + String[] files = getStructureFiles(); if (!waitForFileLoad(files)) { @@ -577,7 +577,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * to the Chimera command 'list models type molecule', see * ChimeraManager.getModelList(). */ - List maps = chimeraMaps.get(getPdbFile()[pdbfnum]); + List maps = chimeraMaps.get(getStructureFiles()[pdbfnum]); boolean hasSubModels = maps != null && maps.size() > 1; return "#" + String.valueOf(pdbfnum) + (hasSubModels ? ".1" : ""); } @@ -745,7 +745,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel // //////////////////////////////// // /StructureListener @Override - public synchronized String[] getPdbFile() + public synchronized String[] getStructureFiles() { if (viewer == null) { @@ -1100,7 +1100,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel // TODO refactor as required to pull up to an interface AlignmentI alignment = avp.getAlignment(); - String[] files = getPdbFile(); + String[] files = getStructureFiles(); if (files == null) { return 0; diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 5d23f49..68a847e 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -410,8 +410,8 @@ public class AppJmol extends StructureViewerBase int waitFor = 35; int waitTotal = 0; while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled() - : !(jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb - .getPdbFile().length == files.size())) + : !(jmb.isFinishedInit() && jmb.getStructureFiles() != null && jmb + .getStructureFiles().length == files.size())) { try { @@ -429,7 +429,7 @@ public class AppJmol extends StructureViewerBase // System.err.println("finished: " + jmb.isFinishedInit() // + "; loaded: " + Arrays.toString(jmb.getPdbFile()) // + "; files: " + files.toString()); - jmb.getPdbFile(); + jmb.getStructureFiles(); break; } } @@ -494,7 +494,7 @@ public class AppJmol extends StructureViewerBase String pdbid = ""; try { - String[] filesInViewer = jmb.getPdbFile(); + String[] filesInViewer = jmb.getStructureFiles(); // TODO: replace with reference fetching/transfer code (validate PDBentry // as a DBRef?) Pdb pdbclient = new Pdb(); diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index d7f7c31..c52be92 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -919,7 +919,7 @@ public abstract class StructureViewerBase extends GStructureViewer { // TODO: cope with multiple PDB files in view in = new BufferedReader( - new FileReader(getBinding().getPdbFile()[0])); + new FileReader(getBinding().getStructureFiles()[0])); File outFile = chooser.getSelectedFile(); PrintWriter out = new PrintWriter(new FileOutputStream(outFile)); @@ -991,7 +991,7 @@ public abstract class StructureViewerBase extends GStructureViewer * enable 'Superpose with' if more than one mapped structure */ viewSelectionMenu.setEnabled(false); - if (getBinding().getPdbFile().length > 1 + if (getBinding().getStructureFiles().length > 1 && getBinding().getSequence().length > 1) { viewSelectionMenu.setEnabled(true); diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 7580222..c390b17 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -126,7 +126,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements } @Override - public String[] getPdbFile() + public String[] getStructureFiles() { return modelSet; } diff --git a/src/jalview/structure/StructureListener.java b/src/jalview/structure/StructureListener.java index e5c5d04..9fde3f1 100644 --- a/src/jalview/structure/StructureListener.java +++ b/src/jalview/structure/StructureListener.java @@ -31,7 +31,7 @@ public interface StructureListener * handles messages for, or null if generic listener (only used by * removeListener method) */ - public String[] getPdbFile(); + public String[] getStructureFiles(); /** * Called by StructureSelectionManager to inform viewer to highlight given diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 3ab642f..6930161 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -739,7 +739,7 @@ public class StructureSelectionManager if (listeners.elementAt(i) instanceof StructureListener) { sl = (StructureListener) listeners.elementAt(i); - for (String pdbfile : sl.getPdbFile()) + for (String pdbfile : sl.getStructureFiles()) { pdbs.remove(pdbfile); } diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 84475fe..d9e8c95 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -532,7 +532,7 @@ public abstract class AAStructureBindingModel extends BitSet matched, SuperposeData[] structures) { int refStructure = -1; - String[] files = getPdbFile(); + String[] files = getStructureFiles(); if (files == null) { return -1; @@ -756,7 +756,7 @@ public abstract class AAStructureBindingModel extends { return; } - String[] files = getPdbFile(); + String[] files = getStructureFiles(); SequenceRenderer sr = getSequenceRenderer(alignmentv); diff --git a/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java b/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java index d85bb10..29fd092 100644 --- a/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java +++ b/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java @@ -217,7 +217,7 @@ public class JalviewChimeraView * (or possibly 52-145 to 1-94 - see JAL-2319) */ StructureSelectionManager ssm = binding.getSsm(); - String pdbFile = binding.getPdbFile()[0]; + String pdbFile = binding.getStructureFiles()[0]; StructureMapping[] mappings = ssm.getMapping(pdbFile); assertTrue(mappings[0].getMappingDetailsOutput().contains("SIFTS"), "Failed to perform SIFTS mapping"); diff --git a/test/jalview/structures/models/AAStructureBindingModelTest.java b/test/jalview/structures/models/AAStructureBindingModelTest.java index 7ba22b4..dc096ed 100644 --- a/test/jalview/structures/models/AAStructureBindingModelTest.java +++ b/test/jalview/structures/models/AAStructureBindingModelTest.java @@ -138,7 +138,7 @@ public class AAStructureBindingModelTest testee = new AAStructureBindingModel(ssm, pdbFiles, seqs, null) { @Override - public String[] getPdbFile() + public String[] getStructureFiles() { return new String[] { "INLINE1YCS", "INLINE3A6S", "INLINE1OOT" }; } @@ -230,7 +230,7 @@ public class AAStructureBindingModelTest /* * create a data bean to hold data per structure file */ - SuperposeData[] structs = new SuperposeData[testee.getPdbFile().length]; + SuperposeData[] structs = new SuperposeData[testee.getStructureFiles().length]; for (int i = 0; i < structs.length; i++) { structs[i] = testee.new SuperposeData(al.getWidth()); -- 1.7.10.2