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
47 private PDBEntry.Type dbRefType;
50 * set to true to add derived sequence annotations (temp factor read from
51 * file, or computed secondary structure) to the alignment
53 protected boolean visibleChainAnnotation = false;
56 * Set true to predict secondary structure (using JMol for protein, Annotate3D
59 protected boolean predictSecondaryStructure = false;
62 * Set true (with predictSecondaryStructure=true) to predict secondary
63 * structure using an external service (currently Annotate3D for RNA only)
65 protected boolean externalSecondaryStructure = false;
67 private Vector<PDBChain> chains;
69 private boolean pdbIdAvailable;
71 public StructureFile(String inFile, DataSourceType sourceType)
74 super(inFile, sourceType);
77 public StructureFile(FileParse fp) throws IOException
82 public void addSettings(boolean addAlignmentAnnotations,
83 boolean predictSecondaryStructure, boolean externalSecStr)
85 this.visibleChainAnnotation = addAlignmentAnnotations;
86 this.predictSecondaryStructure = predictSecondaryStructure;
87 this.externalSecondaryStructure = externalSecStr;
90 public void xferSettings()
92 this.visibleChainAnnotation = StructureImportSettings
93 .isVisibleChainAnnotation();
94 this.predictSecondaryStructure = StructureImportSettings
95 .isProcessSecondaryStructure();
96 this.externalSecondaryStructure = StructureImportSettings
97 .isExternalSecondaryStructure();
101 public StructureFile(boolean parseImmediately, String dataObject,
102 DataSourceType sourceType) throws IOException
104 super(parseImmediately, dataObject, sourceType);
107 public StructureFile(boolean a, FileParse fp) throws IOException
112 public StructureFile()
116 protected SequenceI postProcessChain(PDBChain chain)
118 SequenceI pdbSequence = chain.sequence;
119 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
120 PDBEntry entry = new PDBEntry();
121 entry.setId(getId());
122 entry.setType(getStructureFileType());
123 if (chain.id != null)
125 entry.setChainCode(chain.id);
129 entry.setFile(inFile.getAbsolutePath());
133 entry.setFile(getDataName());
136 DBRefEntry sourceDBRef = new DBRefEntry();
137 sourceDBRef.setAccessionId(getId());
138 sourceDBRef.setSource(DBRefSource.PDB);
139 // TODO: specify version for 'PDB' database ref if it is read from a file.
140 // TODO: decide if jalview.io should be creating primary refs!
141 sourceDBRef.setVersion("");
142 pdbSequence.addPDBId(entry);
143 pdbSequence.addDBRef(sourceDBRef);
144 SequenceI chainseq = pdbSequence;
145 seqs.addElement(chainseq);
146 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
148 if (chainannot != null && visibleChainAnnotation)
150 for (int ai = 0; ai < chainannot.length; ai++)
152 chainannot[ai].visible = visibleChainAnnotation;
153 annotations.addElement(chainannot[ai]);
160 * filetype of structure file - default is PDB
162 String structureFileType = PDBEntry.Type.PDB.toString();
164 protected void setStructureFileType(String structureFileType)
166 this.structureFileType = structureFileType;
170 * filetype of last file processed
174 public String getStructureFileType()
176 return structureFileType;
179 @SuppressWarnings({ "unchecked", "rawtypes" })
180 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
183 // System.out.println("this is a PDB format and RNA sequence");
184 // note: we use reflection here so that the applet can compile and run
185 // without the HTTPClient bits and pieces needed for accessing Annotate3D
189 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
192 // TODO: use the PDB ID of the structure if one is available, to save
193 // bandwidth and avoid uploading the whole structure to the service
194 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
196 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
197 new Class[] { FileParse.class }).invoke(annotate3d,
198 new Object[] { new FileParse(getDataName(), dataSourceType) }));
199 for (SequenceI sq : al.getSequences())
201 if (sq.getDatasetSequence() != null)
203 if (sq.getDatasetSequence().getAllPDBEntries() != null)
205 sq.getDatasetSequence().getAllPDBEntries().clear();
210 if (sq.getAllPDBEntries() != null)
212 sq.getAllPDBEntries().clear();
216 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
218 } catch (ClassNotFoundException x)
220 // ignore classnotfounds - occurs in applet
224 @SuppressWarnings("unchecked")
225 protected void replaceAndUpdateChains(List<SequenceI> prot,
226 AlignmentI al, String pep, boolean b)
228 List<List<? extends Object>> replaced = AlignSeq
229 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
231 for (PDBChain ch : getChains())
234 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
237 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
246 // set shadow entry for chains
247 ch.shadow = (SequenceI) replaced.get(1).get(p);
248 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
249 .getMappingFromS1(false);
255 * Predict secondary structure for RNA and/or protein sequences and add as
258 * @param rnaSequences
259 * @param proteinSequences
261 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
262 List<SequenceI> proteinSequences)
265 * Currently using Annotate3D for RNA, but only if the 'use external
266 * prediction' flag is set
268 if (externalSecondaryStructure && rnaSequences.size() > 0)
272 processPdbFileWithAnnotate3d(rnaSequences);
273 } catch (Exception x)
275 System.err.println("Exceptions when dealing with RNA in pdb file");
282 * Currently using JMol PDB parser for peptide
284 if (proteinSequences.size() > 0)
288 processWithJmolParser(proteinSequences);
289 } catch (Exception x)
292 .println("Exceptions from Jmol when processing data in pdb file");
298 @SuppressWarnings({ "unchecked", "rawtypes" })
299 private void processWithJmolParser(List<SequenceI> prot) throws Exception
304 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
307 final Constructor constructor = cl.getConstructor(new Class[] {FileParse.class });
308 final Object[] args = new Object[] { new FileParse(getDataName(), dataSourceType) };
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();
472 * Answers true if the structure file has a PDBId
476 public boolean isPPDBIdAvailable()
478 return pdbIdAvailable;
481 public void setPDBIdAvailable(boolean pdbIdAvailable)
483 this.pdbIdAvailable = pdbIdAvailable;