From 6d7ab37f37b09174ec61fee301aed6057ef86605 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 25 Feb 2016 16:50:05 +0000 Subject: [PATCH] JAL-1919 initial support for mmCIF using JMol API. Created an Abstract class - StructureFile and refactored PDBfile class and JmolParser class to extend from it. --- src/MCview/AppletPDBCanvas.java | 58 ++-- src/MCview/PDBCanvas.java | 42 +-- src/MCview/PDBChain.java | 4 +- src/MCview/PDBfile.java | 263 +----------------- src/jalview/ext/jmol/JalviewJmolBinding.java | 8 +- src/jalview/ext/jmol/JmolParser.java | 188 +++++++++---- src/jalview/gui/AssociatePdbFileWithSeq.java | 4 +- src/jalview/io/AppletFormatAdapter.java | 13 +- src/jalview/io/StructureFile.java | 291 ++++++++++++++++++++ .../structure/StructureSelectionManager.java | 18 +- src/jalview/ws/sifts/SiftsClient.java | 30 +- test/MCview/PDBfileTest.java | 22 +- test/jalview/ext/jmol/JmolParserTest.java | 25 +- test/jalview/ws/sifts/SiftsClientTest.java | 2 +- 14 files changed, 568 insertions(+), 400 deletions(-) create mode 100644 src/jalview/io/StructureFile.java diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 7f87326..74bec63 100644 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -160,7 +160,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) { - pdbentry.setFile("INLINE" + pdb.id); + pdbentry.setFile("INLINE" + pdb.getId()); } } catch (Exception ex) @@ -169,7 +169,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, return; } - pdbentry.setId(pdb.id); + pdbentry.setId(pdb.getId()); ssm.addStructureViewerListener(this); @@ -185,21 +185,21 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // JUST DEAL WITH ONE SEQUENCE FOR NOW SequenceI sequence = seq[0]; - for (int i = 0; i < pdb.chains.size(); i++) + for (int i = 0; i < pdb.getChains().size(); i++) { mappingDetails.append("\n\nPDB Sequence is :\nSequence = " - + pdb.chains.elementAt(i).sequence.getSequenceAsString()); + + pdb.getChains().elementAt(i).sequence.getSequenceAsString()); mappingDetails.append("\nNo of residues = " - + pdb.chains.elementAt(i).residues.size() + "\n\n"); + + pdb.getChains().elementAt(i).residues.size() + "\n\n"); // Now lets compare the sequences to get // the start and end points. // Align the sequence to the pdb // TODO: DNa/Pep switch AlignSeq as = new AlignSeq(sequence, - pdb.chains.elementAt(i).sequence, - pdb.chains.elementAt(i).isNa ? AlignSeq.DNA : AlignSeq.PEP); + pdb.getChains().elementAt(i).sequence, + pdb.getChains().elementAt(i).isNa ? AlignSeq.DNA : AlignSeq.PEP); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) @@ -232,7 +232,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); } - mainchain = pdb.chains.elementAt(maxchain); + mainchain = pdb.getChains().elementAt(maxchain); mainchain.pdbstart = pdbstart; mainchain.pdbend = pdbend; @@ -289,11 +289,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, // Sort the bonds by z coord visiblebonds = new Vector(); - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector tmp = pdb.chains.elementAt(ii).bonds; + Vector tmp = pdb.getChains().elementAt(ii).bonds; for (int i = 0; i < tmp.size(); i++) { @@ -320,11 +320,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, min[1] = (float) 1e30; min[2] = (float) 1e30; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; for (Bond tmp : bonds) { @@ -448,11 +448,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, int bsize = 0; // Find centre coordinate - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - if (pdb.chains.elementAt(ii).isVisible) + if (pdb.getChains().elementAt(ii).isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; bsize += bonds.size(); @@ -572,9 +572,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener, PDBChain chain; if (bysequence && pdb != null) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - chain = pdb.chains.elementAt(ii); + chain = pdb.getChains().elementAt(ii); for (int i = 0; i < chain.bonds.size(); i++) { @@ -786,7 +786,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, repaint(); if (foundchain != -1) { - PDBChain chain = pdb.chains.elementAt(foundchain); + PDBChain chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { if (fatom.alignmentMapping != -1) @@ -834,7 +834,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, PDBChain chain = null; if (foundchain != -1) { - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { mouseOverStructure(fatom.resNumber, chain.id); @@ -893,7 +893,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, } // Alter the bonds - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { for (Bond tmpBond : chain.bonds) { @@ -930,7 +930,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, void drawLabels(Graphics g) { - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -981,15 +981,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener, foundchain = -1; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); int truex; Bond tmpBond = null; if (chain.isVisible) { - Vector bonds = pdb.chains.elementAt(ii).bonds; + Vector bonds = pdb.getChains().elementAt(ii).bonds; for (int i = 0; i < bonds.size(); i++) { @@ -1030,7 +1030,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (fatom != null) // )&& chain.ds != null) { - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); } } @@ -1096,9 +1096,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener, public void setAllchainsVisible(boolean b) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); chain.isVisible = b; } mainchain.isVisible = true; diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index ac1ba06..dfe7c8f 100644 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -154,7 +154,7 @@ public class PDBCanvas extends JPanel implements MouseListener, if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) { - pdbentry.setFile("INLINE" + pdb.id); + pdbentry.setFile("INLINE" + pdb.getId()); } } catch (Exception ex) @@ -168,7 +168,7 @@ public class PDBCanvas extends JPanel implements MouseListener, errorMessage = "Error loading file: " + pdbentry.getId(); return; } - pdbentry.setId(pdb.id); + pdbentry.setId(pdb.getId()); ssm.addStructureViewerListener(this); @@ -184,19 +184,19 @@ public class PDBCanvas extends JPanel implements MouseListener, // JUST DEAL WITH ONE SEQUENCE FOR NOW SequenceI sequence = seq[0]; - for (int i = 0; i < pdb.chains.size(); i++) + for (int i = 0; i < pdb.getChains().size(); i++) { mappingDetails.append("\n\nPDB Sequence is :\nSequence = " - + pdb.chains.elementAt(i).sequence.getSequenceAsString()); + + pdb.getChains().elementAt(i).sequence.getSequenceAsString()); mappingDetails.append("\nNo of residues = " - + pdb.chains.elementAt(i).residues.size() + "\n\n"); + + pdb.getChains().elementAt(i).residues.size() + "\n\n"); // Now lets compare the sequences to get // the start and end points. // Align the sequence to the pdb AlignSeq as = new AlignSeq(sequence, - pdb.chains.elementAt(i).sequence, "pep"); + pdb.getChains().elementAt(i).sequence, "pep"); as.calcScoreMatrix(); as.traceAlignment(); PrintStream ps = new PrintStream(System.out) @@ -229,7 +229,7 @@ public class PDBCanvas extends JPanel implements MouseListener, mappingDetails.append("\nSEQ start/end " + seqstart + " " + seqend); } - mainchain = pdb.chains.elementAt(maxchain); + mainchain = pdb.getChains().elementAt(maxchain); mainchain.pdbstart = pdbstart; mainchain.pdbend = pdbend; @@ -271,7 +271,7 @@ public class PDBCanvas extends JPanel implements MouseListener, // Sort the bonds by z coord visiblebonds = new Vector(); - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -301,7 +301,7 @@ public class PDBCanvas extends JPanel implements MouseListener, min[1] = (float) 1e30; min[2] = (float) 1e30; - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -432,7 +432,7 @@ public class PDBCanvas extends JPanel implements MouseListener, int bsize = 0; // Find centre coordinate - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -541,9 +541,9 @@ public class PDBCanvas extends JPanel implements MouseListener, PDBChain chain; if (bysequence && pdb != null) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - chain = pdb.chains.elementAt(ii); + chain = pdb.getChains().elementAt(ii); for (int i = 0; i < chain.bonds.size(); i++) { @@ -757,7 +757,7 @@ public class PDBCanvas extends JPanel implements MouseListener, repaint(); if (foundchain != -1) { - PDBChain chain = pdb.chains.elementAt(foundchain); + PDBChain chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { if (fatom.alignmentMapping != -1) @@ -805,7 +805,7 @@ public class PDBCanvas extends JPanel implements MouseListener, PDBChain chain = null; if (foundchain != -1) { - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); if (chain == mainchain) { mouseOverStructure(fatom.resNumber, chain.id); @@ -857,7 +857,7 @@ public class PDBCanvas extends JPanel implements MouseListener, } // Alter the bonds - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { for (Bond tmpBond : chain.bonds) { @@ -894,7 +894,7 @@ public class PDBCanvas extends JPanel implements MouseListener, void drawLabels(Graphics g) { - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (chain.isVisible) { @@ -943,9 +943,9 @@ public class PDBCanvas extends JPanel implements MouseListener, foundchain = -1; - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); int truex; Bond tmpBond = null; @@ -990,7 +990,7 @@ public class PDBCanvas extends JPanel implements MouseListener, if (fatom != null) // )&& chain.ds != null) { // dead code? value of chain is either overwritten or discarded - chain = pdb.chains.elementAt(foundchain); + chain = pdb.getChains().elementAt(foundchain); } } @@ -1053,9 +1053,9 @@ public class PDBCanvas extends JPanel implements MouseListener, public void setAllchainsVisible(boolean b) { - for (int ii = 0; ii < pdb.chains.size(); ii++) + for (int ii = 0; ii < pdb.getChains().size(); ii++) { - PDBChain chain = pdb.chains.elementAt(ii); + PDBChain chain = pdb.getChains().elementAt(ii); chain.isVisible = b; } mainchain.isVisible = true; diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index e4e619c..9545755 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -335,6 +335,7 @@ public class PDBChain // Add inserted residues as features to the base residue Atom currAtom = resAtoms.get(0); if (currAtom.insCode != ' ' + && !residues.isEmpty() && residues.lastElement().atoms.get(0).resNumber == currAtom.resNumber) { SequenceFeature sf = new SequenceFeature("INSERTION", @@ -353,13 +354,14 @@ public class PDBChain Residue tmpres = residues.lastElement(); Atom tmpat = tmpres.atoms.get(0); // Make A new SequenceFeature for the current residue numbering - SequenceFeature sf = new SequenceFeature("RES NUM", tmpat.resName + SequenceFeature sf = new SequenceFeature("RESNUM", tmpat.resName + ":" + tmpat.resNumIns + " " + pdbid + id, "", offset + count, offset + count, pdbid); // MCview.PDBChain.PDBFILEFEATURE); resFeatures.addElement(sf); resAnnotation.addElement(new Annotation(tmpat.tfactor)); // Keep totting up the sequence + if ((symbol = ResidueProperties.getAA3Hash().get(tmpat.resName)) == null) { String nucname = tmpat.resName.trim(); diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index f7eba09..0934fdb 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -24,14 +24,11 @@ import jalview.analysis.AlignSeq; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; -import jalview.datamodel.DBRefEntry; -import jalview.datamodel.DBRefSource; -import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.FileParse; +import jalview.io.StructureFile; import jalview.util.MessageManager; -import java.awt.Color; import java.io.IOException; import java.lang.reflect.Constructor; import java.util.ArrayList; @@ -39,32 +36,10 @@ import java.util.Hashtable; import java.util.List; import java.util.Vector; -public class PDBfile extends jalview.io.AlignFile +public class PDBfile extends StructureFile { private static String CALC_ID_PREFIX = "JalviewPDB"; - public Vector chains; - - public String id; - - /** - * set to true to add derived sequence annotations (temp factor read from - * file, or computed secondary structure) to the alignment - */ - private boolean visibleChainAnnotation = false; - - /* - * Set true to predict secondary structure (using JMol for protein, Annotate3D - * for RNA) - */ - private boolean predictSecondaryStructure = true; - - /* - * Set true (with predictSecondaryStructure=true) to predict secondary - * structure using an external service (currently Annotate3D for RNA only) - */ - private boolean externalSecondaryStructure = false; - public PDBfile(boolean addAlignmentAnnotations, boolean predictSecondaryStructure, boolean externalSecStr) { @@ -106,9 +81,9 @@ public class PDBfile extends jalview.io.AlignFile public void parse() throws IOException { // TODO set the filename sensibly - try using data source name. - id = safeName(getDataName()); + setId(safeName(getDataName())); - chains = new Vector(); + setChains(new Vector()); List rna = new ArrayList(); List prot = new ArrayList(); PDBChain tmpchain; @@ -138,7 +113,7 @@ public class PDBfile extends jalview.io.AlignFile } if (tid.length() > 0) { - id = tid; + setId(tid); } continue; } @@ -175,20 +150,19 @@ public class PDBfile extends jalview.io.AlignFile } Atom tmpatom = new Atom(line); - tmpchain = findChain(tmpatom.chain); - if (tmpchain != null) + try { + tmpchain = findChain(tmpatom.chain); if (tmpatom.resNumIns.trim().equals(lastID)) { // phosphorylated protein - seen both CA and P.. continue; } tmpchain.atoms.addElement(tmpatom); - } - else + } catch (Exception e) { - tmpchain = new PDBChain(id, tmpatom.chain); - chains.addElement(tmpchain); + tmpchain = new PDBChain(getId(), tmpatom.chain); + getChains().add(tmpchain); tmpchain.atoms.addElement(tmpatom); } lastID = tmpatom.resNumIns.trim(); @@ -199,11 +173,11 @@ public class PDBfile extends jalview.io.AlignFile makeResidueList(); makeCaBondList(); - if (id == null) + if (getId() == null) { - id = inFile.getName(); + setId(inFile.getName()); } - for (PDBChain chain : chains) + for (PDBChain chain : getChains()) { SequenceI chainseq = postProcessChain(chain); if (isRNA(chainseq)) @@ -287,55 +261,6 @@ public class PDBfile extends jalview.io.AlignFile * @param chain * @return */ - protected SequenceI postProcessChain(PDBChain chain) - { - SequenceI pdbSequence = chain.sequence; - pdbSequence.setName(id + "|" + pdbSequence.getName()); - PDBEntry entry = new PDBEntry(); - entry.setId(id); - entry.setType(PDBEntry.Type.PDB); - entry.setProperty(new Hashtable()); - if (chain.id != null) - { - // entry.getProperty().put("CHAIN", chains.elementAt(i).id); - entry.setChainCode(String.valueOf(chain.id)); - } - if (inFile != null) - { - entry.setFile(inFile.getAbsolutePath()); - } - else - { - // TODO: decide if we should dump the datasource to disk - entry.setFile(getDataName()); - } - - DBRefEntry sourceDBRef = new DBRefEntry(); - sourceDBRef.setAccessionId(id); - sourceDBRef.setSource(DBRefSource.PDB); - sourceDBRef.setStartRes(pdbSequence.getStart()); - sourceDBRef.setEndRes(pdbSequence.getEnd()); - - // PDBChain objects maintain reference to dataset - SequenceI chainseq = pdbSequence.deriveSequence(); - chainseq.setSourceDBRef(sourceDBRef); - chainseq.addPDBId(entry); - chainseq.addDBRef(sourceDBRef); - - seqs.addElement(chainseq); - - AlignmentAnnotation[] chainannot = chainseq.getAnnotation(); - - if (chainannot != null && visibleChainAnnotation) - { - for (int ai = 0; ai < chainannot.length; ai++) - { - chainannot[ai].visible = visibleChainAnnotation; - annotations.addElement(chainannot[ai]); - } - } - return chainseq; - } public static boolean isCalcIdHandled(String calcId) { @@ -374,7 +299,7 @@ public class PDBfile extends jalview.io.AlignFile oldId = ""; } aa.setCalcId(CALC_ID_PREFIX); - aa.setProperty("PDBID", id); + aa.setProperty("PDBID", getId()); aa.setProperty("oldCalcId", oldId); } } @@ -386,6 +311,7 @@ public class PDBfile extends jalview.io.AlignFile { try { + Class cl = Class.forName("jalview.ext.jmol.JmolParser"); if (cl != null) { @@ -415,163 +341,4 @@ public class PDBfile extends jalview.io.AlignFile { } } - - private void replaceAndUpdateChains(List prot, AlignmentI al, - String pep, boolean b) - { - List> replaced = AlignSeq - .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep, - false); - for (PDBChain ch : chains) - { - int p = 0; - for (SequenceI sq : (List) replaced.get(0)) - { - p++; - if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence) - { - p = -p; - break; - } - } - if (p < 0) - { - p = -p - 1; - // set shadow entry for chains - ch.shadow = (SequenceI) replaced.get(1).get(p); - ch.shadowMap = ((AlignSeq) replaced.get(2).get(p)) - .getMappingFromS1(false); - } - } - } - - private void processPdbFileWithAnnotate3d(List rna) - throws Exception - { - // System.out.println("this is a PDB format and RNA sequence"); - // note: we use reflection here so that the applet can compile and run - // without the HTTPClient bits and pieces needed for accessing Annotate3D - // web service - try - { - Class cl = Class.forName("jalview.ws.jws1.Annotate3D"); - if (cl != null) - { - // TODO: use the PDB ID of the structure if one is available, to save - // bandwidth and avoid uploading the whole structure to the service - Object annotate3d = cl.getConstructor(new Class[] {}).newInstance( - new Object[] {}); - AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor", - new Class[] { FileParse.class }).invoke(annotate3d, - new Object[] { new FileParse(getDataName(), type) })); - for (SequenceI sq : al.getSequences()) - { - if (sq.getDatasetSequence() != null) - { - if (sq.getDatasetSequence().getAllPDBEntries() != null) - { - sq.getDatasetSequence().getAllPDBEntries().clear(); - } - } - else - { - if (sq.getAllPDBEntries() != null) - { - sq.getAllPDBEntries().clear(); - } - } - } - replaceAndUpdateChains(rna, al, AlignSeq.DNA, false); - } - } catch (ClassNotFoundException x) - { - // ignore classnotfounds - occurs in applet - } - ; - } - - /** - * make a friendly ID string. - * - * @param dataName - * @return truncated dataName to after last '/' - */ - private String safeName(String dataName) - { - int p = 0; - while ((p = dataName.indexOf("/")) > -1 && p < dataName.length()) - { - dataName = dataName.substring(p + 1); - } - return dataName; - } - - public void makeResidueList() - { - for (int i = 0; i < chains.size(); i++) - { - chains.elementAt(i).makeResidueList(visibleChainAnnotation); - } - } - - public void makeCaBondList() - { - for (int i = 0; i < chains.size(); i++) - { - chains.elementAt(i).makeCaBondList(); - } - } - - public PDBChain findChain(String id) - { - for (int i = 0; i < chains.size(); i++) - { - if (chains.elementAt(i).id.equals(id)) - { - return chains.elementAt(i); - } - } - - return null; - } - - public void setChargeColours() - { - for (int i = 0; i < chains.size(); i++) - { - chains.elementAt(i).setChargeColours(); - } - } - - public void setColours(jalview.schemes.ColourSchemeI cs) - { - for (int i = 0; i < chains.size(); i++) - { - chains.elementAt(i).setChainColours(cs); - } - } - - public void setChainColours() - { - for (int i = 0; i < chains.size(); i++) - { - // divide by zero --> infinity --> 255 ;-) - chains.elementAt(i).setChainColours( - Color.getHSBColor(1.0f / i, .4f, 1.0f)); - } - } - - public static boolean isRNA(SequenceI seq) - { - for (char c : seq.getSequence()) - { - if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U')) - { - return false; - } - } - - return true; - - } } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index a1b6917..7c3d192 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -1144,7 +1144,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel { pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], pdbfile, AppletFormatAdapter.PASTE); - getPdbEntry(modelnum).setFile("INLINE" + pdb.id); + getPdbEntry(modelnum).setFile("INLINE" + pdb.getId()); matches = true; foundEntry = true; } @@ -1183,10 +1183,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel if (matches) { // add an entry for every chain in the model - for (int i = 0; i < pdb.chains.size(); i++) + for (int i = 0; i < pdb.getChains().size(); i++) { - String chid = new String(pdb.id + ":" - + pdb.chains.elementAt(i).id); + String chid = new String(pdb.getId() + ":" + + pdb.getChains().elementAt(i).id); chainFile.put(chid, fileName); chainNames.addElement(chid); } diff --git a/src/jalview/ext/jmol/JmolParser.java b/src/jalview/ext/jmol/JmolParser.java index dcbd6ad..702c0b1 100644 --- a/src/jalview/ext/jmol/JmolParser.java +++ b/src/jalview/ext/jmol/JmolParser.java @@ -27,18 +27,18 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; -import jalview.io.AlignFile; import jalview.io.FileParse; +import jalview.io.StructureFile; import jalview.schemes.ResidueProperties; import jalview.util.Comparison; import jalview.util.MessageManager; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.Vector; import javajs.awt.Dimension; @@ -54,30 +54,37 @@ import org.jmol.modelsetbio.BioPolymer; import org.jmol.modelsetbio.Monomer; import org.jmol.viewer.Viewer; +import MCview.Atom; import MCview.PDBChain; /** - * Import and process files with Jmol for file like PDB, mmCIF + * Import and process files with Jmol for file like PDB, mmCIF * * @author jprocter * */ -public class JmolParser extends AlignFile implements - JmolStatusListener +public class JmolParser extends StructureFile implements JmolStatusListener { Viewer viewer = null; - private Collection chains; - - /* - * Set true to predict secondary structure (using JMol for protein, Annotate3D - * for RNA) - */ - private boolean predictSecondaryStructure = true; - - public JmolParser(String inFile, String type) throws IOException + public JmolParser(boolean addAlignmentAnnotations, + boolean predictSecondaryStructure, boolean externalSecStr, + String inFile, String type) throws IOException { super(inFile, type); + this.visibleChainAnnotation = addAlignmentAnnotations; + this.predictSecondaryStructure = predictSecondaryStructure; + this.externalSecondaryStructure = externalSecStr; + } + + public JmolParser(boolean addAlignmentAnnotations, + boolean predictSecondaryStructure, boolean externalSecStr, + FileParse fp) throws IOException + { + super(fp); + this.visibleChainAnnotation = addAlignmentAnnotations; + this.predictSecondaryStructure = predictSecondaryStructure; + this.externalSecondaryStructure = externalSecStr; } public JmolParser(FileParse fp) throws IOException @@ -85,6 +92,11 @@ public class JmolParser extends AlignFile implements super(fp); } + public JmolParser(String inFile, String type) throws IOException + { + super(inFile, type); + } + public JmolParser() { } @@ -375,7 +387,7 @@ public class JmolParser extends AlignFile implements public void parse() throws IOException { - chains = new ArrayList(); + setChains(new Vector()); Viewer jmolModel = getJmolData(); jmolModel.openReader(getDataName(), getDataName(), getReader()); waitForScript(jmolModel); @@ -385,7 +397,8 @@ public class JmolParser extends AlignFile implements */ if (jmolModel.ms.mc > 0) { - parseBiopolymers(jmolModel.ms); + // parseBiopolymer(jmolModel.ms); + transformJmolModelToJalview(jmolModel.ms); } } @@ -396,17 +409,16 @@ public class JmolParser extends AlignFile implements * @param ms * @throws IOException */ - public void parseBiopolymers(ModelSet ms) throws IOException + public void parseBiopolymer(ModelSet ms) throws IOException { int modelIndex = -1; for (Model model : ms.am) { modelIndex++; String modelTitle = (String) ms.getInfo(modelIndex, "title"); - /* - * Chains can span BioPolymers, so first make a flattened list, - * and then work out the lengths of chains present + * Chains can span BioPolymers, so first make a flattened list, and then + * work out the lengths of chains present */ List monomers = getMonomers(ms, (BioModel) model); List chainLengths = getChainLengths(monomers); @@ -417,12 +429,99 @@ public class JmolParser extends AlignFile implements int from = 0; for (int length : chainLengths) { - buildSequenceFromChain(monomers.subList(from, from + length), modelTitle); + buildSequenceFromChain(monomers.subList(from, from + length), + modelTitle); from += length; } } } + public void transformJmolModelToJalview(ModelSet ms) + { + try + { + String lastID = ""; + List rna = new ArrayList(); + List prot = new ArrayList(); + PDBChain tmpchain; + String pdbId = (String) ms.getInfo(0, "title"); + setId(pdbId); + List significantAtoms = convertSignificantAtoms(ms); + for (Atom tmpatom : significantAtoms) + { + try + { + tmpchain = findChain(tmpatom.chain); + if (tmpatom.resNumIns.trim().equals(lastID)) + { + // phosphorylated protein - seen both CA and P.. + continue; + } + tmpchain.atoms.addElement(tmpatom); + } catch (Exception e) + { + tmpchain = new PDBChain(pdbId, tmpatom.chain); + getChains().add(tmpchain); + tmpchain.atoms.addElement(tmpatom); + } + lastID = tmpatom.resNumIns.trim(); + } + makeResidueList(); + makeCaBondList(); + + if (getId() == null) + { + setId(inFile.getName()); + } + for (PDBChain chain : getChains()) + { + SequenceI chainseq = postProcessChain(chain); + if (isRNA(chainseq)) + { + rna.add(chainseq); + } + else + { + prot.add(chainseq); + } + } + } catch (OutOfMemoryError er) + { + System.out + .println("OUT OF MEMORY LOADING TRANSFORMING JMOL MODEL TO JALVIEW MODEL"); + // throw new IOException( + // MessageManager + // .getString("exception.outofmemory_loading_pdb_file")); + } + } + + private List convertSignificantAtoms(ModelSet ms) + { + List significantAtoms = new ArrayList(); + for (org.jmol.modelset.Atom atom : ms.at) + { + if (atom.getAtomName().equalsIgnoreCase("CA") + || atom.getAtomName().equalsIgnoreCase("P")) + { + Atom curAtom = new Atom(atom.x, atom.y, atom.z); + curAtom.atomIndex = atom.getIndex(); + curAtom.chain = atom.getChainIDStr(); + curAtom.insCode = atom.group.getInsertionCode(); + curAtom.name = atom.getAtomName(); + curAtom.number = atom.getAtomNumber(); + curAtom.resName = atom.getGroup3(true); + curAtom.resNumber = atom.getResno(); + curAtom.occupancy = ms.occupancies != null ? ms.occupancies[atom + .getIndex()] : Float.valueOf(atom.getOccupancy100()); + curAtom.resNumIns = "" + curAtom.resNumber + curAtom.insCode; + curAtom.tfactor = 0; + curAtom.type = 0; + significantAtoms.add(curAtom); + } + } + return significantAtoms; + } + /** * Helper method to construct a sequence for one chain and add it to the seqs * list @@ -431,7 +530,8 @@ public class JmolParser extends AlignFile implements * a list of all monomers in the chain * @param modelTitle */ - protected void buildSequenceFromChain(List monomers, String modelTitle) + protected void buildSequenceFromChain(List monomers, + String modelTitle) { final int length = monomers.size(); @@ -468,8 +568,7 @@ public class JmolParser extends AlignFile implements /* * construct and add the Jalview sequence */ - String seqName = "" + modelTitle + "|" - + chainId; + String seqName = "" + modelTitle + "|" + chainId; int start = firstResNum; int end = firstResNum + length - 1; @@ -481,28 +580,17 @@ public class JmolParser extends AlignFile implements seqs.add(sq); - addChainMetaData(sq, monomers, chainId); - /* * add secondary structure predictions (if any) */ if (isPredictSecondaryStructure()) { addSecondaryStructureAnnotation(modelTitle, sq, secstr, secstrcode, - chainId, firstResNum); + chainId, firstResNum); } } - public void addChainMetaData(SequenceI sq, List monomers, - String chainId) - { - for (char res : sq.getSequence()) - { - - } - } - /** * Add a source db ref entry for the given sequence. * @@ -523,7 +611,6 @@ public class JmolParser extends AlignFile implements sq.addDBRef(sourceDBRef); } - /** * Add a PDBEntry giving the source of PDB data to the sequence * @@ -574,14 +661,14 @@ public class JmolParser extends AlignFile implements seq[pos] = monomer.getGroup1(); /* - * JAL-1828 replace a modified amino acid with its standard - * equivalent (e.g. MSE with MET->M) to maximise sequence matching + * JAL-1828 replace a modified amino acid with its standard equivalent + * (e.g. MSE with MET->M) to maximise sequence matching */ replaceNonCanonicalResidue(monomer.getGroup3(), seq, pos); /* - * if Jmol has derived a secondary structure prediction for - * this position, convert it to Jalview equivalent and save it + * if Jmol has derived a secondary structure prediction for this position, + * convert it to Jalview equivalent and save it */ setSecondaryStructure(monomer.getProteinStructureSubType(), pos, secstr, secstrcode); @@ -603,8 +690,8 @@ public class JmolParser extends AlignFile implements * @return */ protected void addSecondaryStructureAnnotation(String modelTitle, - SequenceI sq, char[] secstr, char[] secstrcode, - String chainId, int firstResNum) + SequenceI sq, char[] secstr, char[] secstrcode, String chainId, + int firstResNum) { char[] seq = sq.getSequence(); boolean ssFound = false; @@ -660,7 +747,6 @@ public class JmolParser extends AlignFile implements } } - /** * Scans the list of Monomers (residue models), inspecting the chain id for * each, and returns an array whose length is the number of chains, and values @@ -723,8 +809,8 @@ public class JmolParser extends AlignFile implements if (group instanceof Monomer) { /* - * ignore alternate residue at same position - * example: 1ejg has residues A:LEU, B:ILE at RESNUM=25 + * ignore alternate residue at same position example: 1ejg has + * residues A:LEU, B:ILE at RESNUM=25 */ int resNo = group.getResno(); if (lastResNo != resNo) @@ -748,14 +834,4 @@ public class JmolParser extends AlignFile implements this.predictSecondaryStructure = predictSecondaryStructure; } - public Collection getChains() - { - return chains; - } - - public void setChains(Collection chains) - { - this.chains = chains; - } - } diff --git a/src/jalview/gui/AssociatePdbFileWithSeq.java b/src/jalview/gui/AssociatePdbFileWithSeq.java index 861fe56..1247ace 100644 --- a/src/jalview/gui/AssociatePdbFileWithSeq.java +++ b/src/jalview/gui/AssociatePdbFileWithSeq.java @@ -57,7 +57,7 @@ public class AssociatePdbFileWithSeq // stacktrace already thrown so just return return null; } - if (pdbfile.id == null) + if (pdbfile.getId() == null) { String reply = null; @@ -78,7 +78,7 @@ public class AssociatePdbFileWithSeq } else { - entry.setId(pdbfile.id); + entry.setId(pdbfile.getId()); } entry.setType(PDBEntry.Type.FILE); diff --git a/src/jalview/io/AppletFormatAdapter.java b/src/jalview/io/AppletFormatAdapter.java index 2edbee2..e19db81 100755 --- a/src/jalview/io/AppletFormatAdapter.java +++ b/src/jalview/io/AppletFormatAdapter.java @@ -282,7 +282,9 @@ public class AppletFormatAdapter boolean isParseWithJMOL = false; if (isParseWithJMOL) { - alignFile = new jalview.ext.jmol.JmolParser(inFile, type); + alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, inFile, + type); } else { @@ -293,7 +295,8 @@ public class AppletFormatAdapter } else if (format.equals("mmCIF")) { - alignFile = new jalview.ext.jmol.JmolParser(inFile, type); + alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, inFile, type); } else if (format.equals("STH")) { @@ -424,7 +427,8 @@ public class AppletFormatAdapter boolean isParseWithJMOL = false; if (isParseWithJMOL) { - alignFile = new jalview.ext.jmol.JmolParser(source); + alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, source); } else { @@ -434,7 +438,8 @@ public class AppletFormatAdapter } else if (format.equals("mmCIF")) { - alignFile = new jalview.ext.jmol.JmolParser(source); + alignFile = new jalview.ext.jmol.JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, source); } else if (format.equals("STH")) { diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java new file mode 100644 index 0000000..d4c2d7f --- /dev/null +++ b/src/jalview/io/StructureFile.java @@ -0,0 +1,291 @@ +package jalview.io; + +import jalview.analysis.AlignSeq; +import jalview.datamodel.AlignmentAnnotation; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.DBRefSource; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; + +import java.awt.Color; +import java.io.IOException; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + +import MCview.PDBChain; + +public abstract class StructureFile extends AlignFile +{ + + private String id; + + /** + * set to true to add derived sequence annotations (temp factor read from + * file, or computed secondary structure) to the alignment + */ + protected boolean visibleChainAnnotation = false; + + /* + * Set true to predict secondary structure (using JMol for protein, Annotate3D + * for RNA) + */ + protected boolean predictSecondaryStructure = true; + + /* + * Set true (with predictSecondaryStructure=true) to predict secondary + * structure using an external service (currently Annotate3D for RNA only) + */ + protected boolean externalSecondaryStructure = false; + + private Vector chains; + + public StructureFile(String inFile, String type) throws IOException + { + super(inFile, type); + } + + public StructureFile(FileParse fp) throws IOException + { + super(fp); + } + + public StructureFile(boolean parseImmediately, String inFile, String type) + throws IOException + { + super(parseImmediately, inFile, type); + } + + public StructureFile(boolean a, FileParse fp) throws IOException + { + super(a, fp); + } + + public StructureFile() + { + } + + protected SequenceI postProcessChain(PDBChain chain) + { + SequenceI pdbSequence = chain.sequence; + pdbSequence.setName(getId() + "|" + pdbSequence.getName()); + PDBEntry entry = new PDBEntry(); + entry.setId(getId()); + entry.setType(PDBEntry.Type.PDB); + entry.setProperty(new Hashtable()); + if (chain.id != null) + { + entry.setChainCode(String.valueOf(chain.id)); + } + if (inFile != null) + { + entry.setFile(inFile.getAbsolutePath()); + } + else + { + entry.setFile(getDataName()); + } + + DBRefEntry sourceDBRef = new DBRefEntry(); + sourceDBRef.setAccessionId(getId()); + sourceDBRef.setSource(DBRefSource.PDB); + sourceDBRef.setStartRes(pdbSequence.getStart()); + sourceDBRef.setEndRes(pdbSequence.getEnd()); + + // PDBChain objects maintain reference to dataset + SequenceI chainseq = pdbSequence.deriveSequence(); + chainseq.setSourceDBRef(sourceDBRef); + chainseq.addPDBId(entry); + chainseq.addDBRef(sourceDBRef); + + seqs.addElement(chainseq); + + AlignmentAnnotation[] chainannot = chainseq.getAnnotation(); + + if (chainannot != null && visibleChainAnnotation) + { + for (int ai = 0; ai < chainannot.length; ai++) + { + chainannot[ai].visible = visibleChainAnnotation; + annotations.addElement(chainannot[ai]); + } + } + return chainseq; + } + + protected void processPdbFileWithAnnotate3d(List rna) + throws Exception + { + // System.out.println("this is a PDB format and RNA sequence"); + // note: we use reflection here so that the applet can compile and run + // without the HTTPClient bits and pieces needed for accessing Annotate3D + // web service + try + { + Class cl = Class.forName("jalview.ws.jws1.Annotate3D"); + if (cl != null) + { + // TODO: use the PDB ID of the structure if one is available, to save + // bandwidth and avoid uploading the whole structure to the service + Object annotate3d = cl.getConstructor(new Class[] {}).newInstance( + new Object[] {}); + AlignmentI al = ((AlignmentI) cl.getMethod("getRNAMLFor", + new Class[] { FileParse.class }).invoke(annotate3d, + new Object[] { new FileParse(getDataName(), type) })); + for (SequenceI sq : al.getSequences()) + { + if (sq.getDatasetSequence() != null) + { + if (sq.getDatasetSequence().getAllPDBEntries() != null) + { + sq.getDatasetSequence().getAllPDBEntries().clear(); + } + } + else + { + if (sq.getAllPDBEntries() != null) + { + sq.getAllPDBEntries().clear(); + } + } + } + replaceAndUpdateChains(rna, al, AlignSeq.DNA, false); + } + } catch (ClassNotFoundException x) + { + // ignore classnotfounds - occurs in applet + } + } + + protected void replaceAndUpdateChains(List prot, + AlignmentI al, + String pep, boolean b) + { + List> replaced = AlignSeq + .replaceMatchingSeqsWith(seqs, annotations, prot, al, pep, + false); + for (PDBChain ch : getChains()) + { + int p = 0; + for (SequenceI sq : (List) replaced.get(0)) + { + p++; + if (sq == ch.sequence || sq.getDatasetSequence() == ch.sequence) + { + p = -p; + break; + } + } + if (p < 0) + { + p = -p - 1; + // set shadow entry for chains + ch.shadow = (SequenceI) replaced.get(1).get(p); + ch.shadowMap = ((AlignSeq) replaced.get(2).get(p)) + .getMappingFromS1(false); + } + } + } + + public PDBChain findChain(String id) throws Exception + { + for (PDBChain chain : getChains()) + { + if (chain.id.equalsIgnoreCase(id)) + { + return chain; + } + } + throw new Exception("PDB chain not Found!"); + } + + public void makeResidueList() + { + for (PDBChain chain : getChains()) + { + chain.makeResidueList(visibleChainAnnotation); + } + } + + public void makeCaBondList() + { + for (PDBChain chain : getChains()) + { + chain.makeCaBondList(); + } + } + + public void setChargeColours() + { + for (PDBChain chain : getChains()) + { + chain.setChargeColours(); + } + } + + public void setColours(jalview.schemes.ColourSchemeI cs) + { + for (PDBChain chain : getChains()) + { + chain.setChainColours(cs); + } + } + + public void setChainColours() + { + int i = 0; + for (PDBChain chain : getChains()) + { + chain.setChainColours(Color.getHSBColor(1.0f / i++, .4f, 1.0f)); + } + } + + public static boolean isRNA(SequenceI seq) + { + for (char c : seq.getSequence()) + { + if ((c != 'A') && (c != 'C') && (c != 'G') && (c != 'U')) + { + return false; + } + } + return true; + } + + /** + * make a friendly ID string. + * + * @param dataName + * @return truncated dataName to after last '/' + */ + protected String safeName(String dataName) + { + int p = 0; + while ((p = dataName.indexOf("/")) > -1 && p < dataName.length()) + { + dataName = dataName.substring(p + 1); + } + return dataName; + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Vector getChains() + { + return chains; + } + + public void setChains(Vector chains) + { + this.chains = chains; + } +} diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 9d06aef..380c99b 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -387,10 +387,10 @@ public class StructureSelectionManager pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices, pdbFile, protocol); - if (pdb.id != null && pdb.id.trim().length() > 0 + if (pdb.getId() != null && pdb.getId().trim().length() > 0 && AppletFormatAdapter.FILE.equals(protocol)) { - registerPDBFile(pdb.id.trim(), pdbFile); + registerPDBFile(pdb.getId().trim(), pdbFile); } } catch (Exception ex) { @@ -451,7 +451,7 @@ public class StructureSelectionManager String maxChainId = " "; PDBChain maxChain = null; boolean first = true; - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { if (targetChainId.length() > 0 && !targetChainId.equals(chain.id) && !infChain) @@ -485,7 +485,7 @@ public class StructureSelectionManager if (protocol.equals(jalview.io.AppletFormatAdapter.PASTE)) { - pdbFile = "INLINE" + pdb.id; + pdbFile = "INLINE" + pdb.getId(); } ArrayList seqToStrucMapping = new ArrayList(); @@ -503,7 +503,7 @@ public class StructureSelectionManager } else { - for (PDBChain chain : pdb.chains) + for (PDBChain chain : pdb.getChains()) { StructureMapping mapping = getStructureMapping(seq, pdbFile, chain.id, pdb, chain, sqmpping, maxAlignseq); @@ -537,11 +537,17 @@ public class StructureSelectionManager { StructureMapping curChainMapping = siftsClient .getSiftsStructureMapping(seq, pdbFile, targetChainId); + try + { PDBChain chain = pdb.findChain(targetChainId); if (chain != null) { chain.transferResidueAnnotation(curChainMapping, sqmpping); } + } catch (Exception e) + { + e.printStackTrace(); + } return curChainMapping; } catch (SiftsException e) { @@ -628,7 +634,7 @@ public class StructureSelectionManager } while (index < maxChain.atoms.size()); StructureMapping nwMapping = new StructureMapping(seq, pdbFile, - pdb.id, maxChainId, mapping, mappingDetails.toString()); + pdb.getId(), maxChainId, mapping, mappingDetails.toString()); maxChain.transferResidueAnnotation(nwMapping, sqmpping); return nwMapping; } diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index f25c1cf..de8c6a9 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -150,7 +150,7 @@ public class SiftsClient implements SiftsClientI public SiftsClient(PDBfile pdb) throws SiftsException { this.pdb = pdb; - this.pdbId = pdb.id; + this.pdbId = pdb.getId(); File siftsFile = getSiftsFile(pdbId); siftsEntry = parseSIFTs(siftsFile); } @@ -167,7 +167,7 @@ public class SiftsClient implements SiftsClientI public SiftsClient(PDBfile pdb, File siftsFile) throws SiftsException { this.pdb = pdb; - this.pdbId = pdb.id; + this.pdbId = pdb.getId(); siftsEntry = parseSIFTs(siftsFile); } @@ -519,6 +519,7 @@ public class SiftsClient implements SiftsClientI { currSeqIndex = Integer.valueOf(resNumIndexString .split("[a-zA-Z]")[0]); + continue; } if (pdbRefDb != null) { @@ -647,18 +648,25 @@ public class SiftsClient implements SiftsClientI void populateAtomPositions(String chainId, HashMap mapping) throws IllegalArgumentException { - PDBChain chain = pdb.findChain(chainId); - if (chain == null || mapping == null) - { - throw new IllegalArgumentException( - "Chain id or mapping must not be null."); - } - for (int[] map : mapping.values()) + try { - if (map[PDB_RES_POS] != UNASSIGNED) + PDBChain chain = pdb.findChain(chainId); + + if (chain == null || mapping == null) { - map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms); + throw new IllegalArgumentException( + "Chain id or mapping must not be null."); } + for (int[] map : mapping.values()) + { + if (map[PDB_RES_POS] != UNASSIGNED) + { + map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms); + } + } + } catch (Exception e) + { + e.printStackTrace(); } } diff --git a/test/MCview/PDBfileTest.java b/test/MCview/PDBfileTest.java index 82f5c83..31c3beb 100644 --- a/test/MCview/PDBfileTest.java +++ b/test/MCview/PDBfileTest.java @@ -72,17 +72,17 @@ public class PDBfileTest PDBfile pf = new PDBfile(false, false, false, "examples/3W5V.pdb", AppletFormatAdapter.FILE); - assertEquals("3W5V", pf.id); + assertEquals("3W5V", pf.getId()); // verify no alignment annotations created assertNull(getAlignmentAnnotations(pf)); - assertEquals(4, pf.chains.size()); - assertEquals("A", pf.chains.get(0).id); - assertEquals("B", pf.chains.get(1).id); - assertEquals("C", pf.chains.get(2).id); - assertEquals("D", pf.chains.get(3).id); + assertEquals(4, pf.getChains().size()); + assertEquals("A", pf.getChains().get(0).id); + assertEquals("B", pf.getChains().get(1).id); + assertEquals("C", pf.getChains().get(2).id); + assertEquals("D", pf.getChains().get(3).id); - PDBChain chainA = pf.chains.get(0); + PDBChain chainA = pf.getChains().get(0); assertEquals(0, chainA.seqstart); // not set assertEquals(0, chainA.seqend); // not set assertEquals(18, chainA.sequence.getStart()); @@ -97,21 +97,21 @@ public class PDBfileTest assertEquals("PDB", pdb.getType()); assertEquals("3W5V", pdb.getId()); - PDBChain chainB = pf.chains.get(1); + PDBChain chainB = pf.getChains().get(1); assertEquals(1, chainB.sequence.getStart()); assertEquals(96, chainB.sequence.getEnd()); assertTrue(chainB.sequence.getSequenceAsString().startsWith("ATYNVK")); assertTrue(chainB.sequence.getSequenceAsString().endsWith("KEEELT")); assertEquals("3W5V|B", chainB.sequence.getName()); - PDBChain chainC = pf.chains.get(2); + PDBChain chainC = pf.getChains().get(2); assertEquals(18, chainC.sequence.getStart()); assertEquals(314, chainC.sequence.getEnd()); assertTrue(chainC.sequence.getSequenceAsString().startsWith("KCSKKQEE")); assertTrue(chainC.sequence.getSequenceAsString().endsWith("WNVEVY")); assertEquals("3W5V|C", chainC.sequence.getName()); - PDBChain chainD = pf.chains.get(3); + PDBChain chainD = pf.getChains().get(3); assertEquals(1, chainD.sequence.getStart()); assertEquals(96, chainD.sequence.getEnd()); assertTrue(chainD.sequence.getSequenceAsString().startsWith("ATYNVK")); @@ -215,7 +215,7 @@ public class PDBfileTest * no sequence annotations created - tempFactor annotation is not added * unless the flag to 'addAlignmentAnnotations' is set true */ - for (PDBChain c : pf.chains) + for (PDBChain c : pf.getChains()) { assertNull(c.sequence.getAnnotation()); } diff --git a/test/jalview/ext/jmol/JmolParserTest.java b/test/jalview/ext/jmol/JmolParserTest.java index 2a501a7..09b309d 100644 --- a/test/jalview/ext/jmol/JmolParserTest.java +++ b/test/jalview/ext/jmol/JmolParserTest.java @@ -49,9 +49,9 @@ public class JmolParserTest * 1GAQ has been reduced to alpha carbons only * 1QCF is the full PDB file including headers, HETATM etc */ - // String[] testFile = new String[] { "./examples/1GAQ.txt", - // "./test/jalview/ext/jmol/1QCF.pdb" }; // , - String[] testFile = new String[] { "./examples/testdata/1qcf.cif" }; // , + String[] testFile = new String[] { "./examples/1GAQ.txt", + "./test/jalview/ext/jmol/1QCF.pdb" }; // , + // String[] testFile = new String[] { "./examples/testdata/1qcf.cif" }; // , //@formatter:off // a modified and very cut-down extract of 4UJ4 @@ -105,11 +105,15 @@ public class JmolParserTest @Test(groups = { "Functional" }) public void testFileParser() throws Exception { + boolean annotFromStructure = false; + boolean localSecondaryStruct = false; + boolean serviceSecondaryStruct = false; for (String pdbStr : testFile) { PDBfile mctest = new PDBfile(false, false, false, pdbStr, AppletFormatAdapter.FILE); - JmolParser jtest = new JmolParser(pdbStr, + JmolParser jtest = new JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, pdbStr, jalview.io.AppletFormatAdapter.FILE); Vector seqs = jtest.getSeqs(), mcseqs = mctest.getSeqs(); @@ -175,7 +179,12 @@ public class JmolParserTest { PDBfile mctest = new PDBfile(false, false, false, pdbWithChainBreak, AppletFormatAdapter.PASTE); - JmolParser jtest = new JmolParser(pdbWithChainBreak, + boolean annotFromStructure = false; + boolean localSecondaryStruct = false; + boolean serviceSecondaryStruct = false; + JmolParser jtest = new JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, + pdbWithChainBreak, jalview.io.AppletFormatAdapter.PASTE); Vector seqs = jtest.getSeqs(); Vector mcseqs = mctest.getSeqs(); @@ -198,7 +207,11 @@ public class JmolParserTest { PDBfile mctest = new PDBfile(false, false, false, pdbWithAltLoc, AppletFormatAdapter.PASTE); - JmolParser jtest = new JmolParser(pdbWithAltLoc, + boolean annotFromStructure = false; + boolean localSecondaryStruct = false; + boolean serviceSecondaryStruct = false; + JmolParser jtest = new JmolParser(annotFromStructure, + localSecondaryStruct, serviceSecondaryStruct, pdbWithAltLoc, jalview.io.AppletFormatAdapter.PASTE); Vector seqs = jtest.getSeqs(); Vector mcseqs = mctest.getSeqs(); diff --git a/test/jalview/ws/sifts/SiftsClientTest.java b/test/jalview/ws/sifts/SiftsClientTest.java index 28b44e1..a1c2c9a 100644 --- a/test/jalview/ws/sifts/SiftsClientTest.java +++ b/test/jalview/ws/sifts/SiftsClientTest.java @@ -80,7 +80,7 @@ public class SiftsClientTest File testSiftsFile = new File("test/jalview/io/" + testPDBId + ".xml.gz"); PDBfile pdbFile = new PDBfile(false, false, false); - pdbFile.id = testPDBId; + pdbFile.setId(testPDBId); siftsClient = new SiftsClient(pdbFile, testSiftsFile); } -- 1.7.10.2