Skip to content

Commit 5edfed4

Browse files
committed
Merge pull request #376 from sbliven/fix81_squashed
StructureIdentifier framework This has some minor API incompatible changes (i.e. StructureIdentifier existed before but wasn't used anywhere). It also changes the default behavior for some things in AtomCache (e.g. filenames are now supported), but without changing the API.
2 parents 998e360 + 1fa6f3d commit 5edfed4

57 files changed

Lines changed: 2155 additions & 1237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

biojava-core/src/main/java/org/biojava/nbio/core/util/InputStreamProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public InputStream getInputStream(URL u)
130130
return openCompressedURL(u);
131131
} else if (magic == GZIP_MAGIC ) {
132132
return openGZIPURL(u);
133-
} else if ( u.toString().endsWith(".gz")) {
133+
} else if ( u.getPath().endsWith(".gz")) {
134134
return openGZIPURL(u);
135-
} else if ( u.toString().endsWith(".Z")) {
135+
} else if ( u.getPath().endsWith(".Z")) {
136136
// unix compressed
137137
return openCompressedURL(u);
138138

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void testGetNrAtoms(){
126126
assertEquals("did not find the expected number of Atoms (1087), but got " + length,1087,length);
127127
}
128128

129+
@SuppressWarnings("deprecation")
129130
public void testGetSubRanges() throws StructureException {
130131
String range;
131132
Structure substr;
@@ -230,13 +231,13 @@ public void testGetSubRanges() throws StructureException {
230231
try {
231232
range = "7-10";
232233
substr = StructureTools.getSubRanges(structure2, range);
233-
fail("Illegal range '"+range+"'. Should throw StructureException");
234-
} catch(StructureException ex) {} //expected
234+
fail("Illegal range '"+range+"'. Should throw IllegalArgumentException");
235+
} catch(IllegalArgumentException ex) {} //expected
235236
try {
236237
range = "A7-10";
237238
substr = StructureTools.getSubRanges(structure2, range);
238-
fail("Illegal range '"+range+"'. Should throw StructureException");
239-
} catch(StructureException ex) {} //expected
239+
fail("Illegal range '"+range+"'. Should throw IllegalArgumentException");
240+
} catch(IllegalArgumentException ex) {} //expected
240241
}
241242

242243
public void testRevisedConvention() throws IOException, StructureException{
@@ -319,6 +320,7 @@ public void testRevisedConvention() throws IOException, StructureException{
319320
* Test some subranges that we used to have problems with
320321
* @throws StructureException
321322
*/
323+
@SuppressWarnings("deprecation")
322324
public void testGetSubRangesExtended() throws StructureException {
323325
String range;
324326
Structure substr;
@@ -379,6 +381,7 @@ public void testGetSubRangesExtended() throws StructureException {
379381
* Test insertion codes
380382
* @throws StructureException
381383
*/
384+
@SuppressWarnings("deprecation")
382385
public void testGetSubRangesInsertionCodes() throws StructureException {
383386
String range;
384387
Structure substr;

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/cath/CathDomainTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public class CathDomainTest {
3636
public void test() {
3737
String id = "1qvrC03";
3838
CathDomain domain = CathFactory.getCathDatabase().getDomainByCathId(id);
39-
assertEquals("1qvr.C_332-400,C_514-540", domain.getIdentifier());
39+
assertEquals("1qvr.C_332-400,C_514-540", domain.toCanonical().getIdentifier());
4040
}
4141
}

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/AlignmentGui.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,27 @@
2222
*/
2323
package org.biojava.nbio.structure.align.gui;
2424

25+
import java.awt.Dimension;
26+
import java.awt.event.ActionEvent;
27+
import java.io.File;
28+
import java.io.IOException;
29+
30+
import javax.swing.AbstractAction;
31+
import javax.swing.Action;
32+
import javax.swing.Box;
33+
import javax.swing.JButton;
34+
import javax.swing.JComboBox;
35+
import javax.swing.JFrame;
36+
import javax.swing.JLabel;
37+
import javax.swing.JMenuBar;
38+
import javax.swing.JOptionPane;
39+
import javax.swing.JProgressBar;
40+
import javax.swing.JTabbedPane;
41+
42+
import org.biojava.nbio.structure.PassthroughIdentifier;
2543
import org.biojava.nbio.structure.Structure;
2644
import org.biojava.nbio.structure.StructureException;
45+
import org.biojava.nbio.structure.StructureIdentifier;
2746
import org.biojava.nbio.structure.align.StructureAlignment;
2847
import org.biojava.nbio.structure.align.StructureAlignmentFactory;
2948
import org.biojava.nbio.structure.align.ce.AbstractUserArgumentProcessor;
@@ -34,10 +53,6 @@
3453
import org.biojava.nbio.structure.gui.util.PDBUploadPanel;
3554
import org.biojava.nbio.structure.gui.util.ScopSelectPanel;
3655
import org.biojava.nbio.structure.gui.util.StructurePairSelector;
37-
import javax.swing.*;
38-
import java.awt.*;
39-
import java.awt.event.ActionEvent;
40-
import java.io.File;
4156

4257
/** A JFrame that allows to trigger a pairwise structure alignment,
4358
* either from files in a directory,
@@ -368,8 +383,8 @@ private void calcAlignment() {
368383
String name2 = "custom2";
369384

370385
if ( pos == 0){
371-
name1 = tab1.getName1();
372-
name2 = tab1.getName2();
386+
name1 = tab1.getName1().getIdentifier();
387+
name2 = tab1.getName2().getIdentifier();
373388
} else {
374389
name1 = s1.getName();
375390
name2 = s2.getName();
@@ -389,6 +404,8 @@ private void calcAlignment() {
389404
drawer.start();
390405
} catch (StructureException e){
391406
JOptionPane.showMessageDialog(null,"Could not align structures. Exception: " + e.getMessage());
407+
} catch (IOException e) {
408+
JOptionPane.showMessageDialog(null,"Could not align structures. Exception: " + e.getMessage());
392409
}
393410

394411
}

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/MultipleAlignmentCalc.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.biojava.nbio.structure.Atom;
2929
import org.biojava.nbio.structure.Structure;
3030
import org.biojava.nbio.structure.StructureException;
31+
import org.biojava.nbio.structure.StructureIdentifier;
3132
import org.biojava.nbio.structure.StructureTools;
3233
import org.biojava.nbio.structure.align.MultipleStructureAligner;
3334
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
@@ -49,7 +50,7 @@ public class MultipleAlignmentCalc implements AlignmentCalculationRunnable {
4950
private static final Logger logger =
5051
LoggerFactory.getLogger(MultipleAlignmentCalc.class);
5152

52-
private List<String> names;
53+
private List<StructureIdentifier> names;
5354
private List<Structure> structures;
5455

5556
private MultipleAlignmentGUI parent;
@@ -63,7 +64,7 @@ public class MultipleAlignmentCalc implements AlignmentCalculationRunnable {
6364
* @param names
6465
*/
6566
public MultipleAlignmentCalc(MultipleAlignmentGUI parent,
66-
List<Structure> structures, List<String> names) {
67+
List<Structure> structures, List<StructureIdentifier> names) {
6768

6869
this.parent= parent;
6970
this.structures = structures;
@@ -84,7 +85,7 @@ public void run() {
8485
}
8586

8687
MultipleAlignment msa = algorithm.align(atomArrays);
87-
msa.getEnsemble().setStructureNames(names);
88+
msa.getEnsemble().setStructureIdentifiers(names);
8889

8990
MultipleAlignmentDisplay.display(msa);
9091

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/MultipleAlignmentGUI.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import org.biojava.nbio.structure.Structure;
4242
import org.biojava.nbio.structure.StructureException;
43+
import org.biojava.nbio.structure.StructureIdentifier;
4344
import org.biojava.nbio.structure.align.MultipleStructureAligner;
4445
import org.biojava.nbio.structure.align.StructureAlignment;
4546
import org.biojava.nbio.structure.align.StructureAlignmentFactory;
@@ -291,11 +292,11 @@ private void calcAlignment() {
291292
return;
292293
}
293294

294-
List<String> names = tab.getNames();
295+
List<StructureIdentifier> names = tab.getNames();
295296

296297
String message = "aligning: ";
297-
for (String name:names){
298-
message += name + " ";
298+
for (StructureIdentifier name:names){
299+
message += name.getIdentifier() + " ";
299300
}
300301
System.out.println(message);
301302

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/SelectPDBPanel.java

Lines changed: 41 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
*/
2121
package org.biojava.nbio.structure.align.gui;
2222

23+
import java.awt.BorderLayout;
24+
import java.awt.Dimension;
25+
import java.io.IOException;
26+
27+
import javax.swing.Box;
28+
import javax.swing.JLabel;
29+
import javax.swing.JPanel;
30+
import javax.swing.JTabbedPane;
31+
import javax.swing.JTextField;
32+
33+
import org.biojava.nbio.structure.ResidueRange;
2334
import org.biojava.nbio.structure.Structure;
2435
import org.biojava.nbio.structure.StructureException;
25-
import org.biojava.nbio.structure.StructureTools;
36+
import org.biojava.nbio.structure.StructureIdentifier;
37+
import org.biojava.nbio.structure.SubstructureIdentifier;
38+
import org.biojava.nbio.structure.align.util.AtomCache;
2639
import org.biojava.nbio.structure.align.util.UserConfiguration;
2740
import org.biojava.nbio.structure.align.webstart.WebStartMain;
2841
import org.biojava.nbio.structure.gui.util.StructurePairSelector;
29-
import org.biojava.nbio.structure.io.FileParsingParameters;
30-
import org.biojava.nbio.structure.io.MMCIFFileReader;
31-
import org.biojava.nbio.structure.io.PDBFileReader;
32-
import org.biojava.nbio.structure.io.StructureProvider;
33-
34-
import javax.swing.*;
35-
import java.awt.*;
36-
import java.io.IOException;
3742

3843

3944
/** A Panel that allows user to specify PDB & chain ID, as well as sub-ranges
@@ -100,101 +105,46 @@ public SelectPDBPanel(boolean show2PDBs) {
100105
this.add(vBox);
101106
}
102107

103-
public String getName1() {
104-
108+
public StructureIdentifier getName1() {
109+
String pdbId = f1.getText().trim();
105110
String chainId = c1.getText().trim();
106-
107-
String name = f1.getText().trim();
108-
109-
if ( ! chainId.equals("") ){
110-
name += "." + chainId;
111+
String range = r1.getText().trim();
112+
113+
// Prefer range over chain
114+
if( ! range.isEmpty() ) {
115+
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
116+
} else if ( ! chainId.isEmpty() ){
117+
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
111118
}
112-
return name;
119+
return new SubstructureIdentifier(pdbId);
113120
}
114-
public String getName2() {
121+
public StructureIdentifier getName2() {
122+
String pdbId = f2.getText().trim();
115123
String chainId = c2.getText().trim();
116-
117-
String name = f2.getText().trim();
118-
119-
if ( ! chainId.equals("") ){
120-
name += "." + chainId;
124+
String range = r2.getText().trim();
125+
126+
// Prefer range over chain
127+
if( ! range.isEmpty() ) {
128+
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(range));
129+
} else if ( ! chainId.isEmpty() ){
130+
return new SubstructureIdentifier(pdbId, ResidueRange.parseMultiple(chainId));
121131
}
122-
return name;
132+
return new SubstructureIdentifier(pdbId);
123133
}
124134
@Override
125-
public Structure getStructure1() throws StructureException{
126-
return fromPDB(f1,c1,r1);
135+
public Structure getStructure1() throws StructureException, IOException{
136+
return getStructure(getName1());
127137
}
128138

129139
@Override
130-
public Structure getStructure2() throws StructureException{
131-
return fromPDB(f2,c2,r2);
140+
public Structure getStructure2() throws StructureException, IOException{
141+
return getStructure(getName2());
132142
}
133143

134-
135-
136-
137-
138-
139-
private Structure fromPDB(JTextField f, JTextField c,JTextField r) throws StructureException{
140-
String pdb = f.getText().trim();
141-
144+
private Structure getStructure(StructureIdentifier name) throws IOException, StructureException {
142145
UserConfiguration config = WebStartMain.getWebStartConfig();
143-
144-
if ( pdb.length() < 4) {
145-
f.setText("!!!");
146-
return null;
147-
}
148-
149-
String chain = c.getText().trim();
150-
if ( debug )
151-
System.out.println("file :" + pdb + " " + chain);
152-
153-
154-
String range = r.getText().trim();
155-
156-
String fileFormat = config.getFileFormat();
157-
158-
StructureProvider reader = null;
159-
if ( fileFormat.equals(UserConfiguration.PDB_FORMAT)){
160-
PDBFileReader re = new PDBFileReader(config.getPdbFilePath());
161-
re.setFetchBehavior(config.getFetchBehavior());
162-
reader = re;
163-
} else if ( fileFormat.equals(UserConfiguration.MMCIF_FORMAT)){
164-
MMCIFFileReader re = new MMCIFFileReader(config.getPdbFilePath());
165-
re.setFetchBehavior(config.getFetchBehavior());
166-
reader = re;
167-
} else {
168-
throw new StructureException("Unkown file format " + fileFormat);
169-
}
170-
171-
FileParsingParameters params = new FileParsingParameters();
172-
params.setAlignSeqRes(false);
173-
reader.setFileParsingParameters(params);
174-
175-
176-
Structure structure ;
177-
try {
178-
structure = reader.getStructureById(pdb);
179-
} catch (IOException e) {
180-
throw new StructureException("Could not read structure " + pdb ,e);
181-
}
182-
183-
184-
//System.out.println(" got range: " + range);
185-
if ( range != null && ( ! range.equals(""))){
186-
if ( structure.getName() == null || structure.getName().equals(""))
187-
structure.setName(pdb);
188-
Structure s = StructureTools.getSubRanges(structure, range);
189-
//System.out.println("got atoms: " + StructureTools.getAtomCAArray(s).length);
190-
return s;
191-
}
192-
Structure s = StructureTools.getReducedStructure(structure,chain);
193-
//System.out.println("got atoms: " + StructureTools.getAtomCAArray(s).length);
194-
if ( s.getName() == null || s.getName().equals(""))
195-
s.setName(pdb+"."+chain);
196-
return s;
197-
146+
AtomCache cache = new AtomCache(config);
147+
return cache.getStructure(name);
198148
}
199149

200150
private Box getPDBFilePanel(int pos ,JTextField f, JTextField c, JTextField r){

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MultipleAlignmentJmol.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.biojava.nbio.structure.PDBHeader;
4747
import org.biojava.nbio.structure.Structure;
4848
import org.biojava.nbio.structure.StructureException;
49+
import org.biojava.nbio.structure.StructureIdentifier;
4950
import org.biojava.nbio.structure.align.gui.MenuCreator;
5051
import org.biojava.nbio.structure.align.gui.MultipleAlignmentDisplay;
5152
import org.biojava.nbio.structure.align.gui.MultipleAlignmentGUI;
@@ -181,7 +182,7 @@ public void actionPerformed(ActionEvent e) {
181182

182183
for (int str=0; str<multAln.size(); str++){
183184
JCheckBox structureSelection = new JCheckBox(
184-
multAln.getEnsemble().getStructureNames().get(str));
185+
multAln.getEnsemble().getStructureIdentifiers().get(str).getIdentifier());
185186
hBox0.add(structureSelection);
186187
hBox0.add(Box.createGlue());
187188
structureSelection.setSelected(true);
@@ -334,6 +335,7 @@ public void itemStateChanged(ItemEvent e) {
334335
resetDisplay();
335336
}
336337

338+
@Override
337339
protected void initCoords(){
338340
try {
339341
if ( multAln == null ){
@@ -348,8 +350,8 @@ protected void initCoords(){
348350
String title = multAln.getEnsemble().getAlgorithmName() +
349351
" V." +multAln.getEnsemble().getVersion() + " : ";
350352

351-
for (String name:multAln.getEnsemble().getStructureNames()){
352-
title += name + " ";
353+
for (StructureIdentifier name:multAln.getEnsemble().getStructureIdentifiers()){
354+
title += name.getIdentifier() + " ";
353355
}
354356
Structure artificial = MultipleAlignmentDisplay.
355357
getAlignedStructure(transformedAtoms);
@@ -534,6 +536,7 @@ private static void printJmolScript4Block(Atom[] atoms,
534536
jmol.append(buf);
535537
}
536538

539+
@Override
537540
public void resetDisplay() {
538541

539542
if (multAln != null && transformedAtoms != null) {

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/gui/util/ScopSelectPanel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ private Structure getStructure(String domainID) throws StructureException{
137137
//String cacheLocation = config.getPdbFilePath();
138138

139139
AtomCache cache = new AtomCache(config);
140-
cache.setStrictSCOP(false);
141140

142141
Structure s = null;
143142
try {

0 commit comments

Comments
 (0)