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 .isProcessSecondaryStructure();
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 pdbSequence.setSourceDBRef(sourceDBRef);
120 pdbSequence.addPDBId(entry);
121 pdbSequence.addDBRef(sourceDBRef);
122 SequenceI chainseq = pdbSequence;
123 seqs.addElement(chainseq);
124 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
126 if (chainannot != null && visibleChainAnnotation)
128 for (int ai = 0; ai < chainannot.length; ai++)
130 chainannot[ai].visible = visibleChainAnnotation;
131 annotations.addElement(chainannot[ai]);
137 @SuppressWarnings({ "unchecked", "rawtypes" })
138 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
141 // System.out.println("this is a PDB format and RNA sequence");
142 // note: we use reflection here so that the applet can compile and run
143 // without the HTTPClient bits and pieces needed for accessing Annotate3D
147 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
150 // TODO: use the PDB ID of the structure if one is available, to save
151 // bandwidth and avoid uploading the whole structure to the service
152 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
154 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
155 new Class[] { FileParse.class }).invoke(annotate3d,
156 new Object[] { new FileParse(getDataName(), type) }));
157 for (SequenceI sq : al.getSequences())
159 if (sq.getDatasetSequence() != null)
161 if (sq.getDatasetSequence().getAllPDBEntries() != null)
163 sq.getDatasetSequence().getAllPDBEntries().clear();
168 if (sq.getAllPDBEntries() != null)
170 sq.getAllPDBEntries().clear();
174 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
176 } catch (ClassNotFoundException x)
178 // ignore classnotfounds - occurs in applet
182 @SuppressWarnings("unchecked")
183 protected void replaceAndUpdateChains(List<SequenceI> prot,
184 AlignmentI al, String pep, boolean b)
186 List<List<? extends Object>> replaced = AlignSeq
187 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
189 for (PDBChain ch : getChains())
192 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
195 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
204 // set shadow entry for chains
205 ch.shadow = (SequenceI) replaced.get(1).get(p);
206 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
207 .getMappingFromS1(false);
213 * Predict secondary structure for RNA and/or protein sequences and add as
216 * @param rnaSequences
217 * @param proteinSequences
219 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
220 List<SequenceI> proteinSequences)
223 * Currently using Annotate3D for RNA, but only if the 'use external
224 * prediction' flag is set
226 if (externalSecondaryStructure && rnaSequences.size() > 0)
230 processPdbFileWithAnnotate3d(rnaSequences);
231 } catch (Exception x)
233 System.err.println("Exceptions when dealing with RNA in pdb file");
240 * Currently using JMol PDB parser for peptide
242 if (proteinSequences.size() > 0)
246 processWithJmolParser(proteinSequences);
247 } catch (Exception x)
250 .println("Exceptions from Jmol when processing data in pdb file");
256 @SuppressWarnings({ "unchecked", "rawtypes" })
257 private void processWithJmolParser(List<SequenceI> prot) throws Exception
262 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
265 final Constructor constructor = cl.getConstructor(new Class[] {
266 boolean.class, boolean.class, boolean.class, FileParse.class });
267 final Object[] args = new Object[] { visibleChainAnnotation,
268 predictSecondaryStructure, externalSecondaryStructure,
269 new FileParse(getDataName(), type) };
271 StructureImportSettings.setShowSeqFeatures(false);
272 StructureImportSettings.setVisibleChainAnnotation(false);
273 StructureImportSettings
274 .setProcessSecondaryStructure(predictSecondaryStructure);
275 StructureImportSettings
276 .setExternalSecondaryStructure(externalSecondaryStructure);
277 Object jmf = constructor.newInstance(args);
278 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
279 "getSeqsAsArray", new Class[] {}).invoke(jmf));
280 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
282 for (SequenceI sq : al.getSequences())
284 if (sq.getDatasetSequence() != null)
286 sq.getDatasetSequence().getAllPDBEntries().clear();
290 sq.getAllPDBEntries().clear();
293 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
295 } catch (ClassNotFoundException q)
298 StructureImportSettings.setShowSeqFeatures(true);
301 public PDBChain findChain(String id) throws Exception
303 for (PDBChain chain : getChains())
305 if (chain.id.equals(id))
310 throw new Exception("PDB chain not Found!");
313 public void makeResidueList()
315 for (PDBChain chain : getChains())
317 chain.makeResidueList(visibleChainAnnotation);
321 public void makeCaBondList()
323 for (PDBChain chain : getChains())
325 chain.makeCaBondList();
329 public void setChargeColours()
331 for (PDBChain chain : getChains())
333 chain.setChargeColours();
337 public void setColours(jalview.schemes.ColourSchemeI cs)
339 for (PDBChain chain : getChains())
341 chain.setChainColours(cs);
345 public void setChainColours()
348 for (PDBChain chain : getChains())
350 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
354 public static boolean isRNA(SequenceI seq)
356 for (char c : seq.getSequence())
358 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
367 * make a friendly ID string.
370 * @return truncated dataName to after last '/'
372 protected String safeName(String dataName)
375 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
377 dataName = dataName.substring(p + 1);
382 public String getId()
387 public void setId(String id)
392 public Vector<PDBChain> getChains()
397 public void setChains(Vector<PDBChain> chains)
399 this.chains = chains;
402 public String getDbRefType()
407 public void setDbRefType(String dbRefType)
409 this.dbRefType = dbRefType;
413 * Returns a descriptor for suitable feature display settings with
415 * <li>ResNums or insertions features visible</li>
416 * <li>insertions features coloured red</li>
417 * <li>ResNum features coloured by label</li>
418 * <li>Insertions displayed above (on top of) ResNums</li>
422 public FeatureSettingsModelI getFeatureColourScheme()
424 return new PDBFeatureSettings();