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;
66 public StructureFile(boolean parseImmediately, String inFile, String type)
69 super(parseImmediately, inFile, type);
72 public StructureFile(boolean a, FileParse fp) throws IOException
77 public StructureFile()
81 @SuppressWarnings("rawtypes")
82 protected SequenceI postProcessChain(PDBChain chain)
84 SequenceI pdbSequence = chain.sequence;
85 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
86 PDBEntry entry = new PDBEntry();
88 entry.setType(this.dbRefType);
89 entry.setProperty(new Hashtable());
92 entry.setChainCode(String.valueOf(chain.id));
96 entry.setFile(inFile.getAbsolutePath());
100 entry.setFile(getDataName());
103 DBRefEntry sourceDBRef = new DBRefEntry();
104 sourceDBRef.setAccessionId(getId());
105 sourceDBRef.setSource(DBRefSource.PDB);
106 sourceDBRef.setStartRes(pdbSequence.getStart());
107 sourceDBRef.setEndRes(pdbSequence.getEnd());
109 SequenceI chainseq = pdbSequence.deriveSequence();
110 chainseq.setSourceDBRef(sourceDBRef);
111 chainseq.addPDBId(entry);
112 chainseq.addDBRef(sourceDBRef);
114 seqs.addElement(chainseq);
116 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
118 if (chainannot != null && visibleChainAnnotation)
120 for (int ai = 0; ai < chainannot.length; ai++)
122 chainannot[ai].visible = visibleChainAnnotation;
123 annotations.addElement(chainannot[ai]);
129 @SuppressWarnings({ "unchecked", "rawtypes" })
130 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
133 // System.out.println("this is a PDB format and RNA sequence");
134 // note: we use reflection here so that the applet can compile and run
135 // without the HTTPClient bits and pieces needed for accessing Annotate3D
139 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
142 // TODO: use the PDB ID of the structure if one is available, to save
143 // bandwidth and avoid uploading the whole structure to the service
144 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
146 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
147 new Class[] { FileParse.class }).invoke(annotate3d,
148 new Object[] { new FileParse(getDataName(), type) }));
149 for (SequenceI sq : al.getSequences())
151 if (sq.getDatasetSequence() != null)
153 if (sq.getDatasetSequence().getAllPDBEntries() != null)
155 sq.getDatasetSequence().getAllPDBEntries().clear();
160 if (sq.getAllPDBEntries() != null)
162 sq.getAllPDBEntries().clear();
166 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
168 } catch (ClassNotFoundException x)
170 // ignore classnotfounds - occurs in applet
174 @SuppressWarnings("unchecked")
175 protected void replaceAndUpdateChains(List<SequenceI> prot,
177 String pep, boolean b)
179 List<List<? extends Object>> replaced = AlignSeq
180 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
182 for (PDBChain ch : getChains())
185 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
188 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
197 // set shadow entry for chains
198 ch.shadow = (SequenceI) replaced.get(1).get(p);
199 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
200 .getMappingFromS1(false);
206 * Predict secondary structure for RNA and/or protein sequences and add as
209 * @param rnaSequences
210 * @param proteinSequences
212 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
213 List<SequenceI> proteinSequences)
216 * Currently using Annotate3D for RNA, but only if the 'use external
217 * prediction' flag is set
219 if (externalSecondaryStructure && rnaSequences.size() > 0)
223 processPdbFileWithAnnotate3d(rnaSequences);
224 } catch (Exception x)
226 System.err.println("Exceptions when dealing with RNA in pdb file");
233 * Currently using JMol PDB parser for peptide
235 if (proteinSequences.size() > 0)
239 processWithJmolParser(proteinSequences);
240 } catch (Exception x)
243 .println("Exceptions from Jmol when processing data in pdb file");
249 @SuppressWarnings({ "unchecked", "rawtypes" })
250 private void processWithJmolParser(List<SequenceI> prot)
256 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
259 final Constructor constructor = cl
260 .getConstructor(new Class[] {
261 boolean.class, boolean.class, boolean.class, FileParse.class });
262 final Object[] args = new Object[] { true, true, true,
263 new FileParse(getDataName(),
266 StructureViewSettings.setShowSeqFeatures(false);
267 StructureViewSettings.setPredictSecondaryStructure(true);
268 Object jmf = constructor.newInstance(args);
269 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
270 "getSeqsAsArray", new Class[] {}).invoke(jmf));
271 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
273 for (SequenceI sq : al.getSequences())
275 if (sq.getDatasetSequence() != null)
277 sq.getDatasetSequence().getAllPDBEntries().clear();
281 sq.getAllPDBEntries().clear();
284 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
286 } catch (ClassNotFoundException q)
291 public PDBChain findChain(String id) throws Exception
293 for (PDBChain chain : getChains())
295 if (chain.id.equalsIgnoreCase(id))
300 throw new Exception("PDB chain not Found!");
303 public void makeResidueList()
305 for (PDBChain chain : getChains())
307 chain.makeResidueList(visibleChainAnnotation);
311 public void makeCaBondList()
313 for (PDBChain chain : getChains())
315 chain.makeCaBondList();
319 public void setChargeColours()
321 for (PDBChain chain : getChains())
323 chain.setChargeColours();
327 public void setColours(jalview.schemes.ColourSchemeI cs)
329 for (PDBChain chain : getChains())
331 chain.setChainColours(cs);
335 public void setChainColours()
338 for (PDBChain chain : getChains())
340 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
344 public static boolean isRNA(SequenceI seq)
346 for (char c : seq.getSequence())
348 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
357 * make a friendly ID string.
360 * @return truncated dataName to after last '/'
362 protected String safeName(String dataName)
365 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
367 dataName = dataName.substring(p + 1);
372 public String getId()
377 public void setId(String id)
382 public Vector<PDBChain> getChains()
387 public void setChains(Vector<PDBChain> chains)
389 this.chains = chains;
392 public String getDbRefType()
397 public void setDbRefType(String dbRefType)
399 this.dbRefType = dbRefType;
403 * Returns a descriptor for suitable feature display settings with
405 * <li>ResNums or insertions features visible</li>
406 * <li>insertions features coloured red</li>
407 * <li>ResNum features coloured by label</li>
408 * <li>Insertions displayed above (on top of) ResNums</li>
412 public FeatureSettingsModelI getFeatureColourScheme()
414 return new PDBFeatureSettings();