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;
12 import java.awt.Color;
13 import java.io.IOException;
14 import java.lang.reflect.Constructor;
15 import java.util.Hashtable;
16 import java.util.List;
17 import java.util.Vector;
19 import MCview.PDBChain;
21 public abstract class StructureFile extends AlignFile
27 * set to true to add derived sequence annotations (temp factor read from
28 * file, or computed secondary structure) to the alignment
30 protected boolean visibleChainAnnotation = false;
33 * Set true to predict secondary structure (using JMol for protein, Annotate3D
36 protected boolean predictSecondaryStructure = true;
39 * Set true (with predictSecondaryStructure=true) to predict secondary
40 * structure using an external service (currently Annotate3D for RNA only)
42 protected boolean externalSecondaryStructure = false;
44 private Vector<PDBChain> chains;
46 public StructureFile(String inFile, String type) throws IOException
51 public StructureFile(FileParse fp) throws IOException
56 public StructureFile(boolean parseImmediately, String inFile, String type)
59 super(parseImmediately, inFile, type);
62 public StructureFile(boolean a, FileParse fp) throws IOException
67 public StructureFile()
71 @SuppressWarnings("rawtypes")
72 protected SequenceI postProcessChain(PDBChain chain)
74 SequenceI pdbSequence = chain.sequence;
75 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
76 PDBEntry entry = new PDBEntry();
78 entry.setType(PDBEntry.Type.PDB);
79 entry.setProperty(new Hashtable());
82 entry.setChainCode(String.valueOf(chain.id));
86 entry.setFile(inFile.getAbsolutePath());
90 entry.setFile(getDataName());
93 DBRefEntry sourceDBRef = new DBRefEntry();
94 sourceDBRef.setAccessionId(getId());
95 sourceDBRef.setSource(DBRefSource.PDB);
96 sourceDBRef.setStartRes(pdbSequence.getStart());
97 sourceDBRef.setEndRes(pdbSequence.getEnd());
99 // PDBChain objects maintain reference to dataset
101 // SequenceI chainseq = pdbSequence.deriveSequence();
102 // chainseq.setSourceDBRef(sourceDBRef);
103 // chainseq.addPDBId(entry);
104 // chainseq.addDBRef(sourceDBRef);
105 SequenceI chainseq = chain.sequence;
106 chainseq.addPDBId(entry);
107 chainseq.setSourceDBRef(sourceDBRef);
108 chainseq.addDBRef(sourceDBRef);
109 seqs.addElement(chainseq);
111 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
113 if (chainannot != null && visibleChainAnnotation)
115 for (int ai = 0; ai < chainannot.length; ai++)
117 chainannot[ai].visible = visibleChainAnnotation;
118 annotations.addElement(chainannot[ai]);
124 @SuppressWarnings({ "unchecked", "rawtypes" })
125 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
128 // System.out.println("this is a PDB format and RNA sequence");
129 // note: we use reflection here so that the applet can compile and run
130 // without the HTTPClient bits and pieces needed for accessing Annotate3D
134 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
137 // TODO: use the PDB ID of the structure if one is available, to save
138 // bandwidth and avoid uploading the whole structure to the service
139 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
141 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
142 new Class[] { FileParse.class }).invoke(annotate3d,
143 new Object[] { new FileParse(getDataName(), type) }));
144 for (SequenceI sq : al.getSequences())
146 if (sq.getDatasetSequence() != null)
148 if (sq.getDatasetSequence().getAllPDBEntries() != null)
150 sq.getDatasetSequence().getAllPDBEntries().clear();
155 if (sq.getAllPDBEntries() != null)
157 sq.getAllPDBEntries().clear();
161 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
163 } catch (ClassNotFoundException x)
165 // ignore classnotfounds - occurs in applet
169 @SuppressWarnings("unchecked")
170 protected void replaceAndUpdateChains(List<SequenceI> prot,
172 String pep, boolean b)
174 List<List<? extends Object>> replaced = AlignSeq
175 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
177 for (PDBChain ch : getChains())
180 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
183 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
192 // set shadow entry for chains
193 ch.shadow = (SequenceI) replaced.get(1).get(p);
194 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
195 .getMappingFromS1(false);
201 * Predict secondary structure for RNA and/or protein sequences and add as
204 * @param rnaSequences
205 * @param proteinSequences
207 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
208 List<SequenceI> proteinSequences)
211 * Currently using Annotate3D for RNA, but only if the 'use external
212 * prediction' flag is set
214 if (externalSecondaryStructure && rnaSequences.size() > 0)
218 processPdbFileWithAnnotate3d(rnaSequences);
219 } catch (Exception x)
221 System.err.println("Exceptions when dealing with RNA in pdb file");
228 * Currently using JMol PDB parser for peptide
230 if (proteinSequences.size() > 0)
234 processWithJmolParser(proteinSequences);
235 } catch (Exception x)
238 .println("Exceptions from Jmol when processing data in pdb file");
244 @SuppressWarnings({ "unchecked", "rawtypes" })
245 private void processWithJmolParser(List<SequenceI> prot)
251 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
254 final Constructor constructor = cl
255 .getConstructor(new Class[] { FileParse.class });
256 final Object[] args = new Object[] { new FileParse(getDataName(),
258 Object jmf = constructor.newInstance(args);
259 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
260 "getSeqsAsArray", new Class[] {}).invoke(jmf));
261 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
263 for (SequenceI sq : al.getSequences())
265 if (sq.getDatasetSequence() != null)
267 sq.getDatasetSequence().getAllPDBEntries().clear();
271 sq.getAllPDBEntries().clear();
274 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
276 } catch (ClassNotFoundException q)
281 public PDBChain findChain(String id) throws Exception
283 for (PDBChain chain : getChains())
285 if (chain.id.equalsIgnoreCase(id))
290 throw new Exception("PDB chain not Found!");
293 public void makeResidueList()
295 for (PDBChain chain : getChains())
297 chain.makeResidueList(visibleChainAnnotation);
301 public void makeCaBondList()
303 for (PDBChain chain : getChains())
305 chain.makeCaBondList();
309 public void setChargeColours()
311 for (PDBChain chain : getChains())
313 chain.setChargeColours();
317 public void setColours(jalview.schemes.ColourSchemeI cs)
319 for (PDBChain chain : getChains())
321 chain.setChainColours(cs);
325 public void setChainColours()
328 for (PDBChain chain : getChains())
330 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
334 public static boolean isRNA(SequenceI seq)
336 for (char c : seq.getSequence())
338 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
347 * make a friendly ID string.
350 * @return truncated dataName to after last '/'
352 protected String safeName(String dataName)
355 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
357 dataName = dataName.substring(p + 1);
362 public String getId()
367 public void setId(String id)
372 public Vector<PDBChain> getChains()
377 public void setChains(Vector<PDBChain> chains)
379 this.chains = chains;