2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AlignSeq;
24 import jalview.api.FeatureSettingsModelI;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.DBRefEntry;
29 import jalview.datamodel.DBRefSource;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.PDBEntry.Type;
32 import jalview.datamodel.SequenceI;
33 import jalview.structure.StructureImportSettings;
35 import java.awt.Color;
36 import java.io.IOException;
37 import java.lang.reflect.Constructor;
38 import java.util.List;
39 import java.util.Vector;
41 import MCview.PDBChain;
43 public abstract class StructureFile extends AlignFile
48 private PDBEntry.Type dbRefType;
51 * set to true to add derived sequence annotations (temp factor read from
52 * file, or computed secondary structure) to the alignment
54 protected boolean visibleChainAnnotation = false;
57 * Set true to predict secondary structure (using JMol for protein, Annotate3D
60 protected boolean predictSecondaryStructure = false;
63 * Set true (with predictSecondaryStructure=true) to predict secondary
64 * structure using an external service (currently Annotate3D for RNA only)
66 protected boolean externalSecondaryStructure = false;
68 private Vector<PDBChain> chains;
70 public StructureFile(String inFile, String type) throws IOException
75 public StructureFile(FileParse fp) throws IOException
80 public void addSettings(boolean addAlignmentAnnotations,
81 boolean predictSecondaryStructure, boolean externalSecStr)
83 this.visibleChainAnnotation = addAlignmentAnnotations;
84 this.predictSecondaryStructure = predictSecondaryStructure;
85 this.externalSecondaryStructure = externalSecStr;
88 public void xferSettings()
90 this.visibleChainAnnotation = StructureImportSettings
91 .isVisibleChainAnnotation();
92 this.predictSecondaryStructure = StructureImportSettings
93 .isProcessSecondaryStructure();
94 this.externalSecondaryStructure = StructureImportSettings
95 .isExternalSecondaryStructure();
99 public StructureFile(boolean parseImmediately, String dataObject,
100 String type) throws IOException
102 super(parseImmediately, dataObject, type);
105 public StructureFile(boolean a, FileParse fp) throws IOException
110 public StructureFile()
114 protected SequenceI postProcessChain(PDBChain chain)
116 SequenceI pdbSequence = chain.sequence;
117 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
118 PDBEntry entry = new PDBEntry();
119 entry.setId(getId());
120 entry.setType(getStructureFileType());
121 if (chain.id != null)
123 entry.setChainCode(chain.id);
127 entry.setFile(inFile.getAbsolutePath());
131 entry.setFile(getDataName());
134 DBRefEntry sourceDBRef = new DBRefEntry();
135 sourceDBRef.setAccessionId(getId());
136 sourceDBRef.setSource(DBRefSource.PDB);
137 // TODO: specify version for 'PDB' database ref if it is read from a file.
138 // TODO: decide if jalview.io should be creating primary refs!
139 sourceDBRef.setVersion("");
140 pdbSequence.addPDBId(entry);
141 pdbSequence.addDBRef(sourceDBRef);
142 SequenceI chainseq = pdbSequence;
143 seqs.addElement(chainseq);
144 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
146 if (chainannot != null && visibleChainAnnotation)
148 for (int ai = 0; ai < chainannot.length; ai++)
150 chainannot[ai].visible = visibleChainAnnotation;
151 annotations.addElement(chainannot[ai]);
158 * filetype of structure file - default is PDB
160 String structureFileType = PDBEntry.Type.PDB.toString();
162 protected void setStructureFileType(String structureFileType)
164 this.structureFileType = structureFileType;
168 * filetype of last file processed
172 public String getStructureFileType()
174 return structureFileType;
177 @SuppressWarnings({ "unchecked", "rawtypes" })
178 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
181 // System.out.println("this is a PDB format and RNA sequence");
182 // note: we use reflection here so that the applet can compile and run
183 // without the HTTPClient bits and pieces needed for accessing Annotate3D
187 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
190 // TODO: use the PDB ID of the structure if one is available, to save
191 // bandwidth and avoid uploading the whole structure to the service
192 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
194 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
195 new Class[] { FileParse.class }).invoke(annotate3d,
196 new Object[] { new FileParse(getDataName(), type) }));
197 for (SequenceI sq : al.getSequences())
199 if (sq.getDatasetSequence() != null)
201 if (sq.getDatasetSequence().getAllPDBEntries() != null)
203 sq.getDatasetSequence().getAllPDBEntries().clear();
208 if (sq.getAllPDBEntries() != null)
210 sq.getAllPDBEntries().clear();
214 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
216 } catch (ClassNotFoundException x)
218 // ignore classnotfounds - occurs in applet
222 @SuppressWarnings("unchecked")
223 protected void replaceAndUpdateChains(List<SequenceI> prot,
224 AlignmentI al, String pep, boolean b)
226 List<List<? extends Object>> replaced = AlignSeq
227 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
229 for (PDBChain ch : getChains())
232 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
235 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
244 // set shadow entry for chains
245 ch.shadow = (SequenceI) replaced.get(1).get(p);
246 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
247 .getMappingFromS1(false);
253 * Predict secondary structure for RNA and/or protein sequences and add as
256 * @param rnaSequences
257 * @param proteinSequences
259 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
260 List<SequenceI> proteinSequences)
263 * Currently using Annotate3D for RNA, but only if the 'use external
264 * prediction' flag is set
266 if (externalSecondaryStructure && rnaSequences.size() > 0)
270 processPdbFileWithAnnotate3d(rnaSequences);
271 } catch (Exception x)
273 System.err.println("Exceptions when dealing with RNA in pdb file");
280 * Currently using JMol PDB parser for peptide
282 if (proteinSequences.size() > 0)
286 processWithJmolParser(proteinSequences);
287 } catch (Exception x)
290 .println("Exceptions from Jmol when processing data in pdb file");
296 @SuppressWarnings({ "unchecked", "rawtypes" })
297 private void processWithJmolParser(List<SequenceI> prot) throws Exception
302 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
305 final Constructor constructor = cl
306 .getConstructor(new Class[] { FileParse.class });
307 final Object[] args = new Object[] { new FileParse(getDataName(),
310 StructureImportSettings.setShowSeqFeatures(false);
311 StructureImportSettings.setVisibleChainAnnotation(false);
312 StructureImportSettings
313 .setProcessSecondaryStructure(predictSecondaryStructure);
314 StructureImportSettings
315 .setExternalSecondaryStructure(externalSecondaryStructure);
316 Object jmf = constructor.newInstance(args);
317 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
318 "getSeqsAsArray", new Class[] {}).invoke(jmf));
319 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
321 for (SequenceI sq : al.getSequences())
323 if (sq.getDatasetSequence() != null)
325 sq.getDatasetSequence().getAllPDBEntries().clear();
329 sq.getAllPDBEntries().clear();
332 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
334 } catch (ClassNotFoundException q)
337 StructureImportSettings.setShowSeqFeatures(true);
340 public PDBChain findChain(String id) throws Exception
342 for (PDBChain chain : getChains())
344 if (chain.id.equals(id))
349 throw new Exception("PDB chain not Found!");
352 public void makeResidueList()
354 for (PDBChain chain : getChains())
356 chain.makeResidueList(visibleChainAnnotation);
360 public void makeCaBondList()
362 for (PDBChain chain : getChains())
364 chain.makeCaBondList();
368 public void setChargeColours()
370 for (PDBChain chain : getChains())
372 chain.setChargeColours();
376 public void setColours(jalview.schemes.ColourSchemeI cs)
378 for (PDBChain chain : getChains())
380 chain.setChainColours(cs);
384 public void setChainColours()
387 for (PDBChain chain : getChains())
389 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
393 public static boolean isRNA(SequenceI seq)
395 for (char c : seq.getSequence())
397 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
406 * make a friendly ID string.
409 * @return truncated dataName to after last '/'
411 protected String safeName(String dataName)
414 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
416 dataName = dataName.substring(p + 1);
421 public String getId()
426 public void setId(String id)
431 public Vector<PDBChain> getChains()
436 public void setChains(Vector<PDBChain> chains)
438 this.chains = chains;
441 public Type getDbRefType()
446 public void setDbRefType(String dbRefType)
448 this.dbRefType = Type.getType(dbRefType);
451 public void setDbRefType(Type dbRefType)
453 this.dbRefType = dbRefType;
457 * Returns a descriptor for suitable feature display settings with
459 * <li>ResNums or insertions features visible</li>
460 * <li>insertions features coloured red</li>
461 * <li>ResNum features coloured by label</li>
462 * <li>Insertions displayed above (on top of) ResNums</li>
466 public FeatureSettingsModelI getFeatureColourScheme()
468 return new PDBFeatureSettings();