From f2eadfd123e9540bd9af1e5c0ff73f6080ec03c7 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 30 Aug 2017 17:48:35 +0100 Subject: [PATCH] JAL-2694 add maximal set of chain mappings between a PDBEntry and a sequence --- .../structure/StructureSelectionManager.java | 73 ++++++++++++++++---- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index b973f45..83a055e 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -463,6 +463,9 @@ public class StructureSelectionManager String maxChainId = " "; PDBChain maxChain = null; boolean first = true; + List maximalChain = new ArrayList<>(); + List maximalAlignseqs = new ArrayList<>(); + List maximalChainIds = new ArrayList<>(); for (PDBChain chain : pdb.getChains()) { if (targetChainId.length() > 0 && !targetChainId.equals(chain.id) @@ -480,14 +483,39 @@ public class StructureSelectionManager // as.calcScoreMatrix(); // as.traceAlignment(); - if (first || as.maxscore > max - || (as.maxscore == max && chain.id.equals(targetChainId))) + if (targetChainId.length() > 0 && chain.id.equals(targetChainId)) { - first = false; + // Don't care - just pick this chain as the mapping maxChain = chain; max = as.maxscore; maxAlignseq = as; maxChainId = chain.id; + // if targetChainId is specified then it is expected to be unique, so + // precisely one maximal chain will be added + maximalChainIds.add(chain.id); + maximalChain.add(chain); + maximalAlignseqs.add(as); + } + else + { + // select chains with maximal mappings to this sequence + if (first || as.maxscore > max) + { + // clear out old maximal mappings (if any) + max = as.maxscore; + maximalChain.clear(); + maxChain = chain; + max = as.maxscore; + maxAlignseq = as; + maxChainId = chain.id; + first = false; + } + if (as.maxscore == max) + { + maximalChainIds.add(chain.id); + maximalChain.add(chain); + maximalAlignseqs.add(as); + } } } if (maxChain == null) @@ -500,7 +528,7 @@ public class StructureSelectionManager pdbFile = "INLINE" + pdb.getId(); } - List seqToStrucMapping = new ArrayList(); + List seqToStrucMapping = new ArrayList<>(); if (isMapUsingSIFTs && seq.isProtein()) { setProgressBar(null); @@ -527,7 +555,8 @@ public class StructureSelectionManager // fall back to NW alignment System.err.println(e.getMessage()); StructureMapping nwMapping = getNWMappings(seq, pdbFile, - targetChainId, maxChain, pdb, maxAlignseq); + maximalChainIds, maximalChain, pdb, maximalAlignseqs) + .get(0); seqToStrucMapping.add(nwMapping); maxChain.makeExactMapping(maxAlignseq, seq); maxChain.transferRESNUMFeatures(seq, null); // FIXME: is this @@ -538,7 +567,7 @@ public class StructureSelectionManager } else { - List foundSiftsMappings = new ArrayList(); + List foundSiftsMappings = new ArrayList<>(); for (PDBChain chain : pdb.getChains()) { try @@ -564,7 +593,8 @@ public class StructureSelectionManager else { StructureMapping nwMapping = getNWMappings(seq, pdbFile, - maxChainId, maxChain, pdb, maxAlignseq); + maximalChainIds, maximalChain, pdb, maximalAlignseqs) + .get(0); seqToStrucMapping.add(nwMapping); maxChain.transferRESNUMFeatures(seq, null); // FIXME: is this // "IEA:Jalview" ? @@ -578,10 +608,14 @@ public class StructureSelectionManager setProgressBar(null); setProgressBar(MessageManager .getString("status.obtaining_mapping_with_nw_alignment")); - StructureMapping nwMapping = getNWMappings(seq, pdbFile, maxChainId, - maxChain, pdb, maxAlignseq); - seqToStrucMapping.add(nwMapping); - ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0)); + List nwMapping = getNWMappings(seq, pdbFile, + maximalChainIds, maximalChain, pdb, maximalAlignseqs); + seqToStrucMapping.addAll(nwMapping); + for (PDBChain mc : maximalChain) + { + ds.addPDBId(mc.sequence.getAllPDBEntries().get(0)); + } + ; } @@ -633,10 +667,17 @@ public class StructureSelectionManager return curChainMapping; } - private StructureMapping getNWMappings(SequenceI seq, String pdbFile, - String maxChainId, PDBChain maxChain, StructureFile pdb, - AlignSeq maxAlignseq) + private List getNWMappings(SequenceI seq, + String pdbFile, + List maximalChainId, List maximalChain, + StructureFile pdb, List maximalAlignseq) { + List nwMappings = new ArrayList(); + for (int ch = 0; ch < maximalChain.size(); ch++) + { + String maxChainId = maximalChainId.get(ch); + PDBChain maxChain = maximalChain.get(ch); + AlignSeq maxAlignseq = maximalAlignseq.get(ch); final StringBuilder mappingDetails = new StringBuilder(128); mappingDetails.append(NEWLINE) .append("Sequence \u27f7 Structure mapping details"); @@ -710,7 +751,9 @@ public class StructureSelectionManager StructureMapping nwMapping = new StructureMapping(seq, pdbFile, pdb.getId(), maxChainId, mapping, mappingDetails.toString()); maxChain.transferResidueAnnotation(nwMapping, sqmpping); - return nwMapping; + nwMappings.add(nwMapping); + } + return nwMappings; } public void removeStructureViewerListener(Object svl, String[] pdbfiles) -- 1.7.10.2