diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index 3909e67ed0..56992a067a 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 org.biojava biojava-structure - 4.2.0 + 4.2.1 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index 7a815ebc3c..99133e7a97 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-alignment biojava-alignment @@ -46,7 +46,7 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 compile @@ -74,7 +74,7 @@ org.biojava biojava-phylo - 4.2.0 + 4.2.1 diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index e1f805029d..d5f45ef45b 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index 5543090077..5ca7be55b6 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-genome @@ -79,13 +79,13 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 compile org.biojava biojava-alignment - 4.2.0 + 4.2.1 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index e488be4e14..c269db8521 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-integrationtest jar @@ -32,7 +32,7 @@ org.biojava biojava-structure - 4.2.0 + 4.2.1 diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodParseTest.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodParseTest.java index 0936a7998e..f248350896 100644 --- a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodParseTest.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/ecod/EcodParseTest.java @@ -47,8 +47,8 @@ * The most common warning is caused by residue ranges with missing terminal CA atoms, * which cause a warning to print. * - * develop83 and earlier versions also had a number of invalid ranges, which cause - * error messages to print. + * develop134, 127, 84 and earlier versions also had a number of invalid ranges, which + * cause error messages to print. * * Filtering log4j messages to the 'error' level will filter all but the most * grievous errors. diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 49dbd60c73..eda4cc2aae 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 4.2.0 + 4.2.1 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 973e53f4a9..d6558f3875 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.0 + 4.2.1 biojava-ontology diff --git a/biojava-phylo/pom.xml b/biojava-phylo/pom.xml index 9ed7013816..650a14d4f6 100644 --- a/biojava-phylo/pom.xml +++ b/biojava-phylo/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-phylo @@ -44,7 +44,7 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 compile diff --git a/biojava-protein-comparison-tool/pom.xml b/biojava-protein-comparison-tool/pom.xml index 9fef34af1c..f3bd513362 100644 --- a/biojava-protein-comparison-tool/pom.xml +++ b/biojava-protein-comparison-tool/pom.xml @@ -5,7 +5,7 @@ biojava org.biojava - 4.1.1-SNAPSHOT + 4.2.1-SNAPSHOT biojava-protein-comparison-tool @@ -37,23 +37,23 @@ org.biojava biojava-alignment - 4.1.1-SNAPSHOT + 4.2.1-SNAPSHOT org.biojava biojava-core - 4.1.1-SNAPSHOT + 4.2.1-SNAPSHOT org.biojava biojava-structure - 4.1.1-SNAPSHOT + 4.2.1-SNAPSHOT org.biojava biojava-structure-gui - 4.1.1-SNAPSHOT + 4.2.1-SNAPSHOT net.sourceforge.jmol diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index d55af261df..5a1283acba 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 diff --git a/biojava-sequencing/pom.xml b/biojava-sequencing/pom.xml index 0d788a057f..16f7b04040 100644 --- a/biojava-sequencing/pom.xml +++ b/biojava-sequencing/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-sequencing @@ -47,7 +47,7 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 compile diff --git a/biojava-sequencing/src/main/java/org/biojava/nbio/sequencing/io/fastq/package-info.java b/biojava-sequencing/src/main/java/org/biojava/nbio/sequencing/io/fastq/package-info.java index 42650e5389..5a32784d47 100755 --- a/biojava-sequencing/src/main/java/org/biojava/nbio/sequencing/io/fastq/package-info.java +++ b/biojava-sequencing/src/main/java/org/biojava/nbio/sequencing/io/fastq/package-info.java @@ -22,7 +22,7 @@ /** * FASTQ and variants sequence format I/O. * - *

+ *

* To read from an Illumina variant FASTQ sequence file: *

  * FastqReader reader = new IlluminaFastqReader();
@@ -31,30 +31,24 @@
  *   // ...
  * }
  * 
- *

* - *

* To write to an Sanger variant FASTQ sequence file: *

  * Collection<Fastq> fastq = ...;
  * SangerFastqWriter writer = new SangerFastqWriter();
  * writer.write(new File("sanger.fastq"), fastq);
  * 
- *

* - *

* For further documentation on the FASTQ sequence format, * its variants, and how they are handled in O|B|F projects, * see: - *

* - *

+ *

* The Sanger FASTQ file format for sequences - * with quality scores, and the Solexa/Illumina FASTQ variants
+ * with quality scores, and the Solexa/Illumina FASTQ variants
* Peter J. A. Cock (Biopython), Christopher J. Fields (BioPerl), Naohisa Goto (BioRuby), - * Michael L. Heuer (BioJava) and Peter M. Rice (EMBOSS).
+ * Michael L. Heuer (BioJava) and Peter M. Rice (EMBOSS).
* Nucleic Acids Research, doi:10.1093/nar/gkp1137 - *

* * @since 3.0.3 */ diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 580dcbb412..cb01913352 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 4.0.0 biojava-structure-gui @@ -16,42 +16,22 @@ repo - - - - biojava-maven-repo - BioJava repository - http://www.biojava.org/download/maven/ - - true - - - true - always - - - junit junit test - - javaws - javaws - 1.0 - org.biojava biojava-structure - 4.2.0 + 4.2.1 compile org.biojava biojava-core - 4.2.0 + 4.2.1 compile @@ -94,7 +74,7 @@ - + org.apache.maven.plugins maven-jar-plugin @@ -108,4 +88,5 @@ + diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ChooseDirAction.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ChooseDirAction.java index 356a644cb1..c603392c08 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ChooseDirAction.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ChooseDirAction.java @@ -25,7 +25,6 @@ package org.biojava.nbio.structure.align.gui; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.align.webstart.PersistentConfig; import org.biojava.nbio.structure.align.webstart.WebStartMain; import javax.swing.*; @@ -62,14 +61,7 @@ public void actionPerformed(ActionEvent evt) { if ( txt != null){ chooser.setCurrentDirectory(new java.io.File(txt)); config.setPdbFilePath(txt); - try { - PersistentConfig webstartConfig = new PersistentConfig(); - webstartConfig.save(config); - - } catch (Exception e){ - e.printStackTrace(); - } } chooser.setDialogTitle("Choose directory that contains your PDB files"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ConfigPDBInstallPanel.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ConfigPDBInstallPanel.java index 731da66b2a..6c4949dc2c 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ConfigPDBInstallPanel.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/ConfigPDBInstallPanel.java @@ -181,8 +181,7 @@ protected void applyValues() String fileFormat = (String)fileType.getSelectedItem(); config.setFileFormat(fileFormat); - // and now persist.. - WebStartMain.persistConfig(config); + } diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/AbstractAlignmentJmol.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/AbstractAlignmentJmol.java index 83e546de8d..ec2c660deb 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/AbstractAlignmentJmol.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/AbstractAlignmentJmol.java @@ -41,6 +41,8 @@ import org.biojava.nbio.structure.jama.Matrix; import org.jcolorbrewer.ColorBrewer; import org.jmol.api.JmolViewer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * An Abstract Class to generalize the visualization of AFP and @@ -52,6 +54,7 @@ public abstract class AbstractAlignmentJmol implements MouseMotionListener, MouseListener, WindowListener, ActionListener { + private static final Logger logger = LoggerFactory.getLogger(AbstractAlignmentJmol.class); protected Structure structure; protected ColorBrewer colorPalette = ColorBrewer.Spectral; @@ -81,7 +84,7 @@ public abstract class AbstractAlignmentJmol * Set all the member variables to null. */ public void destroy(){ - System.err.println("cleaning up AlignmentJmol window"); + logger.debug("cleaning up AlignmentJmol window"); jmolPanel.removeMouseListener(this); jmolPanel.removeMouseMotionListener(this); jmolPanel.destroy(); @@ -135,7 +138,7 @@ public void setJmolPanel(JmolPanel jmolPanel) { */ public void evalString(String rasmolScript){ if ( jmolPanel == null ){ - System.err.println("please install Jmol first"); + logger.error("please install Jmol first"); return; } jmolPanel.evalString(rasmolScript); @@ -148,7 +151,7 @@ public void evalString(String rasmolScript){ public void setStructure(Structure s) { if (jmolPanel == null){ - System.err.println("please install Jmol first"); + logger.error("please install Jmol first"); return; } setTitle(s.getPDBCode()); diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/PersistentConfig.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/PersistentConfig.java deleted file mode 100644 index b984da8207..0000000000 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/PersistentConfig.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - * Created on 20.09.2004 - * @author Andreas Prlic - * - */ - -package org.biojava.nbio.structure.align.webstart; - -import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.core.util.XMLWriter; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; - -import javax.jnlp.*; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.net.URL; - - -/** a class to store the config using the Java Web Start - * PersistenService. - * @author Andreas Prlic - */ -public class PersistentConfig -{ - - PersistenceService ps; - BasicService bs ; - - public PersistentConfig() - throws UnavailableServiceException - { - try { - ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService"); - bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService"); - } catch (Exception e){ - System.err.println("Can't init webstart - persistent configuration. " + e.getMessage() ); - } - } - - /** writes the configuration - * - * @param config - */ - public void save(UserConfiguration config ) { - if (ps != null && bs != null) { - // Persistent Service is available, running as javaws - saveWebStart(config) ; - } else { - System.err.println("can not save using persistentservice!"); - } - } - - private void saveWebStart(UserConfiguration config ){ - //System.out.println("saving webstart"); - - - try { - - // find all the muffins for our URL - URL codebase = bs.getCodeBase(); - - FileContents fc = null ; - - - try { - // test if persistent storage already created - - fc = ps.get(codebase); - - ps.delete(codebase); - - } catch (IOException e){ - } - - // seems not, create it first - ps.create(codebase,3000000); - fc = ps.get(codebase); - - - OutputStream os = fc.getOutputStream(true); - - //StringWriter sw = new StringWriter(); - //StringWriter stw = new StringWriter(os) ; - PrintWriter pw = new PrintWriter(os,true); - XMLWriter xw = config.toXML(pw); - - - pw.flush(); - os.flush(); - - xw.close(); - pw.close(); - os.close(); - - - } catch (Exception e) { - System.err.println(e.getMessage()); - } - } - - - /** loads Config from PersistenceService - * returns null if no PErsistenceService has been created ... - * - * @return WebStartConfiguration - */ - public UserConfiguration load() { - if (ps != null && bs != null) { - // Persistent Service is available, running as javaws - return loadWebStart() ; - } else { - System.err.println("can not load from persistentservice!"); - } - return null ; - } - - - /** loads Config from PersistenceService - * returns null if no PErsistenceService has been created ... - */ - private UserConfiguration loadWebStart() { - UserConfiguration config = null; - try { - URL codebase = bs.getCodeBase(); - - FileContents fc = null ; - - try { - - fc = ps.get(codebase); - } catch (IOException e){ - // has not been created, so nothing can be loaded ... - e.printStackTrace(); - return null ; - } - - - // parse the XML file ... - InputStream stream = fc.getInputStream(); - config = parseConfigFile(stream); - - } catch (Exception e) { - System.err.println(e.getMessage()); - } - - return config ; - - } - - - private UserConfiguration parseConfigFile(InputStream inStream) { - - try { - SAXParserFactory spfactory = - SAXParserFactory.newInstance(); - - SAXParser saxParser = null ; - - try{ - saxParser = - spfactory.newSAXParser(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - - XMLReader xmlreader = saxParser.getXMLReader(); - - ConfigXMLHandler cont_handle = new ConfigXMLHandler(); - xmlreader.setContentHandler(cont_handle); - xmlreader.setErrorHandler(new org.xml.sax.helpers.DefaultHandler()); - - InputSource insource = new InputSource() ; - insource.setByteStream(inStream); - - // the actual parsing starts now ... - xmlreader.parse(insource); - - - UserConfiguration config = cont_handle.getConfig(); - return config ; - - } catch (Exception e){ - e.printStackTrace(); - return null; - } - - } -} diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/WebStartMain.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/WebStartMain.java index febf4e65df..27c0ceb322 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/WebStartMain.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/webstart/WebStartMain.java @@ -40,7 +40,6 @@ import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.align.util.UserConfiguration; -import javax.jnlp.UnavailableServiceException; import javax.swing.*; import java.io.File; @@ -229,29 +228,10 @@ private static JProgressBar showProgressBar(JFrame frame, String title, String d public static UserConfiguration getWebStartConfig(){ - if ( userConfig == null) { - try { - PersistentConfig webstartConfig = new PersistentConfig(); - - userConfig = webstartConfig.load(); - - } catch (Exception e){ - System.err.println(e.getMessage()); - } - } - // check if we could load it (i.e. we are running in web start mode) if ( userConfig == null ) { userConfig = WebStartMain.getDefaultConfig(); - try { - PersistentConfig webstartConfig = new PersistentConfig(); - - webstartConfig.save(userConfig); - - } catch (UnavailableServiceException e){ - System.err.println(e.getMessage()); - } } return userConfig; @@ -270,18 +250,6 @@ public static UserConfiguration getDefaultConfig(){ return userConfig; } - public static void persistConfig(UserConfiguration config){ - - try { - PersistentConfig webstartConfig = new PersistentConfig(); - - webstartConfig.save(config); - - } catch (UnavailableServiceException e){ - e.printStackTrace(); - } - - } public static UserConfiguration requestUserConfig(){ diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryDisplay.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryDisplay.java index 0ac39ed25e..06fabcf20a 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryDisplay.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryDisplay.java @@ -21,7 +21,11 @@ package org.biojava.nbio.structure.symmetry.gui; import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Set; +import java.util.TreeSet; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -40,10 +44,12 @@ import org.biojava.nbio.structure.symmetry.core.AxisAligner; import org.biojava.nbio.structure.symmetry.core.QuatSymmetryResults; import org.biojava.nbio.structure.symmetry.internal.CeSymmResult; +import org.biojava.nbio.structure.symmetry.internal.SymmetryAxes; import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGenerator; import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGeneratorPointGroup; import org.biojava.nbio.structure.symmetry.utils.SymmetryTools; -import org.jmol.util.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Class that provides visualizations methods for symmetry alignments. Call the @@ -54,6 +60,9 @@ * */ public class SymmetryDisplay { + + private static final Logger logger = LoggerFactory + .getLogger(SymmetryDisplay.class); /** * Displays a multiple alignment of the symmetry repeats. @@ -110,12 +119,12 @@ public static AbstractAlignmentJmol display(CeSymmResult symmResult) jmol.setTitle(jmol.getStructure().getPDBHeader().getTitle()); addSymmetryMenu(jmol, symmResult); jmol.evalString(printSymmetryGroup(symmResult)); - jmol.evalString(printSymmetryAxes(symmResult, false)); + jmol.evalString(printSymmetryAxes(symmResult)); jmol.setTitle(getSymmTitle(symmResult)); return jmol; } else { // Show the optimal self-alignment - Logger.info("Showing optimal self-alignment"); + logger.info("Showing optimal self-alignment"); Atom[] cloned = StructureTools .cloneAtomArray(symmResult.getAtoms()); AbstractAlignmentJmol jmol = StructureAlignmentDisplay.display( @@ -123,7 +132,6 @@ public static AbstractAlignmentJmol display(CeSymmResult symmResult) cloned); RotationAxis axis = new RotationAxis(symmResult.getSelfAlignment()); jmol.evalString(axis.getJmolScript(symmResult.getAtoms())); - jmol.setTitle(getSymmTitle(symmResult)); return jmol; } } @@ -178,30 +186,31 @@ private static void addSymmetryMenu(MultipleAlignmentJmol jmol, /** * Generates a String that displays the symmetry axes of a structure. * - * @param msa - * @param axes - * @param elementary - * only print elementary axes if true + * @param symm CeSymmResult * @return + * @throws StructureException */ - public static String printSymmetryAxes(CeSymmResult symm, boolean elementary) { + public static String printSymmetryAxes(CeSymmResult symm) + throws StructureException { int id = 0; String script = ""; - Atom[] atoms = symm.getAtoms(); - - List symmAxes = null; - if (elementary) { - symmAxes = symm.getAxes().getElementaryAxes(); - } else { - symmAxes = symm.getAxes().getSymmetryAxes(); - } - - for (Matrix4d axis : symmAxes) { - RotationAxis rot = new RotationAxis(axis); - script += rot.getJmolScript(atoms, id); + SymmetryAxes axes = symm.getAxes(); + List repeats = SymmetryTools.toRepeatsAlignment(symm).getAtomArrays(); + + List symmAxes = axes.getElementaryAxes(); + for (int a = 0; a < symmAxes.size(); a++) { + RotationAxis rot = new RotationAxis(symmAxes.get(a)); + Set repIndex = new TreeSet(axes.getRepeatRelation(a).get(0)); + repIndex.addAll(axes.getRepeatRelation(a).get(1)); + List repAtoms = new ArrayList(); + for (Integer r : repIndex) + repAtoms.addAll(Arrays.asList(repeats.get(r))); + + script += rot.getJmolScript(repAtoms.toArray(new Atom[repAtoms.size()]), id); id++; } + return script; } diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryListener.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryListener.java index 9c760582bc..e47cacf2af 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryListener.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryListener.java @@ -66,12 +66,12 @@ public void actionPerformed(ActionEvent ae) { try { if (cmd.equals("Repeats Superposition")) { MultipleAlignmentJmol j = SymmetryDisplay.displayRepeats(symm); - String s = SymmetryDisplay.printSymmetryAxes(symm, true); + String s = SymmetryDisplay.printSymmetryAxes(symm); j.evalString(s); } else if (cmd.equals("Multiple Structure Alignment")) { MultipleAlignmentJmol j = SymmetryDisplay.displayFull(symm); - String s = SymmetryDisplay.printSymmetryAxes(symm, false); + String s = SymmetryDisplay.printSymmetryAxes(symm); j.evalString(s); } else if (cmd.equals("Optimal Self Alignment")) { @@ -87,7 +87,7 @@ public void actionPerformed(ActionEvent ae) { jmol.evalString(script); } else if (cmd.equals("Show Symmetry Axes")) { - String s = SymmetryDisplay.printSymmetryAxes(symm, false); + String s = SymmetryDisplay.printSymmetryAxes(symm); jmol.evalString(s); } diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index d6efe31b01..31c3cddc03 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-structure biojava-structure @@ -22,13 +22,13 @@ org.biojava biojava-alignment - 4.2.0 + 4.2.1 compile org.biojava biojava-core - 4.2.0 + 4.2.1 compile diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java index fe3388dab5..8553734361 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/SubstructureIdentifier.java @@ -264,26 +264,27 @@ public Structure reduce(Structure s) throws StructureException { groups = Arrays.asList(chain.getGroupsByPDB(pdbresnum1, pdbresnum2)); } - // Create new chain, if needed Chain c = null; - if ( prevChainId == null) { - // first chain... - c = new ChainImpl(); - c.setChainID(chain.getChainID()); - newS.addChain(c,modelNr); - } else if ( prevChainId.equals(chain.getChainID())) { + + // Reuse prevChain + if ( prevChainId != null && prevChainId.equals(chain.getChainID())) { c = newS.getChainByPDB(prevChainId,modelNr); - } else { try { c = newS.getChainByPDB(chain.getChainID(),modelNr); } catch (StructureException e){ // chain not in structure yet... - c = new ChainImpl(); - c.setChainID(chain.getChainID()); - newS.addChain(c,modelNr); } } + // Create new chain + if ( c == null) { + // first chain... + c = new ChainImpl(); + c.setChainID(chain.getChainID()); + newS.addChain(c,modelNr); + c.setSeqResGroups(chain.getSeqResGroups()); + c.setSeqMisMatches(chain.getSeqMisMatches()); + } // add the groups to the chain: for ( Group g: groups) { diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/GuiWrapper.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/GuiWrapper.java index 2ab775b198..f8d7eec5e9 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/GuiWrapper.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/GuiWrapper.java @@ -47,6 +47,7 @@ public class GuiWrapper { static final String displayAFP = "org.biojava.nbio.structure.align.gui.DisplayAFP" ; static final String alignmentGUI = "org.biojava.nbio.structure.align.gui.AlignmentGui"; static final String strucAligJmol = "org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol"; + static final String abstractAligJmol = "org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol"; static final String scaleMatrixPanel = "org.biojava.nbio.structure.gui.ScaleableMatrixPanel"; @@ -83,10 +84,10 @@ public static void showAlignmentImage(AFPChain afpChain, Atom[] ca1, Atom[] ca2, Object jmol) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException{ - Class structureAlignmentJmol = Class.forName(strucAligJmol); + Class abstractAligJmolC = Class.forName(abstractAligJmol); Class c = Class.forName(displayAFP); - Method show = c.getMethod("showAlignmentImage", new Class[] {AFPChain.class, Atom[].class, Atom[].class, structureAlignmentJmol}); + Method show = c.getMethod("showAlignmentPanel", new Class[] {AFPChain.class, Atom[].class, Atom[].class, abstractAligJmolC}); show.invoke(null,afpChain, ca1, ca2, jmol); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java index 3ad51ab9ef..401b131ac5 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java @@ -522,6 +522,7 @@ public StructureIdentifier getBaseIdentifier() throws StructureException { break; case BIO: base = new BioAssemblyIdentifier(name); + break; case PDB: base = new SubstructureIdentifier(getIdentifier()); break; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/Block.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/Block.java index 0a8fe07eb6..51164080a5 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/Block.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/Block.java @@ -114,6 +114,14 @@ public interface Block extends ScoresCache { */ public int getCoreLength(); + /** + * Returns the number of non null positions (residues) of each structure in + * the alignment Block. The values can be used to compute the coverages. + * + * @return List of residue counts for each structure + */ + public List getAlignResCounts(); + /** * Calculates and returns the first position of the specified structure in * the alignment that is not null. This will return the aligment index, not diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockImpl.java index 56f31068bf..691b034f1e 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockImpl.java @@ -34,54 +34,61 @@ * @since 4.1.0 * */ -public class BlockImpl extends AbstractScoresCache -implements Serializable, Block, Cloneable { +public class BlockImpl extends AbstractScoresCache implements Serializable, + Block, Cloneable { private static final long serialVersionUID = -5804042669466177641L; private BlockSet parent; private List> alignRes; + + // CACHE private int coreLength; + private List alignResCounts; /** - * Constructor. Links also the parent to this instance, by adding the - * Block to the parent's list. + * Constructor. Links also the parent to this instance, by adding the Block + * to the parent's list. * - * @param blockSet the parent BlockSet of the BlockImpl instance. + * @param blockSet + * the parent BlockSet of the BlockImpl instance. * @return BlockImpl a BlockImpl instance linked to its parent BlockSet. */ public BlockImpl(BlockSet blockSet) { parent = blockSet; - if (parent!=null) parent.getBlocks().add(this); + if (parent != null) + parent.getBlocks().add(this); alignRes = null; - coreLength = -1; //Value -1 indicates not yet calculated. + coreLength = -1; // Value -1 indicates not yet calculated. + alignResCounts = null; // Value null not yet calculated } /** * Copy constructor. * - * @param b BlockImpl object to be copied. + * @param b + * BlockImpl object to be copied. * @return BlockImpl an identical copy of the input BlockImpl object. */ public BlockImpl(BlockImpl b) { - super(b); //This copies the cached scores + super(b); // This copies the cached scores this.parent = b.parent; this.coreLength = b.coreLength; this.alignRes = null; - if (b.alignRes!=null){ - //Make a deep copy of everything + if (b.alignRes != null) { + // Make a deep copy of everything alignRes = new ArrayList>(); - for (int k=0; k(b.alignRes.get(k))); } } } @Override - public Block clone(){ + public Block clone() { return new BlockImpl(this); } @@ -89,12 +96,13 @@ public Block clone(){ public void clear() { super.clear(); coreLength = -1; + alignResCounts = null; } @Override public String toString() { - return "BlockImpl [alignRes=" + alignRes - + ", coreLength=" + coreLength + "]"; + return "BlockImpl [alignRes=" + alignRes + ", coreLength=" + coreLength + + "]"; } @Override @@ -119,8 +127,10 @@ public void setAlignRes(List> alignRes) { @Override public int length() { - if (alignRes == null) return 0; - if (alignRes.size() == 0) return 0; + if (alignRes == null) + return 0; + if (alignRes.size() == 0) + return 0; return alignRes.get(0).size(); } @@ -131,7 +141,8 @@ public int size() { @Override public int getCoreLength() { - if(coreLength == -1) updateCoreLength(); + if (coreLength == -1) + updateCoreLength(); return coreLength; } @@ -171,5 +182,22 @@ public int getFinalResidue(int str) { return alignRes.get(str).get(getFinalIndex(str)); } + @Override + public List getAlignResCounts() { + + if (alignResCounts != null) + return alignResCounts; + + alignResCounts = new ArrayList(size()); + for (int s = 0; s < size(); s++) { + int count = 0; + for (int r = 0; r < length(); r++) { + if (alignRes.get(s).get(r) != null) + count++; + } + alignResCounts.add(count); + } + return alignResCounts; + } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSet.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSet.java index 71f9e7ab2a..0db5e36048 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSet.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSet.java @@ -134,6 +134,14 @@ public interface BlockSet extends ScoresCache { * @see #size() */ public int getCoreLength(); + + /** + * Returns the number of non null positions (residues) of each structure in + * the alignment Block Set. The values can be used to compute the coverages. + * + * @return List of residue counts for each structure + */ + public List getAlignResCounts(); /** * Returns the number of aligned structures in the BlockSet. diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSetImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSetImpl.java index 199a484b1b..c817853634 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSetImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/BlockSetImpl.java @@ -27,74 +27,79 @@ import javax.vecmath.Matrix4d; /** - * A general implementation of a BlockSet to store a flexible part of a - * multiple alignment. + * A general implementation of a BlockSet to store a flexible part of a multiple + * alignment. * * @author Aleix Lafita * @since 4.1.0 * */ -public class BlockSetImpl extends AbstractScoresCache -implements Serializable, BlockSet, Cloneable { +public class BlockSetImpl extends AbstractScoresCache implements Serializable, + BlockSet, Cloneable { private static final long serialVersionUID = -1015791986000076089L; - //Member variables + // Member variables private MultipleAlignment parent; private List blocks; - //Cache variables (can be updated) - private List pose; //Transformation matrices + // Cache variables (can be updated) + private List pose; // Transformation matrices private int length; private int coreLength; + private List alignResCounts; /** * Constructor. Links also the parent to this instance by adding the * BlockSet to the parent's List. * - * @param alignment MultipleAlignment parent of the BlockSet. + * @param alignment + * MultipleAlignment parent of the BlockSet. * @return BlockSet an instance linked to the parent alignment. */ public BlockSetImpl(MultipleAlignment alignment) { parent = alignment; - if (parent!=null) parent.getBlockSets().add(this); + if (parent != null) + parent.getBlockSets().add(this); blocks = null; pose = null; - length = -1; //Value -1 reserved to indicate that has to be calculated + length = -1; // Value -1 reserved to indicate that has to be calculated coreLength = -1; + alignResCounts = null; // Value null means not yet calculated } /** - * Copy constructor. Makes also a deep copy of all constituent - * {@link Block}s. + * Copy constructor. Makes also a deep copy of all constituent {@link Block} + * s. * - * @param bs BlockSet object to be copied. + * @param bs + * BlockSet object to be copied. * @return BlockSet an identical copy of the input object. */ - public BlockSetImpl(BlockSetImpl bs){ + public BlockSetImpl(BlockSetImpl bs) { - super(bs); //This copies the cached scores + super(bs); // This copies the cached scores this.parent = bs.parent; this.length = bs.length; this.coreLength = bs.coreLength; this.pose = null; - if (bs.pose != null){ - //Make a deep copy of everything + if (bs.pose != null) { + // Make a deep copy of everything this.pose = new ArrayList(); - for (Matrix4d trans:bs.pose){ + for (Matrix4d trans : bs.pose) { Matrix4d newTrans = (Matrix4d) trans.clone(); pose.add(newTrans); } } blocks = null; - if (bs.blocks!=null){ - //Make a deep copy of everything + if (bs.blocks != null) { + // Make a deep copy of everything this.blocks = new ArrayList(); - for (Block b:bs.blocks){ + for (Block b : bs.blocks) { Block newB = b.clone(); newB.setBlockSet(this); this.blocks.add(newB); @@ -107,22 +112,22 @@ public void clear() { super.clear(); length = -1; coreLength = -1; + alignResCounts = null; pose = null; - for(Block a : getBlocks()) { + for (Block a : getBlocks()) { a.clear(); } } @Override - public BlockSetImpl clone(){ + public BlockSetImpl clone() { return new BlockSetImpl(this); } @Override public String toString() { - return "BlockSetImpl [blocks=" + blocks - + ", pose=" + pose + ", length=" + length + ", coreLength=" - + coreLength + "]"; + return "BlockSetImpl [blocks=" + blocks + ", pose=" + pose + + ", length=" + length + ", coreLength=" + coreLength + "]"; } @Override @@ -137,14 +142,15 @@ public void setMultipleAlignment(MultipleAlignment parent) { @Override public List getBlocks() { - if (blocks==null) blocks = new ArrayList(); + if (blocks == null) + blocks = new ArrayList(); return blocks; } @Override public void setBlocks(List blocks) { this.blocks = blocks; - for(Block b:blocks) { + for (Block b : blocks) { b.setBlockSet(this); } } @@ -156,7 +162,7 @@ public List getTransformations() { @Override public void setTransformations(List transformations) { - if(size() != transformations.size()) { + if (size() != transformations.size()) { throw new IllegalArgumentException( "Wrong number of structures for this alignment"); } @@ -165,48 +171,53 @@ public void setTransformations(List transformations) { @Override public int length() { - if (length == -1) updateLength(); + if (length == -1) + updateLength(); return length; } @Override public int size() { - //Get the size from the variables that can contain the information - if (parent != null) return parent.size(); - else if (getBlocks().size()==0) { + // Get the size from the variables that can contain the information + if (parent != null) + return parent.size(); + else if (getBlocks().size() == 0) { throw new IndexOutOfBoundsException( "Empty BlockSet: number of Blocks == 0."); - } - else return blocks.get(0).size(); + } else + return blocks.get(0).size(); } @Override public int getCoreLength() { - if (coreLength == -1) updateCoreLength(); + if (coreLength == -1) + updateCoreLength(); return coreLength; } protected void updateLength() { - if(getBlocks().size()==0) { + if (getBlocks().size() == 0) { throw new IndexOutOfBoundsException( "Empty BlockSet: number of Blocks == 0."); } - //Try to calculate it from the Block information + // Try to calculate it from the Block information else { length = 0; - for (Block block:blocks) length += block.length(); + for (Block block : blocks) + length += block.length(); } } protected void updateCoreLength() { - if(getBlocks().size()==0) { + if (getBlocks().size() == 0) { throw new IndexOutOfBoundsException( "Empty BlockSet: number of Blocks == 0."); } - //Try to calculate it from the Block information + // Try to calculate it from the Block information else { coreLength = 0; - for (Block block:blocks) coreLength += block.getCoreLength(); + for (Block block : blocks) + coreLength += block.getCoreLength(); } } @@ -214,4 +225,23 @@ protected void updateCache() { updateCoreLength(); updateLength(); } + + @Override + public List getAlignResCounts() { + + if (alignResCounts != null) + return alignResCounts; + + alignResCounts = new ArrayList(size()); + for (int s = 0; s < size(); s++) + alignResCounts.add(0); + + for (Block b : blocks) { + List bcounts = b.getAlignResCounts(); + for (int s = 0; s < size(); s++) + alignResCounts.set(s, alignResCounts.get(s) + bcounts.get(s)); + } + return alignResCounts; + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignment.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignment.java index ee4f648692..07da93faeb 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignment.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignment.java @@ -30,8 +30,8 @@ * multiple structure alignment, as a return type. *

* Each alignment is described as a collection of: - *

  • {@link BlockSet}s that define the aligned positions and 3D - * superposition, + *
      + *
    • {@link BlockSet}s that define the aligned positions and 3D superposition, *
    • Structure identifiers (i,e. Atom arrays, structure names), *
    • Creation properties (algorithm, version, etc). *
    @@ -48,19 +48,19 @@ public interface MultipleAlignment extends ScoresCache { /** - * Creates and returns an identical copy of this alignment, including a - * deep copy of all constituent BlockSets. + * Creates and returns an identical copy of this alignment, including a deep + * copy of all constituent BlockSets. * * @return MultipleAlignment identical copy of this object. */ public MultipleAlignment clone(); /** - * Returns the parent Ensemble of the MultipleAlignment. - * Returns null if there is no referenced object. + * Returns the parent Ensemble of the MultipleAlignment. Returns null if + * there is no referenced object. * * @return MultipleAlignmentEnsemble the parent MultipleAlignment of the - * BlockSet, or null. + * BlockSet, or null. * @see #setEnsemble(MultipleAlignmentEnsemble) */ public MultipleAlignmentEnsemble getEnsemble(); @@ -69,10 +69,11 @@ public interface MultipleAlignment extends ScoresCache { * Set the back-reference to its parent Ensemble. *

    * Neither removes this alignment from its previous ensemble, if any, nor - * adds it to the new parent. Calling code should assure that links to - * and from the ensemble are consistent and free of memory leaks. + * adds it to the new parent. Calling code should assure that links to and + * from the ensemble are consistent and free of memory leaks. * - * @param parent the parent MultipleAlignmentEnsemble. + * @param parent + * the parent MultipleAlignmentEnsemble. * @see #getEnsemble() */ public void setEnsemble(MultipleAlignmentEnsemble parent); @@ -82,7 +83,7 @@ public interface MultipleAlignment extends ScoresCache { * Initializes the variable if it is null. * * @return List of BlockSets that describe the aligned residues of all the - * structures. + * structures. * @see #getBlocks() * @see #setBlockSets(List) */ @@ -93,7 +94,8 @@ public interface MultipleAlignment extends ScoresCache { * Throws an Exception if the index is out of bounds, like accessing a * normal List. * - * @param index of the BlockSet + * @param index + * of the BlockSet * @return BlockSets at the specified index * @see #getBlocks() * @see #getBlockSets() @@ -103,16 +105,16 @@ public interface MultipleAlignment extends ScoresCache { /** * Sets the List of BlockSet List of the specified alignment. * - * @param blockSets the List of BlockSets that describe the aligned - * residues. + * @param blockSets + * the List of BlockSets that describe the aligned residues. * @see #getBlockSets() */ public void setBlockSets(List blockSets); /** * Convenience method to get a List of all Blocks from all BlockSets. - * Modifications of this List will not alter the MultipleAlignment, - * but modifications to the Blocks will. + * Modifications of this List will not alter the MultipleAlignment, but + * modifications to the Blocks will. * * @return List of Blocks * @see #getBlockSets() @@ -124,7 +126,8 @@ public interface MultipleAlignment extends ScoresCache { * Throws an Exception if the index is out of bounds, like accessing a * normal List. * - * @param index of the BlockSet + * @param index + * of the BlockSet * @return Block at the specified index * @see #getBlocks() * @see #getBlockSets() @@ -132,10 +135,9 @@ public interface MultipleAlignment extends ScoresCache { public Block getBlock(int index); /** - * Returns the array of Atoms for each structure from its parent - * Ensemble. - * Throws an Exception if the parent ensemble is null or the Atom - * variables are not previously set. + * Returns the array of Atoms for each structure from its parent Ensemble. + * Throws an Exception if the parent ensemble is null or the Atom variables + * are not previously set. * * @return List of Atom arrays * @see #getEnsemble() @@ -144,9 +146,8 @@ public interface MultipleAlignment extends ScoresCache { /** * Returns the StructureIdentifier associated with the structure index from - * its parent Ensemble. - * Throws an Exception if the parent ensemble is null or the - * StructureIdentifiers are not previously set. + * its parent Ensemble. Throws an Exception if the parent ensemble is null + * or the StructureIdentifiers are not previously set. * * @return StructureIdentifier * @see #getEnsemble() @@ -183,18 +184,33 @@ public interface MultipleAlignment extends ScoresCache { public int getCoreLength(); /** - * Clear scores and other properties which depend on the specific - * alignment. This frees memory and ensures consistency of the cached - * variables. + * Returns the number of non null positions (residues) of each structure in + * the alignment. The values can be used to compute the coverages. + * + * @return List of residue counts for each structure + */ + public List getAlignResCounts(); + + /** + * Returns the coverage of the alignment for each structure in the + * alignment as a fraction between 0.0 and 1.0. + * + * @return List coverage for each structure + */ + public List getCoverages(); + + /** + * Clear scores and other properties which depend on the specific alignment. + * This frees memory and ensures consistency of the cached variables. *

    * Recursively clears member BlockSets. */ public void clear(); /** - * Return a summary of the MultipleAlignment, containing the structures, - * the lengths and the cached scores. Can be used as a header for the - * differnt display options. + * Return a summary of the MultipleAlignment, containing the structures, the + * lengths and the cached scores. Can be used as a header for the differnt + * display options. * * @return String header summary of the MultipleAlignment */ diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java index 6f504bbd72..ea20b421e3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/multiple/MultipleAlignmentImpl.java @@ -35,17 +35,19 @@ * @since 4.1.0 * */ -public class MultipleAlignmentImpl extends AbstractScoresCache -implements Serializable, MultipleAlignment, Cloneable { +public class MultipleAlignmentImpl extends AbstractScoresCache implements + Serializable, MultipleAlignment, Cloneable { private static final long serialVersionUID = 3432043794125805139L; private MultipleAlignmentEnsemble parent; private List blockSets; - //Cache variables (can be updated) + // Cache variables (can be updated) private int length; private int coreLength; + private List alignResCounts; + private List coverages; /** * Default Constructor. Empty alignment. No structures assigned. @@ -53,47 +55,52 @@ public class MultipleAlignmentImpl extends AbstractScoresCache * @return MultipleAlignment an empty MultipleAlignment instance. */ public MultipleAlignmentImpl() { - this(new MultipleAlignmentEnsembleImpl()); //assign an empty ensemble. + this(new MultipleAlignmentEnsembleImpl()); // assign an empty ensemble. } /** - * Constructor linking to an existing ensemble. - * Automatically adds this alignment to the parent ensemble. + * Constructor linking to an existing ensemble. Automatically adds this + * alignment to the parent ensemble. * - * @param ensemble parent MultipleAlignmentEnsemble. + * @param ensemble + * parent MultipleAlignmentEnsemble. * @return MultipleAlignment an alignment instance part of an ensemble. */ public MultipleAlignmentImpl(MultipleAlignmentEnsemble ensemble) { super(); parent = ensemble; - if (parent!=null) parent.getMultipleAlignments().add(this); + if (parent != null) + parent.getMultipleAlignments().add(this); blockSets = null; - length = -1; //Value -1 reserved to indicate that has to be calculated + length = -1; // Value -1 reserved to indicate that has to be calculated coreLength = -1; + alignResCounts = null; // Value null means not set + coverages = null; } /** * Copy constructor. Recursively copies member BlockSets. * - * @param ma MultipleAlignmentImpl to copy. + * @param ma + * MultipleAlignmentImpl to copy. * @return MultipleAlignmentImpl identical copy of the alignment. */ public MultipleAlignmentImpl(MultipleAlignmentImpl ma) { - super(ma); //Copy the scores + super(ma); // Copy the scores parent = ma.parent; length = ma.length; coreLength = ma.coreLength; blockSets = null; - if (ma.blockSets!=null){ - //Make a deep copy of everything + if (ma.blockSets != null) { + // Make a deep copy of everything this.blockSets = new ArrayList(); - for (BlockSet bs:ma.blockSets){ + for (BlockSet bs : ma.blockSets) { BlockSet newBS = bs.clone(); newBS.setMultipleAlignment(this); this.blockSets.add(newBS); @@ -106,7 +113,8 @@ public void clear() { super.clear(); length = -1; coreLength = -1; - for(BlockSet a : getBlockSets()) { + alignResCounts = null; + for (BlockSet a : getBlockSets()) { a.clear(); } } @@ -118,19 +126,18 @@ public MultipleAlignmentImpl clone() { @Override public String toString() { - List ids = new ArrayList(parent.getStructureIdentifiers().size()); - for(StructureIdentifier i : parent.getStructureIdentifiers()) { + List ids = new ArrayList(parent + .getStructureIdentifiers().size()); + for (StructureIdentifier i : parent.getStructureIdentifiers()) { ids.add(i.getIdentifier()); } - String resume = "Structures:" + ids + - " \nAlgorithm:" + parent.getAlgorithmName() + "_" + - parent.getVersion() + - " \nBlockSets: "+ getBlockSets().size() + - " \nBlocks: " + getBlocks().size() + - " \nLength: " + length() + - " \nCore Length: "+ getCoreLength(); - for (String score:getScores()){ - resume += " \n"+score+": "; + String resume = "Structures:" + ids + " \nAlgorithm:" + + parent.getAlgorithmName() + "_" + parent.getVersion() + + " \nBlockSets: " + getBlockSets().size() + " \nBlocks: " + + getBlocks().size() + " \nLength: " + length() + + " \nCore Length: " + getCoreLength(); + for (String score : getScores()) { + resume += " \n" + score + ": "; resume += String.format("%.2f", getScore(score)); } return resume; @@ -138,14 +145,15 @@ public String toString() { @Override public List getBlockSets() { - if (blockSets == null) blockSets = new ArrayList(); + if (blockSets == null) + blockSets = new ArrayList(); return blockSets; } @Override public List getBlocks() { List blocks = new ArrayList(); - for(BlockSet bs : getBlockSets()) { + for (BlockSet bs : getBlockSets()) { blocks.addAll(bs.getBlocks()); } return blocks; @@ -157,12 +165,12 @@ public void setBlockSets(List blockSets) { } @Override - public BlockSet getBlockSet(int index){ + public BlockSet getBlockSet(int index) { return blockSets.get(index); } @Override - public Block getBlock(int index){ + public Block getBlock(int index) { List blocks = getBlocks(); return blocks.get(index); } @@ -184,28 +192,31 @@ public int size() { @Override public int length() { - if (length < 0 ) updateLength(); + if (length < 0) + updateLength(); return length; } @Override public int getCoreLength() { - if (coreLength < 0) updateCoreLength(); + if (coreLength < 0) + updateCoreLength(); return coreLength; } /** - * Force recalculation of the length (aligned columns) based on the - * BlockSet lengths. + * Force recalculation of the length (aligned columns) based on the BlockSet + * lengths. */ protected void updateLength() { - if(getBlockSets().size()==0) { + if (getBlockSets().size() == 0) { throw new IndexOutOfBoundsException( "Empty MultipleAlignment: blockSets size == 0."); - } //Otherwise try to calculate it from the BlockSet information + } // Otherwise try to calculate it from the BlockSet information else { length = 0; - for (BlockSet blockSet:blockSets) length += blockSet.length(); + for (BlockSet blockSet : blockSets) + length += blockSet.length(); } } @@ -214,13 +225,13 @@ protected void updateLength() { * BlockSet core lengths. */ protected void updateCoreLength() { - if(getBlockSets().size()==0) { + if (getBlockSets().size() == 0) { throw new IndexOutOfBoundsException( "Empty MultipleAlignment: blockSets size == 0."); - } //Otherwise try to calculate it from the BlockSet information + } // Otherwise try to calculate it from the BlockSet information else { coreLength = 0; - for (BlockSet blockSet:blockSets) + for (BlockSet blockSet : blockSets) coreLength += blockSet.getCoreLength(); } } @@ -245,4 +256,36 @@ public void setEnsemble(MultipleAlignmentEnsemble parent) { this.parent = parent; } + @Override + public List getAlignResCounts() { + + if (alignResCounts != null) + return alignResCounts; + + alignResCounts = new ArrayList(size()); + for (int s = 0; s < size(); s++) + alignResCounts.add(0); + + for (BlockSet bs : blockSets) { + List bscounts = bs.getAlignResCounts(); + for (int s = 0; s < size(); s++) + alignResCounts.set(s, alignResCounts.get(s) + bscounts.get(s)); + } + return alignResCounts; + } + + @Override + public List getCoverages() { + + if (coverages != null) + return coverages; + + List counts = getAlignResCounts(); + coverages = new ArrayList(size()); + for (int s = 0; s < size(); s++) + coverages.add(counts.get(s) + / (double) getAtomArrays().get(s).length); + return coverages; + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 99faf3b6ee..f8b97397ef 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -152,12 +152,6 @@ public AtomCache(String pdbFilePath, String cachePath) { currentlyLoading.clear(); params = new FileParsingParameters(); - // we don't need this here - params.setAlignSeqRes(false); - // no secstruc either - params.setParseSecStruc(false); - // - setUseMmCif(true); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java index aba790cba7..d80664affa 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java @@ -36,7 +36,8 @@ public class CathFactory { public static final String VERSION_3_5_0 = "3.5.0"; - public static final String LATEST_VERSION = VERSION_3_5_0; + public static final String VERSION_4_0_0 = "4.0.0"; + public static final String LATEST_VERSION = VERSION_4_0_0; public static String DEFAULT_VERSION = LATEST_VERSION; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java index 179e31c61a..77346f0cc6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java @@ -41,7 +41,7 @@ */ public class CathInstallation implements CathDatabase{ - public static final String DEFAULT_VERSION = "3.5.0"; + public static final String DEFAULT_VERSION = CathFactory.DEFAULT_VERSION; String cathVersion; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDatabase.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDatabase.java index 1d471de40d..d9170766b7 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDatabase.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDatabase.java @@ -23,7 +23,7 @@ import java.io.IOException; import java.util.List; -/** General API for interacting with CATH. +/** General API for interacting with ECOD. * * @author Spencer Bliven */ diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDomain.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDomain.java index d7a12918a9..d0a3ec3308 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDomain.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodDomain.java @@ -29,6 +29,18 @@ import java.util.Set; /** + * An EcodDomain contains all the information of the ECOD database: id, + * classification groups (from higher to lower in the tree: X,H,T,F), PDB code, + * chain, residue ranges and status (manual or automatic classification). + *

    + * For detailed explanation about the ECOD information see the original article + * at: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC4256011. + *

    + * Cheng H, Schaeffer RD, Liao Y, et al. 
    + * ECOD: An Evolutionary Classification of Protein Domains. 
    + * Elofsson A, ed. PLoS Computational Biology. 2014;10(12):e1003926.
    + * 
    + * * @author Spencer Bliven * */ diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodFactory.java index 4495496eb6..73e5f7db7f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodFactory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/ecod/EcodFactory.java @@ -29,29 +29,29 @@ import java.util.Map.Entry; import org.biojava.nbio.structure.align.util.UserConfiguration; -import org.biojava.nbio.structure.cath.CathDatabase; -import org.biojava.nbio.structure.cath.CathInstallation; +import org.biojava.nbio.structure.cath.CathFactory; import org.biojava.nbio.structure.scop.ScopFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Controls global {@link CathDatabase CathDatabases} being used. - * Implements a multiton pattern through {@link #getCathDatabase(String)}, - * and a singleton pattern through {@link #getCathDatabase()}. + * Controls global {@link EcodDatabase EcodDatabases} being used. + * Implements a multiton pattern through {@link #getEcodDatabase(String)}, + * and a singleton pattern through {@link #getEcodDatabase()}. * @author Spencer Bliven * @see ScopFactory - * @see CathInstallation + * @see CathFactory + * @see EcodInstallation */ public class EcodFactory { - private static Logger logger = LoggerFactory.getLogger(EcodFactory.class); - - public static String DEFAULT_VERSION = EcodInstallation.DEFAULT_VERSION; + private static final Logger logger = LoggerFactory.getLogger(EcodFactory.class); + + public static final String DEFAULT_VERSION = EcodInstallation.DEFAULT_VERSION; private static Map> versionedEcodDBs = Collections.synchronizedMap(new HashMap>()); - private static String defaultVersion = DEFAULT_VERSION; + private static String defaultVersion = EcodInstallation.DEFAULT_VERSION; /** * Returns the (singleton) database for the current default version diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java index fa43a31e20..af34edc0d6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/BondMaker.java @@ -148,7 +148,7 @@ private void formPeptideBonds() { } private void formNucleotideBonds() { - for (Chain chain : structure.getChains()) { + for (Chain chain : structure.getChains()) { List groups = chain.getSeqResGroups(); for (int i = 0; i < groups.size() - 1; i++) { @@ -165,8 +165,8 @@ private void formNucleotideBonds() { continue; } - Atom phosphorous = tail.getP(); - Atom oThreePrime = head.getO3Prime(); + Atom phosphorous = head.getP(); + Atom oThreePrime = tail.getO3Prime(); if (phosphorous == null || oThreePrime == null) { continue; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java index 7bf4f58025..d579124bc3 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/ChargeAdder.java @@ -34,38 +34,58 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * A class to add appropriate charge information to a structure. + * @author Anthony Bradley + * + */ public class ChargeAdder { private static final Logger logger = LoggerFactory.getLogger(ChargeAdder.class); - private Structure structure; - - public ChargeAdder(Structure structure) { - this.structure = structure; - } - - public void addCharges() { - // Only adds charges to the first MODEL - for(Chain c: structure.getChains()){ - for(Group g: c.getAtomGroups()){ - ChemComp thisChemComp = ChemCompGroupFactory.getChemComp(g.getPDBName()); - List chemAtoms = thisChemComp.getAtoms(); - List protAtoms = g.getAtoms(); - if(protAtoms.size()!=chemAtoms.size()){ - continue; - } - for(int i=0; i chemAtoms = thisChemComp.getAtoms(); + for(ChemCompAtom chemCompAtom : chemAtoms) { + Atom atom = g.getAtom(chemCompAtom.getAtom_id()); + String stringCharge = chemCompAtom.getCharge(); + short shortCharge = 0; + if (stringCharge!=null){ + if(!stringCharge.equals("?")){ + try{ + shortCharge = Short.parseShort(stringCharge); + } + catch(NumberFormatException e){ + logger.warn("Number format exception. Parsing '"+stringCharge+"' to short"); + } + } + else{ + logger.warn("? charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); + } + } + else{ + logger.warn("Null charge on atom "+chemCompAtom.getAtom_id()+" in group "+thisChemComp.getId()); + } + if(atom!=null){ + atom.setCharge(shortCharge); + } + // Now do the same for alt locs + for (Group altLoc : g.getAltLocs()) { + Atom altAtom = altLoc.getAtom(chemCompAtom.getAtom_id()); + if(altAtom!=null){ + altAtom.setCharge(shortCharge); + } + } } } + } } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java index 603db679f8..10cade8e16 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/PDBFileParser.java @@ -2764,8 +2764,7 @@ else if ( params.isParseSecStruc()) { } private void addCharges() { - ChargeAdder adder = new ChargeAdder(structure); - adder.addCharges(); + ChargeAdder.addCharges(structure); } /** diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java index 1d56d6a2e9..d41e116971 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java @@ -31,6 +31,9 @@ import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -376,16 +379,11 @@ private static boolean downloadChemCompRecord(String recordName) { } pw.flush(); - // Now we move this across to where it actually wants to be - boolean couldRename = newFile.renameTo(new File(localName)); - - if (!couldRename) { - - throw new IOException("Could not rename temp file "+newFile.toString()+" to file " + localName); - } - - return true; } + // Now we move this across to where it actually wants to be + Files.move(newFile.toPath(), Paths.get(localName), StandardCopyOption.REPLACE_EXISTING); + + return true; } catch (IOException e){ logger.error("Could not download "+url.toString()+" OR store locally to "+localName+" Error ="+e.getMessage()); newFile.delete(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java index f15710a880..fcf62bff48 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMCIFFileTools.java @@ -322,7 +322,7 @@ record = "ATOM"; String insCode = MMCIF_MISSING_VALUE; if (g.getResidueNumber().getInsCode()!=null ) { - insCode = Integer.toString(g.getResidueNumber().getInsCode()); + insCode = Character.toString(g.getResidueNumber().getInsCode()); } AtomSite atomSite = new AtomSite(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java index 60bce33e39..8f1fea5747 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java @@ -992,8 +992,7 @@ private void linkCompounds() { } private void addCharges() { - ChargeAdder adder = new ChargeAdder(structure); - adder.addCharges(); + ChargeAdder.addCharges(structure); } /** diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java index 708feb91c8..3878890eb2 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java @@ -524,9 +524,9 @@ private List processSingleLine(String line){ * @return */ private List processLine(String line, - BufferedReader buf, - int fieldLength) - throws IOException{ + BufferedReader buf, + int fieldLength) + throws IOException{ //System.out.println("XX processLine " + fieldLength + " " + line); // go through the line and process each character @@ -594,9 +594,9 @@ private List processLine(String line, private void endLineChecks(String category,List loopFields, List lineData, Set loopWarnings ) throws IOException{ logger.debug("Processing category {}, with fields: {}",category,loopFields.toString()); -// System.out.println("parsed the following data: " +category + " fields: "+ -// loopFields + " DATA: " + -// lineData); + // System.out.println("parsed the following data: " +category + " fields: "+ + // loopFields + " DATA: " + + // lineData); if ( loopFields.size() != lineData.size()){ logger.warn("looks like we got a problem with nested string quote characters:"); @@ -671,8 +671,16 @@ private void endLineChecks(String category,List loopFields, List } else if ( category.equals("_struct_ncs_oper")) { // this guy is special because of the [] in the field names - StructNcsOper sNcsOper = getStructNcsOper(loopFields,lineData); - triggerNewStructNcsOper(sNcsOper); + StructNcsOper sNcsOper = null; + try{ + sNcsOper = getStructNcsOper(loopFields,lineData); + } + catch(NumberFormatException e){ + logger.warn("Error parsing doubles in NCS operator list"); + } + if(sNcsOper!=null){ + triggerNewStructNcsOper(sNcsOper); + } } else if ( category.equals("_struct_ref")){ StructRef sref = (StructRef) buildObject( @@ -750,25 +758,25 @@ private void endLineChecks(String category,List loopFields, List PdbxEntityNonPoly pen = (PdbxEntityNonPoly) buildObject( PdbxEntityNonPoly.class.getName(), loopFields,lineData, loopWarnings - ); + ); triggerNewPdbxEntityNonPoly(pen); } else if ( category.equals("_struct_keywords")){ StructKeywords kw = (StructKeywords)buildObject( StructKeywords.class.getName(), loopFields,lineData, loopWarnings - ); + ); triggerNewStructKeywords(kw); } else if (category.equals("_refine")){ Refine r = (Refine)buildObject( Refine.class.getName(), loopFields,lineData, loopWarnings - ); + ); triggerNewRefine(r); } else if (category.equals("_chem_comp")){ ChemComp c = (ChemComp)buildObject( ChemComp.class.getName(), loopFields, lineData, loopWarnings - ); + ); triggerNewChemComp(c); } else if (category.equals("_audit_author")) { AuditAuthor aa = (AuditAuthor)buildObject( @@ -839,7 +847,7 @@ private void endLineChecks(String category,List loopFields, List private PdbxStructOperList getPdbxStructOperList(List loopFields, - List lineData) { + List lineData) { PdbxStructOperList so = new PdbxStructOperList(); //System.out.println(loopFields); @@ -856,7 +864,7 @@ private PdbxStructOperList getPdbxStructOperList(List loopFields, String val = lineData.get(loopFields.indexOf(max)); Double d = Double.parseDouble(val); matrix.set(j-1,i-1,d); -// matrix.set(i-1,j-1,d); + // matrix.set(i-1,j-1,d); } } @@ -900,10 +908,10 @@ private StructNcsOper getStructNcsOper(List loopFields, List lin op.setElement(3, 2, 0.0); op.setElement(3, 3, 1.0); + for (int i = 1 ; i <=3 ; i++){ for (int j =1 ; j <= 3 ; j++){ String max = String.format("matrix[%d][%d]",i,j); - String val = lineData.get(loopFields.indexOf(max)); Double d = Double.parseDouble(val); op.setElement(i-1,j-1,d); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CESymmParameters.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CESymmParameters.java index 0423c69044..ffc9376ae9 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CESymmParameters.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CESymmParameters.java @@ -43,7 +43,8 @@ public class CESymmParameters extends CeParameters { private boolean optimization; private int rndSeed; private int symmLevels; - private double scoreThreshold; + private double unrefinedScoreThreshold; + private double refinedScoreThreshold; private int sseThreshold; private int minCoreLength; private double distanceCutoff; @@ -97,7 +98,8 @@ public CESymmParameters clone() { p.optimization = optimization; p.rndSeed = rndSeed; p.symmLevels = symmLevels; - p.scoreThreshold = scoreThreshold; + p.unrefinedScoreThreshold = unrefinedScoreThreshold; + p.refinedScoreThreshold = refinedScoreThreshold; p.sseThreshold = sseThreshold; p.minCoreLength = minCoreLength; p.distanceCutoff = distanceCutoff; @@ -132,7 +134,8 @@ public void reset() { optimization = true; rndSeed = new Random().nextInt(10000); symmLevels = 0; - scoreThreshold = DEFAULT_SYMMETRY_THRESHOLD; + unrefinedScoreThreshold = DEFAULT_SYMMETRY_THRESHOLD; + refinedScoreThreshold = DEFAULT_SYMMETRY_THRESHOLD * 0.9; sseThreshold = 0; minCoreLength = 15; distanceCutoff = 7.0; @@ -206,8 +209,13 @@ public List getUserConfigHelp() { + "found. If equal to 2, D and two-level hierarchical C and H " + "can be found, etc. If equal to 0, the number of recursive " + "iterations is unbounded (until thresholds reached)."); - // score threshold - params.add("Score threshold: TM-score values below the " + // unrefined score threshold + params.add("Unrefined score threshold: TM-score values for the optimal" + + " self-alignment, before refinement, below the " + + "threshold will be considered asymmetric."); + // refined score threshold + params.add("Refined score threshold: TM-score values for the refined " + + "multiple alignment of repeats below the " + "threshold will be considered asymmetric."); // SSE threshold params.add("SSE threshold: The minimum number of secondary structure " @@ -222,7 +230,9 @@ public List getUserConfigHelp() { + "between two aligned residues."); // gaps - params.add("MStA Gaps: allow gaps in the multiple alignment if true."); + params.add("Internal Gaps: allow up to 50% of repeats to have gaps in " + + "the multiple alignment if true, " + + "otherwise all repeats must be aligned at each position."); // optimization steps params.add("Optimization Steps: maximum number of optimization steps:" @@ -242,7 +252,8 @@ public List getUserConfigParameters() { params.add("Optimization"); params.add("RndSeed"); params.add("SymmLevels"); - params.add("ScoreThreshold"); + params.add("UnrefinedScoreThreshold"); + params.add("RefinedScoreThreshold"); params.add("SSEThreshold"); params.add("MinCoreLength"); params.add("DistanceCutoff"); @@ -262,11 +273,12 @@ public List getUserConfigParameterNames() { params.add("Optimization"); params.add("Random Seed"); params.add("Symmetry Levels"); - params.add("Score Threshold"); + params.add("Unrefined Score Threshold"); + params.add("Refined Score Threshold"); params.add("SSE Threshold"); params.add("Minimum Core Length"); params.add("Distance Cutoff"); - params.add("MStA Gaps"); + params.add("Internal Gaps"); params.add("Optimization Steps"); return params; } @@ -284,6 +296,7 @@ public List getUserConfigTypes() { params.add(Integer.class); params.add(Integer.class); params.add(Double.class); + params.add(Double.class); params.add(Integer.class); params.add(Integer.class); params.add(Double.class); @@ -365,12 +378,20 @@ public void setSymmLevels(Integer symmLevels) { this.symmLevels = symmLevels; } - public double getScoreThreshold() { - return scoreThreshold; + public double getUnrefinedScoreThreshold() { + return unrefinedScoreThreshold; + } + + public void setUnrefinedScoreThreshold(Double unrefinedScoreThreshold) { + this.unrefinedScoreThreshold = unrefinedScoreThreshold; + } + + public double getRefinedScoreThreshold() { + return refinedScoreThreshold; } - public void setScoreThreshold(Double scoreThreshold) { - this.scoreThreshold = scoreThreshold; + public void setRefinedScoreThreshold(Double refinedScoreThreshold) { + this.refinedScoreThreshold = refinedScoreThreshold; } public int getSSEThreshold() { @@ -415,13 +436,17 @@ public void setOptimizationSteps(Integer optimizationSteps) { @Override public String toString() { - return "CESymmParameters [orderDetectorMethod=" + orderDetectorMethod + return "CESymmParameters [maxSymmOrder=" + maxSymmOrder + + ", userOrder=" + userOrder + ", symmType=" + symmType + + ", orderDetectorMethod=" + orderDetectorMethod + ", refineMethod=" + refineMethod + ", optimization=" - + optimization + ", symmLevels=" + symmLevels - + ", scoreThreshold=" + scoreThreshold + ", sseThreshold=" - + sseThreshold + ", minCoreLength=" + minCoreLength - + ", distanceCutoff=" + distanceCutoff + ", gaps=" + gaps - + ", optimizationSteps=" + optimizationSteps + "]"; + + optimization + ", rndSeed=" + rndSeed + ", symmLevels=" + + symmLevels + ", unrefinedScoreThreshold=" + + unrefinedScoreThreshold + ", refinedScoreThreshold=" + + refinedScoreThreshold + ", sseThreshold=" + sseThreshold + + ", minCoreLength=" + minCoreLength + ", distanceCutoff=" + + distanceCutoff + ", gaps=" + gaps + ", optimizationSteps=" + + optimizationSteps + "]"; } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymm.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymm.java index 3ccd3c31b9..908d20d5f1 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymm.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymm.java @@ -212,7 +212,7 @@ protected static CeSymmResult align(Atom[] atoms, CESymmParameters params) newAFP.setTMScore(tmScore3); // Determine if the alignment is significant, stop if false - if (tmScore3 < params.getScoreThreshold()) { + if (tmScore3 < params.getUnrefinedScoreThreshold()) { // If it is the first alignment save it anyway if (i == 0) selfAlignments.add(newAFP); @@ -262,7 +262,7 @@ protected static CeSymmResult align(Atom[] atoms, CESymmParameters params) result.setType(params.getSymmType()); // Do not try the refinement if the self-alignment is not significant - if (optimalAFP.getTMScore() < params.getScoreThreshold()){ + if (optimalAFP.getTMScore() < params.getUnrefinedScoreThreshold()){ result.setSymmOrder(1); return result; } @@ -300,11 +300,12 @@ protected static CeSymmResult align(Atom[] atoms, CESymmParameters params) atoms); break; } + result.setSymmOrder(order); + // REFINEMENT SymmetryRefiner refiner = null; switch (params.getRefineMethod()) { case NOT_REFINED: - result.setSymmOrder(order); return result; case SEQUENCE_FUNCTION: // Does not work for OPEN alignments @@ -330,7 +331,7 @@ protected static CeSymmResult align(Atom[] atoms, CESymmParameters params) return result; } - // STEP4: determine the symmetry axis and its repeat dependencies + // STEP 4: determine the symmetry axis and its repeat dependencies SymmetryAxes axes = new SymmetryAxes(); int order = result.getMultipleAlignment().size(); Matrix4d axis = result.getMultipleAlignment().getBlockSet(0) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java index 399bbb964b..0a55d6d2f1 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java @@ -223,6 +223,12 @@ else if (!r.isSignificant()) */ private boolean buildAlignment() throws StructureException { + // If one level, nothing to build + if (levels.size() == 1) { + result.setSymmLevels(1); + return false; + } + // Initialize a new multiple alignment MultipleAlignment msa = new MultipleAlignmentImpl(); msa.getEnsemble().setAtomArrays(new ArrayList()); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java index d9e027a920..27647c341a 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java @@ -76,8 +76,8 @@ public boolean isSignificant() { if (symmOrder < 2) return false; - // If the TM-Score is below the threshold - if (selfAlignment.getTMScore() < params.getScoreThreshold()) + // If the TM-Score before refinement is below the threshold + if (selfAlignment.getTMScore() < params.getUnrefinedScoreThreshold()) return false; // If the refinement was attempted @@ -87,7 +87,7 @@ public boolean isSignificant() { return false; // Allow 90% of original TM-Score theshold if (multipleAlignment.getScore(MultipleAlignmentScorer.AVGTM_SCORE) < params - .getScoreThreshold() * 0.9) + .getRefinedScoreThreshold()) return false; return true; } @@ -213,7 +213,8 @@ public String getSymmGroup() { else symmGroup = "R"; } - } else // case asymmetric + } else + // case asymmetric symmGroup = "C1"; } return symmGroup; @@ -255,4 +256,60 @@ public void setStructureId(StructureIdentifier structureId) { this.structureId = structureId; } + /** + * Return a String describing the reasons for the CE-Symm final decision + * in this particular result. + * + * @return String decision reason + */ + public String getReason() { + // Cases: + // 1. Asymmetric because insignificant self-alignment (1itb.A_1-100) + double tm = selfAlignment.getTMScore(); + if (tm < params.getUnrefinedScoreThreshold()) { + return String.format("Insignificant self-alignment (TM=%.2f)", tm); + } + // 2. Asymmetric because order detector returned 1 + if (symmOrder == 1) { + return String.format("Order detector found asymmetric alignment (TM=%.2f)", tm); + } + + // Check that the user requested refinement + if (params.getRefineMethod() != RefineMethod.NOT_REFINED) { + // 3. Asymmetric because refinement failed + if (!refined) { + return "Refinement failed"; + } + tm = multipleAlignment.getScore( + MultipleAlignmentScorer.AVGTM_SCORE); + // 4. Asymmetric because refinement & optimization were not + // significant + if (!isSignificant()) { + return String.format( + "Refinement was not significant (TM=%.2f)", tm); + } + } else { + // 4. Not refined, but result was not significant + if (!isSignificant()) { + return String + .format("Result was not significant (TM=%.2f)", tm); + } + } + + String hierarchical = ""; + if (symmLevels > 1) { + hierarchical = String.format("; Contains %d levels of symmetry", + symmLevels); + } + // 5. Symmetric. + // a. Open. Give # repeats (1n0r.A) + if (type == SymmetryType.OPEN) { + return String.format("Contains %d open repeats (TM=%.2f)%s", + getSymmOrder(), tm, hierarchical); + } + // b. Closed, non-hierarchical (1itb.A) + // c. Closed, heirarchical (4gcr) + return String.format("Significant (TM=%.2f)%s", tm, hierarchical); + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmOptimizer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmOptimizer.java index b874e24b1e..b10e41a00b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmOptimizer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmOptimizer.java @@ -93,10 +93,12 @@ public class SymmOptimizer { // Variables that store the history of the optimization - slower if on private static final boolean history = false; private static final int saveStep = 100; - private static final String pathToHistory = "./results/"; + private static final String pathToHistory = "results/symm-opt/"; + private List timeHistory; private List lengthHistory; private List rmsdHistory; - private List scoreHistory; + private List tmScoreHistory; + private List mcScoreHistory; /** * Constructor with a seed MultipleAligment storing a refined symmetry @@ -136,14 +138,19 @@ public SymmOptimizer(CeSymmResult symmResult) { private void initialize() throws StructureException, RefinerFailedException { - if (order == 1) { + if (order == 1) throw new RefinerFailedException( - "Non-symmetric seed slignment: order = 1"); - } - if (repeatCore < 1) { + "Non-symmetric seed alignment: order = 1"); + if (repeatCore < 1) throw new RefinerFailedException( - "Seed alignment too short: repeat core length == 0"); - } + "Seed alignment too short: repeat core length < 1"); + + // Initialize the history variables + timeHistory = new ArrayList(); + lengthHistory = new ArrayList(); + rmsdHistory = new ArrayList(); + mcScoreHistory = new ArrayList(); + tmScoreHistory = new ArrayList(); C = 20 * order; @@ -154,15 +161,13 @@ private void initialize() throws StructureException, RefinerFailedException { // Store the residues aligned in the block List aligned = new ArrayList(); - for (int su = 0; su < order; su++) { + for (int su = 0; su < order; su++) aligned.addAll(block.get(su)); - } // Add any residue not aligned to the free pool for (int i = 0; i < atoms.length; i++) { - if (!aligned.contains(i)) { + if (!aligned.contains(i)) freePool.add(i); - } } checkGaps(); @@ -190,14 +195,21 @@ public MultipleAlignment optimize() throws StructureException, initialize(); - // Initialize the history variables - lengthHistory = new ArrayList(); - rmsdHistory = new ArrayList(); - scoreHistory = new ArrayList(); + // Save the optimal alignment + List> optBlock = new ArrayList>(); + List optFreePool = new ArrayList(); + optFreePool.addAll(freePool); + for (int k = 0; k < order; k++) { + List b = new ArrayList(); + b.addAll(block.get(k)); + optBlock.add(b); + } + double optScore = mcScore; int conv = 0; // Number of steps without an alignment improvement int i = 1; int stepsToConverge = Math.max(maxIter / 50, 1000); + long initialTime = System.nanoTime()/1000000; while (i < maxIter && conv < stepsToConverge) { @@ -266,24 +278,44 @@ public MultipleAlignment optimize() throws StructureException, logger.debug(i + ": --prob: " + prob + ", --score: " + AS + ", --conv: " + conv); + + // Store as the optimal alignment if better + if (mcScore > optScore) { + optBlock = new ArrayList>(); + optFreePool = new ArrayList(); + optFreePool.addAll(freePool); + for (int k = 0; k < order; k++) { + List b = new ArrayList(); + b.addAll(block.get(k)); + optBlock.add(b); + } + optScore = mcScore; + } if (history) { if (i % saveStep == 1) { // Get the correct superposition again updateMultipleAlignment(); + timeHistory.add(System.nanoTime()/1000000 - initialTime); lengthHistory.add(length); rmsdHistory.add(msa.getScore(MultipleAlignmentScorer.RMSD)); - scoreHistory.add(msa.getScore(MultipleAlignmentScorer.AVGTM_SCORE)); + tmScoreHistory.add(msa + .getScore(MultipleAlignmentScorer.AVGTM_SCORE)); + mcScoreHistory.add(mcScore); } } i++; } + + // Use the optimal alignment of the trajectory + block = optBlock; + freePool = optFreePool; + mcScore = optScore; + // Superimpose and calculate final scores updateMultipleAlignment(); - mcScore = MultipleAlignmentScorer.getMCScore(msa, Gopen, Gextend, - dCutoff); msa.putScore(MultipleAlignmentScorer.MC_SCORE, mcScore); // Save the history to the results folder of the symmetry project @@ -327,8 +359,8 @@ private void updateMultipleAlignment() throws StructureException, * are no more gaps than the maximum allowed: Rmin. *

    * There must be at least Rmin residues different than null in every - * alignment column.In case there is a column with more gaps than allowed it - * will be shrinked (moved to freePool). + * alignment column. In case there is a column with more gaps than allowed + * it will be shrinked (moved to freePool). * * @return true if any columns has been shrinked and false otherwise */ @@ -805,15 +837,17 @@ private double probabilityFunction(double AS, int m, int maxIter) { private void saveHistory(String folder) throws IOException { String name = msa.getStructureIdentifier(0).getIdentifier(); - FileWriter writer = new FileWriter(folder + name + "-symm_optimization.csv"); - writer.append("Structure,Step,Repeat Length,RMSD,TM-Score\n"); + FileWriter writer = new FileWriter(folder + name + + "-symm_opt.csv"); + writer.append("Step,Time,RepeatLength,RMSD,TMscore,MCscore\n"); for (int i = 0; i < lengthHistory.size(); i++) { - writer.append(name + ","); writer.append(i * saveStep + ","); + writer.append(timeHistory.get(i) + ","); writer.append(lengthHistory.get(i) + ","); writer.append(rmsdHistory.get(i) + ","); - writer.append(scoreHistory.get(i) + "\n"); + writer.append(tmScoreHistory.get(i) + ","); + writer.append(mcScoreHistory.get(i) + "\n"); } writer.flush(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmetryAxes.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmetryAxes.java index e5e9a8d96c..fc0af1f14e 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmetryAxes.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmetryAxes.java @@ -221,11 +221,12 @@ public Matrix4d getRepeatTransform(int repeat){ /** * Return all symmetry axes of of the structure: the set of axes that * describe all parts of the structure. This combines the elementary - * axes to generate all possible axes. - * Use this method to display the axes. - * + * axes to generate all possible axes. The axes are returned in the repeat + * order. + * @deprecated because it does not work as expected for open symmetry * @return axes all symmetry axes of the structure. */ + @Deprecated public List getSymmetryAxes(){ List symmAxes = new ArrayList(); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java index 7e73a2b3e8..c0da9c4a41 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestBond.java @@ -21,6 +21,8 @@ package org.biojava.nbio.structure; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.io.FileParsingParameters; @@ -45,7 +47,6 @@ public static void setUp() throws IOException, StructureException { params.setAlignSeqRes(true); params.setCreateAtomBonds(true); - StructureIO.setAtomCache(cache); @@ -138,6 +139,38 @@ public void testLigandBonds() throws StructureException, IOException { assertTrue(areBonded(phosphateP, phosphateO)); } + + /** + * Test whether nucleotide bonds are being generated + * @throws IOException + * @throws StructureException + */ + @Test + public void testNucleotideBonds() throws IOException, StructureException { + Structure bio = StructureIO.getStructure("4y60"); + for( Chain c : bio.getChains()) { + int groupCounter = 0; + List currentGroups = c.getAtomGroups(); + for ( Group g : currentGroups) { + if(groupCounter!=0 && groupCounter atoms = g.getAtoms(); + for ( Atom a : atoms) { + if ( a.getName().equals("P")){ + // Check to see if one of the phosphate atoms has bonding to something + // outside of the group. + List indexList = new ArrayList<>(); + for (Bond b : a.getBonds()){ + indexList.add(atoms.indexOf(b.getOther(a))); + } + assertTrue(indexList.contains(-1)); + } + } + } + groupCounter++; + } + + } + } private boolean areBonded(Atom a, Atom b) { for (Bond bond : a.getBonds()) { if (bond.getOther(a) == b) { diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/TestChargeAdder.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestChargeAdder.java new file mode 100644 index 0000000000..9526e6bc77 --- /dev/null +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/TestChargeAdder.java @@ -0,0 +1,71 @@ +package org.biojava.nbio.structure; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.biojava.nbio.structure.io.ChargeAdder; +import org.junit.Test; + +/** + * Class of functions to test the charge adder. + * @author Anthony Bradley + * + */ +public class TestChargeAdder { + + + /** + * Test that it works on a very basic level. + * @throws StructureException + * @throws IOException + */ + @Test + public void testBasic() throws IOException, StructureException { + + // Get the structure + Structure structure = StructureIO.getStructure("3AAE"); + ChargeAdder.addCharges(structure); + // Now count the charges + int chargeCount = 0; + for(Chain chain : structure.getChains()) { + for (Group group : chain.getAtomGroups()) { + for (Atom atom : group.getAtoms()) { + if (atom.getCharge()!=0) { + chargeCount++; + } + } + } + } + // Check that the count is as excpected + assertEquals(425, chargeCount); + } + + + /** + * Test that it can parse '?' values in the CCD. + * @throws StructureException + * @throws IOException + */ + @Test + public void testQuestionMark() throws IOException, StructureException { + // Get the structure + Structure structure = StructureIO.getStructure("3PE6"); + ChargeAdder.addCharges(structure); + // Now count the charges + int chargeCount = 0; + for(Chain chain : structure.getChains()) { + for (Group group : chain.getAtomGroups()) { + for (Atom atom : group.getAtoms()) { + if (atom.getCharge()!=0) { + chargeCount++; + } + } + } + } + assertEquals(39, chargeCount); + } + + + +} diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index fe70129da9..08858f46b1 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -245,4 +245,71 @@ public void testFetchBehavior() throws IOException, ParseException { } + @Test + public void testSeqRes() throws StructureException, IOException { + String name; + StructureIdentifier id; + Structure full, reduced; + Chain chain; + List seqres; + + // normal structure + name = "1hh0"; + id = new SubstructureIdentifier(name); + + full = id.loadStructure(cache); + assertEquals("Wrong number of models in full "+name,1,full.nrModels()); + assertEquals("Wrong number of chains in full "+name,1,full.getChains().size()); + chain = full.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in full "+name,46,seqres.size()); + + reduced = id.reduce(full); + assertEquals("Wrong number of models in reduced "+name,1,reduced.nrModels()); + assertEquals("Wrong number of chains in reduced "+name,1,reduced.getChains().size()); + chain = reduced.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in reduced "+name,46,seqres.size()); + + // single chain + name = "1hh0.A"; + id = new SubstructureIdentifier(name); + + full = id.loadStructure(cache); + assertEquals("Wrong number of models in full "+name,1,full.nrModels()); + assertEquals("Wrong number of chains in full "+name,1,full.getChains().size()); + chain = full.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in full "+name,46,seqres.size()); + + reduced = id.reduce(full); + assertEquals("Wrong number of models in reduced "+name,1,reduced.nrModels()); + assertEquals("Wrong number of chains in reduced "+name,1,reduced.getChains().size()); + chain = reduced.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in reduced "+name,46,seqres.size()); + + // subrange + name = "1hh0.A:10-20"; + id = new SubstructureIdentifier(name); + + full = id.loadStructure(cache); + assertEquals("Wrong number of models in full "+name,1,full.nrModels()); + assertEquals("Wrong number of chains in full "+name,1,full.getChains().size()); + chain = full.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in full "+name,46,seqres.size()); + assertEquals("Wrong SeqNum at first group in full",1,(int)chain.getAtomGroup(0).getResidueNumber().getSeqNum()); + + reduced = id.reduce(full); + assertEquals("Wrong number of models in reduced "+name,1,reduced.nrModels()); + assertEquals("Wrong number of chains in reduced "+name,1,reduced.getChains().size()); + chain = reduced.getChain(0); + seqres = chain.getSeqResGroups(); + assertEquals("Wrong seqres length in reduced "+name,46,seqres.size()); + + assertEquals("Wrong SeqNum at first group in reduced",10,(int)chain.getAtomGroup(0).getResidueNumber().getSeqNum()); + + } + } diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java index c8767328bc..377297c2e9 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/TestMMCIFWriting.java @@ -160,5 +160,63 @@ public void test2N3J() throws IOException, StructureException { } } + + @Test + public void test1A2C() throws IOException, StructureException { + + // a structure with insertion codes + + AtomCache cache = new AtomCache(); + + StructureIO.setAtomCache(cache); + + cache.setUseMmCif(true); + + FileParsingParameters params = new FileParsingParameters(); + params.setAlignSeqRes(true); + cache.setFileParsingParams(params); + + Structure originalStruct = StructureIO.getStructure("1A2C"); + + File outputFile = File.createTempFile("biojava_testing_", ".cif"); + + + FileWriter fw = new FileWriter(outputFile); + fw.write(originalStruct.toMMCIF()); + fw.close(); + + + MMcifParser parser = new SimpleMMcifParser(); + + SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); + + FileParsingParameters fileParsingParams = new FileParsingParameters(); + fileParsingParams.setAlignSeqRes(true); + + consumer.setFileParsingParameters(fileParsingParams); + + parser.addMMcifConsumer(consumer); + + //parser.parse(new BufferedReader(new FileReader(new File("/home/duarte_j/test.cif")))); + parser.parse(new BufferedReader(new FileReader(outputFile))); + + Structure readStruct = consumer.getStructure(); + + assertNotNull(readStruct); + + assertEquals(originalStruct.getChains().size(), readStruct.getChains().size()); + + for (int i=0;i org.biojava biojava - 4.2.0 + 4.2.1 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 776f3a1926..9d643a2368 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.0 + 4.2.1 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 4.2.0 + 4.2.1 compile diff --git a/biojava-ws/src/main/java/demo/NCBIQBlastServiceDemo.java b/biojava-ws/src/main/java/demo/NCBIQBlastServiceDemo.java index f51d2f03e4..f171c39bfb 100644 --- a/biojava-ws/src/main/java/demo/NCBIQBlastServiceDemo.java +++ b/biojava-ws/src/main/java/demo/NCBIQBlastServiceDemo.java @@ -41,7 +41,12 @@ public class NCBIQBlastServiceDemo { private static final String SEQUENCE = "MKWVTFISLLFLFSSAYSRGVFRRDAHKSEVAHRFKDLGEENFKALVLIAFAQYLQQCPFEDHVKLVNEVTEFAKTCVADESAENCDKS"; public static void main(String[] args) { - NCBIQBlastService service = new NCBIQBlastService(); + NCBIQBlastService service = null; + if (args.length == 1) { + service = new NCBIQBlastService(args[0]); + } else { + service = new NCBIQBlastService(); + } // set alignment options NCBIQBlastAlignmentProperties props = new NCBIQBlastAlignmentProperties(); diff --git a/biojava-ws/src/main/java/org/biojava/nbio/ws/alignment/qblast/NCBIQBlastService.java b/biojava-ws/src/main/java/org/biojava/nbio/ws/alignment/qblast/NCBIQBlastService.java index 81b31a3600..12538465bf 100644 --- a/biojava-ws/src/main/java/org/biojava/nbio/ws/alignment/qblast/NCBIQBlastService.java +++ b/biojava-ws/src/main/java/org/biojava/nbio/ws/alignment/qblast/NCBIQBlastService.java @@ -74,13 +74,36 @@ public class NCBIQBlastService implements RemotePairwiseAlignmentService { private Map jobs = new HashMap(); + /** Constructs a service object that targets the public NCBI BLAST network + * service. + */ public NCBIQBlastService() { + init(SERVICE_URL); + } + + /** Constructs a service object which targets a custom NCBI BLAST network + * service (e.g.: an instance of BLAST in the cloud). + * + * @param svcUrl : a {@code String} containing the base URL to send requests to, + * e.g.: http://host.my.cloud.service.provider.com/cgi-bin/blast.cgi + * + * @see BLAST on the cloud documentation + */ + public NCBIQBlastService(String svcUrl) { + init(svcUrl); + } + + /** Initialize the serviceUrl data member + * @throws MalformedURLException on invalid URL + */ + private void init(String svcUrl) { try { - serviceUrl = new URL(SERVICE_URL); + serviceUrl = new URL(svcUrl); } catch (MalformedURLException e) { - throw new RuntimeException("It looks like the URL for NCBI QBlast service is wrong. Cause: " + e.getMessage(), e); + throw new RuntimeException("It looks like the URL for remote NCBI BLAST service (" + + svcUrl + ") is wrong. Cause: " + e.getMessage(), e); } - } + } /** * A simple method to check the availability of the QBlast service. Sends {@code Info} command to QBlast @@ -252,7 +275,7 @@ public boolean isReady(String id, long present) throws Exception { OutputStreamWriter writer = null; BufferedReader reader = null; try { - String checkRequest = "CMD=Get&RID=" + job.getId(); + String checkRequest = "CMD=Get&RID=" + job.getId() + "&FORMAT_OBJECT=SearchInfo"; URLConnection serviceConnection = setQBlastServiceProperties(serviceUrl.openConnection()); writer = new OutputStreamWriter(serviceConnection.getOutputStream()); writer.write(checkRequest); diff --git a/pom.xml b/pom.xml index 69aa2f705d..330c0798a3 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 4.2.0 + 4.2.1 biojava BioJava is an open-source project dedicated to providing a Java framework for processing biological data. It provides analytical and statistical routines, parsers for common file formats and allows the @@ -44,7 +44,7 @@ scm:git:git@github.com:biojava/biojava.git https://github.com/biojava/biojava - biojava-4.2.0 + biojava-4.2.1