X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=b07b7a4f487dc0ad919e16d239f6d0dea40d8c7d;hb=bc510a49947e32b3886275b869749cd3f42bde08;hp=0a3db6df0e87920bab8acb6ba0dbb21ef5420e5a;hpb=b0123c396580412f9c2218caedfc173696cd0fe5;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 0a3db6d..b07b7a4 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -28,7 +28,9 @@ import jalview.datamodel.*; public class StructureSelectionManager { static StructureSelectionManager instance; + StructureMapping[] mappings; + Hashtable mappingData = new Hashtable(); public static StructureSelectionManager getStructureSelectionManager() @@ -41,7 +43,37 @@ public class StructureSelectionManager return instance; } + /** + * flag controlling whether SeqMappings are relayed from received sequence + * mouse over events to other sequences + */ + boolean relaySeqMappings = true; + + /** + * Enable or disable relay of seqMapping events to other sequences. You might + * want to do this if there are many sequence mappings and the host computer + * is slow + * + * @param relay + */ + public void setRelaySeqMappings(boolean relay) + { + relaySeqMappings = relay; + } + + /** + * get the state of the relay seqMappings flag. + * + * @return true if sequence mouse overs are being relayed to other mapped + * sequences + */ + public boolean isRelaySeqMappingsEnabled() + { + return relaySeqMappings; + } + Vector listeners = new Vector(); + public void addStructureViewerListener(Object svl) { if (!listeners.contains(svl)) @@ -66,33 +98,34 @@ public class StructureSelectionManager } /* - There will be better ways of doing this in the future, for now we'll use - the tried and tested MCview pdb mapping + * There will be better ways of doing this in the future, for now we'll use + * the tried and tested MCview pdb mapping */ - public MCview.PDBfile setMapping(SequenceI[] sequence, - String pdbFile, - String protocol) + synchronized public MCview.PDBfile setMapping(SequenceI[] sequence, + String[] targetChains, String pdbFile, String protocol) { MCview.PDBfile pdb = null; try { pdb = new MCview.PDBfile(pdbFile, protocol); - } - catch (Exception ex) + } catch (Exception ex) { ex.printStackTrace(); return null; } + String targetChain; for (int s = 0; s < sequence.length; s++) { - String targetChain = ""; - - if (sequence[s].getName().indexOf("|") > -1) + if (targetChains != null && targetChains[s] != null) + targetChain = targetChains[s]; + else if (sequence[s].getName().indexOf("|") > -1) { targetChain = sequence[s].getName().substring( - sequence[s].getName().lastIndexOf("|") + 1); + sequence[s].getName().lastIndexOf("|") + 1); } + else + targetChain = ""; int max = -10; AlignSeq maxAlignseq = null; @@ -101,16 +134,14 @@ public class StructureSelectionManager for (int i = 0; i < pdb.chains.size(); i++) { - AlignSeq as = new AlignSeq(sequence[s], - ( (PDBChain) pdb.chains.elementAt(i)). - sequence, - AlignSeq.PEP); + AlignSeq as = new AlignSeq(sequence[s], ((PDBChain) pdb.chains + .elementAt(i)).sequence, AlignSeq.PEP); as.calcScoreMatrix(); as.traceAlignment(); - PDBChain chain = ( (PDBChain) pdb.chains.elementAt(i)); + PDBChain chain = ((PDBChain) pdb.chains.elementAt(i)); if (as.maxscore > max - || (as.maxscore == max && chain.id.equals(targetChain))) + || (as.maxscore == max && chain.id.equals(targetChain))) { maxChain = chain; max = as.maxscore; @@ -120,12 +151,10 @@ public class StructureSelectionManager } final StringBuffer mappingDetails = new StringBuffer(); - mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + - maxChain.sequence.getSequenceAsString()); - mappingDetails.append("\nNo of residues = " + - maxChain.residues. - size() + - "\n\n"); + mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + + maxChain.sequence.getSequenceAsString()); + mappingDetails.append("\nNo of residues = " + + maxChain.residues.size() + "\n\n"); PrintStream ps = new PrintStream(System.out) { public void print(String x) @@ -141,12 +170,11 @@ public class StructureSelectionManager maxAlignseq.printAlignment(ps); - mappingDetails.append("\nPDB start/end " + maxAlignseq.seq2start + " " + - maxAlignseq.seq2end); + mappingDetails.append("\nPDB start/end " + maxAlignseq.seq2start + + " " + maxAlignseq.seq2end); mappingDetails.append("\nSEQ start/end " - + (maxAlignseq.seq1start + sequence[s].getStart() - 1) + - " " - + (maxAlignseq.seq1end + sequence[s].getEnd() - 1)); + + (maxAlignseq.seq1start + sequence[s].getStart() - 1) + " " + + (maxAlignseq.seq1end + sequence[s].getEnd() - 1)); maxChain.makeExactMapping(maxAlignseq, sequence[s]); @@ -156,20 +184,18 @@ public class StructureSelectionManager int resNum = -10000; int index = 0; - do { Atom tmp = (Atom) maxChain.atoms.elementAt(index); if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) { resNum = tmp.resNumber; - mapping[tmp.alignmentMapping+1][0] = tmp.resNumber; - mapping[tmp.alignmentMapping+1][1] = tmp.atomIndex; + mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber; + mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex; } index++; - } - while(index < maxChain.atoms.size()); + } while (index < maxChain.atoms.size()); if (mappings == null) { @@ -182,14 +208,15 @@ public class StructureSelectionManager mappings = tmp; } - if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) - pdbFile = "INLINE"+pdb.id; + if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) + pdbFile = "INLINE" + pdb.id; - mappings[mappings.length - 1] - = new StructureMapping(sequence[s], pdbFile, pdb.id, maxChainId, - mapping, mappingDetails.toString()); + mappings[mappings.length - 1] = new StructureMapping(sequence[s], + pdbFile, pdb.id, maxChainId, mapping, mappingDetails + .toString()); + maxChain.transferResidueAnnotation(mappings[mappings.length - 1]); } - ///////// + // /////// return pdb; } @@ -214,7 +241,7 @@ public class StructureSelectionManager } } - if (removeMapping && mappings!=null) + if (removeMapping && mappings != null) { Vector tmp = new Vector(); for (int i = 0; i < mappings.length; i++) @@ -232,30 +259,44 @@ public class StructureSelectionManager public void mouseOverStructure(int pdbResNum, String chain, String pdbfile) { - SequenceListener sl; + SearchResults results = null; for (int i = 0; i < listeners.size(); i++) { if (listeners.elementAt(i) instanceof SequenceListener) { - sl = (SequenceListener) listeners.elementAt(i); - - for (int j = 0; j < mappings.length; j++) + if (results == null) { - if (mappings[j].pdbfile.equals(pdbfile) && - mappings[j].pdbchain.equals(chain)) + results = new SearchResults(); + + for (int j = 0; j < mappings.length; j++) { - sl.highlightSequence(mappings[j].sequence, - mappings[j].getSeqPos(pdbResNum)); + if (mappings[j].pdbfile.equals(pdbfile) + && mappings[j].pdbchain.equals(chain)) + { + results.addResult(mappings[j].sequence, mappings[j] + .getSeqPos(pdbResNum), mappings[j] + .getSeqPos(pdbResNum)); + } } } + if (results.getSize() > 0) + { + ((SequenceListener) listeners.elementAt(i)) + .highlightSequence(results); + } - sl.highlightSequence(null, pdbResNum); } } } + Vector seqmappings = null; // should be a simpler list of mapped seuqence + + // pairs + public void mouseOverSequence(SequenceI seq, int index) { + boolean hasSequenceListeners = handlingVamsasMo || seqmappings != null; + SearchResults results = null; StructureListener sl; int atomNo = 0; for (int i = 0; i < listeners.size(); i++) @@ -272,33 +313,125 @@ public class StructureSelectionManager if (atomNo > 0) { - sl.highlightAtom(atomNo, - mappings[j].getPDBResNum(index), - mappings[j].pdbchain, - mappings[j].pdbfile); + sl.highlightAtom(atomNo, mappings[j].getPDBResNum(index), + mappings[j].pdbchain, mappings[j].pdbfile); + } + } + } + } + else + { + if (relaySeqMappings && hasSequenceListeners + && listeners.elementAt(i) instanceof SequenceListener) + { + // DEBUG + //System.err.println("relay Seq " + seq.getDisplayId(false) + " " + + // index); + + if (results == null) + { + results = new SearchResults(); + if (index >= seq.getStart() && index <= seq.getEnd()) + { + // construct highlighted sequence list + + if (seqmappings!=null) + { + Enumeration e = seqmappings.elements(); + while (e.hasMoreElements()) + + { + ((AlignedCodonFrame) e.nextElement()).markMappedRegion( + seq, index, results); + } + } + // hasSequenceListeners = results.getSize() > 0; + if (handlingVamsasMo) + { + // add in additional direct sequence and/or dataset sequence + // highlighting + results.addResult(seq, index, index); + } } } + if (hasSequenceListeners) + { + ((SequenceListener) listeners.elementAt(i)) + .highlightSequence(results); + } + } + else if (listeners.elementAt(i) instanceof VamsasListener + && !handlingVamsasMo) + { + // DEBUG + //System.err.println("Vamsas from Seq " + seq.getDisplayId(false) + " " + + // index); + // pass the mouse over onto the VamsasListener(s) + ((VamsasListener) listeners.elementAt(i)).mouseOver(seq, index); } } } } + /** + * true if a mouse over event from an external (ie Vamsas) source is being + * handled + */ + boolean handlingVamsasMo = false; + + /** + * as mouseOverSequence but only route event to SequenceListeners + * + * @param sequenceI + * @param position + */ + public void mouseOverVamsasSequence(SequenceI sequenceI, int position) + { + handlingVamsasMo = true; + mouseOverSequence(sequenceI, position); + handlingVamsasMo = false; + } + + public Annotation[] colourSequenceFromStructure(SequenceI seq, + String pdbid) + { + return null; + // THIS WILL NOT BE AVAILABLE IN JALVIEW 2.3, + // UNTIL THE COLOUR BY ANNOTATION IS REWORKED + /* + * Annotation [] annotations = new Annotation[seq.getLength()]; + * + * StructureListener sl; int atomNo = 0; for (int i = 0; i < + * listeners.size(); i++) { if (listeners.elementAt(i) instanceof + * StructureListener) { sl = (StructureListener) listeners.elementAt(i); + * + * for (int j = 0; j < mappings.length; j++) { + * + * if (mappings[j].sequence == seq && mappings[j].getPdbId().equals(pdbid) && + * mappings[j].pdbfile.equals(sl.getPdbFile())) { System.out.println(pdbid+" + * "+mappings[j].getPdbId() +" "+mappings[j].pdbfile); + * + * java.awt.Color col; for(int index=0; index 0) { col = sl.getColour(atomNo, + * mappings[j].getPDBResNum(index), mappings[j].pdbchain, + * mappings[j].pdbfile); } + * + * annotations[index] = new Annotation("X",null,' ',0,col); } return + * annotations; } } } } + * + * return annotations; + */ + } + public void structureSelectionChanged() { - StructureListener svl; - for (int i = 0; i < listeners.size(); i++) - { - svl = (StructureListener) listeners.elementAt(i); - } } public void sequenceSelectionChanged() { - StructureListener svl; - for (int i = 0; i < listeners.size(); i++) - { - svl = (StructureListener) listeners.elementAt(i); - } } public void sequenceColoursChanged(Object source) @@ -347,4 +480,70 @@ public class StructureSelectionManager return sb.toString(); } + + private int[] seqmappingrefs = null; // refcount for seqmappings elements + + private synchronized void modifySeqMappingList(boolean add, + AlignedCodonFrame[] codonFrames) + { + if (!add && (seqmappings == null || seqmappings.size() == 0)) + return; + if (seqmappings == null) + seqmappings = new Vector(); + if (codonFrames != null && codonFrames.length > 0) + { + for (int cf = 0; cf < codonFrames.length; cf++) + { + if (seqmappings.contains(codonFrames[cf])) + { + if (add) + { + seqmappingrefs[seqmappings.indexOf(codonFrames[cf])]++; + } + else + { + if (--seqmappingrefs[seqmappings.indexOf(codonFrames[cf])] <= 0) + { + int pos = seqmappings.indexOf(codonFrames[cf]); + int[] nr = new int[seqmappingrefs.length - 1]; + if (pos > 0) + { + System.arraycopy(seqmappingrefs, 0, nr, 0, pos); + } + if (pos < seqmappingrefs.length - 1) + { + System.arraycopy(seqmappingrefs, pos + 1, nr, 0, + seqmappingrefs.length - pos - 2); + } + } + } + } + else + { + if (add) + { + seqmappings.addElement(codonFrames[cf]); + + int[] nsr = new int[(seqmappingrefs == null) ? 1 + : seqmappingrefs.length + 1]; + if (seqmappingrefs != null && seqmappingrefs.length > 0) + System.arraycopy(seqmappingrefs, 0, nsr, 0, + seqmappingrefs.length); + nsr[(seqmappingrefs == null) ? 0 : seqmappingrefs.length] = 1; + seqmappingrefs = nsr; + } + } + } + } + } + + public void removeMappings(AlignedCodonFrame[] codonFrames) + { + modifySeqMappingList(false, codonFrames); + } + + public void addMappings(AlignedCodonFrame[] codonFrames) + { + modifySeqMappingList(true, codonFrames); + } }