3 import jalview.analysis.AlignSeq;
4 import jalview.api.FeatureSettingsModelI;
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.DBRefEntry;
9 import jalview.datamodel.DBRefSource;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.PDBEntry.Type;
12 import jalview.datamodel.SequenceI;
13 import jalview.structure.StructureImportSettings;
15 import java.awt.Color;
16 import java.io.IOException;
17 import java.lang.reflect.Constructor;
18 import java.util.List;
19 import java.util.Vector;
21 import MCview.PDBChain;
23 public abstract class StructureFile extends AlignFile
28 private PDBEntry.Type dbRefType;
31 * set to true to add derived sequence annotations (temp factor read from
32 * file, or computed secondary structure) to the alignment
34 protected boolean visibleChainAnnotation = false;
37 * Set true to predict secondary structure (using JMol for protein, Annotate3D
40 protected boolean predictSecondaryStructure = false;
43 * Set true (with predictSecondaryStructure=true) to predict secondary
44 * structure using an external service (currently Annotate3D for RNA only)
46 protected boolean externalSecondaryStructure = false;
48 private Vector<PDBChain> chains;
50 public StructureFile(String inFile, String type) throws IOException
55 public StructureFile(FileParse fp) throws IOException
60 public void addSettings(boolean addAlignmentAnnotations,
61 boolean predictSecondaryStructure, boolean externalSecStr)
63 this.visibleChainAnnotation = addAlignmentAnnotations;
64 this.predictSecondaryStructure = predictSecondaryStructure;
65 this.externalSecondaryStructure = externalSecStr;
68 public void xferSettings()
70 this.visibleChainAnnotation = StructureImportSettings
71 .isVisibleChainAnnotation();
72 this.predictSecondaryStructure = StructureImportSettings
73 .isProcessSecondaryStructure();
74 this.externalSecondaryStructure = StructureImportSettings
75 .isExternalSecondaryStructure();
79 public StructureFile(boolean parseImmediately, String dataObject, String type)
82 super(parseImmediately, dataObject, type);
85 public StructureFile(boolean a, FileParse fp) throws IOException
90 public StructureFile()
94 protected SequenceI postProcessChain(PDBChain chain)
96 SequenceI pdbSequence = chain.sequence;
97 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
98 PDBEntry entry = new PDBEntry();
100 entry.setType(getStructureFileType());
101 if (chain.id != null)
103 entry.setChainCode(chain.id);
107 entry.setFile(inFile.getAbsolutePath());
111 entry.setFile(getDataName());
114 DBRefEntry sourceDBRef = new DBRefEntry();
115 sourceDBRef.setAccessionId(getId());
116 sourceDBRef.setSource(DBRefSource.PDB);
117 // TODO: specify version for 'PDB' database ref if it is read from a file.
118 // TODO: decide if jalview.io should be creating primary refs!
119 sourceDBRef.setVersion("");
120 pdbSequence.addPDBId(entry);
121 pdbSequence.addDBRef(sourceDBRef);
122 SequenceI chainseq = pdbSequence;
123 seqs.addElement(chainseq);
124 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
126 if (chainannot != null && visibleChainAnnotation)
128 for (int ai = 0; ai < chainannot.length; ai++)
130 chainannot[ai].visible = visibleChainAnnotation;
131 annotations.addElement(chainannot[ai]);
138 * filetype of structure file - default is PDB
140 String structureFileType = PDBEntry.Type.PDB.toString();
142 protected void setStructureFileType(String structureFileType)
144 this.structureFileType = structureFileType;
148 * filetype of last file processed
152 public String getStructureFileType()
154 return structureFileType;
157 @SuppressWarnings({ "unchecked", "rawtypes" })
158 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
161 // System.out.println("this is a PDB format and RNA sequence");
162 // note: we use reflection here so that the applet can compile and run
163 // without the HTTPClient bits and pieces needed for accessing Annotate3D
167 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
170 // TODO: use the PDB ID of the structure if one is available, to save
171 // bandwidth and avoid uploading the whole structure to the service
172 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
174 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
175 new Class[] { FileParse.class }).invoke(annotate3d,
176 new Object[] { new FileParse(getDataName(), type) }));
177 for (SequenceI sq : al.getSequences())
179 if (sq.getDatasetSequence() != null)
181 if (sq.getDatasetSequence().getAllPDBEntries() != null)
183 sq.getDatasetSequence().getAllPDBEntries().clear();
188 if (sq.getAllPDBEntries() != null)
190 sq.getAllPDBEntries().clear();
194 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
196 } catch (ClassNotFoundException x)
198 // ignore classnotfounds - occurs in applet
202 @SuppressWarnings("unchecked")
203 protected void replaceAndUpdateChains(List<SequenceI> prot,
204 AlignmentI al, String pep, boolean b)
206 List<List<? extends Object>> replaced = AlignSeq
207 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
209 for (PDBChain ch : getChains())
212 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
215 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
224 // set shadow entry for chains
225 ch.shadow = (SequenceI) replaced.get(1).get(p);
226 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
227 .getMappingFromS1(false);
233 * Predict secondary structure for RNA and/or protein sequences and add as
236 * @param rnaSequences
237 * @param proteinSequences
239 protected void addSecondaryStructure(List<SequenceI> rnaSequences,
240 List<SequenceI> proteinSequences)
243 * Currently using Annotate3D for RNA, but only if the 'use external
244 * prediction' flag is set
246 if (externalSecondaryStructure && rnaSequences.size() > 0)
250 processPdbFileWithAnnotate3d(rnaSequences);
251 } catch (Exception x)
253 System.err.println("Exceptions when dealing with RNA in pdb file");
260 * Currently using JMol PDB parser for peptide
262 if (proteinSequences.size() > 0)
266 processWithJmolParser(proteinSequences);
267 } catch (Exception x)
270 .println("Exceptions from Jmol when processing data in pdb file");
276 @SuppressWarnings({ "unchecked", "rawtypes" })
277 private void processWithJmolParser(List<SequenceI> prot) throws Exception
282 Class cl = Class.forName("jalview.ext.jmol.JmolParser");
285 final Constructor constructor = cl.getConstructor(new Class[] {
286 boolean.class, boolean.class, boolean.class, FileParse.class });
287 final Object[] args = new Object[] { visibleChainAnnotation,
288 predictSecondaryStructure, externalSecondaryStructure,
289 new FileParse(getDataName(), type) };
291 StructureImportSettings.setShowSeqFeatures(false);
292 StructureImportSettings.setVisibleChainAnnotation(false);
293 StructureImportSettings
294 .setProcessSecondaryStructure(predictSecondaryStructure);
295 StructureImportSettings
296 .setExternalSecondaryStructure(externalSecondaryStructure);
297 Object jmf = constructor.newInstance(args);
298 AlignmentI al = new Alignment((SequenceI[]) cl.getMethod(
299 "getSeqsAsArray", new Class[] {}).invoke(jmf));
300 cl.getMethod("addAnnotations", new Class[] { AlignmentI.class })
302 for (SequenceI sq : al.getSequences())
304 if (sq.getDatasetSequence() != null)
306 sq.getDatasetSequence().getAllPDBEntries().clear();
310 sq.getAllPDBEntries().clear();
313 replaceAndUpdateChains(prot, al, AlignSeq.PEP, false);
315 } catch (ClassNotFoundException q)
318 StructureImportSettings.setShowSeqFeatures(true);
321 public PDBChain findChain(String id) throws Exception
323 for (PDBChain chain : getChains())
325 if (chain.id.equals(id))
330 throw new Exception("PDB chain not Found!");
333 public void makeResidueList()
335 for (PDBChain chain : getChains())
337 chain.makeResidueList(visibleChainAnnotation);
341 public void makeCaBondList()
343 for (PDBChain chain : getChains())
345 chain.makeCaBondList();
349 public void setChargeColours()
351 for (PDBChain chain : getChains())
353 chain.setChargeColours();
357 public void setColours(jalview.schemes.ColourSchemeI cs)
359 for (PDBChain chain : getChains())
361 chain.setChainColours(cs);
365 public void setChainColours()
368 for (PDBChain chain : getChains())
370 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
374 public static boolean isRNA(SequenceI seq)
376 for (char c : seq.getSequence())
378 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
387 * make a friendly ID string.
390 * @return truncated dataName to after last '/'
392 protected String safeName(String dataName)
395 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
397 dataName = dataName.substring(p + 1);
402 public String getId()
407 public void setId(String id)
412 public Vector<PDBChain> getChains()
417 public void setChains(Vector<PDBChain> chains)
419 this.chains = chains;
422 public Type getDbRefType()
427 public void setDbRefType(String dbRefType)
429 this.dbRefType = Type.getType(dbRefType);
432 public void setDbRefType(Type dbRefType)
434 this.dbRefType = dbRefType;
438 * Returns a descriptor for suitable feature display settings with
440 * <li>ResNums or insertions features visible</li>
441 * <li>insertions features coloured red</li>
442 * <li>ResNum features coloured by label</li>
443 * <li>Insertions displayed above (on top of) ResNums</li>
447 public FeatureSettingsModelI getFeatureColourScheme()
449 return new PDBFeatureSettings();