3 import jalview.analysis.AlignSeq;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentAnnotation;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.DBRefEntry;
8 import jalview.datamodel.DBRefSource;
9 import jalview.datamodel.PDBEntry;
10 import jalview.datamodel.SequenceI;
11 import jalview.structure.StructureViewSettings;
13 import java.awt.Color;
14 import java.io.IOException;
15 import java.lang.reflect.Constructor;
16 import java.util.Hashtable;
17 import java.util.List;
18 import java.util.Vector;
20 import MCview.PDBChain;
22 public abstract class StructureFile extends AlignFile
27 private String dbRefType;
29 * set to true to add derived sequence annotations (temp factor read from
30 * file, or computed secondary structure) to the alignment
32 protected boolean visibleChainAnnotation = false;
35 * Set true to predict secondary structure (using JMol for protein, Annotate3D
38 protected boolean predictSecondaryStructure = false;
41 * Set true (with predictSecondaryStructure=true) to predict secondary
42 * structure using an external service (currently Annotate3D for RNA only)
44 protected boolean externalSecondaryStructure = false;
46 private Vector<PDBChain> chains;
48 public StructureFile(String inFile, String type) throws IOException
53 public StructureFile(FileParse fp) throws IOException
58 public void addSettings(boolean addAlignmentAnnotations,
59 boolean predictSecondaryStructure, boolean externalSecStr)
61 this.visibleChainAnnotation = addAlignmentAnnotations;
62 this.predictSecondaryStructure = predictSecondaryStructure;
63 this.externalSecondaryStructure = externalSecStr;
65 public StructureFile(boolean parseImmediately, String inFile, String type)
68 super(parseImmediately, inFile, type);
71 public StructureFile(boolean a, FileParse fp) throws IOException
76 public StructureFile()
80 @SuppressWarnings("rawtypes")
81 protected SequenceI postProcessChain(PDBChain chain)
83 SequenceI pdbSequence = chain.sequence;
84 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
85 PDBEntry entry = new PDBEntry();
87 entry.setType(this.dbRefType);
88 entry.setProperty(new Hashtable());
91 entry.setChainCode(String.valueOf(chain.id));
95 entry.setFile(inFile.getAbsolutePath());
99 entry.setFile(getDataName());
102 DBRefEntry sourceDBRef = new DBRefEntry();
103 sourceDBRef.setAccessionId(getId());
104 sourceDBRef.setSource(DBRefSource.PDB);
105 sourceDBRef.setStartRes(pdbSequence.getStart());
106 sourceDBRef.setEndRes(pdbSequence.getEnd());
108 SequenceI chainseq = pdbSequence.deriveSequence();
109 chainseq.setSourceDBRef(sourceDBRef);
110 chainseq.addPDBId(entry);
111 chainseq.addDBRef(sourceDBRef);
113 seqs.addElement(chainseq);
115 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
117 if (chainannot != null && visibleChainAnnotation)
119 for (int ai = 0; ai < chainannot.length; ai++)
121 chainannot[ai].visible = visibleChainAnnotation;
122 annotations.addElement(chainannot[ai]);
128 @SuppressWarnings({ "unchecked", "rawtypes" })
129 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
132 // System.out.println("this is a PDB format and RNA sequence");
133 // note: we use reflection here so that the applet can compile and run
134 // without the HTTPClient bits and pieces needed for accessing Annotate3D
138 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
141 // TODO: use the PDB ID of the structure if one is available, to save
142 // bandwidth and avoid uploading the whole structure to the service
143 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
145 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
146 new Class[] { FileParse.class }).invoke(annotate3d,
147 new Object[] { new FileParse(getDataName(), type) }));
148 for (SequenceI sq : al.getSequences())
150 if (sq.getDatasetSequence() != null)
152 if (sq.getDatasetSequence().getAllPDBEntries() != null)
154 sq.getDatasetSequence().getAllPDBEntries().clear();
159 if (sq.getAllPDBEntries() != null)
161 sq.getAllPDBEntries().clear();
165 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
167 } catch (ClassNotFoundException x)
169 // ignore classnotfounds - occurs in applet
173 @SuppressWarnings("unchecked")
174 protected void replaceAndUpdateChains(List<SequenceI> prot,
176 String pep, boolean b)
178 List<List<? extends Object>> replaced = AlignSeq
179 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
181 for (PDBChain ch : getChains())
184 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
187 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
196 // set shadow entry for chains
197 ch.shadow = (SequenceI) replaced.get(1).get(p);
198 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
199 .getMappingFromS1(false);
205 * Predict secondary structure for RNA and/or protein sequences and add as
208 * @param rnaSequences
209 * @param proteinSequences
211 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
212 List<SequenceI> proteinSequences)
215 * Currently using Annotate3D for RNA, but only if the 'use external
216 * prediction' flag is set
218 if (externalSecondaryStructure && rnaSequences.size() > 0)
222 processPdbFileWithAnnotate3d(rnaSequences);
223 } catch (Exception x)
225 System.err.println("Exceptions when dealing with RNA in pdb file");
232 * Currently using JMol PDB parser for peptide
234 if (proteinSequences.size() > 0)
238 processWithJmolParser(proteinSequences);
239 } catch (Exception x)
242 .println("Exceptions from Jmol when processing data in pdb file");
248 @SuppressWarnings({ "unchecked", "rawtypes" })
249 private void processWithJmolParser(List<SequenceI> prot)
255 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
258 final Constructor constructor = cl
259 .getConstructor(new Class[] {
260 boolean.class, boolean.class, boolean.class, FileParse.class });
261 final Object[] args = new Object[] { true, true, true,
262 new FileParse(getDataName(),
265 StructureViewSettings.setShowSeqFeatures(false);
266 StructureViewSettings.setPredictSecondaryStructure(true);
267 Object jmf = constructor.newInstance(args);
268 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
269 "getSeqsAsArray", new Class[] {}).invoke(jmf));
270 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
272 for (SequenceI sq : al.getSequences())
274 if (sq.getDatasetSequence() != null)
276 sq.getDatasetSequence().getAllPDBEntries().clear();
280 sq.getAllPDBEntries().clear();
283 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
285 } catch (ClassNotFoundException q)
290 public PDBChain findChain(String id) throws Exception
292 for (PDBChain chain : getChains())
294 if (chain.id.equalsIgnoreCase(id))
299 throw new Exception("PDB chain not Found!");
302 public void makeResidueList()
304 for (PDBChain chain : getChains())
306 chain.makeResidueList(visibleChainAnnotation);
310 public void makeCaBondList()
312 for (PDBChain chain : getChains())
314 chain.makeCaBondList();
318 public void setChargeColours()
320 for (PDBChain chain : getChains())
322 chain.setChargeColours();
326 public void setColours(jalview.schemes.ColourSchemeI cs)
328 for (PDBChain chain : getChains())
330 chain.setChainColours(cs);
334 public void setChainColours()
337 for (PDBChain chain : getChains())
339 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
343 public static boolean isRNA(SequenceI seq)
345 for (char c : seq.getSequence())
347 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
356 * make a friendly ID string.
359 * @return truncated dataName to after last '/'
361 protected String safeName(String dataName)
364 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
366 dataName = dataName.substring(p + 1);
371 public String getId()
376 public void setId(String id)
381 public Vector<PDBChain> getChains()
386 public void setChains(Vector<PDBChain> chains)
388 this.chains = chains;
391 public String getDbRefType()
396 public void setDbRefType(String dbRefType)
398 this.dbRefType = dbRefType;