3 import jalview.analysis.AlignSeq;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.DBRefEntry;
7 import jalview.datamodel.DBRefSource;
8 import jalview.datamodel.PDBEntry;
9 import jalview.datamodel.SequenceI;
11 import java.awt.Color;
12 import java.io.IOException;
13 import java.util.Hashtable;
14 import java.util.List;
15 import java.util.Vector;
17 import MCview.PDBChain;
19 public abstract class StructureFile extends AlignFile
25 * set to true to add derived sequence annotations (temp factor read from
26 * file, or computed secondary structure) to the alignment
28 protected boolean visibleChainAnnotation = false;
31 * Set true to predict secondary structure (using JMol for protein, Annotate3D
34 protected boolean predictSecondaryStructure = true;
37 * Set true (with predictSecondaryStructure=true) to predict secondary
38 * structure using an external service (currently Annotate3D for RNA only)
40 protected boolean externalSecondaryStructure = false;
42 private Vector<PDBChain> chains;
44 public StructureFile(String inFile, String type) throws IOException
49 public StructureFile(FileParse fp) throws IOException
54 public StructureFile(boolean parseImmediately, String inFile, String type)
57 super(parseImmediately, inFile, type);
60 public StructureFile(boolean a, FileParse fp) throws IOException
65 public StructureFile()
69 protected SequenceI postProcessChain(PDBChain chain)
71 SequenceI pdbSequence = chain.sequence;
72 pdbSequence.setName(getId() + "|" + pdbSequence.getName());
73 PDBEntry entry = new PDBEntry();
75 entry.setType(PDBEntry.Type.PDB);
76 entry.setProperty(new Hashtable());
79 entry.setChainCode(String.valueOf(chain.id));
83 entry.setFile(inFile.getAbsolutePath());
87 entry.setFile(getDataName());
90 DBRefEntry sourceDBRef = new DBRefEntry();
91 sourceDBRef.setAccessionId(getId());
92 sourceDBRef.setSource(DBRefSource.PDB);
93 sourceDBRef.setStartRes(pdbSequence.getStart());
94 sourceDBRef.setEndRes(pdbSequence.getEnd());
96 // PDBChain objects maintain reference to dataset
97 SequenceI chainseq = pdbSequence.deriveSequence();
98 chainseq.setSourceDBRef(sourceDBRef);
99 chainseq.addPDBId(entry);
100 chainseq.addDBRef(sourceDBRef);
102 seqs.addElement(chainseq);
104 AlignmentAnnotation[] chainannot = chainseq.getAnnotation();
106 if (chainannot != null && visibleChainAnnotation)
108 for (int ai = 0; ai < chainannot.length; ai++)
110 chainannot[ai].visible = visibleChainAnnotation;
111 annotations.addElement(chainannot[ai]);
117 protected void processPdbFileWithAnnotate3d(List<SequenceI> rna)
120 // System.out.println("this is a PDB format and RNA sequence");
121 // note: we use reflection here so that the applet can compile and run
122 // without the HTTPClient bits and pieces needed for accessing Annotate3D
126 Class cl = Class.forName("jalview.ws.jws1.Annotate3D");
129 // TODO: use the PDB ID of the structure if one is available, to save
130 // bandwidth and avoid uploading the whole structure to the service
131 Object annotate3d = cl.getConstructor(new Class[] {}).newInstance(
133 AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor",
134 new Class[] { FileParse.class }).invoke(annotate3d,
135 new Object[] { new FileParse(getDataName(), type) }));
136 for (SequenceI sq : al.getSequences())
138 if (sq.getDatasetSequence() != null)
140 if (sq.getDatasetSequence().getAllPDBEntries() != null)
142 sq.getDatasetSequence().getAllPDBEntries().clear();
147 if (sq.getAllPDBEntries() != null)
149 sq.getAllPDBEntries().clear();
153 replaceAndUpdateChains(rna, al, AlignSeq.DNA, false);
155 } catch (ClassNotFoundException x)
157 // ignore classnotfounds - occurs in applet
161 protected void replaceAndUpdateChains(List<SequenceI> prot,
163 String pep, boolean b)
165 List<List<? extends Object>> replaced = AlignSeq
166 .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep,
168 for (PDBChain ch : getChains())
171 for (SequenceI sq : (List<SequenceI>) replaced.get(0))
174 if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence)
183 // set shadow entry for chains
184 ch.shadow = (SequenceI) replaced.get(1).get(p);
185 ch.shadowMap = ((AlignSeq) replaced.get(2).get(p))
186 .getMappingFromS1(false);
191 public PDBChain findChain(String id) throws Exception
193 for (PDBChain chain : getChains())
195 if (chain.id.equalsIgnoreCase(id))
200 throw new Exception("PDB chain not Found!");
203 public void makeResidueList()
205 for (PDBChain chain : getChains())
207 chain.makeResidueList(visibleChainAnnotation);
211 public void makeCaBondList()
213 for (PDBChain chain : getChains())
215 chain.makeCaBondList();
219 public void setChargeColours()
221 for (PDBChain chain : getChains())
223 chain.setChargeColours();
227 public void setColours(jalview.schemes.ColourSchemeI cs)
229 for (PDBChain chain : getChains())
231 chain.setChainColours(cs);
235 public void setChainColours()
238 for (PDBChain chain : getChains())
240 chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f));
244 public static boolean isRNA(SequenceI seq)
246 for (char c : seq.getSequence())
248 if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U'))
257 * make a friendly ID string.
260 * @return truncated dataName to after last '/'
262 protected String safeName(String dataName)
265 while ((p = dataName.indexOf("/")) > -1 && p < dataName.length())
267 dataName = dataName.substring(p + 1);
272 public String getId()
277 public void setId(String id)
282 public Vector<PDBChain> getChains()
287 public void setChains(Vector<PDBChain> chains)
289 this.chains = chains;