From e2cc0681b90eab3ddbee972632a2e63c4ef82f5a Mon Sep 17 00:00:00 2001 From: Jenkins Date: Fri, 29 Jul 2016 15:07:24 -0700 Subject: [PATCH 01/28] [maven-release-plugin]prepare for next development iteration --- biojava-aa-prop/pom.xml | 6 +++--- biojava-alignment/pom.xml | 6 +++--- biojava-core/pom.xml | 2 +- biojava-genome/pom.xml | 6 +++--- biojava-integrationtest/pom.xml | 4 ++-- biojava-modfinder/pom.xml | 4 ++-- biojava-ontology/pom.xml | 2 +- biojava-phylo/pom.xml | 4 ++-- biojava-protein-disorder/pom.xml | 4 ++-- biojava-sequencing/pom.xml | 4 ++-- biojava-structure-gui/pom.xml | 6 +++--- biojava-structure/pom.xml | 6 +++--- biojava-survival/pom.xml | 2 +- biojava-ws/pom.xml | 4 ++-- pom.xml | 4 ++-- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index d20dfbb6ce..a4b6b60374 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT org.biojava biojava-structure - 4.2.4 + 4.2.5-SNAPSHOT diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index f6dae05256..ab8e9e3cec 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-alignment biojava-alignment @@ -46,7 +46,7 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile @@ -74,7 +74,7 @@ org.biojava biojava-phylo - 4.2.4 + 4.2.5-SNAPSHOT diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index 38b1f1ba0c..c4b2b407df 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index bb8d08147c..4552573e26 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile org.biojava biojava-alignment - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index c10746a76e..c6d9a9e7fa 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-integrationtest jar @@ -32,7 +32,7 @@ org.biojava biojava-structure - 4.2.4 + 4.2.5-SNAPSHOT diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index 4551514d9a..c5d41b753e 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 4.2.4 + 4.2.5-SNAPSHOT jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index 8e0ccad72f..bf8d7cdd86 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-ontology diff --git a/biojava-phylo/pom.xml b/biojava-phylo/pom.xml index e7758ae1ec..44c7aea53f 100644 --- a/biojava-phylo/pom.xml +++ b/biojava-phylo/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-phylo @@ -44,7 +44,7 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 535e7095ff..39745c4f5b 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT diff --git a/biojava-sequencing/pom.xml b/biojava-sequencing/pom.xml index 461bddf663..a565923bb3 100644 --- a/biojava-sequencing/pom.xml +++ b/biojava-sequencing/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-sequencing @@ -47,7 +47,7 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index df3eb75ffe..228be4b371 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT 4.0.0 biojava-structure-gui @@ -25,13 +25,13 @@ org.biojava biojava-structure - 4.2.4 + 4.2.5-SNAPSHOT compile org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index c59b4e1068..49740713a5 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-structure biojava-structure @@ -22,13 +22,13 @@ org.biojava biojava-alignment - 4.2.4 + 4.2.5-SNAPSHOT compile org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 5c87ef8b70..37d9658cbb 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index f6ef1afbfa..2376dc7e81 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.4 + 4.2.5-SNAPSHOT biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 4.2.4 + 4.2.5-SNAPSHOT compile diff --git a/pom.xml b/pom.xml index 3aa5456d2e..9895994a7c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 4.2.4 + 4.2.5-SNAPSHOT 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.4 + biojava-4.2.1 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 ec2c660deb..4663505797 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,7 @@ import org.biojava.nbio.structure.jama.Matrix; import org.jcolorbrewer.ColorBrewer; import org.jmol.api.JmolViewer; +import org.jmol.viewer.Viewer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,7 +103,7 @@ public void destroy(){ public void setAtoms(Atom[] atoms){ Structure s = new StructureImpl(); Chain c = new ChainImpl(); - c.setChainID("A"); + c.setId("A"); for (Atom a: atoms){ c.addGroup(a.getGroup()); } @@ -219,7 +220,7 @@ public void mouseMoved(MouseEvent e) { int pos = viewer.findNearestAtomIndex( e.getX(), e.getY() ); if ( pos == -1 ) { return ; } - String atomInfo = viewer.getAtomInfo(pos); + String atomInfo = ((Viewer) viewer).getAtomInfo(pos); text.setText(atomInfo); } @@ -243,7 +244,7 @@ public void mouseReleased(MouseEvent e) { int pos = viewer.findNearestAtomIndex(e.getX(), e.getY()); if (pos == -1) return; - String atomInfo = viewer.getAtomInfo(pos); + String atomInfo = ((Viewer) viewer).getAtomInfo(pos); status.setText("clicked: " + atomInfo); AtomInfo ai = AtomInfoParser.parse(atomInfo); diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java index b578793f01..95a571eef8 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java @@ -38,9 +38,12 @@ import org.jmol.api.JmolAdapter; import org.jmol.api.JmolStatusListener; import org.jmol.api.JmolViewer; -import org.jmol.util.Logger; +import org.jmol.util.LoggerInterface; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.*; + import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -52,6 +55,8 @@ public class JmolPanel extends JPrintPanel implements ActionListener { + private static final Logger logger = LoggerFactory.getLogger(JmolPanel.class); + private static final long serialVersionUID = -3661941083797644242L; private JmolViewer viewer; @@ -62,13 +67,13 @@ public class JmolPanel Structure structure; - private boolean verbose = false; - public JmolPanel() { super(); statusListener = new MyJmolStatusListener(); adapter = new SmarterJmolAdapter(); - Logger.setLogLevel( verbose?Logger.LEVEL_INFO:Logger.LEVEL_ERROR); + JmolLoggerAdapter jmolLogger = new JmolLoggerAdapter(LoggerFactory.getLogger(org.jmol.api.JmolViewer.class)); + org.jmol.util.Logger.setLogger(jmolLogger); + org.jmol.util.Logger.setLogLevel( jmolLogger.getLogLevel() ); viewer = JmolViewer.allocateViewer(this, adapter, null,null,null,null, @@ -173,7 +178,8 @@ public void actionPerformed(ActionEvent event) { return; } - JComboBox source = (JComboBox) event.getSource(); + @SuppressWarnings("unchecked") + JComboBox source = (JComboBox) event.getSource(); String value = source.getSelectedItem().toString(); evalString("save selection; "); @@ -267,7 +273,7 @@ private void colorBySCOP() { Listranges = domain.getRanges(); for (String range : ranges){ - if(verbose) System.out.println(range); + logger.debug(range); String[] spl = range.split(":"); String script = " select "; if ( spl.length > 1 ) @@ -276,7 +282,7 @@ private void colorBySCOP() { script += "*" + spl[0]+"/1;"; script += " color [" + c1.getRed() + ","+c1.getGreen() + "," +c1.getBlue()+"];"; script += " color cartoon [" + c1.getRed() + ","+c1.getGreen() + "," +c1.getBlue()+"] ;"; - if(verbose) System.out.println(script); + logger.debug(script); evalString(script); } @@ -286,7 +292,7 @@ private void colorBySCOP() { } private void colorByPDP() { - if(verbose) System.out.println("colorByPDP"); + logger.debug("colorByPDP"); if ( structure == null) return; @@ -310,13 +316,13 @@ private void colorByPDP() { int end = s.getTo(); Group startG = ca[start].getGroup(); Group endG = ca[end].getGroup(); - if(verbose) System.out.println(" Segment: " +startG.getResidueNumber() +":" + startG.getChainId() + " - " + endG.getResidueNumber()+":"+endG.getChainId() + " " + s); + logger.debug(" Segment: " +startG.getResidueNumber() +":" + startG.getChainId() + " - " + endG.getResidueNumber()+":"+endG.getChainId() + " " + s); String j1 = startG.getResidueNumber()+""; String j2 = endG.getResidueNumber()+":"+endG.getChainId(); String script = " select " +j1 +"-" +j2 +"/1;"; script += " color [" + c1.getRed() + ","+c1.getGreen() + "," +c1.getBlue()+"];"; script += " color cartoon [" + c1.getRed() + ","+c1.getGreen() + "," +c1.getBlue()+"] ;"; - if(verbose) System.out.println(script); + logger.debug(script); evalString(script); } @@ -356,15 +362,55 @@ public void destroy(){ adapter = null; } - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - if(statusListener instanceof MyJmolStatusListener) { - ((MyJmolStatusListener)statusListener).setVerbose(verbose); + public static class JmolLoggerAdapter implements LoggerInterface { + private Logger slf; + public JmolLoggerAdapter(Logger slf) { + this.slf=slf; + } + public int getLogLevel() { + if( slf.isTraceEnabled() ) + return org.jmol.util.Logger.LEVEL_MAX; + if( slf.isDebugEnabled() ) + return org.jmol.util.Logger.LEVEL_DEBUG; + if( slf.isInfoEnabled() ) + return org.jmol.util.Logger.LEVEL_INFO; + if( slf.isWarnEnabled() ) + return org.jmol.util.Logger.LEVEL_WARN; + if( slf.isErrorEnabled() ) + return org.jmol.util.Logger.LEVEL_ERROR; + throw new IllegalStateException("Unknown SLF4J error level"); + } + @Override + public void debug(String txt) { + slf.debug(txt); + } + @Override + public void info(String txt) { + slf.info(txt); + } + @Override + public void warn(String txt) { + slf.warn(txt); + } + @Override + public void warnEx(String txt, Throwable e) { + slf.warn(txt,e); + } + @Override + public void error(String txt) { + slf.error(txt); + } + @Override + public void errorEx(String txt, Throwable e) { + slf.error(txt,e); + } + @Override + public void fatal(String txt) { + slf.error(txt); + } + @Override + public void fatalEx(String txt, Throwable e) { + slf.error(txt,e); } } - } diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MyJmolStatusListener.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MyJmolStatusListener.java index ae61cc1a73..f0a5a5864d 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MyJmolStatusListener.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MyJmolStatusListener.java @@ -24,17 +24,17 @@ package org.biojava.nbio.structure.align.gui.jmol; -import org.jmol.api.JmolStatusListener; -import org.jmol.constant.EnumCallback; +import java.util.Map; -import javax.swing.*; +import javax.swing.JTextField; -import java.util.Hashtable; -import java.util.Map; +import org.jmol.api.JmolStatusListener; +import org.jmol.c.CBK; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MyJmolStatusListener implements JmolStatusListener { - - private boolean verbose = false; + private static final Logger logger = LoggerFactory.getLogger(MyJmolStatusListener.class); JTextField status; public MyJmolStatusListener(){ @@ -46,33 +46,30 @@ public void setTextField (JTextField statusField) { @Override public String createImage(String arg0, String arg1, Object arg2, int arg3) { - // TODO Auto-generated method stub - return null; + return null; //Cancelled } @Override public String eval(String arg0) { - if(verbose) System.out.println("eval " + arg0); + logger.debug("eval {}",arg0); return null; } @Override public float[][] functionXY(String arg0, int arg1, int arg2) { - if(verbose) System.out.println("XY " + arg0 + " " + arg1 + " " + arg2); - return null; + logger.debug("XY {} {} {}",arg0,arg1, arg2); + return null; //Ignore isosurface commands } @Override public float[][][] functionXYZ(String arg0, int arg1, int arg2, int arg3) { - // TODO Auto-generated method stub - return null; + logger.debug("XYZ {} {} {} {}",arg0,arg1, arg2, arg3); + return null; //Ignore isosurface commands } - @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public Hashtable getRegistryInfo() { - // TODO Auto-generated method stub - return null; + public Map getRegistryInfo() { + return null; //Ignore } @Override @@ -87,79 +84,48 @@ public void notifyCallback(int arg0, Object[] arg1) { } public boolean notifyEnabled(int arg0) { - // TODO Auto-generated method stub return false; } @Override public void setCallbackFunction(String arg0, String arg1) { - if(verbose) System.out.println("callback:" + arg0 + " " + arg1); + logger.debug("callback: {} {}", arg0, arg1); status.setText(arg0 + " " + arg1); - } public String dialogAsk(String arg0, String arg1) { - // TODO Auto-generated method stub - if(verbose) System.out.println("dialogAsk"); - return null; + logger.debug("dialogAsk {} {}",arg0,arg1); + return null; //Ignore } public void handlePopupMenu(int arg0, int arg1) { - // TODO Auto-generated method stub - if(verbose) System.out.println("handlePopupMenu"); + logger.debug("handlePopupMenu {} {}",arg0,arg1); } public void showConsole(boolean arg0) { - - // TODO Auto-generated method stub - if(verbose) System.out.println("showConsole"); - + logger.debug("showConsole {}",arg0); } - @Override - public void notifyCallback(EnumCallback arg0, Object[] arg1) { - // TODO Auto-generated method stub + @Override + public void notifyCallback(CBK message, Object[] data) { } - @Override - public boolean notifyEnabled(EnumCallback arg0) { - // TODO Auto-generated method stub + public boolean notifyEnabled(CBK type) { return false; } - @Override - public Map getProperty(String arg0) { - // TODO Auto-generated method stub - return null; - } - - - public Map getJSpecViewProperty(String arg0) { - // TODO Auto-generated method stub return null; } @Override - public void resizeInnerPanel(String data) { - // TODO Auto-generated method stub - - } - - public boolean isVerbose() { - return verbose; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; + public int[] resizeInnerPanel(String data) { + return null; } - - - } From 50595e08865e1d7de2e85b8a3a16078ebb668ba6 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Fri, 26 Aug 2016 15:09:32 +0200 Subject: [PATCH 05/28] Switching Jmol interchange format to MMCIF Any bugs are probably due to the poor MMCIF writer. However, at least we can use multi-letter chain Ids now. --- .../org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java index 95a571eef8..738888f0c4 100644 --- a/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java +++ b/biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/JmolPanel.java @@ -117,8 +117,8 @@ public void executeCmd(String rasmolScript) { public void setStructure(Structure s) { this.structure = s; - String pdb = s.toPDB(); - viewer.openStringInline(pdb); + String serialized = s.toMMCIF(); + viewer.openStringInline(serialized); evalString("save STATE state_1"); } From 69e105a3279abfb66adbe65c9db7206518b0d567 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Mon, 29 Aug 2016 14:55:18 +0200 Subject: [PATCH 06/28] Update Jmol to 14.6.2_2016.08.28 --- biojava-structure-gui/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index 7f2c61cb65..a3e13fbddb 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -40,7 +40,7 @@ net.sourceforge.jmol jmol - 14.6.1_2016.08.20 + 14.6.2_2016.08.28 From 5d4eba257257ac48edc1eb49507e9e6e40081454 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Tue, 30 Aug 2016 15:36:34 +0200 Subject: [PATCH 07/28] Fix compilation error after cherry-pick --- .../nbio/structure/align/gui/jmol/AbstractAlignmentJmol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4663505797..2a62b84961 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 @@ -103,7 +103,7 @@ public void destroy(){ public void setAtoms(Atom[] atoms){ Structure s = new StructureImpl(); Chain c = new ChainImpl(); - c.setId("A"); + c.setChainID("A"); for (Atom a: atoms){ c.addGroup(a.getGroup()); } From b30a0e2fa4bd8337103601af7a3f67af2fc13120 Mon Sep 17 00:00:00 2001 From: "audrius.meskauskas" Date: Wed, 24 Aug 2016 20:13:15 +0200 Subject: [PATCH 08/28] Fix 355 --- .../nbio/genome/parsers/gff/Location.java | 1153 ++++++++--------- 1 file changed, 541 insertions(+), 612 deletions(-) diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java index d36389ce89..5280069542 100644 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java @@ -21,183 +21,187 @@ package org.biojava.nbio.genome.parsers.gff; import org.biojava.nbio.genome.App; +import org.biojava.nbio.genome.parsers.gff.Intersector.Interval; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** - * A location on a sequence. - * A location is a contiguous range of indices, with a single start and end point. - *

- * Internally, location indices are stored in Java "half-open" format: the start is the (origin 0) index of - * the first symbol in the range; the end is the origin 0 index of the first symbol PAST the - * end of the range, so that end - start == length. - *

- * Location objects, once constructed, cannot be changed. Instead, all methods return a new - * location. This allows the use of "method chaining" to implement a particular calculation. - * For example, consider the chained statement "loc.prefix( 100 ).suffix( 10 )", - * which first applies the prefix method to - * the variable named loc, and then the suffix method to the result. - * Together, the chained operations create a new location object of length 10 - * whose start is the index of the 90th symbol. - * Here's another example. This one returns a location object holding the coordinates of the intron between - * the first exon (location exon1) and - * the second exon (location exon2) on a sequence (seq): "seq.prefix( exon2 ).suffix( exon1 )" - *

- * About the negative (reverse) strand: The location object stores reverse strand locations as - * negative indices. For example, the positive strand location from index 12 to index 97 is - * on the opposite side as index -97 (start) to index -12 (end). Note that the larger index is - * always downstream from the smaller index, (i.e. start <= end, regardless of strand). - * Obviously this representation makes it trivial - * to convert a location from one strand to the other. - *

- * Additional points regarding the use of locations on opposite strands: - *
- * (1) Opposite strand locations cannot be compared, eg isBefore() will - * throw an exception.
+ * A location on a sequence. A location is a contiguous range of indices, with a + * single start and end point.
+ *
+ * Internally, location indices are stored in Java "half-open" format: the start + * is the (origin 0) index of the first symbol in the range; the end is the + * origin 0 index of the first symbol PAST the end of the range, so that end - + * start == length.
+ *
+ * Location objects, once constructed, cannot be changed. Instead, all methods + * return a new location. This allows the use of "method chaining" to implement + * a particular calculation. For example, consider the chained statement + * "loc.prefix( 100 ).suffix( 10 )", which first applies the prefix method to + * the variable named loc, and then the suffix method to the result. Together, + * the chained operations create a new location object of length 10 whose start + * is the index of the 90th symbol. Here's another example. This one returns a + * location object holding the coordinates of the intron between the first exon + * (location exon1) and the second exon (location exon2) on a sequence (seq): + * "seq.prefix( exon2 ).suffix( exon1 )"
+ *
+ * About the negative (reverse) strand: The location object stores reverse + * strand locations as negative indices. For example, the positive strand + * location from index 12 to index 97 is on the opposite side as index -97 + * (start) to index -12 (end). Note that the larger index is always downstream + * from the smaller index, (i.e. start <= end, regardless of strand). + * Obviously this representation makes it trivial to convert a location from one + * strand to the other.
+ *
+ * Additional points regarding the use of locations on opposite strands:
+ * (1) Opposite strand locations cannot be compared, eg isBefore() will throw an + * exception.
* (2) Containment queries ( eg overlaps(), contains() ) also throw exceptions. - *
- * (3) The plus() method will map a location to its positive strand equivalent; use it on both args - * before calling, for example the intersection() method, - * if your code needs to be indifferent to strand. - *

- * Exceptions and how they are (typically) used: - *
- * IllegalArgumentException - the location given as a parameter is not on the same strand as the location. - *
- * IndexOutOfBoundsException - often means the operation caused the location to span the origin, ie - * be partially on positive and partially on negative strand. - *
+ *
+ * (3) The plus() method will map a location to its positive strand equivalent; + * use it on both args before calling, for example the intersection() method, if + * your code needs to be indifferent to strand.
+ *
+ * Exceptions and how they are (typically) used:
+ * IllegalArgumentException - the location given as a parameter is not on the + * same strand as the location.
+ * IndexOutOfBoundsException - often means the operation caused the location to + * span the origin, ie be partially on positive and partially on negative + * strand.
+ * * @author Hanno Hinsch */ -public class Location implements Iterable -{ +public class Location implements Iterable { private static final Logger logger = LoggerFactory.getLogger(App.class); private int mStart; private int mEnd; -// /** -// */ -// private Location() -// { -// } + // /** + // */ + // private Location() + // { + // } /** - * Construct new location from coordinates. - * See package description of coordinate format. - * @param start Origin 0 index of first symbol. - * @param end Origin 0 index of last symbol + 1. - * @throws IllegalArgumentException End is not after start, or location spans the origin + * Construct new location from coordinates. See package description of + * coordinate format. + * + * @param start + * Origin 0 index of first symbol. + * @param end + * Origin 0 index of last symbol + 1. + * @throws IllegalArgumentException + * End is not after start, or location spans the origin */ - public Location( int start, int end ) - { - mStart= start; - mEnd= end; + public Location(int start, int end) { + mStart = start; + mEnd = end; - if( !isHealthy() ) - { - throw new IllegalArgumentException( "Improper location parameters: (" + start + "," + end + ")" ); + if (!isHealthy()) { + throw new IllegalArgumentException("Improper location parameters: (" + start + "," + end + ")"); } } /** * Clone other location. - * @param other The location to clone. + * + * @param other + * The location to clone. */ - public Location( Location other ) - { - mStart= other.mStart; - mEnd= other.mEnd; + public Location(Location other) { + mStart = other.mStart; + mEnd = other.mEnd; - assert isHealthy(): toString(); + assert isHealthy() : toString(); } - public int getBegin(){ - if(isNegative()) - return mEnd; - else - return mStart; - } - - public int getEnd(){ - if(isNegative()) - return mStart; - else - return mEnd; - } + public int getBegin() { + if (isNegative()) + return mEnd; + else + return mStart; + } + public int getEnd() { + if (isNegative()) + return mStart; + else + return mEnd; + } /** * Create location from "biocoordinates", as in GFF file. In biocoordinates, - * the start index of a range is represented in origin 1 (ie the very first index is 1, not 0), - * and end= start + length - 1. - * - * @param start Origin 1 index of first symbol. - * @param end Origin 1 index of last symbol. - * @param strand '+' or '-' or '.' ('.' is interpreted as '+'). + * the start index of a range is represented in origin 1 (ie the very first + * index is 1, not 0), and end= start + length - 1. + * + * @param start + * Origin 1 index of first symbol. + * @param end + * Origin 1 index of last symbol. + * @param strand + * '+' or '-' or '.' ('.' is interpreted as '+'). * @return Created location. - * @throws IllegalArgumentException strand must be '+', '-' or '.' + * @throws IllegalArgumentException + * strand must be '+', '-' or '.' */ - public static Location fromBio( int start, int end, char strand ) - { - int s= start - 1; - int e= end; + public static Location fromBio(int start, int end, char strand) { + int s = start - 1; + int e = end; - if( !( strand == '-' || strand == '+' || strand == '.' )) - { - throw new IllegalArgumentException( "Strand must be '+', '-', or '.'" ); + if (!(strand == '-' || strand == '+' || strand == '.')) { + throw new IllegalArgumentException("Strand must be '+', '-', or '.'"); } - if( strand == '-' ) - { - //negate - s= - end; - e= - ( start - 1); + if (strand == '-') { + // negate + s = -end; + e = -(start - 1); } - return new Location( s, e ); + return new Location(s, e); } /** * Create a location from MAF file coordinates, which represent negative * strand locations as the distance from the end of the sequence. * - * @param start Origin 1 index of first symbol. - * @param length Number of symbols in range. - * @param strand '+' or '-' or '.' ('.' is interpreted as '+'). - * @param totalLength Total number of symbols in sequence. - * @throws IllegalArgumentException Strand must be '+', '-', '.' + * @param start + * Origin 1 index of first symbol. + * @param length + * Number of symbols in range. + * @param strand + * '+' or '-' or '.' ('.' is interpreted as '+'). + * @param totalLength + * Total number of symbols in sequence. + * @throws IllegalArgumentException + * Strand must be '+', '-', '.' * */ - public static Location fromBioExt( int start, int length, char strand, int totalLength ) - { - int s= start; - int e= s + length; + public static Location fromBioExt(int start, int length, char strand, int totalLength) { + int s = start; + int e = s + length; - if( !( strand == '-' || strand == '+' || strand == '.' )) - { - throw new IllegalArgumentException( "Strand must be '+', '-', or '.'" ); + if (!(strand == '-' || strand == '+' || strand == '.')) { + throw new IllegalArgumentException("Strand must be '+', '-', or '.'"); } - if( strand == '-' ) - { - s= s - totalLength; - e= e - totalLength; + if (strand == '-') { + s = s - totalLength; + e = e - totalLength; } - return new Location( s, e ); - } + return new Location(s, e); + } /** * Get character representation of strand. * * @return '+' or '-' */ - public char bioStrand() - { - return ( isNegative() )?'-':'+'; + public char bioStrand() { + return (isNegative()) ? '-' : '+'; } /** @@ -205,8 +209,7 @@ public char bioStrand() * * @return The origin 1 index of the first symbol in location. */ - public int bioStart() - { + public int bioStart() { return plus().start() + 1; } @@ -215,123 +218,113 @@ public int bioStart() * * @return The origin 1 index of the final symbol in location. */ - public int bioEnd() - { + public int bioEnd() { return plus().end(); } - - /** - * Return location that is in same position on plus strand. If location is already - * on plus strand, just return the location unchanged. + * Return location that is in same position on plus strand. If location is + * already on plus strand, just return the location unchanged. * * @return Location on plus strand. */ - public Location plus() - { - if( isNegative() ) - { + public Location plus() { + if (isNegative()) { return opposite(); - } - else - { + } else { return this; } } /** - * Return location that is in same position on negative strand. If location is already - * on negative strand, just return the location unchanged. + * Return location that is in same position on negative strand. If location + * is already on negative strand, just return the location unchanged. * * @return Location on negative strand. */ - public Location minus() - { - if( isNegative() ) - { + public Location minus() { + if (isNegative()) { return this; - } - else - { + } else { return opposite(); } } - /** - * Return the union. - *
- * - * @param other The location to join. - * @return The union is a range that starts at the lesser of the two starting indices and ends at the - * greater of the two ends. - * @throws IllegalArgumentException Locations are on opposite strands. - */ - public Location union( Location other ) - { + * Return the union.
+ * + * @param other + * The location to join. + * @return The union is a range that starts at the lesser of the two + * starting indices and ends at the greater of the two ends. + * @throws IllegalArgumentException + * Locations are on opposite strands. + */ + public Location union(Location other) { - if( !isSameStrand( other )) - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); - } - else - { - int start= (other.mStart < mStart)? other.mStart: mStart; - int end= (other.mEnd > mEnd)? other.mEnd: mEnd; + if (!isSameStrand(other)) { + throw new IllegalArgumentException("Locations are on opposite strands."); + } else { + int start = (other.mStart < mStart) ? other.mStart : mStart; + int end = (other.mEnd > mEnd) ? other.mEnd : mEnd; - return new Location( start, end ); + return new Location(start, end); } } /** - * Return the intersection, or null if no overlap. - * - * @param other The location to intersect. - * @return The maximal location that is contained by both. Returns null if no overlap! - * @throws IllegalArgumentException Locations are on opposite strands. - */ - public Location intersection( Location other ) - { - if( isSameStrand( other ) ) - { - int start= ( mStart > other.mStart)? mStart: other.mStart; //pick larger - int end= ( mEnd < other.mEnd)? mEnd: other.mEnd; //pick smaller - - if( start <= end ) - { - return new Location( start, end ); - } - else - { - return null; - } - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + * Return the intersection, or null if no overlap. + * + * @param other + * The location to intersect. + * @return The maximal location that is contained by both. Returns null if + * no overlap! + * @throws IllegalArgumentException + * Locations are on opposite strands. + */ + public Location intersection(Location other) { + if (isSameStrand(other)) { + return intersect(mStart, mEnd, other.mStart, other.mEnd); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } - } + + private Location intersect(int a1, int a2, int b1, int b2) { + if (a1 > b1) { + return intersect(b1, b2, a1, a2); + } + // Safe to assume a1 <= b1 + if (b1 >= a2) { + // b starts after a ends + return null; + } else if (b1 < a2 && b2 < a2) { + // b starts after a and ends before a ends + return new Location(b1, b2); + } else if (a2 < b2) { + // b starts after a but extends after the end of a + return new Location(b1, a2); + } + return null; + } /** * Get starting index (origin 0). * * @return The start index. */ - public int start() - { + public int start() { return mStart; } /** * Get the ending index. * - * @return The index of last symbol + 1 (remember Java half-open coordinates). + * @return The index of last symbol + 1 (remember Java half-open + * coordinates). */ - public int end() - { + public int end() { return mEnd; } @@ -340,46 +333,44 @@ public int end() * * @return The length of the range (end - start). */ - public int length() - { + public int length() { return mEnd - mStart; } - /** - * Enable a "sliding window" iteration over a location - * to use with Java's "for" loop construct. - * The returned helper object implements the Iterable interface; the windowSize and increment semantics are implemented - * by an underlying LocIterator. - *

- * For example, given a location variable "loc": - *
-
-	//use window size of 3 and increment of +3
-	for( Location temp: loc.window( 3, 3 ))
-	{
-	//at each iteration, temp will be the location of the next 3 symbols
-	}
-
- * - * @param windowSize The number of symbols to get on each iteration. - * @param increment The direction and number of symbols to advance at each iteration. - * @return An anonymous iterable object to use with Java's for( ... ) loop construct. - */ - public Iterable window( final int windowSize, final int increment ) - { - final Location loc= this; - - //return iterable anonymous inner class - return new Iterable () - { - @Override - public LocIterator iterator() - { - return new LocIterator( loc, windowSize, increment ); - } + * Enable a "sliding window" iteration over a location to use with Java's + * "for" loop construct. The returned helper object implements the Iterable + * interface; the windowSize and increment semantics are implemented by an + * underlying LocIterator.
+ *
+ * For example, given a location variable "loc":
+ * + *
+	 * // use window size of 3 and increment of +3
+	 * for (Location temp : loc.window(3, 3)) {
+	 * 	// at each iteration, temp will be the location of the next 3 symbols
+	 * }
+	 * 
+ * + * @param windowSize + * The number of symbols to get on each iteration. + * @param increment + * The direction and number of symbols to advance at each + * iteration. + * @return An anonymous iterable object to use with Java's for( ... ) loop + * construct. + */ + public Iterable window(final int windowSize, final int increment) { + final Location loc = this; + + // return iterable anonymous inner class + return new Iterable() { + @Override + public LocIterator iterator() { + return new LocIterator(loc, windowSize, increment); + } - }; + }; } /** @@ -389,260 +380,226 @@ public LocIterator iterator() * @return An iterator over a Location (a LocIterator object). */ @Override - public LocIterator iterator() - { - return new LocIterator( this, 1, 1 ); + public LocIterator iterator() { + return new LocIterator(this, 1, 1); } /** - * Create a location iterator over this location, - * using specified window size and increment. + * Create a location iterator over this location, using specified window + * size and increment. * - * @param windowSize The number of symbols to get on each iteration. - * @param increment The direction and number of symbols to advance at each iteration. + * @param windowSize + * The number of symbols to get on each iteration. + * @param increment + * The direction and number of symbols to advance at each + * iteration. * @return An iterator over a Location (a LocIterator object). */ - public LocIterator iterator( int windowSize, int increment ) - { - return new LocIterator( this, windowSize, increment ); + public LocIterator iterator(int windowSize, int increment) { + return new LocIterator(this, windowSize, increment); } - /** - * The part of this location before the specified position. If position is negative, - * count backwards from the end. - *

- * For position >= 0, return Location( start, start + position ). - *
- * For position < 0, return Location( start, end + position ). + * The part of this location before the specified position. If position is + * negative, count backwards from the end.
*
- * @return New location from start of this location to directly before position. - * @param position Where the prefix ends. - * @throws IndexOutOfBoundsException Specified prefix is longer than location. - */ - public Location prefix( int position ) - { + * For position >= 0, return Location( start, start + position ).
+ * For position < 0, return Location( start, end + position ).
+ * + * @return New location from start of this location to directly before + * position. + * @param position + * Where the prefix ends. + * @throws IndexOutOfBoundsException + * Specified prefix is longer than location. + */ + public Location prefix(int position) { int end; - if( position >= 0 ) - { - if( (mStart + position <= mEnd) ) - { - end= mStart + position; - } - else - { - throw new IndexOutOfBoundsException( "Specified prefix longer than location." ); - } - } - else - { - if( (mEnd + position > mStart)) - { - end= mEnd + position; + if (position >= 0) { + if ((mStart + position <= mEnd)) { + end = mStart + position; + } else { + throw new IndexOutOfBoundsException("Specified prefix longer than location."); } - else - { - throw new IndexOutOfBoundsException( "Specified prefix longer than location." ); + } else { + if ((mEnd + position > mStart)) { + end = mEnd + position; + } else { + throw new IndexOutOfBoundsException("Specified prefix longer than location."); } } - return new Location( mStart, end ); + return new Location(mStart, end); } - /** - * The part of this location after the specified position. If position is negative, count backwards - * from the end. - *

- * For position >= 0, return Location( start + position, end ). - *
- * For position < 0, return Location( end - position, end ). + * The part of this location after the specified position. If position is + * negative, count backwards from the end.
*
+ * For position >= 0, return Location( start + position, end ).
+ * For position < 0, return Location( end - position, end ).
+ * * @return New location from position to end of this location. - * @param position Where the suffix starts. - * @throws IndexOutOfBoundsException Specified suffix is longer than location. + * @param position + * Where the suffix starts. + * @throws IndexOutOfBoundsException + * Specified suffix is longer than location. */ - public Location suffix( int position ) - { + public Location suffix(int position) { int start; - if( position >= 0 ) - { - if( mStart + position <= mEnd ) // Scooter willis when 60 + 60 = 120 no remainder - { - start= mStart + position; - } - else - { - throw new IndexOutOfBoundsException( "Specified suffix longer than location." ); - } - } - else - { - if( mEnd + position >= mStart ) + if (position >= 0) { + if (mStart + position <= mEnd) // Scooter willis when 60 + 60 = 120 + // no remainder { - start= mEnd + position; + start = mStart + position; + } else { + throw new IndexOutOfBoundsException("Specified suffix longer than location."); } - else - { - throw new IndexOutOfBoundsException( "Specified suffix longer than location." ); + } else { + if (mEnd + position >= mStart) { + start = mEnd + position; + } else { + throw new IndexOutOfBoundsException("Specified suffix longer than location."); } } - return new Location( start, mEnd ); + return new Location(start, mEnd); } /** * The part of this location before the other location (not inclusive). * - * @param other The other location. + * @param other + * The other location. * @return The part of this location before the other location. - * @throws IllegalArgumentException Locations are on opposite strands. - * @throws IndexOutOfBoundsException This location does not contain other location. - */ - public Location prefix( Location other ) - { - - if( isSameStrand( other ) ) - { - if( other.mStart >= mStart ) - { - return new Location( mStart, (other.mStart < mEnd)? other.mStart: mEnd ); + * @throws IllegalArgumentException + * Locations are on opposite strands. + * @throws IndexOutOfBoundsException + * This location does not contain other location. + */ + public Location prefix(Location other) { + + if (isSameStrand(other)) { + if (other.mStart >= mStart) { + return new Location(mStart, (other.mStart < mEnd) ? other.mStart : mEnd); + } else { + // other is out of bounds -- no prefix + throw new IndexOutOfBoundsException("Specified location not within this location."); } - else - { - //other is out of bounds -- no prefix - throw new IndexOutOfBoundsException( "Specified location not within this location." ); - } - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** * The part of this location after the other location (not inclusive). * - * @param other The other location. + * @param other + * The other location. * @return The part of this location after the other location. - * @throws IllegalArgumentException Locations are on opposite strands. - * @throws IndexOutOfBoundsException This location does not contain other location. - */ - public Location suffix( Location other ) - { - if( isSameStrand( other )) - { - if( other.mEnd <= mEnd ) - { - return new Location( (other.mEnd > mStart)? other.mEnd: mStart, mEnd ); + * @throws IllegalArgumentException + * Locations are on opposite strands. + * @throws IndexOutOfBoundsException + * This location does not contain other location. + */ + public Location suffix(Location other) { + if (isSameStrand(other)) { + if (other.mEnd <= mEnd) { + return new Location((other.mEnd > mStart) ? other.mEnd : mStart, mEnd); + } else { + // other is out of bounds -- no suffix + throw new IndexOutOfBoundsException("Specified location not within this location."); } - else - { - //other is out of bounds -- no suffix - throw new IndexOutOfBoundsException( "Specified location not within this location." ); - } - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** - * Return the adjacent location of specified length directly upstream of this location. + * Return the adjacent location of specified length directly upstream of + * this location. * * @return Upstream location. - * @param length The length of the upstream location. - * @throws IndexOutOfBoundsException Specified length causes crossing of origin. - */ - public Location upstream( int length ) - { - if( length < 0 ) - { - throw new IllegalArgumentException( "Parameter must be >= 0; is=" + length ); + * @param length + * The length of the upstream location. + * @throws IndexOutOfBoundsException + * Specified length causes crossing of origin. + */ + public Location upstream(int length) { + if (length < 0) { + throw new IllegalArgumentException("Parameter must be >= 0; is=" + length); } - if( Math.signum( mStart - length) == Math.signum( mStart ) || 0 == Math.signum( mStart - length ) ) - { - return new Location(mStart - length, mStart ); - } - else - { - throw new IndexOutOfBoundsException( "Specified length causes crossing of origin: " + length + "; " + toString() ); + if (Math.signum(mStart - length) == Math.signum(mStart) || 0 == Math.signum(mStart - length)) { + return new Location(mStart - length, mStart); + } else { + throw new IndexOutOfBoundsException( + "Specified length causes crossing of origin: " + length + "; " + toString()); } } /** - * Return the adjacent location of specified length directly downstream of this location. + * Return the adjacent location of specified length directly downstream of + * this location. * * @return The downstream location. - * @param length The length of the downstream location. - * @throws IndexOutOfBoundsException Specified length causes crossing of origin. - */ - public Location downstream( int length ) - { - if( length < 0 ) - { - throw new IllegalArgumentException( "Parameter must be >= 0; is=" + length ); + * @param length + * The length of the downstream location. + * @throws IndexOutOfBoundsException + * Specified length causes crossing of origin. + */ + public Location downstream(int length) { + if (length < 0) { + throw new IllegalArgumentException("Parameter must be >= 0; is=" + length); } - if( Math.signum( mEnd + length) == Math.signum( mEnd ) || 0 == Math.signum( mEnd + length ) ) - { - return new Location( mEnd, mEnd + length ); - } - else - { - throw new IndexOutOfBoundsException( "Specified length causes crossing of origin: " + length + "; " + toString() ); + if (Math.signum(mEnd + length) == Math.signum(mEnd) || 0 == Math.signum(mEnd + length)) { + return new Location(mEnd, mEnd + length); + } else { + throw new IndexOutOfBoundsException( + "Specified length causes crossing of origin: " + length + "; " + toString()); } } - - /** - * Return distance between this location and the other location. - * - * Distance is defined only if both locations are on same strand. + * Return distance between this location and the other location. * - * @param other The location to compare. - * @return The integer distance. Returns -1 if they overlap; 0 if directly adjacent. - * @throws IllegalArgumentException Locations are on opposite strands. + * Distance is defined only if both locations are on same strand. + * + * @param other + * The location to compare. + * @return The integer distance. Returns -1 if they overlap; 0 if directly + * adjacent. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public int distance( Location other ) - { - if( isSameStrand( other )) - { - if( overlaps( other )) - { + public int distance(Location other) { + if (isSameStrand(other)) { + if (overlaps(other)) { return -1; + } else { + return (mEnd <= other.mStart) ? (other.mStart - mEnd) : (mStart - other.mEnd); } - else - { - return ( mEnd <= other.mStart )? (other.mStart - mEnd) : (mStart - other.mEnd); - } - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** * Return percent overlap of two locations. * - * @param other The location to compare. + * @param other + * The location to compare. * @return 100.0 * intersection(other).length() / this.length() - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public double percentOverlap( Location other ) - { - if( length() > 0 && overlaps( other )) - { - return 100.0 * (((double) intersection( other ).length()) / (double) length()); - } - else - { + public double percentOverlap(Location other) { + if (length() > 0 && overlaps(other)) { + return 100.0 * (((double) intersection(other).length()) / (double) length()); + } else { return 0; } } @@ -650,170 +607,151 @@ public double percentOverlap( Location other ) /** * Check if this location and other location overlap. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if they overlap. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean overlaps( Location other ) - { - if( isSameStrand( other )) - { - return !( mStart >= other.mEnd || mEnd <= other.mStart ); - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + public boolean overlaps(Location other) { + if (isSameStrand(other)) { + return !(mStart >= other.mEnd || mEnd <= other.mStart); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** * Check if this location contains the other. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if other is entirely contained by this location. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean contains( Location other ) - { - if( isSameStrand( other )) - { - return ( mStart <= other.mStart && mEnd >= other.mEnd ); - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + public boolean contains(Location other) { + if (isSameStrand(other)) { + return (mStart <= other.mStart && mEnd >= other.mEnd); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } - /** - * Check if this location starts after the other location starts. - * The locations may overlap. + * Check if this location starts after the other location starts. The + * locations may overlap. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if this starts after other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean startsAfter( Location other ) - { - if( isSameStrand( other )) - { + public boolean startsAfter(Location other) { + if (isSameStrand(other)) { return mStart > other.mStart; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** - * Check if this location starts before other location starts. - * The locations may overlap. + * Check if this location starts before other location starts. The locations + * may overlap. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if this starts before other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean startsBefore( Location other ) - { - if( isSameStrand( other )) - { + public boolean startsBefore(Location other) { + if (isSameStrand(other)) { return mStart < other.mStart; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** - * Check if this location ends after other location ends. - * The locations may overlap. + * Check if this location ends after other location ends. The locations may + * overlap. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if location ends after other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean endsAfter( Location other ) - { - if( isSameStrand( other ) ) - { + public boolean endsAfter(Location other) { + if (isSameStrand(other)) { return mEnd > other.mEnd; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** - * Check if this location ends before other location ends. - * The locations may overlap. + * Check if this location ends before other location ends. The locations may + * overlap. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if this ends before other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean endsBefore( Location other ) - { - if( isSameStrand( other ) ) - { + public boolean endsBefore(Location other) { + if (isSameStrand(other)) { return mEnd < other.mEnd; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** * Check if this location is entirely after the other location (no overlap). * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if this is after other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean isAfter( Location other ) - { - if( isSameStrand( other ) ) - { + public boolean isAfter(Location other) { + if (isSameStrand(other)) { return mStart >= other.mEnd; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** * Check if this location is entirely before other location (no overlap). * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if this is before other. - * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IllegalArgumentException + * Locations are on opposite strands. */ - public boolean isBefore( Location other ) - { - if( isSameStrand( other ) ) - { + public boolean isBefore(Location other) { + if (isSameStrand(other)) { return mEnd <= other.mStart; - } - else - { - throw new IllegalArgumentException( "Locations are on opposite strands." ); + } else { + throw new IllegalArgumentException("Locations are on opposite strands."); } } /** - * Check if location is on negative strand. - * Note that Location( 0, 0 ) is by construction defined to be on the - * positive strand. + * Check if location is on negative strand. Note that Location( 0, 0 ) is by + * construction defined to be on the positive strand. * * @return True if on negative (reverse) strand. */ - public boolean isNegative() - { - return ( mStart <= 0 && mEnd <= 0 ); + public boolean isNegative() { + return (mStart <= 0 && mEnd <= 0); } /** @@ -821,35 +759,34 @@ public boolean isNegative() * * @return Location on opposite strand. */ - public Location opposite() - { - return new Location( - mEnd, - mStart ); + public Location opposite() { + return new Location(-mEnd, -mStart); } /** * Check if this location is on same strand as other location. * - * @param other The location to compare. + * @param other + * The location to compare. * @return True if on same strand. */ - public boolean isSameStrand( Location other ) - { - return ( isNegative() && other.isNegative() ) || ( !isNegative() && !other.isNegative() ); + public boolean isSameStrand(Location other) { + return (isNegative() && other.isNegative()) || (!isNegative() && !other.isNegative()); } - /** * Return a string representation of location. * * @return Text string. */ @Override - public String toString() - { - return new String( "[L=" + (mEnd - mStart) + "; S=" + mStart + "; E=" + mEnd +"]" ); + public String toString() { + return new String("[L=" + (mEnd - mStart) + "; S=" + mStart + "; E=" + mEnd + "]"); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#hashCode() */ @Override @@ -861,7 +798,9 @@ public int hashCode() { return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see java.lang.Object#equals(java.lang.Object) */ @Override @@ -883,111 +822,101 @@ public boolean equals(Object obj) { /** * */ - private boolean isHealthy() - { - return ( mStart <= mEnd ) && (( mStart <= 0 && mEnd <= 0 ) || (mStart >= 0 && mEnd >= 0)); + private boolean isHealthy() { + return (mStart <= mEnd) && ((mStart <= 0 && mEnd <= 0) || (mStart >= 0 && mEnd >= 0)); } - //shorthand for testing - static private Location L( int s, int e ) - { - return new Location( s, e ); + // shorthand for testing + static private Location L(int s, int e) { + return new Location(s, e); } @SuppressWarnings("unused") - static private Location R( int s, int e ) - { - return new Location( -e, -s ); + static private Location R(int s, int e) { + return new Location(-e, -s); } - /** * @deprecated */ @Deprecated @SuppressWarnings("unused") - public static void main( String args[] ) - throws Exception - { - Location p3_7= new Location( 3, 7 ); - Location p16_19= new Location( 16, 19 ); - Location p15_19= new Location( 15, 19 ); - Location p15_16= new Location( 15, 16 ); - Location p10_17= new Location( 10, 17 ); - Location p10_12= new Location( 10, 12 ); - Location p14_17= new Location( 14, 17 ); - Location p14_14= new Location( 14, 14 ); - - Location r13_17= new Location( 13, 17 ); - Location r21_25= new Location( 21, 25 ); - - Location r4_7= new Location( 4, 7 ); - Location r2_5= new Location( 2, 5 ); - Location r0_3= new Location( 0, 3 ); - Location r5_8= new Location( 5, 8 ); - - //distance - assert L(14,14).distance( L(3,7) ) == 7; - assert L(3,7).distance( L(14,14) ) == 7; - assert L(1,4).distance( L(7, 10) ) == 3; - - //union - assert p10_12.union( p14_17 ).equals( p10_17 ); - assert p14_17.union( p10_12 ).equals( p10_17 ); - assert p15_19.union( p15_16).equals( p15_19 ); - - //intersection - assert r13_17.union( r21_25 ).intersection( r21_25 ).equals( new Location( 21, 25 )); - - - //isBefore - assert r2_5.isBefore( r5_8 ); - assert !r2_5.isBefore( r4_7 ); - - //isAfter - assert r5_8.isAfter( r2_5 ); - assert !r5_8.isAfter( r4_7 ); - - //contains - assert p15_19.contains( p16_19 ); - - //overlaps - assert r2_5.overlaps( r4_7 ); - assert r2_5.overlaps( r0_3 ); - assert !r5_8.overlaps( r2_5 ); - assert !r2_5.overlaps( r5_8 ); - - - //prefix - assert L(2,20).prefix(1).equals( L(2,3)); - assert L(2,20).prefix(-1).equals( L(2,19)); - assert L(2,20).prefix( L(10,12)).equals( L(2,10)); - - //suffix - assert L(2,20).suffix(1).equals( L(3,20)); - assert L(2,20).suffix(-1).equals( L(19,20)); - assert L(2,20).suffix( L(10,12)).equals( L(12,20)); - - - //upstream - //downstream - - //startsBefore - //startsAfter - //endsBefore - //endsAfter - - //equals - - //percentoverlap - - - //plus - //minus - //isNegative - //oppposite - - //fromBio, etc. + public static void main(String[] args) throws Exception { + Location p3_7 = new Location(3, 7); + Location p16_19 = new Location(16, 19); + Location p15_19 = new Location(15, 19); + Location p15_16 = new Location(15, 16); + Location p10_17 = new Location(10, 17); + Location p10_12 = new Location(10, 12); + Location p14_17 = new Location(14, 17); + Location p14_14 = new Location(14, 14); + + Location r13_17 = new Location(13, 17); + Location r21_25 = new Location(21, 25); + + Location r4_7 = new Location(4, 7); + Location r2_5 = new Location(2, 5); + Location r0_3 = new Location(0, 3); + Location r5_8 = new Location(5, 8); + + // distance + assert L(14, 14).distance(L(3, 7)) == 7; + assert L(3, 7).distance(L(14, 14)) == 7; + assert L(1, 4).distance(L(7, 10)) == 3; + + // union + assert p10_12.union(p14_17).equals(p10_17); + assert p14_17.union(p10_12).equals(p10_17); + assert p15_19.union(p15_16).equals(p15_19); + + // intersection + assert r13_17.union(r21_25).intersection(r21_25).equals(new Location(21, 25)); + + // isBefore + assert r2_5.isBefore(r5_8); + assert !r2_5.isBefore(r4_7); + + // isAfter + assert r5_8.isAfter(r2_5); + assert !r5_8.isAfter(r4_7); + + // contains + assert p15_19.contains(p16_19); + + // overlaps + assert r2_5.overlaps(r4_7); + assert r2_5.overlaps(r0_3); + assert !r5_8.overlaps(r2_5); + assert !r2_5.overlaps(r5_8); + + // prefix + assert L(2, 20).prefix(1).equals(L(2, 3)); + assert L(2, 20).prefix(-1).equals(L(2, 19)); + assert L(2, 20).prefix(L(10, 12)).equals(L(2, 10)); + + // suffix + assert L(2, 20).suffix(1).equals(L(3, 20)); + assert L(2, 20).suffix(-1).equals(L(19, 20)); + assert L(2, 20).suffix(L(10, 12)).equals(L(12, 20)); + + // upstream + // downstream + + // startsBefore + // startsAfter + // endsBefore + // endsAfter + + // equals + + // percentoverlap + + // plus + // minus + // isNegative + // oppposite + + // fromBio, etc. logger.info("JavaGene.Location Passed."); } From 8ce7640d3dfdfadc57bcecd818e6c51b8d1ee460 Mon Sep 17 00:00:00 2001 From: "audrius.meskauskas" Date: Wed, 24 Aug 2016 20:22:15 +0200 Subject: [PATCH 09/28] Cleanup --- .../nbio/genome/parsers/gff/Location.java | 1092 +++++++++-------- 1 file changed, 585 insertions(+), 507 deletions(-) diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java index 5280069542..87944f8546 100644 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java @@ -21,187 +21,183 @@ package org.biojava.nbio.genome.parsers.gff; import org.biojava.nbio.genome.App; -import org.biojava.nbio.genome.parsers.gff.Intersector.Interval; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** - * A location on a sequence. A location is a contiguous range of indices, with a - * single start and end point.
- *
- * Internally, location indices are stored in Java "half-open" format: the start - * is the (origin 0) index of the first symbol in the range; the end is the - * origin 0 index of the first symbol PAST the end of the range, so that end - - * start == length.
- *
- * Location objects, once constructed, cannot be changed. Instead, all methods - * return a new location. This allows the use of "method chaining" to implement - * a particular calculation. For example, consider the chained statement - * "loc.prefix( 100 ).suffix( 10 )", which first applies the prefix method to - * the variable named loc, and then the suffix method to the result. Together, - * the chained operations create a new location object of length 10 whose start - * is the index of the 90th symbol. Here's another example. This one returns a - * location object holding the coordinates of the intron between the first exon - * (location exon1) and the second exon (location exon2) on a sequence (seq): - * "seq.prefix( exon2 ).suffix( exon1 )"
- *
- * About the negative (reverse) strand: The location object stores reverse - * strand locations as negative indices. For example, the positive strand - * location from index 12 to index 97 is on the opposite side as index -97 - * (start) to index -12 (end). Note that the larger index is always downstream - * from the smaller index, (i.e. start <= end, regardless of strand). - * Obviously this representation makes it trivial to convert a location from one - * strand to the other.
- *
- * Additional points regarding the use of locations on opposite strands:
- * (1) Opposite strand locations cannot be compared, eg isBefore() will throw an - * exception.
+ * A location on a sequence. + * A location is a contiguous range of indices, with a single start and end point. + *

+ * Internally, location indices are stored in Java "half-open" format: the start is the (origin 0) index of + * the first symbol in the range; the end is the origin 0 index of the first symbol PAST the + * end of the range, so that end - start == length. + *

+ * Location objects, once constructed, cannot be changed. Instead, all methods return a new + * location. This allows the use of "method chaining" to implement a particular calculation. + * For example, consider the chained statement "loc.prefix( 100 ).suffix( 10 )", + * which first applies the prefix method to + * the variable named loc, and then the suffix method to the result. + * Together, the chained operations create a new location object of length 10 + * whose start is the index of the 90th symbol. + * Here's another example. This one returns a location object holding the coordinates of the intron between + * the first exon (location exon1) and + * the second exon (location exon2) on a sequence (seq): "seq.prefix( exon2 ).suffix( exon1 )" + *

+ * About the negative (reverse) strand: The location object stores reverse strand locations as + * negative indices. For example, the positive strand location from index 12 to index 97 is + * on the opposite side as index -97 (start) to index -12 (end). Note that the larger index is + * always downstream from the smaller index, (i.e. start <= end, regardless of strand). + * Obviously this representation makes it trivial + * to convert a location from one strand to the other. + *

+ * Additional points regarding the use of locations on opposite strands: + *
+ * (1) Opposite strand locations cannot be compared, eg isBefore() will + * throw an exception.
* (2) Containment queries ( eg overlaps(), contains() ) also throw exceptions. - *
- * (3) The plus() method will map a location to its positive strand equivalent; - * use it on both args before calling, for example the intersection() method, if - * your code needs to be indifferent to strand.
- *
- * Exceptions and how they are (typically) used:
- * IllegalArgumentException - the location given as a parameter is not on the - * same strand as the location.
- * IndexOutOfBoundsException - often means the operation caused the location to - * span the origin, ie be partially on positive and partially on negative - * strand.
- * + *
+ * (3) The plus() method will map a location to its positive strand equivalent; use it on both args + * before calling, for example the intersection() method, + * if your code needs to be indifferent to strand. + *

+ * Exceptions and how they are (typically) used: + *
+ * IllegalArgumentException - the location given as a parameter is not on the same strand as the location. + *
+ * IndexOutOfBoundsException - often means the operation caused the location to span the origin, ie + * be partially on positive and partially on negative strand. + *
* @author Hanno Hinsch */ -public class Location implements Iterable { +public class Location implements Iterable +{ private static final Logger logger = LoggerFactory.getLogger(App.class); private int mStart; private int mEnd; - // /** - // */ - // private Location() - // { - // } +// /** +// */ +// private Location() +// { +// } /** - * Construct new location from coordinates. See package description of - * coordinate format. - * - * @param start - * Origin 0 index of first symbol. - * @param end - * Origin 0 index of last symbol + 1. - * @throws IllegalArgumentException - * End is not after start, or location spans the origin + * Construct new location from coordinates. + * See package description of coordinate format. + * @param start Origin 0 index of first symbol. + * @param end Origin 0 index of last symbol + 1. + * @throws IllegalArgumentException End is not after start, or location spans the origin */ - public Location(int start, int end) { - mStart = start; - mEnd = end; + public Location( int start, int end ) + { + mStart= start; + mEnd= end; - if (!isHealthy()) { - throw new IllegalArgumentException("Improper location parameters: (" + start + "," + end + ")"); + if( !isHealthy() ) + { + throw new IllegalArgumentException( "Improper location parameters: (" + start + "," + end + ")" ); } } /** * Clone other location. - * - * @param other - * The location to clone. + * @param other The location to clone. */ - public Location(Location other) { - mStart = other.mStart; - mEnd = other.mEnd; + public Location( Location other ) + { + mStart= other.mStart; + mEnd= other.mEnd; - assert isHealthy() : toString(); + assert isHealthy(): toString(); } - public int getBegin() { - if (isNegative()) - return mEnd; - else - return mStart; - } + public int getBegin(){ + if(isNegative()) + return mEnd; + else + return mStart; + } + + public int getEnd(){ + if(isNegative()) + return mStart; + else + return mEnd; + } - public int getEnd() { - if (isNegative()) - return mStart; - else - return mEnd; - } /** * Create location from "biocoordinates", as in GFF file. In biocoordinates, - * the start index of a range is represented in origin 1 (ie the very first - * index is 1, not 0), and end= start + length - 1. - * - * @param start - * Origin 1 index of first symbol. - * @param end - * Origin 1 index of last symbol. - * @param strand - * '+' or '-' or '.' ('.' is interpreted as '+'). + * the start index of a range is represented in origin 1 (ie the very first index is 1, not 0), + * and end= start + length - 1. + * + * @param start Origin 1 index of first symbol. + * @param end Origin 1 index of last symbol. + * @param strand '+' or '-' or '.' ('.' is interpreted as '+'). * @return Created location. - * @throws IllegalArgumentException - * strand must be '+', '-' or '.' + * @throws IllegalArgumentException strand must be '+', '-' or '.' */ - public static Location fromBio(int start, int end, char strand) { - int s = start - 1; - int e = end; + public static Location fromBio( int start, int end, char strand ) + { + int s= start - 1; + int e= end; - if (!(strand == '-' || strand == '+' || strand == '.')) { - throw new IllegalArgumentException("Strand must be '+', '-', or '.'"); + if( !( strand == '-' || strand == '+' || strand == '.' )) + { + throw new IllegalArgumentException( "Strand must be '+', '-', or '.'" ); } - if (strand == '-') { - // negate - s = -end; - e = -(start - 1); + if( strand == '-' ) + { + //negate + s= - end; + e= - ( start - 1); } - return new Location(s, e); + return new Location( s, e ); } /** * Create a location from MAF file coordinates, which represent negative * strand locations as the distance from the end of the sequence. * - * @param start - * Origin 1 index of first symbol. - * @param length - * Number of symbols in range. - * @param strand - * '+' or '-' or '.' ('.' is interpreted as '+'). - * @param totalLength - * Total number of symbols in sequence. - * @throws IllegalArgumentException - * Strand must be '+', '-', '.' + * @param start Origin 1 index of first symbol. + * @param length Number of symbols in range. + * @param strand '+' or '-' or '.' ('.' is interpreted as '+'). + * @param totalLength Total number of symbols in sequence. + * @throws IllegalArgumentException Strand must be '+', '-', '.' * */ - public static Location fromBioExt(int start, int length, char strand, int totalLength) { - int s = start; - int e = s + length; + public static Location fromBioExt( int start, int length, char strand, int totalLength ) + { + int s= start; + int e= s + length; - if (!(strand == '-' || strand == '+' || strand == '.')) { - throw new IllegalArgumentException("Strand must be '+', '-', or '.'"); + if( !( strand == '-' || strand == '+' || strand == '.' )) + { + throw new IllegalArgumentException( "Strand must be '+', '-', or '.'" ); } - if (strand == '-') { - s = s - totalLength; - e = e - totalLength; + if( strand == '-' ) + { + s= s - totalLength; + e= e - totalLength; } - return new Location(s, e); - } + return new Location( s, e ); + } /** * Get character representation of strand. * * @return '+' or '-' */ - public char bioStrand() { - return (isNegative()) ? '-' : '+'; + public char bioStrand() + { + return ( isNegative() )?'-':'+'; } /** @@ -209,7 +205,8 @@ public char bioStrand() { * * @return The origin 1 index of the first symbol in location. */ - public int bioStart() { + public int bioStart() + { return plus().start() + 1; } @@ -218,57 +215,72 @@ public int bioStart() { * * @return The origin 1 index of the final symbol in location. */ - public int bioEnd() { + public int bioEnd() + { return plus().end(); } + + /** - * Return location that is in same position on plus strand. If location is - * already on plus strand, just return the location unchanged. + * Return location that is in same position on plus strand. If location is already + * on plus strand, just return the location unchanged. * * @return Location on plus strand. */ - public Location plus() { - if (isNegative()) { + public Location plus() + { + if( isNegative() ) + { return opposite(); - } else { + } + else + { return this; } } /** - * Return location that is in same position on negative strand. If location - * is already on negative strand, just return the location unchanged. + * Return location that is in same position on negative strand. If location is already + * on negative strand, just return the location unchanged. * * @return Location on negative strand. */ - public Location minus() { - if (isNegative()) { + public Location minus() + { + if( isNegative() ) + { return this; - } else { + } + else + { return opposite(); } } + /** - * Return the union.
- * - * @param other - * The location to join. - * @return The union is a range that starts at the lesser of the two - * starting indices and ends at the greater of the two ends. - * @throws IllegalArgumentException - * Locations are on opposite strands. - */ - public Location union(Location other) { + * Return the union. + *
+ * + * @param other The location to join. + * @return The union is a range that starts at the lesser of the two starting indices and ends at the + * greater of the two ends. + * @throws IllegalArgumentException Locations are on opposite strands. + */ + public Location union( Location other ) + { - if (!isSameStrand(other)) { - throw new IllegalArgumentException("Locations are on opposite strands."); - } else { - int start = (other.mStart < mStart) ? other.mStart : mStart; - int end = (other.mEnd > mEnd) ? other.mEnd : mEnd; + if( !isSameStrand( other )) + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); + } + else + { + int start= (other.mStart < mStart)? other.mStart: mStart; + int end= (other.mEnd > mEnd)? other.mEnd: mEnd; - return new Location(start, end); + return new Location( start, end ); } } @@ -309,22 +321,24 @@ private Location intersect(int a1, int a2, int b1, int b2) { return null; } + /** * Get starting index (origin 0). * * @return The start index. */ - public int start() { + public int start() + { return mStart; } /** * Get the ending index. * - * @return The index of last symbol + 1 (remember Java half-open - * coordinates). + * @return The index of last symbol + 1 (remember Java half-open coordinates). */ - public int end() { + public int end() + { return mEnd; } @@ -333,44 +347,46 @@ public int end() { * * @return The length of the range (end - start). */ - public int length() { + public int length() + { return mEnd - mStart; } + /** - * Enable a "sliding window" iteration over a location to use with Java's - * "for" loop construct. The returned helper object implements the Iterable - * interface; the windowSize and increment semantics are implemented by an - * underlying LocIterator.
- *
- * For example, given a location variable "loc":
- * - *
-	 * // use window size of 3 and increment of +3
-	 * for (Location temp : loc.window(3, 3)) {
-	 * 	// at each iteration, temp will be the location of the next 3 symbols
-	 * }
-	 * 
- * - * @param windowSize - * The number of symbols to get on each iteration. - * @param increment - * The direction and number of symbols to advance at each - * iteration. - * @return An anonymous iterable object to use with Java's for( ... ) loop - * construct. - */ - public Iterable window(final int windowSize, final int increment) { - final Location loc = this; - - // return iterable anonymous inner class - return new Iterable() { - @Override - public LocIterator iterator() { - return new LocIterator(loc, windowSize, increment); - } + * Enable a "sliding window" iteration over a location + * to use with Java's "for" loop construct. + * The returned helper object implements the Iterable interface; the windowSize and increment semantics are implemented + * by an underlying LocIterator. + *

+ * For example, given a location variable "loc": + *
+
+	//use window size of 3 and increment of +3
+	for( Location temp: loc.window( 3, 3 ))
+	{
+	//at each iteration, temp will be the location of the next 3 symbols
+	}
+
+ * + * @param windowSize The number of symbols to get on each iteration. + * @param increment The direction and number of symbols to advance at each iteration. + * @return An anonymous iterable object to use with Java's for( ... ) loop construct. + */ + public Iterable window( final int windowSize, final int increment ) + { + final Location loc= this; - }; + //return iterable anonymous inner class + return new Iterable () + { + @Override + public LocIterator iterator() + { + return new LocIterator( loc, windowSize, increment ); + } + + }; } /** @@ -380,226 +396,260 @@ public LocIterator iterator() { * @return An iterator over a Location (a LocIterator object). */ @Override - public LocIterator iterator() { - return new LocIterator(this, 1, 1); + public LocIterator iterator() + { + return new LocIterator( this, 1, 1 ); } /** - * Create a location iterator over this location, using specified window - * size and increment. + * Create a location iterator over this location, + * using specified window size and increment. * - * @param windowSize - * The number of symbols to get on each iteration. - * @param increment - * The direction and number of symbols to advance at each - * iteration. + * @param windowSize The number of symbols to get on each iteration. + * @param increment The direction and number of symbols to advance at each iteration. * @return An iterator over a Location (a LocIterator object). */ - public LocIterator iterator(int windowSize, int increment) { - return new LocIterator(this, windowSize, increment); + public LocIterator iterator( int windowSize, int increment ) + { + return new LocIterator( this, windowSize, increment ); } + /** - * The part of this location before the specified position. If position is - * negative, count backwards from the end.
+ * The part of this location before the specified position. If position is negative, + * count backwards from the end. + *

+ * For position >= 0, return Location( start, start + position ). *
- * For position >= 0, return Location( start, start + position ).
- * For position < 0, return Location( start, end + position ).
- * - * @return New location from start of this location to directly before - * position. - * @param position - * Where the prefix ends. - * @throws IndexOutOfBoundsException - * Specified prefix is longer than location. - */ - public Location prefix(int position) { + * For position < 0, return Location( start, end + position ). + *
+ * @return New location from start of this location to directly before position. + * @param position Where the prefix ends. + * @throws IndexOutOfBoundsException Specified prefix is longer than location. + */ + public Location prefix( int position ) + { int end; - if (position >= 0) { - if ((mStart + position <= mEnd)) { - end = mStart + position; - } else { - throw new IndexOutOfBoundsException("Specified prefix longer than location."); + if( position >= 0 ) + { + if( (mStart + position <= mEnd) ) + { + end= mStart + position; } - } else { - if ((mEnd + position > mStart)) { - end = mEnd + position; - } else { - throw new IndexOutOfBoundsException("Specified prefix longer than location."); + else + { + throw new IndexOutOfBoundsException( "Specified prefix longer than location." ); + } + } + else + { + if( (mEnd + position > mStart)) + { + end= mEnd + position; + } + else + { + throw new IndexOutOfBoundsException( "Specified prefix longer than location." ); } } - return new Location(mStart, end); + return new Location( mStart, end ); } + /** - * The part of this location after the specified position. If position is - * negative, count backwards from the end.
+ * The part of this location after the specified position. If position is negative, count backwards + * from the end. + *

+ * For position >= 0, return Location( start + position, end ). + *
+ * For position < 0, return Location( end - position, end ). *
- * For position >= 0, return Location( start + position, end ).
- * For position < 0, return Location( end - position, end ).
- * * @return New location from position to end of this location. - * @param position - * Where the suffix starts. - * @throws IndexOutOfBoundsException - * Specified suffix is longer than location. + * @param position Where the suffix starts. + * @throws IndexOutOfBoundsException Specified suffix is longer than location. */ - public Location suffix(int position) { + public Location suffix( int position ) + { int start; - if (position >= 0) { - if (mStart + position <= mEnd) // Scooter willis when 60 + 60 = 120 - // no remainder + if( position >= 0 ) + { + if( mStart + position <= mEnd ) // Scooter willis when 60 + 60 = 120 no remainder { - start = mStart + position; - } else { - throw new IndexOutOfBoundsException("Specified suffix longer than location."); + start= mStart + position; } - } else { - if (mEnd + position >= mStart) { - start = mEnd + position; - } else { - throw new IndexOutOfBoundsException("Specified suffix longer than location."); + else + { + throw new IndexOutOfBoundsException( "Specified suffix longer than location." ); + } + } + else + { + if( mEnd + position >= mStart ) + { + start= mEnd + position; + } + else + { + throw new IndexOutOfBoundsException( "Specified suffix longer than location." ); } } - return new Location(start, mEnd); + return new Location( start, mEnd ); } /** * The part of this location before the other location (not inclusive). * - * @param other - * The other location. + * @param other The other location. * @return The part of this location before the other location. - * @throws IllegalArgumentException - * Locations are on opposite strands. - * @throws IndexOutOfBoundsException - * This location does not contain other location. + * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IndexOutOfBoundsException This location does not contain other location. */ - public Location prefix(Location other) { + public Location prefix( Location other ) + { - if (isSameStrand(other)) { - if (other.mStart >= mStart) { - return new Location(mStart, (other.mStart < mEnd) ? other.mStart : mEnd); - } else { - // other is out of bounds -- no prefix - throw new IndexOutOfBoundsException("Specified location not within this location."); + if( isSameStrand( other ) ) + { + if( other.mStart >= mStart ) + { + return new Location( mStart, (other.mStart < mEnd)? other.mStart: mEnd ); } - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + else + { + //other is out of bounds -- no prefix + throw new IndexOutOfBoundsException( "Specified location not within this location." ); + } + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** * The part of this location after the other location (not inclusive). * - * @param other - * The other location. + * @param other The other location. * @return The part of this location after the other location. - * @throws IllegalArgumentException - * Locations are on opposite strands. - * @throws IndexOutOfBoundsException - * This location does not contain other location. - */ - public Location suffix(Location other) { - if (isSameStrand(other)) { - if (other.mEnd <= mEnd) { - return new Location((other.mEnd > mStart) ? other.mEnd : mStart, mEnd); - } else { - // other is out of bounds -- no suffix - throw new IndexOutOfBoundsException("Specified location not within this location."); + * @throws IllegalArgumentException Locations are on opposite strands. + * @throws IndexOutOfBoundsException This location does not contain other location. + */ + public Location suffix( Location other ) + { + if( isSameStrand( other )) + { + if( other.mEnd <= mEnd ) + { + return new Location( (other.mEnd > mStart)? other.mEnd: mStart, mEnd ); + } + else + { + //other is out of bounds -- no suffix + throw new IndexOutOfBoundsException( "Specified location not within this location." ); } - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** - * Return the adjacent location of specified length directly upstream of - * this location. + * Return the adjacent location of specified length directly upstream of this location. * * @return Upstream location. - * @param length - * The length of the upstream location. - * @throws IndexOutOfBoundsException - * Specified length causes crossing of origin. - */ - public Location upstream(int length) { - if (length < 0) { - throw new IllegalArgumentException("Parameter must be >= 0; is=" + length); + * @param length The length of the upstream location. + * @throws IndexOutOfBoundsException Specified length causes crossing of origin. + */ + public Location upstream( int length ) + { + if( length < 0 ) + { + throw new IllegalArgumentException( "Parameter must be >= 0; is=" + length ); } - if (Math.signum(mStart - length) == Math.signum(mStart) || 0 == Math.signum(mStart - length)) { - return new Location(mStart - length, mStart); - } else { - throw new IndexOutOfBoundsException( - "Specified length causes crossing of origin: " + length + "; " + toString()); + if( Math.signum( mStart - length) == Math.signum( mStart ) || 0 == Math.signum( mStart - length ) ) + { + return new Location(mStart - length, mStart ); + } + else + { + throw new IndexOutOfBoundsException( "Specified length causes crossing of origin: " + length + "; " + toString() ); } } /** - * Return the adjacent location of specified length directly downstream of - * this location. + * Return the adjacent location of specified length directly downstream of this location. * * @return The downstream location. - * @param length - * The length of the downstream location. - * @throws IndexOutOfBoundsException - * Specified length causes crossing of origin. - */ - public Location downstream(int length) { - if (length < 0) { - throw new IllegalArgumentException("Parameter must be >= 0; is=" + length); + * @param length The length of the downstream location. + * @throws IndexOutOfBoundsException Specified length causes crossing of origin. + */ + public Location downstream( int length ) + { + if( length < 0 ) + { + throw new IllegalArgumentException( "Parameter must be >= 0; is=" + length ); } - if (Math.signum(mEnd + length) == Math.signum(mEnd) || 0 == Math.signum(mEnd + length)) { - return new Location(mEnd, mEnd + length); - } else { - throw new IndexOutOfBoundsException( - "Specified length causes crossing of origin: " + length + "; " + toString()); + if( Math.signum( mEnd + length) == Math.signum( mEnd ) || 0 == Math.signum( mEnd + length ) ) + { + return new Location( mEnd, mEnd + length ); + } + else + { + throw new IndexOutOfBoundsException( "Specified length causes crossing of origin: " + length + "; " + toString() ); } } + + /** - * Return distance between this location and the other location. + * Return distance between this location and the other location. + * + * Distance is defined only if both locations are on same strand. * - * Distance is defined only if both locations are on same strand. - * - * @param other - * The location to compare. - * @return The integer distance. Returns -1 if they overlap; 0 if directly - * adjacent. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @param other The location to compare. + * @return The integer distance. Returns -1 if they overlap; 0 if directly adjacent. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public int distance(Location other) { - if (isSameStrand(other)) { - if (overlaps(other)) { + public int distance( Location other ) + { + if( isSameStrand( other )) + { + if( overlaps( other )) + { return -1; - } else { - return (mEnd <= other.mStart) ? (other.mStart - mEnd) : (mStart - other.mEnd); } - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + else + { + return ( mEnd <= other.mStart )? (other.mStart - mEnd) : (mStart - other.mEnd); + } + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** * Return percent overlap of two locations. * - * @param other - * The location to compare. + * @param other The location to compare. * @return 100.0 * intersection(other).length() / this.length() - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public double percentOverlap(Location other) { - if (length() > 0 && overlaps(other)) { - return 100.0 * (((double) intersection(other).length()) / (double) length()); - } else { + public double percentOverlap( Location other ) + { + if( length() > 0 && overlaps( other )) + { + return 100.0 * (((double) intersection( other ).length()) / (double) length()); + } + else + { return 0; } } @@ -607,151 +657,170 @@ public double percentOverlap(Location other) { /** * Check if this location and other location overlap. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if they overlap. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean overlaps(Location other) { - if (isSameStrand(other)) { - return !(mStart >= other.mEnd || mEnd <= other.mStart); - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + public boolean overlaps( Location other ) + { + if( isSameStrand( other )) + { + return !( mStart >= other.mEnd || mEnd <= other.mStart ); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** * Check if this location contains the other. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if other is entirely contained by this location. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean contains(Location other) { - if (isSameStrand(other)) { - return (mStart <= other.mStart && mEnd >= other.mEnd); - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + public boolean contains( Location other ) + { + if( isSameStrand( other )) + { + return ( mStart <= other.mStart && mEnd >= other.mEnd ); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } + /** - * Check if this location starts after the other location starts. The - * locations may overlap. + * Check if this location starts after the other location starts. + * The locations may overlap. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if this starts after other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean startsAfter(Location other) { - if (isSameStrand(other)) { + public boolean startsAfter( Location other ) + { + if( isSameStrand( other )) + { return mStart > other.mStart; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** - * Check if this location starts before other location starts. The locations - * may overlap. + * Check if this location starts before other location starts. + * The locations may overlap. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if this starts before other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean startsBefore(Location other) { - if (isSameStrand(other)) { + public boolean startsBefore( Location other ) + { + if( isSameStrand( other )) + { return mStart < other.mStart; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** - * Check if this location ends after other location ends. The locations may - * overlap. + * Check if this location ends after other location ends. + * The locations may overlap. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if location ends after other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean endsAfter(Location other) { - if (isSameStrand(other)) { + public boolean endsAfter( Location other ) + { + if( isSameStrand( other ) ) + { return mEnd > other.mEnd; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** - * Check if this location ends before other location ends. The locations may - * overlap. + * Check if this location ends before other location ends. + * The locations may overlap. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if this ends before other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean endsBefore(Location other) { - if (isSameStrand(other)) { + public boolean endsBefore( Location other ) + { + if( isSameStrand( other ) ) + { return mEnd < other.mEnd; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** * Check if this location is entirely after the other location (no overlap). * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if this is after other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean isAfter(Location other) { - if (isSameStrand(other)) { + public boolean isAfter( Location other ) + { + if( isSameStrand( other ) ) + { return mStart >= other.mEnd; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** * Check if this location is entirely before other location (no overlap). * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if this is before other. - * @throws IllegalArgumentException - * Locations are on opposite strands. + * @throws IllegalArgumentException Locations are on opposite strands. */ - public boolean isBefore(Location other) { - if (isSameStrand(other)) { + public boolean isBefore( Location other ) + { + if( isSameStrand( other ) ) + { return mEnd <= other.mStart; - } else { - throw new IllegalArgumentException("Locations are on opposite strands."); + } + else + { + throw new IllegalArgumentException( "Locations are on opposite strands." ); } } /** - * Check if location is on negative strand. Note that Location( 0, 0 ) is by - * construction defined to be on the positive strand. + * Check if location is on negative strand. + * Note that Location( 0, 0 ) is by construction defined to be on the + * positive strand. * * @return True if on negative (reverse) strand. */ - public boolean isNegative() { - return (mStart <= 0 && mEnd <= 0); + public boolean isNegative() + { + return ( mStart <= 0 && mEnd <= 0 ); } /** @@ -759,34 +828,35 @@ public boolean isNegative() { * * @return Location on opposite strand. */ - public Location opposite() { - return new Location(-mEnd, -mStart); + public Location opposite() + { + return new Location( - mEnd, - mStart ); } /** * Check if this location is on same strand as other location. * - * @param other - * The location to compare. + * @param other The location to compare. * @return True if on same strand. */ - public boolean isSameStrand(Location other) { - return (isNegative() && other.isNegative()) || (!isNegative() && !other.isNegative()); + public boolean isSameStrand( Location other ) + { + return ( isNegative() && other.isNegative() ) || ( !isNegative() && !other.isNegative() ); } + /** * Return a string representation of location. * * @return Text string. */ @Override - public String toString() { - return new String("[L=" + (mEnd - mStart) + "; S=" + mStart + "; E=" + mEnd + "]"); + public String toString() + { + return new String( "[L=" + (mEnd - mStart) + "; S=" + mStart + "; E=" + mEnd +"]" ); } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override @@ -798,9 +868,7 @@ public int hashCode() { return result; } - /* - * (non-Javadoc) - * + /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override @@ -822,101 +890,111 @@ public boolean equals(Object obj) { /** * */ - private boolean isHealthy() { - return (mStart <= mEnd) && ((mStart <= 0 && mEnd <= 0) || (mStart >= 0 && mEnd >= 0)); + private boolean isHealthy() + { + return ( mStart <= mEnd ) && (( mStart <= 0 && mEnd <= 0 ) || (mStart >= 0 && mEnd >= 0)); } - // shorthand for testing - static private Location L(int s, int e) { - return new Location(s, e); + //shorthand for testing + static private Location L( int s, int e ) + { + return new Location( s, e ); } @SuppressWarnings("unused") - static private Location R(int s, int e) { - return new Location(-e, -s); + static private Location R( int s, int e ) + { + return new Location( -e, -s ); } + /** * @deprecated */ @Deprecated @SuppressWarnings("unused") - public static void main(String[] args) throws Exception { - Location p3_7 = new Location(3, 7); - Location p16_19 = new Location(16, 19); - Location p15_19 = new Location(15, 19); - Location p15_16 = new Location(15, 16); - Location p10_17 = new Location(10, 17); - Location p10_12 = new Location(10, 12); - Location p14_17 = new Location(14, 17); - Location p14_14 = new Location(14, 14); - - Location r13_17 = new Location(13, 17); - Location r21_25 = new Location(21, 25); - - Location r4_7 = new Location(4, 7); - Location r2_5 = new Location(2, 5); - Location r0_3 = new Location(0, 3); - Location r5_8 = new Location(5, 8); - - // distance - assert L(14, 14).distance(L(3, 7)) == 7; - assert L(3, 7).distance(L(14, 14)) == 7; - assert L(1, 4).distance(L(7, 10)) == 3; - - // union - assert p10_12.union(p14_17).equals(p10_17); - assert p14_17.union(p10_12).equals(p10_17); - assert p15_19.union(p15_16).equals(p15_19); - - // intersection - assert r13_17.union(r21_25).intersection(r21_25).equals(new Location(21, 25)); - - // isBefore - assert r2_5.isBefore(r5_8); - assert !r2_5.isBefore(r4_7); - - // isAfter - assert r5_8.isAfter(r2_5); - assert !r5_8.isAfter(r4_7); - - // contains - assert p15_19.contains(p16_19); - - // overlaps - assert r2_5.overlaps(r4_7); - assert r2_5.overlaps(r0_3); - assert !r5_8.overlaps(r2_5); - assert !r2_5.overlaps(r5_8); - - // prefix - assert L(2, 20).prefix(1).equals(L(2, 3)); - assert L(2, 20).prefix(-1).equals(L(2, 19)); - assert L(2, 20).prefix(L(10, 12)).equals(L(2, 10)); - - // suffix - assert L(2, 20).suffix(1).equals(L(3, 20)); - assert L(2, 20).suffix(-1).equals(L(19, 20)); - assert L(2, 20).suffix(L(10, 12)).equals(L(12, 20)); - - // upstream - // downstream - - // startsBefore - // startsAfter - // endsBefore - // endsAfter - - // equals - - // percentoverlap - - // plus - // minus - // isNegative - // oppposite - - // fromBio, etc. + public static void main(String[] args ) + throws Exception + { + Location p3_7= new Location( 3, 7 ); + Location p16_19= new Location( 16, 19 ); + Location p15_19= new Location( 15, 19 ); + Location p15_16= new Location( 15, 16 ); + Location p10_17= new Location( 10, 17 ); + Location p10_12= new Location( 10, 12 ); + Location p14_17= new Location( 14, 17 ); + Location p14_14= new Location( 14, 14 ); + + Location r13_17= new Location( 13, 17 ); + Location r21_25= new Location( 21, 25 ); + + Location r4_7= new Location( 4, 7 ); + Location r2_5= new Location( 2, 5 ); + Location r0_3= new Location( 0, 3 ); + Location r5_8= new Location( 5, 8 ); + + //distance + assert L(14,14).distance( L(3,7) ) == 7; + assert L(3,7).distance( L(14,14) ) == 7; + assert L(1,4).distance( L(7, 10) ) == 3; + + //union + assert p10_12.union( p14_17 ).equals( p10_17 ); + assert p14_17.union( p10_12 ).equals( p10_17 ); + assert p15_19.union( p15_16).equals( p15_19 ); + + //intersection + assert r13_17.union( r21_25 ).intersection( r21_25 ).equals( new Location( 21, 25 )); + + + //isBefore + assert r2_5.isBefore( r5_8 ); + assert !r2_5.isBefore( r4_7 ); + + //isAfter + assert r5_8.isAfter( r2_5 ); + assert !r5_8.isAfter( r4_7 ); + + //contains + assert p15_19.contains( p16_19 ); + + //overlaps + assert r2_5.overlaps( r4_7 ); + assert r2_5.overlaps( r0_3 ); + assert !r5_8.overlaps( r2_5 ); + assert !r2_5.overlaps( r5_8 ); + + + //prefix + assert L(2,20).prefix(1).equals( L(2,3)); + assert L(2,20).prefix(-1).equals( L(2,19)); + assert L(2,20).prefix( L(10,12)).equals( L(2,10)); + + //suffix + assert L(2,20).suffix(1).equals( L(3,20)); + assert L(2,20).suffix(-1).equals( L(19,20)); + assert L(2,20).suffix( L(10,12)).equals( L(12,20)); + + + //upstream + //downstream + + //startsBefore + //startsAfter + //endsBefore + //endsAfter + + //equals + + //percentoverlap + + + //plus + //minus + //isNegative + //oppposite + + //fromBio, etc. logger.info("JavaGene.Location Passed."); } From 66933a60e07fe304d7fc82489ad5cec04ebf2f01 Mon Sep 17 00:00:00 2001 From: "audrius.meskauskas" Date: Thu, 25 Aug 2016 21:51:37 +0200 Subject: [PATCH 10/28] Pulling in the @josemduarte test case for issue #355 --- .../org/biojava/nbio/genome/TestIssue355.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 biojava-genome/src/test/java/org/biojava/nbio/genome/TestIssue355.java diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/TestIssue355.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/TestIssue355.java new file mode 100644 index 0000000000..ad4639882d --- /dev/null +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/TestIssue355.java @@ -0,0 +1,29 @@ +package org.biojava.nbio.genome; + +import static org.junit.Assert.*; + +import org.biojava.nbio.genome.parsers.gff.Location; +import org.junit.Test; + +public class TestIssue355 { + + @Test + public void testIssue1() { + Location l1 = Location.fromBio(51227320, 51227381, '+'); + Location l2 = Location.fromBio(51227323, 51227382, '+'); + + Location union = l1.union(l2); + assertEquals(51227320,union.bioStart()); + assertEquals(51227382,union.bioEnd()); + } + + @Test + public void testIssue2() { + Location l1 = Location.fromBio(100, 200, '+'); + Location l2 = Location.fromBio(1, 99, '+'); + Location intersection = l1.intersection(l2); + assertNull(intersection); + } + +} + From 2c35f17baf0b49354615ef99d6b169001be8c382 Mon Sep 17 00:00:00 2001 From: "audrius.meskauskas" Date: Thu, 25 Aug 2016 22:25:03 +0200 Subject: [PATCH 11/28] More tests for issue #355 --- .../nbio/genome/parsers/gff/Location.java | 6 ++--- .../org/biojava/nbio/genome/TestLocation.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java index 87944f8546..76e092d0d6 100644 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java @@ -311,10 +311,10 @@ private Location intersect(int a1, int a2, int b1, int b2) { if (b1 >= a2) { // b starts after a ends return null; - } else if (b1 < a2 && b2 < a2) { - // b starts after a and ends before a ends + } else if (b1 < a2 && b2 <= a2) { + // b starts after a starts and ends before or at where a ends return new Location(b1, b2); - } else if (a2 < b2) { + } else if (b1 >= a1 && a2 <= b2) { // b starts after a but extends after the end of a return new Location(b1, a2); } diff --git a/biojava-genome/src/test/java/org/biojava/nbio/genome/TestLocation.java b/biojava-genome/src/test/java/org/biojava/nbio/genome/TestLocation.java index 14e277b66b..57de38b909 100644 --- a/biojava-genome/src/test/java/org/biojava/nbio/genome/TestLocation.java +++ b/biojava-genome/src/test/java/org/biojava/nbio/genome/TestLocation.java @@ -91,6 +91,29 @@ public void testLocation() { assertEquals(L(12,20), L(2,20).suffix( L(10,12))); } + + @Test + public void testLocationIntersections() { + // One inside another + Location r21_25 = new Location( 21, 25 ); + Location r1_100 = new Location(1, 100 ); + + assertEquals(r21_25, r21_25.intersection( r1_100)); + assertEquals(r21_25, r1_100.intersection( r21_25)); + + // Non overlapping + Location r10_100 = new Location(10, 100 ); + Location r1_9 = new Location( 1, 9 ); + + assertNull(r10_100.intersection( r1_9)); + assertNull(r1_9.intersection( new Location( 9, 10 ))); + + // Partially overlappping + Location r1_25 = new Location( 1, 25 ); + Location r21_100 = new Location(21, 100 ); + assertEquals(r21_25, r1_25.intersection( r21_100)); + assertEquals(r21_25, r21_100.intersection( r1_25)); + } //shorthand for testing private static Location L( int s, int e ) { From 48708c315fede4d58a7a31f6e156ceedf2d02c7c Mon Sep 17 00:00:00 2001 From: Antonin Pavelka Date: Tue, 13 Sep 2016 16:13:18 -0700 Subject: [PATCH 12/28] FileConvert fix - added empty space if altLoc is null. --- .../main/java/org/biojava/nbio/structure/io/FileConvert.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java index 0d3127b9b4..04d5f83cd5 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java @@ -410,6 +410,10 @@ record = "ATOM "; Character altLoc = a.getAltLoc() ; + + if ( altLoc == null) + altLoc = ' '; + String resseq = "" ; if ( hasInsertionCode(pdbcode) ) resseq = String.format("%5s",pdbcode); From 6aa44f82f871f8f59cd58a52473b16a853bfd5bc Mon Sep 17 00:00:00 2001 From: Antonin Pavelka Date: Thu, 15 Sep 2016 15:42:08 -0700 Subject: [PATCH 13/28] Inserts space when altLoc is null, so that the rest of fields are properly aligned. --- .../main/java/org/biojava/nbio/structure/io/FileConvert.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java index 04d5f83cd5..4103e4ef1f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/FileConvert.java @@ -407,10 +407,7 @@ record = "ATOM "; String serial = String.format("%5d",seri); String fullName = formatAtomName(a); - - - Character altLoc = a.getAltLoc() ; - + Character altLoc = a.getAltLoc(); if ( altLoc == null) altLoc = ' '; From 31ace5a99c54fb5c2b6ae88007ce40d7e1440803 Mon Sep 17 00:00:00 2001 From: Spencer Bliven Date: Wed, 9 Nov 2016 12:19:24 +0100 Subject: [PATCH 14/28] Fix #596. Remove test for GenBank identifier parsing Starting Nov 2016, Entrez stopped including the GI identifier in GenBank files. In such cases, getAccession().getIdentifier() will return null. This updates the tests to reflect that null identifiers are acceptable. Users who need the GI identifier should store it manually after fetching the sequence. --- .../java/org/biojava/nbio/core/sequence/AccessionID.java | 2 ++ .../sequence/loader/GenbankProxySequenceReaderTest.java | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/AccessionID.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/AccessionID.java index a1199e4706..a9fb6a1b47 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/AccessionID.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/AccessionID.java @@ -133,6 +133,8 @@ public void setVersion(Integer version) { /** * In case if {@link #getID() } in not unique keeps the alternative id, eg. NCBI GI number. + * + * This may null. * * @return */ diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReaderTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReaderTest.java index a20faf7ce7..78b6c16607 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReaderTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/sequence/loader/GenbankProxySequenceReaderTest.java @@ -99,9 +99,10 @@ so it should be done here (manualy). logger.info("accession id: {}", seq.getAccession().getID()); Assert.assertNotNull(seq.getAccession().getID()); // test GID number - Assert.assertEquals(gi, seq.getAccession().getIdentifier()); - logger.info("found identifier '{}'", seq.getAccession().getIdentifier()); - + if( seq.getAccession().getIdentifier() != null) { // GI: in header now optional. See #596 + Assert.assertEquals(gi, seq.getAccession().getIdentifier()); + logger.info("found identifier '{}'", seq.getAccession().getIdentifier()); + } // test taxonomy id logger.info("taxonomy id: {}", seq.getTaxonomy().getID()); Assert.assertNotNull(seq.getTaxonomy().getID()); From ad79f0e76a6ab7776796b999bd4dc8b13c9832ed Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Mon, 21 Nov 2016 16:50:31 -0800 Subject: [PATCH 15/28] Implementing parsing of atom_sites category in mmcif parser/consumer --- .../structure/io/mmcif/ChemCompConsumer.java | 69 +++--- .../structure/io/mmcif/MMcifConsumer.java | 1 + .../structure/io/mmcif/MetalBondConsumer.java | 5 + .../io/mmcif/SimpleMMcifConsumer.java | 10 + .../structure/io/mmcif/SimpleMMcifParser.java | 13 ++ .../structure/io/mmcif/model/AtomSites.java | 218 ++++++++++++++++++ .../io/mmcif/TestAtomSitesParsing.java | 61 +++++ 7 files changed, 345 insertions(+), 32 deletions(-) create mode 100644 biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java create mode 100644 biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java index 00cbd87ec6..c9fbef0b06 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompConsumer.java @@ -78,19 +78,19 @@ public void documentEnd() { @Override public void newAtomSite(AtomSite atom) { - // TODO Auto-generated method stub + } @Override public void newDatabasePDBremark(DatabasePDBremark remark) { - // TODO Auto-generated method stub + } @Override public void newDatabasePDBrev(DatabasePDBrev dbrev) { - // TODO Auto-generated method stub + } @@ -101,94 +101,99 @@ public void newDatabasePDBrevRecord(DatabasePdbrevRecord dbrev) { @Override public void newEntity(Entity entity) { - // TODO Auto-generated method stub + } @Override public void newEntityPolySeq(EntityPolySeq epolseq) { - // TODO Auto-generated method stub + } @Override public void newExptl(Exptl exptl) { - // TODO Auto-generated method stub + } @Override public void newCell(Cell cell) { - // TODO Auto-generated method stub + } @Override public void newSymmetry(Symmetry symmetry) { - // TODO Auto-generated method stub + } @Override public void newStructNcsOper(StructNcsOper sNcsOper) { - // TODO Auto-generated method stub + + } + + @Override + public void newAtomSites(AtomSites atomSites) { + } @Override public void newPdbxEntityNonPoly(PdbxEntityNonPoly pen) { - // TODO Auto-generated method stub + } @Override public void newPdbxNonPolyScheme(PdbxNonPolyScheme ppss) { - // TODO Auto-generated method stub + } @Override public void newPdbxPolySeqScheme(PdbxPolySeqScheme ppss) { - // TODO Auto-generated method stub + } @Override public void newRefine(Refine r) { - // TODO Auto-generated method stub + } @Override public void newStructAsym(StructAsym sasym) { - // TODO Auto-generated method stub + } @Override public void newStructKeywords(StructKeywords kw) { - // TODO Auto-generated method stub + } @Override public void newStructRef(StructRef sref) { - // TODO Auto-generated method stub + } @Override public void newStructRefSeq(StructRefSeq sref) { - // TODO Auto-generated method stub + } @Override public void newStructRefSeqDif(StructRefSeqDif sref) { - // TODO Auto-generated method stub + } @Override public void setStruct(Struct struct) { - // TODO Auto-generated method stub + } @@ -203,7 +208,7 @@ public void newGenericData(String category, List loopFields, @Override public void newAuditAuthor(AuditAuthor aa) { - // TODO Auto-generated method stub + } @@ -217,7 +222,7 @@ public FileParsingParameters getFileParsingParameters() @Override public void setFileParsingParameters(FileParsingParameters params) { - // TODO Auto-generated method stub + } @@ -230,19 +235,19 @@ public void newChemCompDescriptor(ChemCompDescriptor ccd) { @Override public void newPdbxStructOperList(PdbxStructOperList structOper) { - // TODO Auto-generated method stub + } @Override public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly) { - // TODO Auto-generated method stub + } @Override public void newPdbxStrucAssemblyGen(PdbxStructAssemblyGen strucAssembly) { - // TODO Auto-generated method stub + } @@ -253,7 +258,7 @@ public void newChemCompAtom(ChemCompAtom atom) { @Override public void newPdbxChemCompIndentifier(PdbxChemCompIdentifier id) { - // TODO Auto-generated method stub + } @@ -264,41 +269,41 @@ public void newChemCompBond(ChemCompBond bond) { @Override public void newPdbxChemCompDescriptor(PdbxChemCompDescriptor desc) { - // TODO Auto-generated method stub + } @Override public void newEntitySrcGen(EntitySrcGen entitySrcGen) { - // TODO Auto-generated method stub + } @Override public void newEntitySrcNat(EntitySrcNat entitySrcNat) { - // TODO Auto-generated method stub + } @Override public void newEntitySrcSyn(EntitySrcSyn entitySrcSyn) { - // TODO Auto-generated method stub + } @Override public void newStructConn(StructConn structConn) { - // TODO Auto-generated method stub + } @Override public void newStructSiteGen(StructSiteGen gen) { - // TODO + } @Override public void newStructSite(StructSite site) { - // TODO + } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java index 1204d3cf9b..e86a30826f 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MMcifConsumer.java @@ -61,6 +61,7 @@ public interface MMcifConsumer { public void newCell(Cell cell); public void newSymmetry(Symmetry symmetry); public void newStructNcsOper(StructNcsOper sNcsOper); + public void newAtomSites(AtomSites atomSites); public void newStructRef(StructRef sref); public void newStructRefSeq(StructRefSeq sref); public void newStructRefSeqDif(StructRefSeqDif sref); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java index 34f85b6614..a76e55a795 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/MetalBondConsumer.java @@ -94,6 +94,11 @@ public void newSymmetry(Symmetry symmetry) { @Override public void newStructNcsOper(StructNcsOper sNcsOper) { + } + + @Override + public void newAtomSites(AtomSites atomSites) { + } @Override 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 5ef567c93c..44d467b35e 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 @@ -59,6 +59,7 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.SeqRes2AtomAligner; import org.biojava.nbio.structure.io.mmcif.model.AtomSite; +import org.biojava.nbio.structure.io.mmcif.model.AtomSites; import org.biojava.nbio.structure.io.mmcif.model.AuditAuthor; import org.biojava.nbio.structure.io.mmcif.model.Cell; import org.biojava.nbio.structure.io.mmcif.model.ChemComp; @@ -136,6 +137,8 @@ public class SimpleMMcifConsumer implements MMcifConsumer { private List structNcsOper; private List sequenceDifs; private List structSiteGens; + + private AtomSites atomSites; /** * A map of asym ids (internal chain ids) to strand ids (author chain ids) @@ -1516,6 +1519,10 @@ public void newSymmetry(Symmetry symmetry) { public void newStructNcsOper(StructNcsOper sNcsOper) { structNcsOper.add(sNcsOper); } + + public void newAtomSites(AtomSites atomSites) { + this.atomSites = atomSites; + } @Override public void newStructRef(StructRef sref) { @@ -1850,6 +1857,9 @@ public List getStructOpers() { return structOpers; } + public AtomSites getAtomSites() { + return atomSites; + } @Override 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 90b03c8da1..1b6851c6d8 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 @@ -40,6 +40,7 @@ import org.biojava.nbio.structure.io.MMCIFFileReader; import org.biojava.nbio.structure.io.StructureIOFile; import org.biojava.nbio.structure.io.mmcif.model.AtomSite; +import org.biojava.nbio.structure.io.mmcif.model.AtomSites; import org.biojava.nbio.structure.io.mmcif.model.AuditAuthor; import org.biojava.nbio.structure.io.mmcif.model.CIFLabel; import org.biojava.nbio.structure.io.mmcif.model.Cell; @@ -675,6 +676,12 @@ private void endLineChecks(String category,List loopFields, List StructNcsOper.class.getName(), loopFields, lineData, loopWarnings); triggerNewStructNcsOper(sNcsOper); + } else if ( category.equals("_atom_sites")) { + + AtomSites atomSites = (AtomSites) buildObject( + AtomSites.class.getName(), + loopFields, lineData, loopWarnings); + triggerNewAtomSites(atomSites); } else if ( category.equals("_struct_ref")){ StructRef sref = (StructRef) buildObject( @@ -892,6 +899,12 @@ public void triggerNewStructNcsOper(StructNcsOper sNcsOper) { } } + + public void triggerNewAtomSites(AtomSites atomSites) { + for(MMcifConsumer c : consumers){ + c.newAtomSites(atomSites); + } + } /** * Populates a bean object from the {@link org.biojava.nbio.structure.io.mmcif.model} package, diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java new file mode 100644 index 0000000000..61f4a18ca1 --- /dev/null +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java @@ -0,0 +1,218 @@ +package org.biojava.nbio.structure.io.mmcif.model; + +/** + * A class containing the _atom_sites data. Equivalent to the SCALE records in PDB files. + * + * + * @author Jose Duarte + * + */ +public class AtomSites extends AbstractBean { + + String entry_id; + String Cartn_transform_axes; + + @CIFLabel(label="fract_transf_matrix[1][1]") + String fract_transf_matrix11; + + @CIFLabel(label="fract_transf_matrix[1][2]") + String fract_transf_matrix12; + + @CIFLabel(label="fract_transf_matrix[1][3]") + String fract_transf_matrix13; + + + @CIFLabel(label="fract_transf_matrix[2][1]") + String fract_transf_matrix21; + + @CIFLabel(label="fract_transf_matrix[2][2]") + String fract_transf_matrix22; + + @CIFLabel(label="fract_transf_matrix[2][3]") + String fract_transf_matrix23; + + + @CIFLabel(label="fract_transf_matrix[3][1]") + String fract_transf_matrix31; + + @CIFLabel(label="fract_transf_matrix[3][2]") + String fract_transf_matrix32; + + @CIFLabel(label="fract_transf_matrix[3][3]") + String fract_transf_matrix33; + + + @CIFLabel(label="fract_transf_vector[1]") + String fract_transf_vector1; + + @CIFLabel(label="fract_transf_vector[2]") + String fract_transf_vector2; + + @CIFLabel(label="fract_transf_vector[3]") + String fract_transf_vector3; + + + public String getEntry_id() { + return entry_id; + } + public void setEntry_id(String entry_id) { + this.entry_id = entry_id; + } + /** + * @return the cartn_transform_axes + */ + public String getCartn_transform_axes() { + return Cartn_transform_axes; + } + /** + * @param cartn_transform_axes the cartn_transform_axes to set + */ + public void setCartn_transform_axes(String cartn_transform_axes) { + Cartn_transform_axes = cartn_transform_axes; + } + /** + * @return the fract_transf_matrix11 + */ + public String getFract_transf_matrix11() { + return fract_transf_matrix11; + } + /** + * @param fract_transf_matrix11 the fract_transf_matrix11 to set + */ + public void setFract_transf_matrix11(String fract_transf_matrix11) { + this.fract_transf_matrix11 = fract_transf_matrix11; + } + /** + * @return the fract_transf_matrix12 + */ + public String getFract_transf_matrix12() { + return fract_transf_matrix12; + } + /** + * @param fract_transf_matrix12 the fract_transf_matrix12 to set + */ + public void setFract_transf_matrix12(String fract_transf_matrix12) { + this.fract_transf_matrix12 = fract_transf_matrix12; + } + /** + * @return the fract_transf_matrix13 + */ + public String getFract_transf_matrix13() { + return fract_transf_matrix13; + } + /** + * @param fract_transf_matrix13 the fract_transf_matrix13 to set + */ + public void setFract_transf_matrix13(String fract_transf_matrix13) { + this.fract_transf_matrix13 = fract_transf_matrix13; + } + /** + * @return the fract_transf_matrix21 + */ + public String getFract_transf_matrix21() { + return fract_transf_matrix21; + } + /** + * @param fract_transf_matrix21 the fract_transf_matrix21 to set + */ + public void setFract_transf_matrix21(String fract_transf_matrix21) { + this.fract_transf_matrix21 = fract_transf_matrix21; + } + /** + * @return the fract_transf_matrix22 + */ + public String getFract_transf_matrix22() { + return fract_transf_matrix22; + } + /** + * @param fract_transf_matrix22 the fract_transf_matrix22 to set + */ + public void setFract_transf_matrix22(String fract_transf_matrix22) { + this.fract_transf_matrix22 = fract_transf_matrix22; + } + /** + * @return the fract_transf_matrix23 + */ + public String getFract_transf_matrix23() { + return fract_transf_matrix23; + } + /** + * @param fract_transf_matrix23 the fract_transf_matrix23 to set + */ + public void setFract_transf_matrix23(String fract_transf_matrix23) { + this.fract_transf_matrix23 = fract_transf_matrix23; + } + /** + * @return the fract_transf_matrix31 + */ + public String getFract_transf_matrix31() { + return fract_transf_matrix31; + } + /** + * @param fract_transf_matrix31 the fract_transf_matrix31 to set + */ + public void setFract_transf_matrix31(String fract_transf_matrix31) { + this.fract_transf_matrix31 = fract_transf_matrix31; + } + /** + * @return the fract_transf_matrix32 + */ + public String getFract_transf_matrix32() { + return fract_transf_matrix32; + } + /** + * @param fract_transf_matrix32 the fract_transf_matrix32 to set + */ + public void setFract_transf_matrix32(String fract_transf_matrix32) { + this.fract_transf_matrix32 = fract_transf_matrix32; + } + /** + * @return the fract_transf_matrix33 + */ + public String getFract_transf_matrix33() { + return fract_transf_matrix33; + } + /** + * @param fract_transf_matrix33 the fract_transf_matrix33 to set + */ + public void setFract_transf_matrix33(String fract_transf_matrix33) { + this.fract_transf_matrix33 = fract_transf_matrix33; + } + /** + * @return the fract_transf_vector1 + */ + public String getFract_transf_vector1() { + return fract_transf_vector1; + } + /** + * @param fract_transf_vector1 the fract_transf_vector1 to set + */ + public void setFract_transf_vector1(String fract_transf_vector1) { + this.fract_transf_vector1 = fract_transf_vector1; + } + /** + * @return the fract_transf_vector2 + */ + public String getFract_transf_vector2() { + return fract_transf_vector2; + } + /** + * @param fract_transf_vector2 the fract_transf_vector2 to set + */ + public void setFract_transf_vector2(String fract_transf_vector2) { + this.fract_transf_vector2 = fract_transf_vector2; + } + /** + * @return the fract_transf_vector3 + */ + public String getFract_transf_vector3() { + return fract_transf_vector3; + } + /** + * @param fract_transf_vector3 the fract_transf_vector3 to set + */ + public void setFract_transf_vector3(String fract_transf_vector3) { + this.fract_transf_vector3 = fract_transf_vector3; + } + +} diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java new file mode 100644 index 0000000000..86f3e23459 --- /dev/null +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java @@ -0,0 +1,61 @@ +package org.biojava.nbio.structure.io.mmcif; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.io.InputStream; +import java.util.zip.GZIPInputStream; + +import javax.vecmath.Matrix4d; + +import org.biojava.nbio.structure.io.mmcif.MMcifParser; +import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; +import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; +import org.biojava.nbio.structure.io.mmcif.model.AtomSites; + +/** + * A test for the parsing of _atom_sites category in mmcif, equivalent to SCALE records + * in PDB files. Currently the category is parsed but is not used to populate any field + * in the Structure hierarchy. Getting the data from the parser can be useful for things like + * checking the consistency of the SCALE matrix, see https://github.com/eppic-team/owl/issues/4 + * + * + * + * @author Jose Duarte + * + */ +public class TestAtomSitesParsing { + + @Test + public void test4hhb() throws Exception { + + InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream("/4hhb.cif.gz")); + assertNotNull(inStream); + + MMcifParser mmcifpars = new SimpleMMcifParser(); + SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); + + mmcifpars.addMMcifConsumer(consumer); + + mmcifpars.parse(inStream) ; + + AtomSites atomSites = consumer.getAtomSites(); + + //System.out.println(consumer.getAtomSites()); + + Matrix4d m = new Matrix4d( + Double.parseDouble(atomSites.getFract_transf_matrix11()), Double.parseDouble(atomSites.getFract_transf_matrix12()), Double.parseDouble(atomSites.getFract_transf_matrix13()), Double.parseDouble(atomSites.getFract_transf_vector1()), + Double.parseDouble(atomSites.getFract_transf_matrix21()), Double.parseDouble(atomSites.getFract_transf_matrix22()), Double.parseDouble(atomSites.getFract_transf_matrix23()), Double.parseDouble(atomSites.getFract_transf_vector2()), + Double.parseDouble(atomSites.getFract_transf_matrix31()), Double.parseDouble(atomSites.getFract_transf_matrix32()), Double.parseDouble(atomSites.getFract_transf_matrix33()), Double.parseDouble(atomSites.getFract_transf_vector3()), + 0,0,0,1); + + // translation components are 0 + assertEquals(0.26656, m.m03, 0.00001); + assertEquals(0.16413, m.m13, 0.00001); + assertEquals(0.75059, m.m23, 0.00001); + + assertEquals(0.015462, m.m00, 0.00001); + assertEquals(0.002192, m.m01, 0.00001); + } + +} From 508e770e2c870c3f4d6f4d025f7fe67a0d9a44b2 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 22 Nov 2016 15:00:08 -0800 Subject: [PATCH 16/28] Implementing new crystallographic metadata fields. --- .../test/io/TestCrystallographicMetadata.java | 76 +++++++++++++++++++ .../structure/PDBCrystallographicInfo.java | 56 ++++++++++++++ .../io/mmcif/SimpleMMcifConsumer.java | 51 ++++++++++--- .../nbio/structure/xtal/CrystalCell.java | 3 +- .../io/mmcif/TestAtomSitesParsing.java | 61 --------------- 5 files changed, 175 insertions(+), 72 deletions(-) create mode 100644 biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java delete mode 100644 biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java diff --git a/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java new file mode 100644 index 0000000000..5e53ddc793 --- /dev/null +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/io/TestCrystallographicMetadata.java @@ -0,0 +1,76 @@ +package org.biojava.nbio.structure.test.io; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.biojava.nbio.structure.Structure; +import org.biojava.nbio.structure.StructureIO; +import org.biojava.nbio.structure.align.util.AtomCache; + +/** + * A test for the parsing of some crystallographic metadata: non standard space group and non standard coordinate frame convention. + * + * + * For more info see https://github.com/eppic-team/owl/issues/4 and https://github.com/eppic-team/eppic/issues/37 + * + * + * + * @author Jose Duarte + * @since 4.2.5 + */ +public class TestCrystallographicMetadata { + + + @Test + public void test4hhb() throws Exception { + + AtomCache cache = new AtomCache(); + // at the moment implemented only in mmcif + cache.setUseMmCif(true); + StructureIO.setAtomCache(cache); + + Structure s = StructureIO.getStructure("4hhb"); + + // 4hhb is one of the few entries that aren't in the standard coordinate frame convention + assertTrue(s.getCrystallographicInfo().isNonStandardCoordFrameConvention()); + + // 4hhn has a standard SG + assertFalse(s.getCrystallographicInfo().isNonStandardSg()); + assertNotNull(s.getCrystallographicInfo().getSpaceGroup()); + } + + @Test + public void test1smt() throws Exception { + + AtomCache cache = new AtomCache(); + // at the moment implemented only in mmcif + cache.setUseMmCif(true); + StructureIO.setAtomCache(cache); + + Structure s = StructureIO.getStructure("1smt"); + + // 1smt is a normal entry, should be standard + assertFalse(s.getCrystallographicInfo().isNonStandardCoordFrameConvention()); + + // 1smt has a standard SG + assertFalse(s.getCrystallographicInfo().isNonStandardSg()); + assertNotNull(s.getCrystallographicInfo().getSpaceGroup()); + + } + + @Test + public void test1zna() throws Exception { + AtomCache cache = new AtomCache(); + // at the moment implemented only in mmcif + cache.setUseMmCif(true); + StructureIO.setAtomCache(cache); + + Structure s = StructureIO.getStructure("1zna"); + + // 1zna is one of the few entries that has a non-standard SG + assertTrue(s.getCrystallographicInfo().isNonStandardSg()); + assertNull(s.getCrystallographicInfo().getSpaceGroup()); + } + + +} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBCrystallographicInfo.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBCrystallographicInfo.java index b8d9ef18ee..2e10faef06 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBCrystallographicInfo.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/PDBCrystallographicInfo.java @@ -48,6 +48,23 @@ public class PDBCrystallographicInfo implements Serializable { * are not stored. */ private Matrix4d[] ncsOperators; + + /** + * Whether this structure has a non-standard space group not supported + * by Biojava. If this is true the sg member will be null. + * @since 4.2.5 + */ + private boolean nonStandardSg; + + /** + * Whether this structure is non-standard coordinate frame convention, for which our scale matrix + * calculation and thus the crystal reconstruction will be incorrect. + * There's ~ 200 old structures in the PDB affected by the non-standard frame problem, hopefully they will + * be remediated in the future. + * For more info see: https://github.com/eppic-team/owl/issues/4 + * @since 4.2.5 + */ + private boolean nonStandardCoordFrameConvention; public PDBCrystallographicInfo() { @@ -179,6 +196,45 @@ public Matrix4d[] getNcsOperators() { public void setNcsOperators(Matrix4d[] ncsOperators) { this.ncsOperators = ncsOperators; } + + /** + * Whether this structure has a non-standard space group not supported + * by Biojava. If this is true {@link #getSpaceGroup()} will be null. + * @since 4.2.5 + */ + public boolean isNonStandardSg() { + return nonStandardSg; + } + + /** + * Set the non-standard space group field + * @param nonStandardSg + * @since 4.2.5 + */ + public void setNonStandardSg(boolean nonStandardSg) { + this.nonStandardSg = nonStandardSg; + } + + /** + * Whether this structure is non-standard coordinate frame convention, for which our scale matrix + * calculation and thus the crystal reconstruction will be incorrect. + * There's ~ 200 old structures in the PDB affected by the non-standard frame problem, hopefully they will + * be remediated in the future. + * For more info see: https://github.com/eppic-team/owl/issues/4 + * @since 4.2.5 + */ + public boolean isNonStandardCoordFrameConvention() { + return nonStandardCoordFrameConvention; + } + + /** + * Set the non-standard coordinate frame convention field + * @param nonStandardCoordFrameConvention + * @since 4.2.5 + */ + public void setNonStandardCoordFrameConvention(boolean nonStandardCoordFrameConvention) { + this.nonStandardCoordFrameConvention = nonStandardCoordFrameConvention; + } @Override 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 44d467b35e..b4f0ad467c 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 @@ -45,6 +45,7 @@ import org.biojava.nbio.structure.GroupType; import org.biojava.nbio.structure.HetatomImpl; import org.biojava.nbio.structure.NucleotideImpl; +import org.biojava.nbio.structure.PDBCrystallographicInfo; import org.biojava.nbio.structure.PDBHeader; import org.biojava.nbio.structure.ResidueNumber; import org.biojava.nbio.structure.SeqMisMatch; @@ -138,7 +139,7 @@ public class SimpleMMcifConsumer implements MMcifConsumer { private List sequenceDifs; private List structSiteGens; - private AtomSites atomSites; + private Matrix4d parsedScaleMatrix; /** * A map of asym ids (internal chain ids) to strand ids (author chain ids) @@ -874,6 +875,8 @@ public void documentEnd() { } setStructNcsOps(); + + setCrystallographicInfoMetadata(); Map> misMatchMap = new HashMap>(); @@ -1276,6 +1279,20 @@ private void setStructNcsOps() { ncsOperators.toArray(new Matrix4d[ncsOperators.size()])); } } + + private void setCrystallographicInfoMetadata() { + if (parsedScaleMatrix!=null) { + + PDBCrystallographicInfo crystalInfo = structure.getCrystallographicInfo(); + + boolean nonStd = false; + if (!crystalInfo.getCrystalCell().checkScaleMatrix(parsedScaleMatrix)) { + nonStd = true; + } + + crystalInfo.setNonStandardCoordFrameConvention(nonStd); + } + } /** This method will return the parsed protein structure, once the parsing has been finished * @@ -1510,9 +1527,13 @@ public void newCell(Cell cell) { public void newSymmetry(Symmetry symmetry) { String spaceGroup = symmetry.getSpace_group_name_H_M(); SpaceGroup sg = SymoplibParser.getSpaceGroup(spaceGroup); - if (sg==null) logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group"); - - structure.getPDBHeader().getCrystallographicInfo().setSpaceGroup(sg); + if (sg==null) { + logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group"); + structure.getPDBHeader().getCrystallographicInfo().setNonStandardSg(true); + } else { + structure.getPDBHeader().getCrystallographicInfo().setSpaceGroup(sg); + structure.getPDBHeader().getCrystallographicInfo().setNonStandardSg(false); + } } @Override @@ -1521,7 +1542,22 @@ public void newStructNcsOper(StructNcsOper sNcsOper) { } public void newAtomSites(AtomSites atomSites) { - this.atomSites = atomSites; + + try { + Matrix4d m = new Matrix4d( + Double.parseDouble(atomSites.getFract_transf_matrix11()), Double.parseDouble(atomSites.getFract_transf_matrix12()), Double.parseDouble(atomSites.getFract_transf_matrix13()), Double.parseDouble(atomSites.getFract_transf_vector1()), + Double.parseDouble(atomSites.getFract_transf_matrix21()), Double.parseDouble(atomSites.getFract_transf_matrix22()), Double.parseDouble(atomSites.getFract_transf_matrix23()), Double.parseDouble(atomSites.getFract_transf_vector2()), + Double.parseDouble(atomSites.getFract_transf_matrix31()), Double.parseDouble(atomSites.getFract_transf_matrix32()), Double.parseDouble(atomSites.getFract_transf_matrix33()), Double.parseDouble(atomSites.getFract_transf_vector3()), + 0,0,0,1); + + parsedScaleMatrix = m; + + } catch (NumberFormatException e) { + logger.warn("Some values in _atom_sites.fract_transf_matrix or _atom_sites.fract_transf_vector could not be parsed as numbers. Can't check whether coordinate frame convention is correct! Error: {}", e.getMessage()); + structure.getPDBHeader().getCrystallographicInfo().setNonStandardCoordFrameConvention(false); + + // in this case parsedScaleMatrix stays null and can't be used in documentEnd() + } } @Override @@ -1857,11 +1893,6 @@ public List getStructOpers() { return structOpers; } - public AtomSites getAtomSites() { - return atomSites; - } - - @Override public void newPdbxStrucAssembly(PdbxStructAssembly strucAssembly) { strucAssemblies.add(strucAssembly); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalCell.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalCell.java index 95c409d6d5..3850c0b87b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalCell.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalCell.java @@ -547,9 +547,10 @@ public boolean checkScaleMatrixConsistency(Matrix4d scaleMatrix) { */ public boolean checkScaleMatrix(Matrix4d scaleMatrix) { + Matrix3d mtranspose = getMTranspose(); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { - if (!deltaComp(getMTranspose().getElement(i, j),scaleMatrix.getElement(i, j))) { + if (!deltaComp(mtranspose.getElement(i, j),scaleMatrix.getElement(i, j))) { //System.out.println("Our value ("+i+","+j+"): "+getM().getElement(i,j)); //System.out.println("Their value ("+i+","+j+"): "+scaleMatrix.getElement(i,j)); return false; diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java deleted file mode 100644 index 86f3e23459..0000000000 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/io/mmcif/TestAtomSitesParsing.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.biojava.nbio.structure.io.mmcif; - -import org.junit.Test; -import static org.junit.Assert.*; - -import java.io.InputStream; -import java.util.zip.GZIPInputStream; - -import javax.vecmath.Matrix4d; - -import org.biojava.nbio.structure.io.mmcif.MMcifParser; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifConsumer; -import org.biojava.nbio.structure.io.mmcif.SimpleMMcifParser; -import org.biojava.nbio.structure.io.mmcif.model.AtomSites; - -/** - * A test for the parsing of _atom_sites category in mmcif, equivalent to SCALE records - * in PDB files. Currently the category is parsed but is not used to populate any field - * in the Structure hierarchy. Getting the data from the parser can be useful for things like - * checking the consistency of the SCALE matrix, see https://github.com/eppic-team/owl/issues/4 - * - * - * - * @author Jose Duarte - * - */ -public class TestAtomSitesParsing { - - @Test - public void test4hhb() throws Exception { - - InputStream inStream = new GZIPInputStream(this.getClass().getResourceAsStream("/4hhb.cif.gz")); - assertNotNull(inStream); - - MMcifParser mmcifpars = new SimpleMMcifParser(); - SimpleMMcifConsumer consumer = new SimpleMMcifConsumer(); - - mmcifpars.addMMcifConsumer(consumer); - - mmcifpars.parse(inStream) ; - - AtomSites atomSites = consumer.getAtomSites(); - - //System.out.println(consumer.getAtomSites()); - - Matrix4d m = new Matrix4d( - Double.parseDouble(atomSites.getFract_transf_matrix11()), Double.parseDouble(atomSites.getFract_transf_matrix12()), Double.parseDouble(atomSites.getFract_transf_matrix13()), Double.parseDouble(atomSites.getFract_transf_vector1()), - Double.parseDouble(atomSites.getFract_transf_matrix21()), Double.parseDouble(atomSites.getFract_transf_matrix22()), Double.parseDouble(atomSites.getFract_transf_matrix23()), Double.parseDouble(atomSites.getFract_transf_vector2()), - Double.parseDouble(atomSites.getFract_transf_matrix31()), Double.parseDouble(atomSites.getFract_transf_matrix32()), Double.parseDouble(atomSites.getFract_transf_matrix33()), Double.parseDouble(atomSites.getFract_transf_vector3()), - 0,0,0,1); - - // translation components are 0 - assertEquals(0.26656, m.m03, 0.00001); - assertEquals(0.16413, m.m13, 0.00001); - assertEquals(0.75059, m.m23, 0.00001); - - assertEquals(0.015462, m.m00, 0.00001); - assertEquals(0.002192, m.m01, 0.00001); - } - -} From b8246121ba957786991d86e3a2a03856189fadec Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 22 Nov 2016 15:39:40 -0800 Subject: [PATCH 17/28] Fixing npe introduced in last commit --- .../biojava/nbio/structure/io/mmcif/SimpleMMcifConsumer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b4f0ad467c..096bd77797 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 @@ -1286,7 +1286,7 @@ private void setCrystallographicInfoMetadata() { PDBCrystallographicInfo crystalInfo = structure.getCrystallographicInfo(); boolean nonStd = false; - if (!crystalInfo.getCrystalCell().checkScaleMatrix(parsedScaleMatrix)) { + if (crystalInfo.getCrystalCell()!=null && !crystalInfo.getCrystalCell().checkScaleMatrix(parsedScaleMatrix)) { nonStd = true; } From 1dbfcbd4cb7b88f9a2d0dae6e4e239e0df3e6689 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 22 Nov 2016 15:50:54 -0800 Subject: [PATCH 18/28] Some extra rare fields in atom_sites --- .../structure/io/mmcif/model/AtomSites.java | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java index 61f4a18ca1..d0581402df 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/model/AtomSites.java @@ -10,6 +10,8 @@ public class AtomSites extends AbstractBean { String entry_id; + + // to my knowledge this field is not used - JD 2016-11-22 String Cartn_transform_axes; @CIFLabel(label="fract_transf_matrix[1][1]") @@ -50,6 +52,43 @@ public class AtomSites extends AbstractBean { @CIFLabel(label="fract_transf_vector[3]") String fract_transf_vector3; + + // these fields are unusual but appear in some entries like 5e5j - JD 2016-11-22 + @CIFLabel(label="Cartn_transf_matrix[1][1]") + String Cartn_transf_matrix11; + + @CIFLabel(label="Cartn_transf_matrix[1][2]") + String Cartn_transf_matrix12; + + @CIFLabel(label="Cartn_transf_matrix[1][3]") + String Cartn_transf_matrix13; + + @CIFLabel(label="Cartn_transf_matrix[2][1]") + String Cartn_transf_matrix21; + + @CIFLabel(label="Cartn_transf_matrix[2][2]") + String Cartn_transf_matrix22; + + @CIFLabel(label="Cartn_transf_matrix[2][3]") + String Cartn_transf_matrix23; + + @CIFLabel(label="Cartn_transf_matrix[3][1]") + String Cartn_transf_matrix31; + + @CIFLabel(label="Cartn_transf_matrix[3][2]") + String Cartn_transf_matrix32; + + @CIFLabel(label="Cartn_transf_matrix[3][3]") + String Cartn_transf_matrix33; + + @CIFLabel(label="Cartn_transf_vector[1]") + String Cartn_transf_vector1; + + @CIFLabel(label="Cartn_transf_vector[2]") + String Cartn_transf_vector2; + + @CIFLabel(label="Cartn_transf_vector[3]") + String Cartn_transf_vector3; public String getEntry_id() { @@ -214,5 +253,149 @@ public String getFract_transf_vector3() { public void setFract_transf_vector3(String fract_transf_vector3) { this.fract_transf_vector3 = fract_transf_vector3; } + /** + * @return the cartn_transf_matrix11 + */ + public String getCartn_transf_matrix11() { + return Cartn_transf_matrix11; + } + /** + * @param cartn_transf_matrix11 the cartn_transf_matrix11 to set + */ + public void setCartn_transf_matrix11(String cartn_transf_matrix11) { + Cartn_transf_matrix11 = cartn_transf_matrix11; + } + /** + * @return the cartn_transf_matrix12 + */ + public String getCartn_transf_matrix12() { + return Cartn_transf_matrix12; + } + /** + * @param cartn_transf_matrix12 the cartn_transf_matrix12 to set + */ + public void setCartn_transf_matrix12(String cartn_transf_matrix12) { + Cartn_transf_matrix12 = cartn_transf_matrix12; + } + /** + * @return the cartn_transf_matrix13 + */ + public String getCartn_transf_matrix13() { + return Cartn_transf_matrix13; + } + /** + * @param cartn_transf_matrix13 the cartn_transf_matrix13 to set + */ + public void setCartn_transf_matrix13(String cartn_transf_matrix13) { + Cartn_transf_matrix13 = cartn_transf_matrix13; + } + /** + * @return the cartn_transf_matrix21 + */ + public String getCartn_transf_matrix21() { + return Cartn_transf_matrix21; + } + /** + * @param cartn_transf_matrix21 the cartn_transf_matrix21 to set + */ + public void setCartn_transf_matrix21(String cartn_transf_matrix21) { + Cartn_transf_matrix21 = cartn_transf_matrix21; + } + /** + * @return the cartn_transf_matrix22 + */ + public String getCartn_transf_matrix22() { + return Cartn_transf_matrix22; + } + /** + * @param cartn_transf_matrix22 the cartn_transf_matrix22 to set + */ + public void setCartn_transf_matrix22(String cartn_transf_matrix22) { + Cartn_transf_matrix22 = cartn_transf_matrix22; + } + /** + * @return the cartn_transf_matrix23 + */ + public String getCartn_transf_matrix23() { + return Cartn_transf_matrix23; + } + /** + * @param cartn_transf_matrix23 the cartn_transf_matrix23 to set + */ + public void setCartn_transf_matrix23(String cartn_transf_matrix23) { + Cartn_transf_matrix23 = cartn_transf_matrix23; + } + /** + * @return the cartn_transf_matrix31 + */ + public String getCartn_transf_matrix31() { + return Cartn_transf_matrix31; + } + /** + * @param cartn_transf_matrix31 the cartn_transf_matrix31 to set + */ + public void setCartn_transf_matrix31(String cartn_transf_matrix31) { + Cartn_transf_matrix31 = cartn_transf_matrix31; + } + /** + * @return the cartn_transf_matrix32 + */ + public String getCartn_transf_matrix32() { + return Cartn_transf_matrix32; + } + /** + * @param cartn_transf_matrix32 the cartn_transf_matrix32 to set + */ + public void setCartn_transf_matrix32(String cartn_transf_matrix32) { + Cartn_transf_matrix32 = cartn_transf_matrix32; + } + /** + * @return the cartn_transf_matrix33 + */ + public String getCartn_transf_matrix33() { + return Cartn_transf_matrix33; + } + /** + * @param cartn_transf_matrix33 the cartn_transf_matrix33 to set + */ + public void setCartn_transf_matrix33(String cartn_transf_matrix33) { + Cartn_transf_matrix33 = cartn_transf_matrix33; + } + /** + * @return the cartn_transf_vector1 + */ + public String getCartn_transf_vector1() { + return Cartn_transf_vector1; + } + /** + * @param cartn_transf_vector1 the cartn_transf_vector1 to set + */ + public void setCartn_transf_vector1(String cartn_transf_vector1) { + Cartn_transf_vector1 = cartn_transf_vector1; + } + /** + * @return the cartn_transf_vector2 + */ + public String getCartn_transf_vector2() { + return Cartn_transf_vector2; + } + /** + * @param cartn_transf_vector2 the cartn_transf_vector2 to set + */ + public void setCartn_transf_vector2(String cartn_transf_vector2) { + Cartn_transf_vector2 = cartn_transf_vector2; + } + /** + * @return the cartn_transf_vector3 + */ + public String getCartn_transf_vector3() { + return Cartn_transf_vector3; + } + /** + * @param cartn_transf_vector3 the cartn_transf_vector3 to set + */ + public void setCartn_transf_vector3(String cartn_transf_vector3) { + Cartn_transf_vector3 = cartn_transf_vector3; + } } From cfd6f4ad060c2f8000b3fb94f310ab38c7458e34 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Tue, 22 Nov 2016 16:53:29 -0800 Subject: [PATCH 19/28] Now using the new fields from CrystalBuilder --- .../nbio/structure/xtal/CrystalBuilder.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java index 2d0ea1b3b4..738c8ea5e0 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java @@ -102,20 +102,33 @@ public CrystalBuilder(Structure structure) { if (structure.isCrystallographic()) { this.isCrystallographic = true; + // we need to check space group not null for the cases where the entry is crystallographic but // the space group is not a standard one recognized by biojava, e.g. 1mnk (SG: 'I 21') - if (this.crystallographicInfo.getSpaceGroup()==null) { - logger.warn("Could not find a space group, will only calculate asymmetric unit interfaces."); + if (this.crystallographicInfo.isNonStandardSg()) { + logger.warn("Space group is non-standard, will only calculate asymmetric unit interfaces."); + this.isCrystallographic = false; + + } else if (this.crystallographicInfo.getSpaceGroup()==null) { + // just in case we still check for space group null (a user pdb file could potentially be crystallographic and have no space group) + logger.warn("Space group is null, will only calculate asymmetric unit interfaces."); this.isCrystallographic = false; } else { this.numOperatorsSg = this.crystallographicInfo.getSpaceGroup().getMultiplicity(); } + // we need to check crystal cell not null for the rare cases where the entry is crystallographic but // the crystal cell is not given, e.g. 2i68, 2xkm, 4bpq if (this.crystallographicInfo.getCrystalCell()==null) { logger.warn("Could not find a crystal cell definition, will only calculate asymmetric unit interfaces."); this.isCrystallographic = false; } + + // check for cases like 4hhb that are in a non-standard coordinate frame convention, see https://github.com/eppic-team/owl/issues/4 + if (this.crystallographicInfo.isNonStandardCoordFrameConvention()) { + logger.warn("Non-standard coordinate frame convention, will only calculate asymmetric unit interfaces."); + this.isCrystallographic = false; + } } else { this.isCrystallographic = false; From a2f900ca69c2bacfccff21460b1306b4bf55b182 Mon Sep 17 00:00:00 2001 From: josemduarte Date: Tue, 22 Nov 2016 18:19:17 -0800 Subject: [PATCH 20/28] Fixed bug: NPE for CrystalBuilder on 4hhb. Moved TestCrystalBuilder to integrationtest. --- .../test}/xtal/TestCrystalBuilder.java | 34 +++++++++++++++---- .../nbio/structure/xtal/CrystalBuilder.java | 1 + 2 files changed, 28 insertions(+), 7 deletions(-) rename {biojava-structure/src/test/java/org/biojava/nbio/structure => biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test}/xtal/TestCrystalBuilder.java (79%) diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalBuilder.java b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java similarity index 79% rename from biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalBuilder.java rename to biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java index cb4b536ee0..b275b2d3f2 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/xtal/TestCrystalBuilder.java +++ b/biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/xtal/TestCrystalBuilder.java @@ -18,18 +18,19 @@ * http://www.biojava.org/ * */ -package org.biojava.nbio.structure.xtal; +package org.biojava.nbio.structure.test.xtal; import org.biojava.nbio.structure.Structure; import org.biojava.nbio.structure.StructureException; import org.biojava.nbio.structure.StructureIO; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.StructureInterfaceList; +import org.biojava.nbio.structure.xtal.CrystalBuilder; import org.junit.Test; import java.io.IOException; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; public class TestCrystalBuilder { @@ -42,7 +43,7 @@ public void test1NMR() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setUseMmCif(true); Structure s1 = StructureIO.getStructure("1NMR"); CrystalBuilder cb = new CrystalBuilder(s1); @@ -60,7 +61,7 @@ public void test1B8G() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setUseMmCif(true); Structure s1 = StructureIO.getStructure("1B8G"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -78,7 +79,7 @@ public void test2MFZ() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setUseMmCif(true); Structure s1 = StructureIO.getStructure("2MFZ"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -95,7 +96,7 @@ public void test4MF8() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setUseMmCif(true); Structure s1 = StructureIO.getStructure("4MF8"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); @@ -115,11 +116,30 @@ public void test2H2Z() throws IOException, StructureException { StructureIO.setAtomCache(cache); - cache.setUseMmCif(false); + cache.setUseMmCif(true); Structure s1 = StructureIO.getStructure("2H2Z"); CrystalBuilder cb = new CrystalBuilder(s1); StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); assertTrue(interfaces.size()>=3); } + + @Test + public void test4HHB() throws IOException, StructureException { + + // 4hhb is a very old entry with a non-standard coordinate frame convention, we should calculate only AU contacts + + AtomCache cache = new AtomCache(); + + StructureIO.setAtomCache(cache); + + cache.setUseMmCif(true); + Structure s1 = StructureIO.getStructure("4HHB"); + CrystalBuilder cb = new CrystalBuilder(s1); + StructureInterfaceList interfaces = cb.getUniqueInterfaces(5.5); + // 5 interfaces in the AU: the 4 of the tetramer + 1 cross-interface + assertEquals(5, interfaces.size()); + + } + } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java index 738c8ea5e0..f24ea9b4a8 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/xtal/CrystalBuilder.java @@ -128,6 +128,7 @@ public CrystalBuilder(Structure structure) { if (this.crystallographicInfo.isNonStandardCoordFrameConvention()) { logger.warn("Non-standard coordinate frame convention, will only calculate asymmetric unit interfaces."); this.isCrystallographic = false; + this.numOperatorsSg = 1; // we force here to 1 or otherwise it gets filled from sg above } } else { From 2d4a720666806ce67de5c0b5dacfc0314794f369 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Wed, 23 Nov 2016 09:34:31 -0800 Subject: [PATCH 21/28] Adding non-standard sg check to pdb parser --- .../org/biojava/nbio/structure/io/PDBFileParser.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 10cade8e16..ba52b5794c 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 @@ -1502,8 +1502,13 @@ private void pdb_CRYST1_Handler(String line) { } SpaceGroup sg = SymoplibParser.getSpaceGroup(spaceGroup); - if (sg==null) logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group"); - crystallographicInfo.setSpaceGroup(sg); + if (sg==null) { + logger.warn("Space group '"+spaceGroup+"' not recognised as a standard space group"); + crystallographicInfo.setNonStandardSg(true); + } else { + crystallographicInfo.setSpaceGroup(sg); + crystallographicInfo.setNonStandardSg(false); + } } /** From 8acab40aae37ca7d849b1cd8d37159c5a86f21b2 Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Tue, 29 Nov 2016 09:51:18 -0500 Subject: [PATCH 22/28] fix for #610 --- .../org/biojava/nbio/phosphosite/Dataset.java | 3 +- .../org/biojava/nbio/phosphosite/Site.java | 24 +++++---- .../protmod/phosphosite/TestAcetylation.java | 53 +++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java diff --git a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java index 7fde73973f..cae8227f35 100644 --- a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java +++ b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java @@ -154,7 +154,7 @@ public void download(){ } - private void downloadFile(URL u, File localFile) throws IOException { + public void downloadFile(URL u, File localFile) throws IOException { System.out.println("Downloading " + u); @@ -234,6 +234,7 @@ public static void main(String[] args) { List sites = Site.parseSites(f); + System.out.println("Got " + sites.size() + " sites"); for (Site s : sites) { if (s.getUniprot().equals("P50225") || s.getUniprot().equals("P48025")) { System.out.println(s); diff --git a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java index 1585f8a588..906489c9ea 100644 --- a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java +++ b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java @@ -56,25 +56,25 @@ public static List parseSites(File f) throws IOException { int proteinIndex = -1; int uniprotIndex = -1; - int modTypeIndex = -1; int residueIndex = -1; int orgIndex = -1; int groupIndex = -1; + int geneIndex = -1; boolean inHeader = true; while ((line = buf.readLine()) != null){ - if ( line.startsWith("PROTEIN")) { + if ( line.startsWith("GENE")) { headerFields = parseHeaderFields(line); proteinIndex = headerFields.indexOf("PROTEIN"); uniprotIndex = headerFields.indexOf("ACC_ID"); - modTypeIndex = headerFields.indexOf("MOD_TYPE"); residueIndex = headerFields.indexOf("MOD_RSD"); - orgIndex = headerFields.indexOf("ORG"); + orgIndex = headerFields.indexOf("ORGANISM"); groupIndex = headerFields.indexOf("SITE_GRP_ID"); + geneIndex = headerFields.indexOf("GENE"); inHeader = false; continue; @@ -95,19 +95,25 @@ public static List parseSites(File f) throws IOException { String protein = spl[proteinIndex]; String uniprot = spl[uniprotIndex]; - //String geneSymb = spl[2]; - //String chrLoc = spl[3]; - String modType = spl[modTypeIndex]; + String residue = spl[residueIndex]; + + String[] resSpl = residue.split("-"); + String modType = null; + if ( resSpl.length == 2) { + + modType = resSpl[1]; + } String group = spl[groupIndex]; String organism = spl[orgIndex]; + String geneSymb = spl[geneIndex]; + Site s = new Site(); s.setProtein(protein); s.setUniprot(uniprot); - //s.setGeneSymb(geneSymb); - //s.setChrLoc(chrLoc); + s.setGeneSymb(geneSymb); s.setModType(modType); s.setResidue(residue); s.setGroup(group); diff --git a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java new file mode 100644 index 0000000000..c97816b08b --- /dev/null +++ b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java @@ -0,0 +1,53 @@ +package org.biojava.nbio.protmod.phosphosite; + +import junit.framework.TestCase; +import org.biojava.nbio.phosphosite.Dataset; +import org.biojava.nbio.phosphosite.Site; + +import java.io.File; +import java.net.URL; +import java.util.List; + +/** + * Created by andreas on 11/29/16. + */ +public class TestAcetylation extends TestCase { + + + /** Tests that the acetylation file can get downloaded and parsed + * + */ + public void testAcetylation() { + String f = Dataset.ACETYLATION; + + Dataset ds = new Dataset(); + + try { + File localDir = ds.getLocalDir(); + int slashIndex = f.lastIndexOf("/"); + + String fileName = f.substring(slashIndex); + + File localFile = new File(localDir + "/" + fileName); + + if (!localFile.exists()) { + ds.downloadFile(new URL(f), localFile); + } + + List sites = Site.parseSites(localFile); + + assertTrue(sites.size() > 0); + + for (Site s : sites) { + + assertTrue(s.getResidue() != null); + + } + + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +} From 41452233e47969f57fb526dd3f0f6cec01b9c229 Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Tue, 29 Nov 2016 11:19:04 -0500 Subject: [PATCH 23/28] creating local dir, if it does not exist. --- .../org/biojava/nbio/protmod/phosphosite/TestAcetylation.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java index c97816b08b..e32210e2c9 100644 --- a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java +++ b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java @@ -24,6 +24,9 @@ public void testAcetylation() { try { File localDir = ds.getLocalDir(); + if ( ! localDir.exists()) + localDir.mkdir(); + int slashIndex = f.lastIndexOf("/"); String fileName = f.substring(slashIndex); From ad609024e040523f64d1758d65b28cd161cdd9dc Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Tue, 29 Nov 2016 22:42:26 -0500 Subject: [PATCH 24/28] #610 switching test to junit version 4 --- .../protmod/phosphosite/TestAcetylation.java | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java index e32210e2c9..fd2c009fb2 100644 --- a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java +++ b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java @@ -1,41 +1,80 @@ package org.biojava.nbio.protmod.phosphosite; -import junit.framework.TestCase; + import org.biojava.nbio.phosphosite.Dataset; import org.biojava.nbio.phosphosite.Site; +import org.junit.Before; +import org.junit.Test; import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.List; -/** +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** Makes sure there is a local installation of the Acetyaltion site file from Phosphosite and + * tests if it can get parsed by the parser. + * * Created by andreas on 11/29/16. */ -public class TestAcetylation extends TestCase { +public class TestAcetylation { - /** Tests that the acetylation file can get downloaded and parsed + /** Make sure an Acetylation file is available locally. + * Downloads from Phosphosite if needed. * */ - public void testAcetylation() { - String f = Dataset.ACETYLATION; + @Before + public void setUp(){ Dataset ds = new Dataset(); - try { - File localDir = ds.getLocalDir(); - if ( ! localDir.exists()) - localDir.mkdir(); - - int slashIndex = f.lastIndexOf("/"); - - String fileName = f.substring(slashIndex); + String f = Dataset.ACETYLATION; - File localFile = new File(localDir + "/" + fileName); + File localFile = getLocalFileName(f); + try { if (!localFile.exists()) { ds.downloadFile(new URL(f), localFile); } + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** returns the local file name where the Acetylation file will get cached locally. + * + * @param phosphoSiteFileLocation location of file at PhosphoSitePlus. + * @return a File pointing to the location of the locally cached file. + */ + private File getLocalFileName(String phosphoSiteFileLocation){ + + Dataset ds = new Dataset(); + File localDir = ds.getLocalDir(); + if ( ! localDir.exists()) { + boolean success = localDir.mkdir(); + if ( ! success) + fail("Could not create directory " + localDir.getAbsolutePath()); + } + + int slashIndex = phosphoSiteFileLocation.lastIndexOf("/"); + + String fileName = phosphoSiteFileLocation.substring(slashIndex); + + return new File(localDir + "/" + fileName); + } + + /** Tests that the acetylation file can get parsed without problems. + * + */ + @Test + public void testAcetylation() { + + try { + + File localFile = getLocalFileName(Dataset.ACETYLATION); List sites = Site.parseSites(localFile); From f15e4cfbee16448f81cb2c62f9bd8e98231c89ee Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Wed, 30 Nov 2016 09:38:43 -0500 Subject: [PATCH 25/28] now also accepting old header line --- .../src/main/java/org/biojava/nbio/phosphosite/Site.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java index 906489c9ea..ca5e4a5f2f 100644 --- a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java +++ b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Site.java @@ -65,7 +65,8 @@ public static List parseSites(File f) throws IOException { while ((line = buf.readLine()) != null){ - if ( line.startsWith("GENE")) { + if ( line.startsWith("GENE") || + line.startsWith("PROTEIN")) { headerFields = parseHeaderFields(line); From aae364beb7b1c912c0008a78db4cd847fda94a61 Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Wed, 30 Nov 2016 11:14:42 -0500 Subject: [PATCH 26/28] moving to Java 7 --- .../org/biojava/nbio/phosphosite/Dataset.java | 49 +++++-------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java index cae8227f35..ec65c2385a 100644 --- a/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java +++ b/biojava-modfinder/src/main/java/org/biojava/nbio/phosphosite/Dataset.java @@ -21,10 +21,14 @@ package org.biojava.nbio.phosphosite; import org.biojava.nbio.structure.align.util.AtomCache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.net.URL; import java.nio.channels.FileChannel; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; @@ -43,6 +47,7 @@ */ public class Dataset { + private static final Logger logger = LoggerFactory.getLogger(Dataset.class); public static final String ACETYLATION = "http://www.phosphosite.org/downloads/Acetylation_site_dataset.gz"; @@ -110,8 +115,8 @@ public File getLocalDir(){ public void download(){ - System.out.println("Downloading data from www.phosposite.org. Data is under CC-BY-NC-SA license. Please link to site and cite: "); - System.out.println("Hornbeck PV, Kornhauser JM, Tkachev S, Zhang B, Skrzypek E, Murray B, Latham V, Sullivan M (2012) PhosphoSitePlus: a comprehensive resource for investigating the structure and function of experimentally determined post-translational modifications in man and mouse. Nucleic Acids Res. 40(Database issue), D261–70."); + logger.warn("Downloading data from www.phosposite.org. Data is under CC-BY-NC-SA license. Please link to site and cite: "); + logger.warn("Hornbeck PV, Kornhauser JM, Tkachev S, Zhang B, Skrzypek E, Murray B, Latham V, Sullivan M (2012) PhosphoSitePlus: a comprehensive resource for investigating the structure and function of experimentally determined post-translational modifications in man and mouse. Nucleic Acids Res. 40(Database issue), D261–70."); File dir = getLocalDir(); @@ -156,7 +161,7 @@ public void download(){ public void downloadFile(URL u, File localFile) throws IOException { - System.out.println("Downloading " + u); + logger.info("Downloading " + u); File tmp = File.createTempFile("tmp","phosphosite"); @@ -185,37 +190,8 @@ public void downloadFile(URL u, File localFile) throws IOException { public static void copyFile(File src, File dst) throws IOException { - // TODO: upgrade to Java 7: + Files.copy(src.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING); - // Files.copy(src.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING); - - - - long p = 0, dp, size; - FileChannel in = null, out = null; - - try - { - if (!dst.exists()) dst.createNewFile(); - - in = new FileInputStream(src).getChannel(); - out = new FileOutputStream(dst).getChannel(); - size = in.size(); - - while ((dp = out.transferFrom(in, p, size)) > 0) - { - p += dp; - } - } - finally { - try - { - if (out != null) out.close(); - } - finally { - if (in != null) in.close(); - } - } } @@ -227,17 +203,16 @@ public static void main(String[] args) { try { - for (File f : ds.getLocalFiles()) { - System.out.println(f.getAbsoluteFile()); + logger.info(f.getAbsolutePath()); List sites = Site.parseSites(f); - System.out.println("Got " + sites.size() + " sites"); + logger.info("Got " + sites.size() + " sites"); for (Site s : sites) { if (s.getUniprot().equals("P50225") || s.getUniprot().equals("P48025")) { - System.out.println(s); + logger.info(s.toString()); } } From 4c6c348ea649adf378bd7467638e3d31e77aaee3 Mon Sep 17 00:00:00 2001 From: Andreas Prlic Date: Wed, 30 Nov 2016 11:15:18 -0500 Subject: [PATCH 27/28] addressing requested changes re. throwing exceptions. --- .../protmod/phosphosite/TestAcetylation.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java index fd2c009fb2..fea66a55b3 100644 --- a/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java +++ b/biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java @@ -14,7 +14,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -/** Makes sure there is a local installation of the Acetyaltion site file from Phosphosite and + +/** Makes sure there is a local installation of the Acetylation site file from Phosphosite and * tests if it can get parsed by the parser. * * Created by andreas on 11/29/16. @@ -27,7 +28,7 @@ public class TestAcetylation { * */ @Before - public void setUp(){ + public void setUp() throws IOException{ Dataset ds = new Dataset(); @@ -35,13 +36,10 @@ public void setUp(){ File localFile = getLocalFileName(f); - try { - if (!localFile.exists()) { - ds.downloadFile(new URL(f), localFile); - } - } catch (IOException e) { - e.printStackTrace(); + if (!localFile.exists()) { + ds.downloadFile(new URL(f), localFile); } + } /** returns the local file name where the Acetylation file will get cached locally. @@ -70,26 +68,19 @@ private File getLocalFileName(String phosphoSiteFileLocation){ * */ @Test - public void testAcetylation() { - - try { + public void testAcetylation() throws IOException { - File localFile = getLocalFileName(Dataset.ACETYLATION); + File localFile = getLocalFileName(Dataset.ACETYLATION); - List sites = Site.parseSites(localFile); + List sites = Site.parseSites(localFile); - assertTrue(sites.size() > 0); + assertTrue(sites.size() > 0); - for (Site s : sites) { + for (Site s : sites) { - assertTrue(s.getResidue() != null); + assertTrue(s.getResidue() != null); - } - - - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); } + } } From 4db283220ad5a6defaf124f731f9ea205947e3c5 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Wed, 7 Dec 2016 11:22:59 -0800 Subject: [PATCH 28/28] [maven-release-plugin]prepare release biojava-4.2.5 --- biojava-aa-prop/pom.xml | 6 +++--- biojava-alignment/pom.xml | 6 +++--- biojava-core/pom.xml | 2 +- biojava-genome/pom.xml | 6 +++--- biojava-integrationtest/pom.xml | 4 ++-- biojava-modfinder/pom.xml | 4 ++-- biojava-ontology/pom.xml | 2 +- biojava-phylo/pom.xml | 4 ++-- biojava-protein-disorder/pom.xml | 4 ++-- biojava-sequencing/pom.xml | 4 ++-- biojava-structure-gui/pom.xml | 6 +++--- biojava-structure/pom.xml | 6 +++--- biojava-survival/pom.xml | 2 +- biojava-ws/pom.xml | 4 ++-- pom.xml | 4 ++-- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/biojava-aa-prop/pom.xml b/biojava-aa-prop/pom.xml index a4b6b60374..5c35a618b8 100644 --- a/biojava-aa-prop/pom.xml +++ b/biojava-aa-prop/pom.xml @@ -2,7 +2,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-aa-prop @@ -70,12 +70,12 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 org.biojava biojava-structure - 4.2.5-SNAPSHOT + 4.2.5 diff --git a/biojava-alignment/pom.xml b/biojava-alignment/pom.xml index ab8e9e3cec..d42f48f857 100644 --- a/biojava-alignment/pom.xml +++ b/biojava-alignment/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-alignment biojava-alignment @@ -46,7 +46,7 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile @@ -74,7 +74,7 @@ org.biojava biojava-phylo - 4.2.5-SNAPSHOT + 4.2.5 diff --git a/biojava-core/pom.xml b/biojava-core/pom.xml index c4b2b407df..80cab2a58a 100644 --- a/biojava-core/pom.xml +++ b/biojava-core/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-core diff --git a/biojava-genome/pom.xml b/biojava-genome/pom.xml index 4552573e26..93ca9d0423 100644 --- a/biojava-genome/pom.xml +++ b/biojava-genome/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-genome @@ -85,13 +85,13 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile org.biojava biojava-alignment - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/biojava-integrationtest/pom.xml b/biojava-integrationtest/pom.xml index c6d9a9e7fa..82703c0da0 100644 --- a/biojava-integrationtest/pom.xml +++ b/biojava-integrationtest/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-integrationtest jar @@ -32,7 +32,7 @@ org.biojava biojava-structure - 4.2.5-SNAPSHOT + 4.2.5 diff --git a/biojava-modfinder/pom.xml b/biojava-modfinder/pom.xml index c5d41b753e..a1f7b57970 100644 --- a/biojava-modfinder/pom.xml +++ b/biojava-modfinder/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-modfinder biojava-modfinder @@ -31,7 +31,7 @@ org.biojava biojava-structure - 4.2.5-SNAPSHOT + 4.2.5 jar compile diff --git a/biojava-ontology/pom.xml b/biojava-ontology/pom.xml index bf8d7cdd86..441b3bded0 100644 --- a/biojava-ontology/pom.xml +++ b/biojava-ontology/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-ontology diff --git a/biojava-phylo/pom.xml b/biojava-phylo/pom.xml index 44c7aea53f..affe865373 100644 --- a/biojava-phylo/pom.xml +++ b/biojava-phylo/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-phylo @@ -44,7 +44,7 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/biojava-protein-disorder/pom.xml b/biojava-protein-disorder/pom.xml index 39745c4f5b..9e12925676 100644 --- a/biojava-protein-disorder/pom.xml +++ b/biojava-protein-disorder/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-protein-disorder jar @@ -63,7 +63,7 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 diff --git a/biojava-sequencing/pom.xml b/biojava-sequencing/pom.xml index a565923bb3..eb65c46b23 100644 --- a/biojava-sequencing/pom.xml +++ b/biojava-sequencing/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-sequencing @@ -47,7 +47,7 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/biojava-structure-gui/pom.xml b/biojava-structure-gui/pom.xml index a3e13fbddb..d5b18c9e14 100644 --- a/biojava-structure-gui/pom.xml +++ b/biojava-structure-gui/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 4.0.0 biojava-structure-gui @@ -25,13 +25,13 @@ org.biojava biojava-structure - 4.2.5-SNAPSHOT + 4.2.5 compile org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/biojava-structure/pom.xml b/biojava-structure/pom.xml index 49740713a5..0be0265a08 100644 --- a/biojava-structure/pom.xml +++ b/biojava-structure/pom.xml @@ -4,7 +4,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-structure biojava-structure @@ -22,13 +22,13 @@ org.biojava biojava-alignment - 4.2.5-SNAPSHOT + 4.2.5 compile org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/biojava-survival/pom.xml b/biojava-survival/pom.xml index 37d9658cbb..d7c072c558 100644 --- a/biojava-survival/pom.xml +++ b/biojava-survival/pom.xml @@ -4,7 +4,7 @@ org.biojava biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-survival diff --git a/biojava-ws/pom.xml b/biojava-ws/pom.xml index 2376dc7e81..490d79c32d 100644 --- a/biojava-ws/pom.xml +++ b/biojava-ws/pom.xml @@ -3,7 +3,7 @@ biojava org.biojava - 4.2.5-SNAPSHOT + 4.2.5 biojava-ws biojava-ws @@ -19,7 +19,7 @@ org.biojava biojava-core - 4.2.5-SNAPSHOT + 4.2.5 compile diff --git a/pom.xml b/pom.xml index 9895994a7c..e1daf1fcea 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.biojava biojava pom - 4.2.5-SNAPSHOT + 4.2.5 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.1 + biojava-4.2.5