3 import jalview.analysis.AlignSeq;
4 import jalview.api.FeatureSettingsModelI;
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.DBRefEntry;
9 import jalview.datamodel.DBRefSource;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.SequenceI;
12 import jalview.structure.StructureViewSettings;
14 import java.awt.Color;
15 import java.io.IOException;
16 import java.lang.reflect.Constructor;
17 import java.util.Hashtable;
18 import java.util.List;
19 import java.util.Vector;
21 import MCview.PDBChain;
23 public abstract class StructureFile extends AlignFile
28 private String dbRefType;
30 * set to true to add derived sequence annotations (temp factor read from
31 * file, or computed secondary structure) to the alignment
33 protected boolean visibleChainAnnotation = false;
36 * Set true to predict secondary structure (using JMol for protein, Annotate3D
39 protected boolean predictSecondaryStructure = false;
42 * Set true (with predictSecondaryStructure=true) to predict secondary
43 * structure using an external service (currently Annotate3D for RNA only)
45 protected boolean externalSecondaryStructure = false;
47 private Vector<PDBChain> chains;
49 public StructureFile(String inFile, String type) throws IOException
54 public StructureFile(FileParse fp) throws IOException
59 public void addSettings(boolean addAlignmentAnnotations,
60 boolean predictSecondaryStructure, boolean externalSecStr)
62 this.visibleChainAnnotation = addAlignmentAnnotations;
63 this.predictSecondaryStructure = predictSecondaryStructure;
64 this.externalSecondaryStructure = externalSecStr;
67 public void xferSettings()
69 this.visibleChainAnnotation = StructureViewSettings
70 .isVisibleChainAnnotation();
71 this.predictSecondaryStructure = StructureViewSettings
72 .isPredictSecondaryStructure();
73 this.externalSecondaryStructure = StructureViewSettings
74 .isExternalSecondaryStructure();
78 public StructureFile(boolean parseImmediately, String inFile, String type)
81 super(parseImmediately, inFile, type);
84 public StructureFile(boolean a, FileParse fp) throws IOException
89 public StructureFile()
93 @SuppressWarnings("rawtypes")
94 protected SequenceI postProcessChain(PDBChain chain)
96 SequenceI pdbSequence = chain.sequence;
97 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
98 PDBEntry entry = new PDBEntry();
100 entry.setType(this.dbRefType);
101 entry.setProperty(new Hashtable());
102 if (chain.id != null)
104 entry.setChainCode(String.valueOf(chain.id));
108 entry.setFile(inFile.getAbsolutePath());
112 entry.setFile(getDataName());
115 DBRefEntry sourceDBRef = new DBRefEntry();
116 sourceDBRef.setAccessionId(getId());
117 sourceDBRef.setSource(DBRefSource.PDB);
118 sourceDBRef.setStartRes(pdbSequence.getStart());
119 sourceDBRef.setEndRes(pdbSequence.getEnd());
121 SequenceI chainseq = pdbSequence.deriveSequence();
122 chainseq.setSourceDBRef(sourceDBRef);
123 chainseq.addPDBId(entry);
124 chainseq.addDBRef(sourceDBRef);
126 seqs.addElement(chainseq);
128 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
130 if (chainannot != null && visibleChainAnnotation)
132 for (int ai = 0; ai < chainannot.length; ai++)
134 chainannot[ai].visible = visibleChainAnnotation;
135 annotations.addElement(chainannot[ai]);
141 @SuppressWarnings({ "unchecked", "rawtypes" })
142 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
145 // System.out.println("this is a PDB format and RNA sequence");
146 // note: we use reflection here so that the applet can compile and run
147 // without the HTTPClient bits and pieces needed for accessing Annotate3D
151 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
154 // TODO: use the PDB ID of the structure if one is available, to save
155 // bandwidth and avoid uploading the whole structure to the service
156 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
158 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
159 new Class[] { FileParse.class }).invoke(annotate3d,
160 new Object[] { new FileParse(getDataName(), type) }));
161 for (SequenceI sq : al.getSequences())
163 if (sq.getDatasetSequence() != null)
165 if (sq.getDatasetSequence().getAllPDBEntries() != null)
167 sq.getDatasetSequence().getAllPDBEntries().clear();
172 if (sq.getAllPDBEntries() != null)
174 sq.getAllPDBEntries().clear();
178 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
180 } catch (ClassNotFoundException x)
182 // ignore classnotfounds - occurs in applet
186 @SuppressWarnings("unchecked")
187 protected void replaceAndUpdateChains(List<SequenceI> prot,
189 String pep, boolean b)
191 List<List<? extends Object>> replaced = AlignSeq
192 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
194 for (PDBChain ch : getChains())
197 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
200 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
209 // set shadow entry for chains
210 ch.shadow = (SequenceI) replaced.get(1).get(p);
211 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
212 .getMappingFromS1(false);
218 * Predict secondary structure for RNA and/or protein sequences and add as
221 * @param rnaSequences
222 * @param proteinSequences
224 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
225 List<SequenceI> proteinSequences)
228 * Currently using Annotate3D for RNA, but only if the 'use external
229 * prediction' flag is set
231 if (externalSecondaryStructure && rnaSequences.size() > 0)
235 processPdbFileWithAnnotate3d(rnaSequences);
236 } catch (Exception x)
238 System.err.println("Exceptions when dealing with RNA in pdb file");
245 * Currently using JMol PDB parser for peptide
247 if (proteinSequences.size() > 0)
251 processWithJmolParser(proteinSequences);
252 } catch (Exception x)
255 .println("Exceptions from Jmol when processing data in pdb file");
261 @SuppressWarnings({ "unchecked", "rawtypes" })
262 private void processWithJmolParser(List<SequenceI> prot)
268 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
271 final Constructor constructor = cl
272 .getConstructor(new Class[] {
273 boolean.class, boolean.class, boolean.class, FileParse.class });
274 final Object[] args = new Object[] { visibleChainAnnotation,
275 predictSecondaryStructure, externalSecondaryStructure,
276 new FileParse(getDataName(),
279 StructureViewSettings.setShowSeqFeatures(false);
280 StructureViewSettings.setVisibleChainAnnotation(false);
281 StructureViewSettings
282 .setPredictSecondaryStructure(predictSecondaryStructure);
283 StructureViewSettings
284 .setExternalSecondaryStructure(externalSecondaryStructure);
285 Object jmf = constructor.newInstance(args);
286 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
287 "getSeqsAsArray", new Class[] {}).invoke(jmf));
288 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
290 for (SequenceI sq : al.getSequences())
292 if (sq.getDatasetSequence() != null)
294 sq.getDatasetSequence().getAllPDBEntries().clear();
298 sq.getAllPDBEntries().clear();
301 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
303 } catch (ClassNotFoundException q)
308 public PDBChain findChain(String id) throws Exception
310 for (PDBChain chain : getChains())
312 if (chain.id.equalsIgnoreCase(id))
317 throw new Exception("PDB chain not Found!");
320 public void makeResidueList()
322 for (PDBChain chain : getChains())
324 chain.makeResidueList(visibleChainAnnotation);
328 public void makeCaBondList()
330 for (PDBChain chain : getChains())
332 chain.makeCaBondList();
336 public void setChargeColours()
338 for (PDBChain chain : getChains())
340 chain.setChargeColours();
344 public void setColours(jalview.schemes.ColourSchemeI cs)
346 for (PDBChain chain : getChains())
348 chain.setChainColours(cs);
352 public void setChainColours()
355 for (PDBChain chain : getChains())
357 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
361 public static boolean isRNA(SequenceI seq)
363 for (char c : seq.getSequence())
365 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
374 * make a friendly ID string.
377 * @return truncated dataName to after last '/'
379 protected String safeName(String dataName)
382 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
384 dataName = dataName.substring(p + 1);
389 public String getId()
394 public void setId(String id)
399 public Vector<PDBChain> getChains()
404 public void setChains(Vector<PDBChain> chains)
406 this.chains = chains;
409 public String getDbRefType()
414 public void setDbRefType(String dbRefType)
416 this.dbRefType = dbRefType;
420 * Returns a descriptor for suitable feature display settings with
422 * <li>ResNums or insertions features visible</li>
423 * <li>insertions features coloured red</li>
424 * <li>ResNum features coloured by label</li>
425 * <li>Insertions displayed above (on top of) ResNums</li>
429 public FeatureSettingsModelI getFeatureColourScheme()
431 return new PDBFeatureSettings();