Skip to content

Commit 5d11f63

Browse files
authored
Merge pull request #798 from josemduarte/issue797
Fixing issue 797
2 parents 2bb0857 + 453aaf8 commit 5d11f63

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

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: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@
2424

2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.util.ArrayList;
28+
import java.util.List;
2729
import java.util.zip.GZIPInputStream;
2830

2931
import org.biojava.nbio.structure.align.util.AtomCache;
3032
import org.biojava.nbio.structure.io.FileParsingParameters;
3133
import org.biojava.nbio.structure.io.PDBFileParser;
34+
import org.junit.Ignore;
3235
import org.junit.Test;
3336

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

3643
private static final String PATH_TO_TEST_FILES = "/org/biojava/nbio/structure/io/";
3744

@@ -67,7 +74,6 @@ public void test1SMT() throws IOException, StructureException {
6774
params.setAlignSeqRes(true);
6875
cache.setFileParsingParams(params);
6976

70-
7177
StructureIO.setAtomCache(cache);
7278

7379
cache.setUseMmCif(false);
@@ -78,7 +84,11 @@ public void test1SMT() throws IOException, StructureException {
7884
assertEquals("First residue in 1smtA "+chainA.getAtomGroup(0).toString()+" should map to 24 in SEQRES",24,i);
7985
Chain chainB = s.getPolyChainByPDB("B");
8086
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);
87+
assertEquals("First residue in 1smtB "+chainB.getAtomGroup(0).toString()+" should map to 20 in SEQRES",20,i);
88+
89+
// group with seqres index 19 is observed in chain B but not in chain A, we should still get the index back from getAlignedResIndex
90+
i = chainA.getEntityInfo().getAlignedResIndex(chainA.getSeqResGroup(19),chainA);
91+
assertEquals("Seqres residue 20 in 1smtA "+chainA.getSeqResGroup(19).toString()+" should map to 20 in SEQRES",20,i);
8292

8393
checkAllResidues(s);
8494
}
@@ -97,17 +107,25 @@ private void checkAllResidues(Structure s) {
97107
}
98108

99109
// 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
110+
// in that case EntityInfo.getAlignedResIndex() returns residue numbers as given (without insertion codes) and
101111
// thus in general residues will not be correctly aligned between different chains of same entity. This breaks
102112
// cases like 3ddo (with no SEQRES records) where residue numbering is different in every chain of the one entity.
103113
// see https://github.com/eppic-team/eppic/issues/39
104-
//@Test
114+
@Ignore
115+
@Test
105116
public void test3ddoRawNoSeqres() throws IOException, StructureException {
106117

107118
// 3ddo has 6 chains in 1 entity, all of them with different residue numbering (chain A is 1000+, chain B 2000+ ...)
108119
Structure s = getStructure("3ddo_raw_noseqres.pdb.gz", true);
109120

110-
assertEquals(1,s.getEntityInfos().size());
121+
List<EntityInfo> polyEntities = new ArrayList<>();
122+
for (EntityInfo entityInfo : s.getEntityInfos()) {
123+
if (entityInfo.getType() == EntityType.POLYMER) {
124+
polyEntities.add(entityInfo);
125+
}
126+
}
127+
128+
assertEquals(1, polyEntities.size());
111129

112130
Chain chainA = s.getPolyChainByPDB("A");
113131
Chain chainB = s.getPolyChainByPDB("B");
@@ -134,10 +152,17 @@ public void test3ddoRawNoSeqres() throws IOException, StructureException {
134152

135153

136154

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

140-
assertEquals(1,s.getEntityInfos().size());
158+
polyEntities = new ArrayList<>();
159+
for (EntityInfo entityInfo : s.getEntityInfos()) {
160+
if (entityInfo.getType() == EntityType.POLYMER) {
161+
polyEntities.add(entityInfo);
162+
}
163+
}
164+
165+
assertEquals(1, polyEntities.size());
141166

142167
chainA = s.getPolyChainByPDB("A");
143168
chainB = s.getPolyChainByPDB("B");

0 commit comments

Comments
 (0)