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 SequenceI chainseq = pdbSequence.deriveSequence();
100 chainseq.setSourceDBRef(sourceDBRef);
101 chainseq.addPDBId(entry);
102 chainseq.addDBRef(sourceDBRef);
104 seqs.addElement(chainseq);
106 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
108 if (chainannot != null && visibleChainAnnotation)
110 for (int ai = 0; ai < chainannot.length; ai++)
112 chainannot[ai].visible = visibleChainAnnotation;
113 annotations.addElement(chainannot[ai]);
119 @SuppressWarnings({ "unchecked", "rawtypes" })
120 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
123 // System.out.println("this is a PDB format and RNA sequence");
124 // note: we use reflection here so that the applet can compile and run
125 // without the HTTPClient bits and pieces needed for accessing Annotate3D
129 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
132 // TODO: use the PDB ID of the structure if one is available, to save
133 // bandwidth and avoid uploading the whole structure to the service
134 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
136 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
137 new Class[] { FileParse.class }).invoke(annotate3d,
138 new Object[] { new FileParse(getDataName(), type) }));
139 for (SequenceI sq : al.getSequences())
141 if (sq.getDatasetSequence() != null)
143 if (sq.getDatasetSequence().getAllPDBEntries() != null)
145 sq.getDatasetSequence().getAllPDBEntries().clear();
150 if (sq.getAllPDBEntries() != null)
152 sq.getAllPDBEntries().clear();
156 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
158 } catch (ClassNotFoundException x)
160 // ignore classnotfounds - occurs in applet
164 @SuppressWarnings("unchecked")
165 protected void replaceAndUpdateChains(List<SequenceI> prot,
167 String pep, boolean b)
169 List<List<? extends Object>> replaced = AlignSeq
170 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
172 for (PDBChain ch : getChains())
175 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
178 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
187 // set shadow entry for chains
188 ch.shadow = (SequenceI) replaced.get(1).get(p);
189 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
190 .getMappingFromS1(false);
196 * Predict secondary structure for RNA and/or protein sequences and add as
199 * @param rnaSequences
200 * @param proteinSequences
202 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
203 List<SequenceI> proteinSequences)
206 * Currently using Annotate3D for RNA, but only if the 'use external
207 * prediction' flag is set
209 if (externalSecondaryStructure && rnaSequences.size() > 0)
213 processPdbFileWithAnnotate3d(rnaSequences);
214 } catch (Exception x)
216 System.err.println("Exceptions when dealing with RNA in pdb file");
223 * Currently using JMol PDB parser for peptide
225 if (proteinSequences.size() > 0)
229 processWithJmolParser(proteinSequences);
230 } catch (Exception x)
233 .println("Exceptions from Jmol when processing data in pdb file");
239 @SuppressWarnings({ "unchecked", "rawtypes" })
240 private void processWithJmolParser(List<SequenceI> prot)
246 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
249 final Constructor constructor = cl
250 .getConstructor(new Class[] { FileParse.class });
251 final Object[] args = new Object[] { new FileParse(getDataName(),
253 Object jmf = constructor.newInstance(args);
254 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
255 "getSeqsAsArray", new Class[] {}).invoke(jmf));
256 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
258 for (SequenceI sq : al.getSequences())
260 if (sq.getDatasetSequence() != null)
262 sq.getDatasetSequence().getAllPDBEntries().clear();
266 sq.getAllPDBEntries().clear();
269 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
271 } catch (ClassNotFoundException q)
276 public PDBChain findChain(String id) throws Exception
278 for (PDBChain chain : getChains())
280 if (chain.id.equalsIgnoreCase(id))
285 throw new Exception("PDB chain not Found!");
288 public void makeResidueList()
290 for (PDBChain chain : getChains())
292 chain.makeResidueList(visibleChainAnnotation);
296 public void makeCaBondList()
298 for (PDBChain chain : getChains())
300 chain.makeCaBondList();
304 public void setChargeColours()
306 for (PDBChain chain : getChains())
308 chain.setChargeColours();
312 public void setColours(jalview.schemes.ColourSchemeI cs)
314 for (PDBChain chain : getChains())
316 chain.setChainColours(cs);
320 public void setChainColours()
323 for (PDBChain chain : getChains())
325 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
329 public static boolean isRNA(SequenceI seq)
331 for (char c : seq.getSequence())
333 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
342 * make a friendly ID string.
345 * @return truncated dataName to after last '/'
347 protected String safeName(String dataName)
350 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
352 dataName = dataName.substring(p + 1);
357 public String getId()
362 public void setId(String id)
367 public Vector<PDBChain> getChains()
372 public void setChains(Vector<PDBChain> chains)
374 this.chains = chains;