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.PDBEntry.Type;
12 import jalview.datamodel.SequenceI;
13 import jalview.structure.StructureImportSettings;
15 import java.awt.Color;
16 import java.io.IOException;
17 import java.lang.reflect.Constructor;
18 import java.util.Hashtable;
19 import java.util.List;
20 import java.util.Vector;
22 import MCview.PDBChain;
24 public abstract class StructureFile extends AlignFile
29 private PDBEntry.Type dbRefType;
32 * set to true to add derived sequence annotations (temp factor read from
33 * file, or computed secondary structure) to the alignment
35 protected boolean visibleChainAnnotation = false;
38 * Set true to predict secondary structure (using JMol for protein, Annotate3D
41 protected boolean predictSecondaryStructure = false;
44 * Set true (with predictSecondaryStructure=true) to predict secondary
45 * structure using an external service (currently Annotate3D for RNA only)
47 protected boolean externalSecondaryStructure = false;
49 private Vector<PDBChain> chains;
51 public StructureFile(String inFile, String type) throws IOException
56 public StructureFile(FileParse fp) throws IOException
61 public void addSettings(boolean addAlignmentAnnotations,
62 boolean predictSecondaryStructure, boolean externalSecStr)
64 this.visibleChainAnnotation = addAlignmentAnnotations;
65 this.predictSecondaryStructure = predictSecondaryStructure;
66 this.externalSecondaryStructure = externalSecStr;
69 public void xferSettings()
71 this.visibleChainAnnotation = StructureImportSettings
72 .isVisibleChainAnnotation();
73 this.predictSecondaryStructure = StructureImportSettings
74 .isProcessSecondaryStructure();
75 this.externalSecondaryStructure = StructureImportSettings
76 .isExternalSecondaryStructure();
80 public StructureFile(boolean parseImmediately, String dataObject, String type)
83 super(parseImmediately, dataObject, type);
86 public StructureFile(boolean a, FileParse fp) throws IOException
91 public StructureFile()
95 @SuppressWarnings("rawtypes")
96 protected SequenceI postProcessChain(PDBChain chain)
98 SequenceI pdbSequence = chain.sequence;
99 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
100 PDBEntry entry = new PDBEntry();
101 entry.setId(getId());
102 entry.setType(getStructureFileType());
103 entry.setProperty(new Hashtable());
104 if (chain.id != null)
106 entry.setChainCode(String.valueOf(chain.id));
110 entry.setFile(inFile.getAbsolutePath());
114 entry.setFile(getDataName());
117 DBRefEntry sourceDBRef = new DBRefEntry();
118 sourceDBRef.setAccessionId(getId());
119 sourceDBRef.setSource(DBRefSource.PDB);
120 // TODO: specify version for 'PDB' database ref if it is read from a file.
121 // TODO: decide if jalview.io should be creating primary refs!
122 sourceDBRef.setVersion("");
123 pdbSequence.addPDBId(entry);
124 pdbSequence.addDBRef(sourceDBRef);
125 SequenceI chainseq = pdbSequence;
126 seqs.addElement(chainseq);
127 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
129 if (chainannot != null && visibleChainAnnotation)
131 for (int ai = 0; ai < chainannot.length; ai++)
133 chainannot[ai].visible = visibleChainAnnotation;
134 annotations.addElement(chainannot[ai]);
141 * filetype of structure file - default is PDB
143 String structureFileType = PDBEntry.Type.PDB.toString();
145 protected void setStructureFileType(String structureFileType)
147 this.structureFileType = structureFileType;
151 * filetype of last file processed
155 public String getStructureFileType()
157 return structureFileType;
160 @SuppressWarnings({ "unchecked", "rawtypes" })
161 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
164 // System.out.println("this is a PDB format and RNA sequence");
165 // note: we use reflection here so that the applet can compile and run
166 // without the HTTPClient bits and pieces needed for accessing Annotate3D
170 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
173 // TODO: use the PDB ID of the structure if one is available, to save
174 // bandwidth and avoid uploading the whole structure to the service
175 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
177 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
178 new Class[] { FileParse.class }).invoke(annotate3d,
179 new Object[] { new FileParse(getDataName(), type) }));
180 for (SequenceI sq : al.getSequences())
182 if (sq.getDatasetSequence() != null)
184 if (sq.getDatasetSequence().getAllPDBEntries() != null)
186 sq.getDatasetSequence().getAllPDBEntries().clear();
191 if (sq.getAllPDBEntries() != null)
193 sq.getAllPDBEntries().clear();
197 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
199 } catch (ClassNotFoundException x)
201 // ignore classnotfounds - occurs in applet
205 @SuppressWarnings("unchecked")
206 protected void replaceAndUpdateChains(List<SequenceI> prot,
207 AlignmentI al, String pep, boolean b)
209 List<List<? extends Object>> replaced = AlignSeq
210 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
212 for (PDBChain ch : getChains())
215 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
218 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
227 // set shadow entry for chains
228 ch.shadow = (SequenceI) replaced.get(1).get(p);
229 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
230 .getMappingFromS1(false);
236 * Predict secondary structure for RNA and/or protein sequences and add as
239 * @param rnaSequences
240 * @param proteinSequences
242 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
243 List<SequenceI> proteinSequences)
246 * Currently using Annotate3D for RNA, but only if the 'use external
247 * prediction' flag is set
249 if (externalSecondaryStructure && rnaSequences.size() > 0)
253 processPdbFileWithAnnotate3d(rnaSequences);
254 } catch (Exception x)
256 System.err.println("Exceptions when dealing with RNA in pdb file");
263 * Currently using JMol PDB parser for peptide
265 if (proteinSequences.size() > 0)
269 processWithJmolParser(proteinSequences);
270 } catch (Exception x)
273 .println("Exceptions from Jmol when processing data in pdb file");
279 @SuppressWarnings({ "unchecked", "rawtypes" })
280 private void processWithJmolParser(List<SequenceI> prot) throws Exception
285 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
288 final Constructor constructor = cl
289 .getConstructor(new Class[] { FileParse.class });
290 final Object[] args = new Object[] { new FileParse(getDataName(),
293 StructureImportSettings.setShowSeqFeatures(false);
294 StructureImportSettings.setVisibleChainAnnotation(false);
295 StructureImportSettings
296 .setProcessSecondaryStructure(predictSecondaryStructure);
297 StructureImportSettings
298 .setExternalSecondaryStructure(externalSecondaryStructure);
299 Object jmf = constructor.newInstance(args);
300 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
301 "getSeqsAsArray", new Class[] {}).invoke(jmf));
302 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
304 for (SequenceI sq : al.getSequences())
306 if (sq.getDatasetSequence() != null)
308 sq.getDatasetSequence().getAllPDBEntries().clear();
312 sq.getAllPDBEntries().clear();
315 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
317 } catch (ClassNotFoundException q)
320 StructureImportSettings.setShowSeqFeatures(true);
323 public PDBChain findChain(String id) throws Exception
325 for (PDBChain chain : getChains())
327 if (chain.id.equals(id))
332 throw new Exception("PDB chain not Found!");
335 public void makeResidueList()
337 for (PDBChain chain : getChains())
339 chain.makeResidueList(visibleChainAnnotation);
343 public void makeCaBondList()
345 for (PDBChain chain : getChains())
347 chain.makeCaBondList();
351 public void setChargeColours()
353 for (PDBChain chain : getChains())
355 chain.setChargeColours();
359 public void setColours(jalview.schemes.ColourSchemeI cs)
361 for (PDBChain chain : getChains())
363 chain.setChainColours(cs);
367 public void setChainColours()
370 for (PDBChain chain : getChains())
372 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
376 public static boolean isRNA(SequenceI seq)
378 for (char c : seq.getSequence())
380 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
389 * make a friendly ID string.
392 * @return truncated dataName to after last '/'
394 protected String safeName(String dataName)
397 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
399 dataName = dataName.substring(p + 1);
404 public String getId()
409 public void setId(String id)
414 public Vector<PDBChain> getChains()
419 public void setChains(Vector<PDBChain> chains)
421 this.chains = chains;
424 public Type getDbRefType()
429 public void setDbRefType(String dbRefType)
431 this.dbRefType = Type.getType(dbRefType);
434 public void setDbRefType(Type dbRefType)
436 this.dbRefType = dbRefType;
440 * Returns a descriptor for suitable feature display settings with
442 * <li>ResNums or insertions features visible</li>
443 * <li>insertions features coloured red</li>
444 * <li>ResNum features coloured by label</li>
445 * <li>Insertions displayed above (on top of) ResNums</li>
449 public FeatureSettingsModelI getFeatureColourScheme()
451 return new PDBFeatureSettings();