2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.structure;
\r
25 import jalview.analysis.*;
\r
26 import jalview.datamodel.*;
\r
28 public class StructureSelectionManager
\r
30 static StructureSelectionManager instance;
\r
31 StructureMapping[] mappings;
\r
32 Hashtable mappingData = new Hashtable();
\r
34 public static StructureSelectionManager getStructureSelectionManager()
\r
36 if (instance == null)
\r
38 instance = new StructureSelectionManager();
\r
44 Vector listeners = new Vector();
\r
45 public void addStructureViewerListener(Object svl)
\r
47 if (!listeners.contains(svl))
\r
49 listeners.addElement(svl);
\r
53 public String alreadyMappedToFile(String pdbid)
\r
55 if (mappings != null)
\r
57 for (int i = 0; i < mappings.length; i++)
\r
59 if (mappings[i].getPdbId().equals(pdbid))
\r
61 return mappings[i].pdbfile;
\r
69 There will be better ways of doing this in the future, for now we'll use
\r
70 the tried and tested MCview pdb mapping
\r
72 public MCview.PDBfile setMapping(SequenceI[] sequence,
\r
76 MCview.PDBfile pdb = null;
\r
79 pdb = new MCview.PDBfile(pdbFile, protocol);
\r
81 catch (Exception ex)
\r
83 ex.printStackTrace();
\r
87 for (int s = 0; s < sequence.length; s++)
\r
89 String targetChain = "";
\r
91 if (sequence[s].getName().indexOf("|") > -1)
\r
93 targetChain = sequence[s].getName().substring(
\r
94 sequence[s].getName().lastIndexOf("|") + 1);
\r
98 AlignSeq maxAlignseq = null;
\r
99 String maxChainId = " ";
\r
100 PDBChain maxChain = null;
\r
102 for (int i = 0; i < pdb.chains.size(); i++)
\r
104 AlignSeq as = new AlignSeq(sequence[s],
\r
105 ( (PDBChain) pdb.chains.elementAt(i)).
\r
108 as.calcScoreMatrix();
\r
109 as.traceAlignment();
\r
110 PDBChain chain = ( (PDBChain) pdb.chains.elementAt(i));
\r
112 if (as.maxscore > max
\r
113 || (as.maxscore == max && chain.id.equals(targetChain)))
\r
118 maxChainId = chain.id;
\r
122 final StringBuffer mappingDetails = new StringBuffer();
\r
123 mappingDetails.append("\n\nPDB Sequence is :\nSequence = " +
\r
124 maxChain.sequence.getSequenceAsString());
\r
125 mappingDetails.append("\nNo of residues = " +
\r
129 PrintStream ps = new PrintStream(System.out)
\r
131 public void print(String x)
\r
133 mappingDetails.append(x);
\r
136 public void println()
\r
138 mappingDetails.append("\n");
\r
142 maxAlignseq.printAlignment(ps);
\r
144 mappingDetails.append("\nPDB start/end " + maxAlignseq.seq2start + " " +
\r
145 maxAlignseq.seq2end);
\r
146 mappingDetails.append("\nSEQ start/end "
\r
147 + (maxAlignseq.seq1start + sequence[s].getStart() - 1) +
\r
149 + (maxAlignseq.seq1end + sequence[s].getEnd() - 1));
\r
151 maxChain.makeExactMapping(maxAlignseq, sequence[s]);
\r
153 // maxChain.transferRESNUMFeatures(sequence[s], null);
\r
155 int[][] mapping = new int[sequence[s].getEnd() + 2][2];
\r
156 int resNum = -10000;
\r
162 Atom tmp = (Atom) maxChain.atoms.elementAt(index);
\r
163 if (resNum != tmp.resNumber && tmp.alignmentMapping != -1)
\r
165 resNum = tmp.resNumber;
\r
166 mapping[tmp.alignmentMapping+1][0] = tmp.resNumber;
\r
167 mapping[tmp.alignmentMapping+1][1] = tmp.atomIndex;
\r
172 while(index < maxChain.atoms.size());
\r
174 if (mappings == null)
\r
176 mappings = new StructureMapping[1];
\r
180 StructureMapping[] tmp = new StructureMapping[mappings.length + 1];
\r
181 System.arraycopy(mappings, 0, tmp, 0, mappings.length);
\r
185 if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
\r
186 pdbFile = "INLINE"+pdb.id;
\r
188 mappings[mappings.length - 1]
\r
189 = new StructureMapping(sequence[s], pdbFile, pdb.id, maxChainId,
\r
190 mapping, mappingDetails.toString());
\r
197 public void removeStructureViewerListener(Object svl, String pdbfile)
\r
199 listeners.removeElement(svl);
\r
201 boolean removeMapping = true;
\r
203 StructureListener sl;
\r
204 for (int i = 0; i < listeners.size(); i++)
\r
206 if (listeners.elementAt(i) instanceof StructureListener)
\r
208 sl = (StructureListener) listeners.elementAt(i);
\r
209 if (sl.getPdbFile().equals(pdbfile))
\r
211 removeMapping = false;
\r
217 if (removeMapping && mappings!=null)
\r
219 Vector tmp = new Vector();
\r
220 for (int i = 0; i < mappings.length; i++)
\r
222 if (!mappings[i].pdbfile.equals(pdbfile))
\r
224 tmp.addElement(mappings[i]);
\r
228 mappings = new StructureMapping[tmp.size()];
\r
229 tmp.copyInto(mappings);
\r
233 public void mouseOverStructure(int pdbResNum, String chain, String pdbfile)
\r
235 SequenceListener sl;
\r
236 for (int i = 0; i < listeners.size(); i++)
\r
238 if (listeners.elementAt(i) instanceof SequenceListener)
\r
240 sl = (SequenceListener) listeners.elementAt(i);
\r
242 for (int j = 0; j < mappings.length; j++)
\r
244 if (mappings[j].pdbfile.equals(pdbfile) &&
\r
245 mappings[j].pdbchain.equals(chain))
\r
247 sl.highlightSequence(mappings[j].sequence,
\r
248 mappings[j].getSeqPos(pdbResNum));
\r
252 sl.highlightSequence(null, pdbResNum);
\r
257 public void mouseOverSequence(SequenceI seq, int index)
\r
259 StructureListener sl;
\r
261 for (int i = 0; i < listeners.size(); i++)
\r
263 if (listeners.elementAt(i) instanceof StructureListener)
\r
265 sl = (StructureListener) listeners.elementAt(i);
\r
267 for (int j = 0; j < mappings.length; j++)
\r
269 if (mappings[j].sequence == seq)
\r
271 atomNo = mappings[j].getAtomNum(index);
\r
275 sl.highlightAtom(atomNo,
\r
276 mappings[j].getPDBResNum(index),
\r
277 mappings[j].pdbchain,
\r
278 mappings[j].pdbfile);
\r
286 public void structureSelectionChanged()
\r
288 StructureListener svl;
\r
289 for (int i = 0; i < listeners.size(); i++)
\r
291 svl = (StructureListener) listeners.elementAt(i);
\r
295 public void sequenceSelectionChanged()
\r
297 StructureListener svl;
\r
298 for (int i = 0; i < listeners.size(); i++)
\r
300 svl = (StructureListener) listeners.elementAt(i);
\r
304 public void sequenceColoursChanged(Object source)
\r
306 StructureListener sl;
\r
307 for (int i = 0; i < listeners.size(); i++)
\r
309 if (listeners.elementAt(i) instanceof StructureListener)
\r
311 sl = (StructureListener) listeners.elementAt(i);
\r
312 sl.updateColours(source);
\r
317 public StructureMapping[] getMapping(String pdbfile)
\r
319 Vector tmp = new Vector();
\r
320 for (int i = 0; i < mappings.length; i++)
\r
322 if (mappings[i].pdbfile.equals(pdbfile))
\r
324 tmp.addElement(mappings[i]);
\r
328 StructureMapping[] ret = new StructureMapping[tmp.size()];
\r
329 for (int i = 0; i < tmp.size(); i++)
\r
331 ret[i] = (StructureMapping) tmp.elementAt(i);
\r
337 public String printMapping(String pdbfile)
\r
339 StringBuffer sb = new StringBuffer();
\r
340 for (int i = 0; i < mappings.length; i++)
\r
342 if (mappings[i].pdbfile.equals(pdbfile))
\r
344 sb.append(mappings[i].mappingDetails);
\r
348 return sb.toString();
\r