Skip to content

Commit 351464c

Browse files
committed
Refactored getChain(int chainIndex) and getChain(int modelNr, int chainIndex) to getChainByIndex().
This avoids ambiguity around whether the input can by a char (implicitally converted to an int).
1 parent 7027064 commit 351464c

File tree

18 files changed

+65
-65
lines changed

18 files changed

+65
-65
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public void testReadPDBFile() throws Exception {
108108

109109
// since biojava 5.0, we have 4 chains here: 1 protein, 2 non-poly (ligands), 1 water
110110

111-
Chain c = structure.getChain(0);
111+
Chain c = structure.getChainByIndex(0);
112112
assertEquals("did not find the expected 58 amino acids!",58,c.getAtomGroups(GroupType.AMINOACID).size());
113113

114114
assertEquals(0 , c.getAtomGroups(GroupType.HETATM).size());
115115

116-
Chain c4 = structure.getChain(3);
116+
Chain c4 = structure.getChainByIndex(3);
117117

118118
// The fourth chain in the file contains 63 molecules of deutarated
119119
assertEquals(63, c4.getAtomGroups(GroupType.HETATM).size());
@@ -221,7 +221,7 @@ public void testPDBHeader(){
221221
@Test
222222
public void testCreateVirtualCBAtom(){
223223

224-
Group g1 = structure.getChain(0).getAtomGroup(11);
224+
Group g1 = structure.getChainByIndex(0).getAtomGroup(11);
225225

226226
if ( g1.getPDBName().equals("GLY")){
227227
if ( g1 instanceof AminoAcid){
@@ -240,11 +240,11 @@ public void testCreateVirtualCBAtom(){
240240
@Test
241241
public void testMutation() throws Exception {
242242

243-
Group g1 = (Group)structure.getChain(0).getAtomGroup(21).clone();
243+
Group g1 = (Group)structure.getChainByIndex(0).getAtomGroup(21).clone();
244244
assertTrue(g1 != null);
245245

246246

247-
Group g2 = (Group)structure.getChain(0).getAtomGroup(53).clone();
247+
Group g2 = (Group)structure.getChainByIndex(0).getAtomGroup(53).clone();
248248
assertTrue(g2 != null);
249249

250250

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void setUp() throws IOException
5656
assertEquals("structure does not contain one chain ", 1 ,structure.size());
5757

5858
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 58 residues
59-
Chain chain = structure.getChain(0);
59+
Chain chain = structure.getChainByIndex(0);
6060
assertEquals("Wrong number of residues.",58,chain.getAtomLength());
6161

6262
inStream.close();
@@ -104,12 +104,12 @@ public void testGetAtomsConsistency() throws IOException, StructureException{
104104

105105
Structure hivA = cache.getStructure("1hiv.A");
106106
Atom[] caSa = StructureTools.getRepresentativeAtomArray(hivA);
107-
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChain(0));
107+
Atom[] caCa = StructureTools.getRepresentativeAtomArray(hivA.getChainByIndex(0));
108108
assertEquals("did not find the same number of Atoms from structure and from chain..",
109109
caSa.length,caCa.length);
110110
Structure hivB = cache.getStructure("1hiv.B");
111111
Atom[] caSb = StructureTools.getRepresentativeAtomArray(hivB);
112-
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChain(0));
112+
Atom[] caCb = StructureTools.getRepresentativeAtomArray(hivB.getChainByIndex(0));
113113
assertEquals("did not find the same number of Atoms from structure and from chain..",
114114
caSb.length,caCb.length);
115115
//Both chains have to be the same size (A and B)
@@ -137,7 +137,7 @@ public void testGetSubRanges() throws StructureException {
137137
substr = StructureTools.getSubRanges(structure2, range);
138138
assertEquals("Wrong number of chains in "+range, 1, substr.size());
139139

140-
chain = substr.getChain(0);
140+
chain = substr.getChainByIndex(0);
141141

142142
assertEquals("Did not find the expected number of residues in "+range, 5, chain.getAtomLength() );
143143

@@ -146,7 +146,7 @@ public void testGetSubRanges() throws StructureException {
146146
substr = StructureTools.getSubRanges(structure2, range);
147147
assertEquals("Wrong number of chains in "+range, 1, substr.size());
148148

149-
chain = substr.getChain(0);
149+
chain = substr.getChainByIndex(0);
150150

151151
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 408 residues
152152
assertEquals("Did not find the expected number of residues in "+range, 408, chain.getAtomLength() );
@@ -157,7 +157,7 @@ public void testGetSubRanges() throws StructureException {
157157
substr = StructureTools.getSubRanges(structure2, range);
158158
assertEquals("Wrong number of chains in "+range, 1, substr.size());
159159

160-
chain = substr.getChain(0);
160+
chain = substr.getChainByIndex(0);
161161

162162
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 408 residues
163163
assertEquals("Did not find the expected number of residues in "+range, 408, chain.getAtomLength() );
@@ -168,10 +168,10 @@ public void testGetSubRanges() throws StructureException {
168168
substr = StructureTools.getSubRanges(structure2, range);
169169
assertEquals("Wrong number of chains in "+range, 2, substr.size());
170170

171-
chain = substr.getChain(0);
171+
chain = substr.getChainByIndex(0);
172172
assertEquals("Did not find the expected number of residues in first chain of "+range, 5, chain.getAtomLength() );
173173

174-
chain = substr.getChain(1);
174+
chain = substr.getChainByIndex(1);
175175
assertEquals("Did not find the expected number of residues in second chain of "+range, 5, chain.getAtomLength() );
176176

177177
// combined ranges
@@ -180,25 +180,25 @@ public void testGetSubRanges() throws StructureException {
180180
assertEquals("Wrong number of chains in "+range, 2, substr.size());
181181

182182
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 408 residues
183-
chain = substr.getChain(0);
183+
chain = substr.getChainByIndex(0);
184184
assertEquals("Did not find the expected number of residues in first chain of "+range, 408, chain.getAtomLength() );
185185

186-
chain = substr.getChain(1);
186+
chain = substr.getChainByIndex(1);
187187
assertEquals("Did not find the expected number of residues in second chain of "+range, 5, chain.getAtomLength() );
188188

189189
// parentheses
190190
range = "(A:3-7)";
191191
substr = StructureTools.getSubRanges(structure2, range);
192192
assertEquals("Wrong number of chains in "+range, 1, substr.size());
193193

194-
chain = substr.getChain(0);
194+
chain = substr.getChainByIndex(0);
195195
assertEquals("Did not find the expected number of residues in "+range, 5, chain.getAtomLength() );
196196

197197
// single residue
198198
range = "A:3";
199199
substr = StructureTools.getSubRanges(structure2, range);
200200
assertEquals("Wrong number of chains in "+range, 1, substr.size());
201-
chain = substr.getChain(0);
201+
chain = substr.getChainByIndex(0);
202202
assertEquals("Did not find the expected number of residues in "+range, 1, chain.getAtomLength() );
203203

204204
// Special '-' case
@@ -212,7 +212,7 @@ public void testGetSubRanges() throws StructureException {
212212
assertEquals("Wrong number of chains in "+range, 1, substr.size());
213213

214214
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 58 residues
215-
chain = substr.getChain(0);
215+
chain = substr.getChainByIndex(0);
216216
assertEquals("Did not find the expected number of residues in first chain of "+range, 58, chain.getAtomLength() );
217217

218218
// Test single-chain syntax in a multi-chain structure. Should give chain A.
@@ -221,7 +221,7 @@ public void testGetSubRanges() throws StructureException {
221221
assertEquals("Wrong number of chains in "+range, 1, substr.size());
222222

223223
// since biojava 5, chains contain either only polymers or only nonpolymers: here we get the first protein chain with 408 residues
224-
chain = substr.getChain(0);
224+
chain = substr.getChainByIndex(0);
225225
assertEquals("Chain _ not converted to chain A.","A",chain.getChainID());
226226
assertEquals("Did not find the expected number of residues in first chain of "+range, 408, chain.getAtomLength() );
227227

@@ -336,7 +336,7 @@ public void testGetSubRangesExtended() throws StructureException {
336336
substr = StructureTools.getSubRanges(structure2, range);
337337
assertEquals("Wrong number of chains in "+range, 1, substr.size());
338338

339-
chain = substr.getChain(0);
339+
chain = substr.getChainByIndex(0);
340340

341341
// Note residue 0 is missing from 1lnl
342342
assertEquals("Did not find the expected number of residues in "+range, 10, chain.getAtomLength() );
@@ -346,7 +346,7 @@ public void testGetSubRangesExtended() throws StructureException {
346346
substr = StructureTools.getSubRanges(structure2, range);
347347
assertEquals("Wrong number of chains in "+range, 1, substr.size());
348348

349-
chain = substr.getChain(0);
349+
chain = substr.getChainByIndex(0);
350350

351351
assertEquals("Did not find the expected number of residues in "+range, 3, chain.getAtomLength() );
352352

@@ -355,7 +355,7 @@ public void testGetSubRangesExtended() throws StructureException {
355355
substr = StructureTools.getSubRanges(structure2, range);
356356
assertEquals("Wrong number of chains in "+range, 1, substr.size());
357357

358-
chain = substr.getChain(0);
358+
chain = substr.getChainByIndex(0);
359359

360360
assertEquals("Did not find the expected number of residues in "+range, 4, chain.getAtomLength() );
361361

@@ -364,7 +364,7 @@ public void testGetSubRangesExtended() throws StructureException {
364364
substr = StructureTools.getSubRanges(structure2, range);
365365
assertEquals("Wrong number of chains in "+range, 1, substr.size());
366366

367-
chain = substr.getChain(0);
367+
chain = substr.getChainByIndex(0);
368368

369369
assertEquals("Did not find the expected number of residues in "+range, 6, chain.getAtomLength() );
370370

@@ -374,10 +374,10 @@ public void testGetSubRangesExtended() throws StructureException {
374374
substr = StructureTools.getSubRanges(structure2, range);
375375
assertEquals("Wrong number of chains in "+range, 2, substr.size());
376376

377-
chain = substr.getChain(0);
377+
chain = substr.getChainByIndex(0);
378378
assertEquals("Did not find the expected number of residues in first chain of "+range, 5, chain.getAtomLength() );
379379

380-
chain = substr.getChain(1);
380+
chain = substr.getChainByIndex(1);
381381
assertEquals("Did not find the expected number of residues in second chain of "+range, 5, chain.getAtomLength() );
382382

383383
}
@@ -397,7 +397,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
397397
substr = StructureTools.getSubRanges(structure3, range);
398398
assertEquals("Wrong number of chains in "+range, 1, substr.size());
399399

400-
chain = substr.getChain(0);
400+
chain = substr.getChainByIndex(0);
401401

402402
assertEquals("Did not find the expected number of residues in "+range, 4, chain.getAtomLength() );
403403

@@ -407,7 +407,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
407407
substr = StructureTools.getSubRanges(structure3, range);
408408
assertEquals("Wrong number of chains in "+range, 1, substr.size());
409409

410-
chain = substr.getChain(0);
410+
chain = substr.getChainByIndex(0);
411411

412412
assertEquals("Did not find the expected number of residues in "+range, 3, chain.getAtomLength() );
413413

@@ -416,7 +416,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
416416
substr = StructureTools.getSubRanges(structure3, range);
417417
assertEquals("Wrong number of chains in "+range, 1, substr.size());
418418

419-
chain = substr.getChain(0);
419+
chain = substr.getChainByIndex(0);
420420

421421
assertEquals("Did not find the expected number of residues in "+range, 3, chain.getAtomLength() );
422422

@@ -425,7 +425,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
425425
substr = StructureTools.getSubRanges(structure3, range);
426426
assertEquals("Wrong number of chains in "+range, 1, substr.size());
427427

428-
chain = substr.getChain(0);
428+
chain = substr.getChainByIndex(0);
429429

430430
assertEquals("Did not find the expected number of residues in "+range, 12, chain.getAtomLength() );
431431

@@ -434,7 +434,7 @@ public void testGetSubRangesInsertionCodes() throws StructureException {
434434
substr = StructureTools.getSubRanges(structure3, range);
435435
assertEquals("Wrong number of chains in "+range, 1, substr.size());
436436

437-
chain = substr.getChain(0);
437+
chain = substr.getChainByIndex(0);
438438

439439
assertEquals("Did not find the expected number of residues in "+range, 8, chain.getAtomLength() );
440440
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void test1a4wPDBFile() throws IOException
106106
assertEquals(structure.getPDBHeader().toPDB().toLowerCase(),structure2.getPDBHeader().toPDB().toLowerCase());
107107

108108
for ( int i = 0 ; i < 3 ; i++){
109-
Chain c1 = structure.getChain(i);
110-
Chain c2 = structure.getChain(i);
109+
Chain c1 = structure.getChainByIndex(i);
110+
Chain c2 = structure.getChainByIndex(i);
111111
testEqualChains(c1, c2);
112112
}
113113
}
@@ -159,7 +159,7 @@ public void testChemComps() throws IOException, StructureException {
159159

160160
assertEquals(3, s.getPolyChains().size());
161161

162-
Chain c2 = s.getChain(1);
162+
Chain c2 = s.getChainByIndex(1);
163163
assertEquals("H", c2.getName());
164164

165165

@@ -194,7 +194,7 @@ else if ( pdbName.equals("H2O"))
194194
}
195195

196196
public void testLigandLoading(){
197-
Chain c2 = structure.getChain(1);
197+
Chain c2 = structure.getChainByIndex(1);
198198
assertEquals("H", c2.getName());
199199

200200

@@ -227,7 +227,7 @@ public void testSiteGroups(){
227227
// for (Chain chain : s.getChains()) {
228228
// System.out.println("Chain: " + chain.getChainID());
229229
// }
230-
Chain c2 = s.getChain(1);
230+
Chain c2 = s.getChainByIndex(1);
231231
assertEquals("H", c2.getName());
232232

233233
// if (s == null) {

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestSeqResParsing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void test11GS() throws IOException, StructureException{
5454
s = StructureIO.getStructure(pdbID);
5555
assertNotNull(s);
5656
assertTrue(s.getChains().size() > 0);
57-
Chain c = s.getChain(0);
57+
Chain c = s.getChainByIndex(0);
5858

5959
assertTrue(c.getSeqResGroups().size() > 2);
6060

biojava-structure/src/main/java/demo/DemoContacts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static void demoContacts(String pdbCode) throws IOException, StructureEx
8484
System.out.println("Total number of residue contacts: "+groupContacts.size());
8585

8686

87-
contacts = StructureTools.getAtomsInContact(structure.getChain(0),structure.getChain(1),5.5, false);
87+
contacts = StructureTools.getAtomsInContact(structure.getChainByIndex(0),structure.getChainByIndex(1),5.5, false);
8888

8989
System.out.println("Contacting residues between 2 first chains (all non-H non-hetatoms)");
9090

biojava-structure/src/main/java/demo/DemoLoadStructure.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void loadStructureIO(){
5858
System.out.println(StructureTools.getNrAtoms(s1));
5959

6060

61-
Chain chain1 = s1.getChain(0);
61+
Chain chain1 = s1.getChainByIndex(0);
6262

6363
System.out.println("First chain: " + chain1);
6464

biojava-structure/src/main/java/org/biojava/nbio/structure/Structure.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,19 +395,19 @@ public interface Structure extends Cloneable {
395395
/**
396396
* Retrieve a chain by its index within the Structure .
397397
*
398-
* @param pos an int for the position in the List of Chains.
398+
* @param chainIndex the index of the desired chain in the structure
399399
* @return a Chain object
400400
*/
401-
Chain getChain(int pos);
401+
Chain getChainByIndex(int chainIndex);
402402

403403
/**
404404
* Retrieve a chain by its indices within the Structure and model.
405405
*
406-
* @param pos an int
407-
* @param modelnr an int
406+
* @param chainIndex the index of the desired chain in the structure
407+
* @param modelnr the model the desired chain is in
408408
* @return a Chain object
409409
*/
410-
Chain getChain( int modelnr, int pos);
410+
Chain getChainByIndex(int modelnr, int chainIndex);
411411

412412
/**
413413
* Request a particular chain from a structure.

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public Structure clone() {
150150

151151
for (int j=0;j<size(i);j++){
152152

153-
Chain cloned_chain = (Chain) getChain(i,j).clone();
153+
Chain cloned_chain = (Chain) getChainByIndex(i,j).clone();
154154

155155
// setting the parent: can only be done from the parent
156156
cloned_chain.setStructure(n);
@@ -338,17 +338,17 @@ public void addChain(Chain chain, int modelnr) {
338338

339339
/** {@inheritDoc} */
340340
@Override
341-
public Chain getChain(int number) {
341+
public Chain getChainByIndex(int number) {
342342

343343
int modelnr = 0 ;
344344

345-
return getChain(modelnr,number);
345+
return getChainByIndex(modelnr,number);
346346
}
347347

348348

349349
/** {@inheritDoc} */
350350
@Override
351-
public Chain getChain(int modelnr,int number) {
351+
public Chain getChainByIndex(int modelnr,int number) {
352352

353353
Model model = models.get(modelnr);
354354

@@ -434,7 +434,7 @@ public String toString(){
434434

435435
for (int j=0;j<size(i);j++){
436436

437-
Chain cha = getChain(i,j);
437+
Chain cha = getChainByIndex(i,j);
438438
List<Group> agr = cha.getAtomGroups(GroupType.AMINOACID);
439439
List<Group> hgr = cha.getAtomGroups(GroupType.HETATM);
440440
List<Group> ngr = cha.getAtomGroups(GroupType.NUCLEOTIDE);

biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ public static final Structure getReducedStructure(Structure s, int chainNr) {
11411141
}
11421142
Chain c = null;
11431143

1144-
c = s.getChain(0, chainNr);
1144+
c = s.getChainByIndex(0, chainNr);
11451145

11461146
newStructure.addChain(c);
11471147

biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public Structure reduce(Structure s) throws StructureException {
213213
Chain chain;
214214
if(chainId.equals("_") ) {
215215
// Handle special case of "_" chain for single-chain proteins
216-
chain = s.getChain(modelNr,0);
216+
chain = s.getChainByIndex(modelNr,0);
217217
if(pdbresnum1 != null)
218218
pdbresnum1.setChainName(chain.getName());
219219
if(pdbresnum2 != null)
@@ -234,7 +234,7 @@ public Structure reduce(Structure s) throws StructureException {
234234
try {
235235
int chainNum = Integer.parseInt(chainId);
236236
try {
237-
chain = s.getChain(modelNr, chainNum);
237+
chain = s.getChainByIndex(modelNr, chainNum);
238238
logger.warn("No chain found for {}. Interpretting it as an index, using chain {} instead",chainId,chain.getChainID());
239239
} catch(Exception e2) { //we don't care what gets thrown here -sbliven
240240
throw e; // Nope, not an index. Throw the original exception

0 commit comments

Comments
 (0)