Skip to content

Commit 8286260

Browse files
committed
Dealing with struct_ref_seq_dif strand_id by referencing through struct_ref_seq and struct_ref
1 parent a6723d4 commit 8286260

1 file changed

Lines changed: 63 additions & 18 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/io/cif/CifStructureConsumerImpl.java

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public class CifStructureConsumerImpl implements CifStructureConsumer {
144144
private StructNcsOper structNcsOper;
145145
private PdbxStructOperList structOpers;
146146
private StructRef structRef;
147+
private StructRefSeq structRefSeq;
147148
private StructRefSeqDif structRefSeqDif;
148149
private StructSiteGen structSiteGen;
149150

@@ -689,7 +690,7 @@ public void consumeEntitySrcSyn(PdbxEntitySrcSyn entitySrcSyn) {
689690
@Override
690691
public void consumeEntityPolySeq(EntityPolySeq entityPolySeq) {
691692
for (int rowIndex = 0; rowIndex < entityPolySeq.getRowCount(); rowIndex++) {
692-
Chain entityChain = getEntityChain(entityPolySeq.getEntityId().get(rowIndex));
693+
Chain entityChain = getEntityChain(entityPolySeq.getEntityId().get(rowIndex), true);
693694

694695
// first we check through the chemcomp provider, if it fails we do some heuristics to guess the type of group
695696
// TODO some of this code is analogous to getNewGroup() and we should try to unify them - JD 2016-03-08
@@ -728,19 +729,27 @@ public void consumeEntityPolySeq(EntityPolySeq entityPolySeq) {
728729
}
729730
}
730731

731-
private Chain getEntityChain(String entityId) {
732+
/**
733+
* Get a chain from the temporary list holding them. If createNewChains is true, a new chain
734+
* will be added is none are found with the given entityId
735+
* @param entityId the entity id
736+
* @param createNewChains whether to add new chains if not found or not. If false, null will be returned if chain not found
737+
* @return the chain
738+
*/
739+
private Chain getEntityChain(String entityId, boolean createNewChains) {
732740
for (Chain chain : entityChains) {
733741
if (chain.getId().equals(entityId)) {
734742
return chain;
735743
}
736744
}
737-
738-
// does not exist yet, so create...
739-
Chain chain = new ChainImpl();
740-
chain.setId(entityId);
741-
entityChains.add(chain);
742-
743-
return chain;
745+
if (createNewChains) {
746+
// does not exist yet, so create...
747+
Chain chain = new ChainImpl();
748+
chain.setId(entityId);
749+
entityChains.add(chain);
750+
return chain;
751+
}
752+
return null;
744753
}
745754

746755
@Override
@@ -967,6 +976,7 @@ public void consumeStructRef(StructRef structRef) {
967976

968977
@Override
969978
public void consumeStructRefSeq(StructRefSeq structRefSeq) {
979+
this.structRefSeq = structRefSeq;
970980
for (int rowIndex = 0; rowIndex < structRefSeq.getRowCount(); rowIndex++) {
971981
String refId = structRefSeq.getRefId().get(rowIndex);
972982

@@ -1173,7 +1183,7 @@ public void finish() {
11731183
String entityId = structAsym.getEntityId().get(rowIndex);
11741184
logger.debug("Entity {} matches asym_id: {}", entityId, id);
11751185

1176-
Chain chain = getEntityChain(entityId);
1186+
Chain chain = getEntityChain(entityId, true);
11771187
Chain seqRes = (Chain) chain.clone();
11781188
// to solve issue #160 (e.g. 3u7t)
11791189
seqRes = removeSeqResHeterogeneity(seqRes);
@@ -1292,7 +1302,8 @@ public void finish() {
12921302
setStructNcsOps();
12931303
setCrystallographicInfoMetadata();
12941304

1295-
Map<String, List<SeqMisMatch>> misMatchMap = new HashMap<>();
1305+
// entity id to list of SeqMisMatch
1306+
Map<Integer, List<SeqMisMatch>> misMatchMap = new HashMap<>();
12961307
for (int rowIndex = 0; rowIndex < structRefSeqDif.getRowCount(); rowIndex++) {
12971308
SeqMisMatch seqMisMatch = new SeqMisMatchImpl();
12981309
seqMisMatch.setDetails(structRefSeqDif.getDetails().get(rowIndex));
@@ -1311,20 +1322,54 @@ public void finish() {
13111322
seqMisMatch.setUniProtId(structRefSeqDif.getPdbxSeqDbAccessionCode().isDefined()? structRefSeqDif.getPdbxSeqDbAccessionCode().get(rowIndex):null);
13121323
seqMisMatch.setSeqNum(structRefSeqDif.getSeqNum().get(rowIndex));
13131324

1314-
String strandId = structRefSeqDif.getPdbxPdbStrandId().get(rowIndex);
1315-
List<SeqMisMatch> seqMisMatches = misMatchMap.computeIfAbsent(strandId, k -> new ArrayList<>());
1316-
seqMisMatches.add(seqMisMatch);
1325+
// try to trace the reference entity_id to struct_ref_seq -> struct_ref
1326+
String alignId = findRefIdInStructRefSeq(structRefSeqDif.getAlignId().get(rowIndex));
1327+
if (alignId!=null) {
1328+
int entityId = findEntityIdInStructRef(alignId);
1329+
if (entityId > 0) {
1330+
List<SeqMisMatch> seqMisMatches = misMatchMap.computeIfAbsent(entityId, k -> new ArrayList<>());
1331+
seqMisMatches.add(seqMisMatch);
1332+
}
1333+
}
13171334
}
13181335

1319-
for (String chainId : misMatchMap.keySet()){
1320-
Chain chain = structure.getPolyChainByPDB(chainId);
1336+
for (int entityId : misMatchMap.keySet()){
1337+
Chain chain = getEntityChain(String.valueOf(entityId), false);
13211338
if (chain == null) {
1322-
logger.warn("Could not set mismatches for chain with author id {}", chainId);
1339+
logger.warn("Could not set mismatches for chain with entity id {}", entityId);
13231340
continue;
13241341
}
1342+
chain.setSeqMisMatches(misMatchMap.get(entityId));
1343+
}
1344+
}
13251345

1326-
chain.setSeqMisMatches(misMatchMap.get(chainId));
1346+
private String findRefIdInStructRefSeq(String alignId) {
1347+
for (int rowIndex = 0; rowIndex < structRefSeq.getRowCount(); rowIndex++) {
1348+
String currentAlignId = structRefSeq.getAlignId().get(rowIndex);
1349+
if (alignId.equals(currentAlignId)) {
1350+
return structRefSeq.getRefId().isDefined()? structRefSeq.getRefId().get(rowIndex) : null;
1351+
}
1352+
}
1353+
return null;
1354+
}
1355+
1356+
private int findEntityIdInStructRef(String refId) {
1357+
String entityIdStr = null;
1358+
for (int rowIndex = 0; rowIndex < structRef.getRowCount(); rowIndex++) {
1359+
String currentId = structRef.getId().get(rowIndex);
1360+
if (refId.equals(currentId)) {
1361+
entityIdStr = structRef.getEntityId().isDefined()? structRef.getEntityId().get(rowIndex) : null;
1362+
}
1363+
}
1364+
int entityId = -1;
1365+
if (entityIdStr != null) {
1366+
try {
1367+
entityId = Integer.parseInt(entityIdStr);
1368+
} catch (NumberFormatException e) {
1369+
logger.warn("Could not parse entity id from '{}'", entityIdStr);
1370+
}
13271371
}
1372+
return entityId;
13281373
}
13291374

13301375
private String getEntityType(String entityId) {

0 commit comments

Comments
 (0)