Skip to content

Commit e2a97bf

Browse files
committed
Fixing issue biojava#797 and better docs and naming
1 parent 2bb0857 commit e2a97bf

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@
2828
import org.slf4j.LoggerFactory;
2929

3030
import java.io.Serializable;
31-
import java.util.ArrayList;
32-
import java.util.Collections;
33-
import java.util.HashMap;
34-
import java.util.List;
35-
import java.util.Map;
36-
import java.util.Set;
37-
import java.util.TreeSet;
31+
import java.util.*;
3832

3933
/**
4034
* An object to contain the info from the PDB header for a Molecule.
@@ -811,17 +805,19 @@ public List<Chain> getChains(){
811805
}
812806

813807
private List<Chain> getFirstModelChains() {
814-
List<Chain> firstModel = new ArrayList<>();
815-
outer:
816-
for (String id: getChainIds()) {
817-
for (Chain chain:chains) {
818-
if (chain.getId().equals(id)) {
819-
firstModel.add(chain);
820-
break outer;
808+
809+
Map<String, Chain> firstModelChains = new LinkedHashMap<>();
810+
Set<String> lookupChainIds = new HashSet<>(getChainIds());
811+
812+
for (Chain chain : chains) {
813+
if (lookupChainIds.contains(chain.getId())) {
814+
if (!firstModelChains.containsKey(chain.getId())) {
815+
firstModelChains.put(chain.getId(), chain);
821816
}
822817
}
823818
}
824-
return firstModel;
819+
820+
return new ArrayList<>(firstModelChains.values());
825821
}
826822

827823
/**

biojava-structure/src/test/java/org/biojava/nbio/structure/TestCompoundResIndexMapping.java renamed to biojava-structure/src/test/java/org/biojava/nbio/structure/TestEntityResIndexMapping.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
import org.biojava.nbio.structure.io.PDBFileParser;
3232
import org.junit.Test;
3333

34-
public class TestCompoundResIndexMapping {
34+
/**
35+
* Various tests for functionality in {@link EntityInfo} and {@link org.biojava.nbio.structure.io.EntityFinder}
36+
* @author Jose Duarte
37+
*/
38+
public class TestEntityResIndexMapping {
3539

3640
private static final String PATH_TO_TEST_FILES = "/org/biojava/nbio/structure/io/";
3741

@@ -67,7 +71,6 @@ public void test1SMT() throws IOException, StructureException {
6771
params.setAlignSeqRes(true);
6872
cache.setFileParsingParams(params);
6973

70-
7174
StructureIO.setAtomCache(cache);
7275

7376
cache.setUseMmCif(false);
@@ -78,7 +81,11 @@ public void test1SMT() throws IOException, StructureException {
7881
assertEquals("First residue in 1smtA "+chainA.getAtomGroup(0).toString()+" should map to 24 in SEQRES",24,i);
7982
Chain chainB = s.getPolyChainByPDB("B");
8083
i = chainB.getEntityInfo().getAlignedResIndex(chainB.getAtomGroup(0),chainB);
81-
assertEquals("First residue in 1smtB "+chainA.getAtomGroup(0).toString()+" should map to 20 in SEQRES",20,i);
84+
assertEquals("First residue in 1smtB "+chainB.getAtomGroup(0).toString()+" should map to 20 in SEQRES",20,i);
85+
86+
// group with seqres index 19 is observed in chain B but not in chain A, we should still get the index back from getAlignedResIndex
87+
i = chainA.getEntityInfo().getAlignedResIndex(chainA.getSeqResGroup(19),chainA);
88+
assertEquals("Seqres residue 20 in 1smtA "+chainA.getSeqResGroup(19).toString()+" should map to 20 in SEQRES",20,i);
8289

8390
checkAllResidues(s);
8491
}
@@ -97,7 +104,7 @@ private void checkAllResidues(Structure s) {
97104
}
98105

99106
// This doesn't work yet, since for raw files without a SEQRES, the seqres groups are not populated. Instead
100-
// in that case Compound.getAlignedResIndex() returns residue numbers as given (without insertion codes) and
107+
// in that case EntityInfo.getAlignedResIndex() returns residue numbers as given (without insertion codes) and
101108
// thus in general residues will not be correctly aligned between different chains of same entity. This breaks
102109
// cases like 3ddo (with no SEQRES records) where residue numbering is different in every chain of the one entity.
103110
// see https://github.com/eppic-team/eppic/issues/39
@@ -134,7 +141,7 @@ public void test3ddoRawNoSeqres() throws IOException, StructureException {
134141

135142

136143

137-
// this should work either with or without setAlignSeqRes, since the mapping happens in CompoundFinder
144+
// this should work either with or without setAlignSeqRes, since the mapping happens in EntityFinder
138145
s = getStructure("3ddo_raw_noseqres.pdb.gz", false);
139146

140147
assertEquals(1,s.getEntityInfos().size());

0 commit comments

Comments
 (0)