X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=2f81ec4786ef3a07876ab8d5f36a33c03365d45c;hb=adf4e6df363330f72c49409a21a10a480e7b9f56;hp=3d5a97576e2221e81a5ceb127302a9709b6ef74b;hpb=49f0437d385ee4c6dbe701180a4ba704da76b5f8;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 3d5a975..2f81ec4 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -32,11 +32,13 @@ import jalview.datamodel.Annotation; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResults; import jalview.datamodel.SequenceI; +import jalview.gui.IProgressIndicator; import jalview.io.AppletFormatAdapter; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.ws.sifts.SiftsClient; import jalview.ws.sifts.SiftsException; +import jalview.ws.sifts.SiftsSettings; import java.io.PrintStream; import java.util.ArrayList; @@ -45,10 +47,8 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.IdentityHashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Vector; import MCview.Atom; @@ -69,10 +69,16 @@ public class StructureSelectionManager private boolean addTempFacAnnot = false; + private IProgressIndicator progressIndicator; + + private SiftsClient siftsClient = null; + + private long progressSessionId; + /* * Set of any registered mappings between (dataset) sequences. */ - public Set seqmappings = new LinkedHashSet(); + private List seqmappings = new ArrayList(); private List commandListeners = new ArrayList(); @@ -328,7 +334,7 @@ public class StructureSelectionManager * * @param sequenceArray * - one or more sequences to be mapped to pdbFile - * @param targetChains + * @param targetChainIds * - optional chain specification for mapping each sequence to pdb * (may be nill, individual elements may be nill) * @param pdbFile @@ -338,7 +344,8 @@ public class StructureSelectionManager * @return null or the structure data parsed as a pdb file */ synchronized public PDBfile setMapping(boolean forStructureView, - SequenceI[] sequenceArray, String[] targetChains, String pdbFile, + SequenceI[] sequenceArray, String[] targetChainIds, + String pdbFile, String protocol) { /* @@ -372,61 +379,65 @@ public class StructureSelectionManager } } PDBfile pdb = null; - boolean isMapUsingSIFTs = Boolean.valueOf(jalview.bin.Cache.getDefault( - "MAP_WITH_SIFTS", "false")); - SiftsClient siftsClient = null; + boolean isMapUsingSIFTs = SiftsSettings.isMapWithSifts(); try { pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices, pdbFile, protocol); - if (isMapUsingSIFTs) - { - siftsClient = new SiftsClient(pdb); - } + if (pdb.id != null && pdb.id.trim().length() > 0 && AppletFormatAdapter.FILE.equals(protocol)) { registerPDBFile(pdb.id.trim(), pdbFile); } - } catch (SiftsException e) - { - e.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); return null; } - String targetChain; + try + { + if (isMapUsingSIFTs) + { + siftsClient = new SiftsClient(pdb); + } + } catch (SiftsException e) + { + isMapUsingSIFTs = false; + e.printStackTrace(); + } + + String targetChainId; for (int s = 0; s < sequenceArray.length; s++) { boolean infChain = true; final SequenceI seq = sequenceArray[s]; - if (targetChains != null && targetChains[s] != null) + if (targetChainIds != null && targetChainIds[s] != null) { infChain = false; - targetChain = targetChains[s]; + targetChainId = targetChainIds[s]; } else if (seq.getName().indexOf("|") > -1) { - targetChain = seq.getName().substring( + targetChainId = seq.getName().substring( seq.getName().lastIndexOf("|") + 1); - if (targetChain.length() > 1) + if (targetChainId.length() > 1) { - if (targetChain.trim().length() == 0) + if (targetChainId.trim().length() == 0) { - targetChain = " "; + targetChainId = " "; } else { // not a valid chain identifier - targetChain = ""; + targetChainId = ""; } } } else { - targetChain = ""; + targetChainId = ""; } /* @@ -440,7 +451,7 @@ public class StructureSelectionManager boolean first = true; for (PDBChain chain : pdb.chains) { - if (targetChain.length() > 0 && !targetChain.equals(chain.id) + if (targetChainId.length() > 0 && !targetChainId.equals(chain.id) && !infChain) { continue; // don't try to map chains don't match. @@ -456,7 +467,7 @@ public class StructureSelectionManager // as.traceAlignment(); if (first || as.maxscore > max - || (as.maxscore == max && chain.id.equals(targetChain))) + || (as.maxscore == max && chain.id.equals(targetChainId))) { first = false; maxChain = chain; @@ -475,54 +486,73 @@ public class StructureSelectionManager pdbFile = "INLINE" + pdb.id; } - ArrayList seqToStrucMapping = null; + ArrayList seqToStrucMapping = new ArrayList(); if (isMapUsingSIFTs) { - try + setProgressBar(null); + setProgressBar("Obtaining mapping with SIFTS"); + jalview.datamodel.Mapping sqmpping = maxAlignseq + .getMappingFromS1(false); + if (targetChainId != null && !targetChainId.trim().isEmpty()) { - seqToStrucMapping = new ArrayList(); - if (targetChain != null && !targetChain.trim().isEmpty()) - { - maxChainId = targetChain; - StructureMapping curChainMapping = siftsClient - .getSiftsStructureMapping(seq, pdbFile, targetChain); - seqToStrucMapping.add(curChainMapping); - } - else + StructureMapping mapping = getStructureMapping(seq, pdbFile, + targetChainId, pdb, maxChain, sqmpping, maxAlignseq); + seqToStrucMapping.add(mapping); + } + else + { + for (PDBChain chain : pdb.chains) { - for (PDBChain chain : pdb.chains) - { - maxChainId = chain.id; - StructureMapping curChainMapping = siftsClient - .getSiftsStructureMapping(seq, pdbFile, chain.id); - seqToStrucMapping.add(curChainMapping); - } + StructureMapping mapping = getStructureMapping(seq, pdbFile, + chain.id, pdb, chain, sqmpping, maxAlignseq); + seqToStrucMapping.add(mapping); } - } catch (SiftsException e) - { - System.err - .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment"); - seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId, - maxChain, pdb, maxAlignseq); } } else { - seqToStrucMapping = getNWMappings(seq, pdbFile, - maxChainId, maxChain, pdb, - maxAlignseq); + setProgressBar(null); + setProgressBar("Obtaining mapping with NW alignment"); + seqToStrucMapping.add(getNWMappings(seq, pdbFile, maxChainId, + maxChain, pdb, maxAlignseq)); } if (forStructureView) { - // mappings.add(seqToStrucMapping); mappings.addAll(seqToStrucMapping); } } return pdb; } - private ArrayList getNWMappings(SequenceI seq, + private StructureMapping getStructureMapping(SequenceI seq, + String pdbFile, String targetChainId, PDBfile pdb, + PDBChain maxChain, jalview.datamodel.Mapping sqmpping, + AlignSeq maxAlignseq) + { + String maxChainId = targetChainId; + try + { + StructureMapping curChainMapping = siftsClient + .getSiftsStructureMapping(seq, pdbFile, targetChainId); + PDBChain chain = pdb.findChain(targetChainId); + if (chain != null) + { + chain.transferResidueAnnotation(curChainMapping, sqmpping); + } + return curChainMapping; + } catch (SiftsException e) + { + System.err.println(e.getMessage()); + System.err.println(">>> Now switching mapping with NW alignment..."); + setProgressBar(null); + setProgressBar(">>> Now switching mapping with NW alignment..."); + return getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb, + maxAlignseq); + } + } + + private StructureMapping getNWMappings(SequenceI seq, String pdbFile, String maxChainId, PDBChain maxChain, PDBfile pdb, AlignSeq maxAlignseq) @@ -572,24 +602,23 @@ public class StructureSelectionManager .getMappingFromS1(false); maxChain.transferRESNUMFeatures(seq, null); - // allocate enough slots to store the mapping from positions in - // sequence[s] to the associated chain - int[][] mapping = new int[seq.findPosition(seq.getLength()) + 2][2]; + HashMap mapping = new HashMap(); int resNum = -10000; int index = 0; + char insCode = ' '; do { Atom tmp = maxChain.atoms.elementAt(index); - if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) + if ((resNum != tmp.resNumber || insCode != tmp.insCode) + && tmp.alignmentMapping != -1) { resNum = tmp.resNumber; + insCode = tmp.insCode; if (tmp.alignmentMapping >= -1) { - // TODO (JAL-1836) address root cause: negative residue no in PDB - // file - mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; - mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; + mapping.put(tmp.alignmentMapping + 1, new int[] { tmp.resNumber, + tmp.atomIndex }); } } @@ -599,9 +628,7 @@ public class StructureSelectionManager StructureMapping nwMapping = new StructureMapping(seq, pdbFile, pdb.id, maxChainId, mapping, mappingDetails.toString()); maxChain.transferResidueAnnotation(nwMapping, sqmpping); - ArrayList mappings = new ArrayList(); - mappings.add(nwMapping); - return mappings; + return nwMapping; } public void removeStructureViewerListener(Object svl, String[] pdbfiles) @@ -742,19 +769,19 @@ public class StructureSelectionManager * the sequence that the mouse over occurred on * @param indexpos * the absolute position being mouseovered in seq (0 to seq.length()) - * @param index + * @param seqPos * the sequence position (if -1, seq.findPosition is called to * resolve the residue number) */ - public void mouseOverSequence(SequenceI seq, int indexpos, int index, + public void mouseOverSequence(SequenceI seq, int indexpos, int seqPos, VamsasSource source) { boolean hasSequenceListeners = handlingVamsasMo || !seqmappings.isEmpty(); SearchResults results = null; - if (index == -1) + if (seqPos == -1) { - index = seq.findPosition(indexpos); + seqPos = seq.findPosition(indexpos); } for (int i = 0; i < listeners.size(); i++) { @@ -767,7 +794,7 @@ public class StructureSelectionManager } if (listener instanceof StructureListener) { - highlightStructure((StructureListener) listener, seq, index); + highlightStructure((StructureListener) listener, seq, seqPos); } else { @@ -781,12 +808,12 @@ public class StructureSelectionManager { if (results == null) { - results = MappingUtils.buildSearchResults(seq, index, + results = MappingUtils.buildSearchResults(seq, seqPos, seqmappings); } if (handlingVamsasMo) { - results.addResult(seq, index, index); + results.addResult(seq, seqPos, seqPos); } if (!results.isEmpty()) @@ -804,7 +831,7 @@ public class StructureSelectionManager else if (listener instanceof SecondaryStructureListener) { ((SecondaryStructureListener) listener).mouseOverSequence(seq, - indexpos, index); + indexpos, seqPos); } } } @@ -812,14 +839,14 @@ public class StructureSelectionManager /** * Send suitable messages to a StructureListener to highlight atoms - * corresponding to the given sequence position. + * corresponding to the given sequence position(s) * * @param sl * @param seq - * @param index + * @param positions */ - protected void highlightStructure(StructureListener sl, SequenceI seq, - int index) + public void highlightStructure(StructureListener sl, SequenceI seq, + int... positions) { if (!sl.isListeningFor(seq)) { @@ -831,12 +858,15 @@ public class StructureSelectionManager { if (sm.sequence == seq || sm.sequence == seq.getDatasetSequence()) { - atomNo = sm.getAtomNum(index); - - if (atomNo > 0) + for (int index : positions) { - atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain, sm - .getPDBResNum(index), atomNo)); + atomNo = sm.getAtomNum(index); + + if (atomNo > 0) + { + atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain, sm + .getPDBResNum(index), atomNo)); + } } } } @@ -992,13 +1022,13 @@ public class StructureSelectionManager /** * Add each of the given codonFrames to the stored set, if not aready present. * - * @param set + * @param mappings */ - public void registerMappings(Set set) + public void registerMappings(List mappings) { - if (set != null) + if (mappings != null) { - for (AlignedCodonFrame acf : set) + for (AlignedCodonFrame acf : mappings) { registerMapping(acf); } @@ -1210,4 +1240,35 @@ public class StructureSelectionManager } return null; } + + public IProgressIndicator getProgressIndicator() + { + return progressIndicator; + } + + public void setProgressIndicator(IProgressIndicator progressIndicator) + { + this.progressIndicator = progressIndicator; + } + + public long getProgressSessionId() + { + return progressSessionId; + } + + public void setProgressSessionId(long progressSessionId) + { + this.progressSessionId = progressSessionId; + } + + public void setProgressBar(String message) + { + progressIndicator.setProgressBar(message, progressSessionId); + } + + public List getSequenceMappings() + { + return seqmappings; + } + }