Skip to content

Commit

Permalink
Better API, throw IOException publically.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Dec 28, 2017
1 parent a6cfdf6 commit a132332
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
24 changes: 13 additions & 11 deletions core/src/test/java/uk/ac/ebi/beam/GraphBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static uk.ac.ebi.beam.Configuration.DoubleBond.OPPOSITE;
Expand All @@ -42,7 +44,7 @@
public class GraphBuilderTest {

@Test
public void clockwise_parity() throws InvalidSmilesException {
public void clockwise_parity() throws IOException {

GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomBuilder.aliphatic("C").build())
Expand All @@ -64,7 +66,7 @@ public void clockwise_parity() throws InvalidSmilesException {
}

@Test
public void anticlockwise_parity() throws InvalidSmilesException {
public void anticlockwise_parity() throws IOException {

GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomBuilder.aliphatic("C").build())
Expand All @@ -86,7 +88,7 @@ public void anticlockwise_parity() throws InvalidSmilesException {
}

@Test
public void e_1_2_difluroethene() throws InvalidSmilesException {
public void e_1_2_difluroethene() throws IOException {
GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomImpl.AliphaticSubset.Fluorine)
.add(AtomImpl.AliphaticSubset.Carbon)
Expand All @@ -101,7 +103,7 @@ public void e_1_2_difluroethene() throws InvalidSmilesException {
}

@Test
public void z_1_2_difluroethene() throws InvalidSmilesException {
public void z_1_2_difluroethene() throws IOException {
GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomImpl.AliphaticSubset.Fluorine)
.add(AtomImpl.AliphaticSubset.Carbon)
Expand All @@ -117,7 +119,7 @@ public void z_1_2_difluroethene() throws InvalidSmilesException {


@Test
public void conjugated_consider_existing() throws InvalidSmilesException {
public void conjugated_consider_existing() throws IOException {
// the second configuration considers the existing configuration
GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomImpl.AliphaticSubset.Fluorine)
Expand All @@ -138,7 +140,7 @@ public void conjugated_consider_existing() throws InvalidSmilesException {
}

@Test
public void conjugated_resolve_conflict() throws InvalidSmilesException {
public void conjugated_resolve_conflict() throws IOException {
// assigning the second one first means we have to consider this
// on the first one
GraphBuilder gb = GraphBuilder.create(5);
Expand All @@ -160,7 +162,7 @@ public void conjugated_resolve_conflict() throws InvalidSmilesException {
}

@Test
public void conjugated_resolve_conflict2() throws InvalidSmilesException {
public void conjugated_resolve_conflict2() throws IOException {
// we assign the first, third then second - the second one cause
// a conflict and we must flip one of the others
GraphBuilder gb = GraphBuilder.create(5);
Expand Down Expand Up @@ -213,7 +215,7 @@ public void resolveConflict3() throws Exception {
}

@Test
public void all_trans_octatetraene() throws InvalidSmilesException {
public void all_trans_octatetraene() throws IOException {
GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomImpl.AliphaticSubset.Carbon)
.add(AtomImpl.AliphaticSubset.Carbon)
Expand All @@ -240,7 +242,7 @@ public void all_trans_octatetraene() throws InvalidSmilesException {
}

@Test(expected = IllegalArgumentException.class)
public void impossible_octatetraene() throws InvalidSmilesException {
public void impossible_octatetraene() throws IOException {
GraphBuilder gb = GraphBuilder.create(5);
Graph g = gb.add(AtomImpl.AliphaticSubset.Carbon)
.add(AtomImpl.AliphaticSubset.Carbon)
Expand Down Expand Up @@ -302,7 +304,7 @@ public void correctCyclicDb() {
}

@Test
public void suppress_benzene() throws InvalidSmilesException {
public void suppress_benzene() throws IOException {
GraphBuilder gb = GraphBuilder.create(5);
assertThat(gb.add(Element.Carbon, 1)
.add(Element.Carbon, 1)
Expand All @@ -320,7 +322,7 @@ public void suppress_benzene() throws InvalidSmilesException {
}

@Test
public void buildExtendedTetrahedral() throws InvalidSmilesException {
public void buildExtendedTetrahedral() throws IOException {
GraphBuilder gb = GraphBuilder.create(4);
gb = gb.add(Element.Carbon, 3)
.add(Element.Carbon, 1)
Expand Down
11 changes: 6 additions & 5 deletions core/src/test/java/uk/ac/ebi/beam/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -492,7 +493,7 @@ public void invalidPermutation() {
containsString("C1C[N@@]2CC[C@H]1C2"));
}

@Test public void cisplatin() throws InvalidSmilesException {
@Test public void cisplatin() throws IOException {
Graph g = Graph.fromSmiles("[NH3][Pt@SP1]([NH3])(Cl)Cl");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.SquarePlanar));
Expand All @@ -501,7 +502,7 @@ public void invalidPermutation() {
is("[NH3][Pt@SP3]([NH3])(Cl)Cl"));
}

@Test public void trigonalBipyramidal() throws InvalidSmilesException {
@Test public void trigonalBipyramidal() throws IOException {
Graph g = Graph.fromSmiles("S[As@TB1](F)(Cl)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
Expand All @@ -510,7 +511,7 @@ public void invalidPermutation() {
is("S[As@@](F)(Br)(Cl)N"));
}

@Test public void trigonalBipyramidal2() throws InvalidSmilesException {
@Test public void trigonalBipyramidal2() throws IOException {
Graph g = Graph.fromSmiles("S[As@TB2](F)(Cl)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
Expand All @@ -519,7 +520,7 @@ public void invalidPermutation() {
is("S[As@](F)(Br)(Cl)N"));
}

@Test public void trigonalBipyramidal15() throws InvalidSmilesException {
@Test public void trigonalBipyramidal15() throws IOException {
Graph g = Graph.fromSmiles("F[As@TB15](Cl)(S)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
Expand All @@ -528,7 +529,7 @@ public void invalidPermutation() {
is("F[As@TB17](Cl)(Br)(S)N"));
}

@Test public void octahedral1() throws InvalidSmilesException {
@Test public void octahedral1() throws IOException {
Graph g = Graph.fromSmiles("C[Co@](F)(Cl)(Br)(I)S");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.Octahedral));
Expand Down
4 changes: 3 additions & 1 deletion core/src/test/java/uk/ac/ebi/beam/LocaliseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -403,7 +405,7 @@ static void test(String delocalised, String localised) throws Exception {
}


@Test public void biphenylene() throws InvalidSmilesException
@Test public void biphenylene() throws IOException
{
String smi = "c1cccc2-c3ccccc3-c12";
assertThat(Graph.fromSmiles(smi).kekule().toSmiles(),
Expand Down
2 changes: 1 addition & 1 deletion exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 3 additions & 1 deletion exec/src/main/java/uk/ac/ebi/beam/Anonymise.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import joptsimple.OptionSet;

import java.io.IOException;

/**
* Anonymise SMILES input to all '*' atoms. Bond orders can optionally be emitted.
*/
Expand All @@ -23,7 +25,7 @@ Functor createFunctor(OptionSet optionSet) {
final boolean bondorders = optionSet.has("bo");
return new Functor() {
@Override
String map(String str) throws InvalidSmilesException {
String map(String str) throws IOException {

Graph g = Graph.fromSmiles(str);

Expand Down
4 changes: 3 additions & 1 deletion exec/src/main/java/uk/ac/ebi/beam/Aromatise.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import joptsimple.OptionSet;

import java.io.IOException;

/**
* Simple module simply Kekulises then emits and normalised
* (by beam's model) aromatic form of the SMILES.
Expand All @@ -20,7 +22,7 @@ public Aromatise() {
Functor createFunctor(OptionSet optionSet) {
return new Functor() {
@Override
String map(String str) throws InvalidSmilesException {
String map(String str) throws IOException {
return Graph.fromSmiles(str).kekule().aromatic().toSmiles() + suffixedId(str);
}
};
Expand Down
2 changes: 1 addition & 1 deletion exec/src/main/java/uk/ac/ebi/beam/FunctorCmdLnModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,6 @@ static String escapeForPrintf(String str) {
}

abstract class Functor {
abstract String map(String str) throws InvalidSmilesException;
abstract String map(String str) throws IOException;
}
}
2 changes: 1 addition & 1 deletion exec/src/main/java/uk/ac/ebi/beam/Shuffle.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void process(BufferedReader brdr, BufferedWriter bwtr, InputCounter counter, Opt
report("%d => %d\n", cnt, gencnt);
}

private Set<String> generate(String str, int n, int m) throws InvalidSmilesException {
private Set<String> generate(String str, int n, int m) throws IOException {

final Set<String> smis = new HashSet<String>();

Expand Down
2 changes: 1 addition & 1 deletion func/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>SMILES parsing and generation library for cheminformatics</description>
<url>http://www.github.com/johnmay/beam/</url>
<packaging>pom</packaging>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
<modules>
<module>core</module>
<module>func</module>
Expand Down

0 comments on commit a132332

Please sign in to comment.