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.StructureImportSettings;
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;
31 * set to true to add derived sequence annotations (temp factor read from
32 * file, or computed secondary structure) to the alignment
34 protected boolean visibleChainAnnotation = false;
37 * Set true to predict secondary structure (using JMol for protein, Annotate3D
40 protected boolean predictSecondaryStructure = false;
43 * Set true (with predictSecondaryStructure=true) to predict secondary
44 * structure using an external service (currently Annotate3D for RNA only)
46 protected boolean externalSecondaryStructure = false;
48 private Vector<PDBChain> chains;
50 public StructureFile(String inFile, String type) throws IOException
55 public StructureFile(FileParse fp) throws IOException
60 public void addSettings(boolean addAlignmentAnnotations,
61 boolean predictSecondaryStructure, boolean externalSecStr)
63 this.visibleChainAnnotation = addAlignmentAnnotations;
64 this.predictSecondaryStructure = predictSecondaryStructure;
65 this.externalSecondaryStructure = externalSecStr;
68 public void xferSettings()
70 this.visibleChainAnnotation = StructureImportSettings
71 .isVisibleChainAnnotation();
72 this.predictSecondaryStructure = StructureImportSettings
73 .isPredictSecondaryStructure();
74 this.externalSecondaryStructure = StructureImportSettings
75 .isExternalSecondaryStructure();
79 public StructureFile(boolean parseImmediately, String dataObject, String type)
82 super(parseImmediately, dataObject, type);
85 public StructureFile(boolean a, FileParse fp) throws IOException
90 public StructureFile()
94 @SuppressWarnings("rawtypes")
95 protected SequenceI postProcessChain(PDBChain chain)
97 SequenceI pdbSequence = chain.sequence;
98 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
99 PDBEntry entry = new PDBEntry();
100 entry.setId(getId());
101 entry.setType(this.dbRefType);
102 entry.setProperty(new Hashtable());
103 if (chain.id != null)
105 entry.setChainCode(String.valueOf(chain.id));
109 entry.setFile(inFile.getAbsolutePath());
113 entry.setFile(getDataName());
116 DBRefEntry sourceDBRef = new DBRefEntry();
117 sourceDBRef.setAccessionId(getId());
118 sourceDBRef.setSource(DBRefSource.PDB);
119 sourceDBRef.setStartRes(pdbSequence.getStart());
120 sourceDBRef.setEndRes(pdbSequence.getEnd());
121 pdbSequence.setSourceDBRef(sourceDBRef);
122 pdbSequence.addPDBId(entry);
123 pdbSequence.addDBRef(sourceDBRef);
124 SequenceI chainseq = pdbSequence;
125 seqs.addElement(chainseq);
126 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
128 if (chainannot != null && visibleChainAnnotation)
130 for (int ai = 0; ai < chainannot.length; ai++)
132 chainannot[ai].visible = visibleChainAnnotation;
133 annotations.addElement(chainannot[ai]);
139 @SuppressWarnings({ "unchecked", "rawtypes" })
140 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
143 // System.out.println("this is a PDB format and RNA sequence");
144 // note: we use reflection here so that the applet can compile and run
145 // without the HTTPClient bits and pieces needed for accessing Annotate3D
149 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
152 // TODO: use the PDB ID of the structure if one is available, to save
153 // bandwidth and avoid uploading the whole structure to the service
154 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
156 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
157 new Class[] { FileParse.class }).invoke(annotate3d,
158 new Object[] { new FileParse(getDataName(), type) }));
159 for (SequenceI sq : al.getSequences())
161 if (sq.getDatasetSequence() != null)
163 if (sq.getDatasetSequence().getAllPDBEntries() != null)
165 sq.getDatasetSequence().getAllPDBEntries().clear();
170 if (sq.getAllPDBEntries() != null)
172 sq.getAllPDBEntries().clear();
176 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
178 } catch (ClassNotFoundException x)
180 // ignore classnotfounds - occurs in applet
184 @SuppressWarnings("unchecked")
185 protected void replaceAndUpdateChains(List<SequenceI> prot,
186 AlignmentI al, String pep, boolean b)
188 List<List<? extends Object>> replaced = AlignSeq
189 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
191 for (PDBChain ch : getChains())
194 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
197 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
206 // set shadow entry for chains
207 ch.shadow = (SequenceI) replaced.get(1).get(p);
208 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
209 .getMappingFromS1(false);
215 * Predict secondary structure for RNA and/or protein sequences and add as
218 * @param rnaSequences
219 * @param proteinSequences
221 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
222 List<SequenceI> proteinSequences)
225 * Currently using Annotate3D for RNA, but only if the 'use external
226 * prediction' flag is set
228 if (externalSecondaryStructure && rnaSequences.size() > 0)
232 processPdbFileWithAnnotate3d(rnaSequences);
233 } catch (Exception x)
235 System.err.println("Exceptions when dealing with RNA in pdb file");
242 * Currently using JMol PDB parser for peptide
244 if (proteinSequences.size() > 0)
248 processWithJmolParser(proteinSequences);
249 } catch (Exception x)
252 .println("Exceptions from Jmol when processing data in pdb file");
258 @SuppressWarnings({ "unchecked", "rawtypes" })
259 private void processWithJmolParser(List<SequenceI> prot) throws Exception
264 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
267 final Constructor constructor = cl.getConstructor(new Class[] {
268 boolean.class, boolean.class, boolean.class, FileParse.class });
269 final Object[] args = new Object[] { visibleChainAnnotation,
270 predictSecondaryStructure, externalSecondaryStructure,
271 new FileParse(getDataName(), type) };
273 StructureImportSettings.setShowSeqFeatures(false);
274 StructureImportSettings.setVisibleChainAnnotation(false);
275 StructureImportSettings
276 .setPredictSecondaryStructure(predictSecondaryStructure);
277 StructureImportSettings
278 .setExternalSecondaryStructure(externalSecondaryStructure);
279 Object jmf = constructor.newInstance(args);
280 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
281 "getSeqsAsArray", new Class[] {}).invoke(jmf));
282 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
284 for (SequenceI sq : al.getSequences())
286 if (sq.getDatasetSequence() != null)
288 sq.getDatasetSequence().getAllPDBEntries().clear();
292 sq.getAllPDBEntries().clear();
295 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
297 } catch (ClassNotFoundException q)
300 StructureImportSettings.setShowSeqFeatures(true);
303 public PDBChain findChain(String id) throws Exception
305 for (PDBChain chain : getChains())
307 if (chain.id.equals(id))
312 throw new Exception("PDB chain not Found!");
315 public void makeResidueList()
317 for (PDBChain chain : getChains())
319 chain.makeResidueList(visibleChainAnnotation);
323 public void makeCaBondList()
325 for (PDBChain chain : getChains())
327 chain.makeCaBondList();
331 public void setChargeColours()
333 for (PDBChain chain : getChains())
335 chain.setChargeColours();
339 public void setColours(jalview.schemes.ColourSchemeI cs)
341 for (PDBChain chain : getChains())
343 chain.setChainColours(cs);
347 public void setChainColours()
350 for (PDBChain chain : getChains())
352 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
356 public static boolean isRNA(SequenceI seq)
358 for (char c : seq.getSequence())
360 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
369 * make a friendly ID string.
372 * @return truncated dataName to after last '/'
374 protected String safeName(String dataName)
377 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
379 dataName = dataName.substring(p + 1);
384 public String getId()
389 public void setId(String id)
394 public Vector<PDBChain> getChains()
399 public void setChains(Vector<PDBChain> chains)
401 this.chains = chains;
404 public String getDbRefType()
409 public void setDbRefType(String dbRefType)
411 this.dbRefType = dbRefType;
415 * Returns a descriptor for suitable feature display settings with
417 * <li>ResNums or insertions features visible</li>
418 * <li>insertions features coloured red</li>
419 * <li>ResNum features coloured by label</li>
420 * <li>Insertions displayed above (on top of) ResNums</li>
424 public FeatureSettingsModelI getFeatureColourScheme()
426 return new PDBFeatureSettings();