Skip to content

Commit

Permalink
A new executable module for beam command line utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Apr 5, 2015
1 parent 1f84c9d commit 8132b04
Show file tree
Hide file tree
Showing 12 changed files with 680 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exec/make-stub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

# Builds self contained unix executable
cat ${DIR}/src/main/resources/stub.sh ${DIR}/target/beam.jar > ${DIR}/target/beam && chmod +x ${DIR}/target/beam
cp ${DIR}/target/beam /usr/local/bin/beam
65 changes: 65 additions & 0 deletions exec/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2015. NextMove Software Ltd
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>0.9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>beam-exec</artifactId>

<dependencies>
<dependency>
<groupId>uk.ac.ebi.beam</groupId>
<artifactId>beam-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>uk.ac.ebi.beam</groupId>
<artifactId>beam-func</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>4.8</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>beam</id>
<configuration>
<archive>
<manifest>
<mainClass>uk.ac.ebi.beam.Main</mainClass>
</manifest>
</archive>
<finalName>beam</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
66 changes: 66 additions & 0 deletions exec/src/main/java/uk/ac/ebi/beam/Anonymise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2015. John May
*/

package uk.ac.ebi.beam;

import joptsimple.OptionSet;

/**
* Anonymise SMILES input to all '*' atoms. Bond orders can optionally be emitted.
*/
public final class Anonymise extends FunctorCmdLnModule {

private final Atom UNKN_ATOM = AtomImpl.AliphaticSubset.Unknown;

public Anonymise() {
super("anon");
super.optparser.accepts("bo", "keep bond orders");
}

@Override
Functor createFunctor(OptionSet optionSet) {
final boolean bondorders = optionSet.has("bo");
return new Functor() {
@Override
String map(String str) throws InvalidSmilesException {

Graph g = Graph.fromSmiles(str);

if (bondorders)
g = g.kekule();

final GraphBuilder gb = GraphBuilder.create(g.order());

for (int v = 0; v < g.order(); v++) {
gb.add(UNKN_ATOM);
for (Edge e : g.edges(v)) {
if (e.other(v) < v) {
if (bondorders)
gb.add(new Edge(v, e.other(v), bondForOrder(e.bond().order())));
else
gb.add(new Edge(v, e.other(v), Bond.IMPLICIT));
}
}
}

return gb.build().toSmiles() + suffixedId(str);
}
};
}

private Bond bondForOrder(int ord) {
switch (ord) {
case 1:
return Bond.IMPLICIT;
case 2:
return Bond.DOUBLE;
case 3:
return Bond.TRIPLE;
case 4:
return Bond.QUADRUPLE;
default:
return Bond.IMPLICIT;
}
}
}
28 changes: 28 additions & 0 deletions exec/src/main/java/uk/ac/ebi/beam/Aromatise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2015. John May
*/

package uk.ac.ebi.beam;

import joptsimple.OptionSet;

/**
* Simple module simply Kekulises then emits and normalised
* (by beam's model) aromatic form of the SMILES.
*/
public final class Aromatise extends FunctorCmdLnModule {

public Aromatise() {
super("arom");
}

@Override
Functor createFunctor(OptionSet optionSet) {
return new Functor() {
@Override
String map(String str) throws InvalidSmilesException {
return Graph.fromSmiles(str).kekule().aromatic().toSmiles() + suffixedId(str);
}
};
}
}
41 changes: 41 additions & 0 deletions exec/src/main/java/uk/ac/ebi/beam/CmdLnModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2015. John May
*/

package uk.ac.ebi.beam;

/**
* A plugable command line module providing functionality
* from the primary dispatch {@link Main}. Modules should
* be implemented and added to an SPI
* (META-INF/services/uk.ac.ebi.beam.CmdLnModule).
*
* @see <a href="https://docs.oracle.com/javase/tutorial/ext/basics/spi.html">SPI</a>
*/
public interface CmdLnModule {

/**
* The module name is a concise, often abbreviated, description
* of the module function. It is used to reference the
* functionality from the primary dispatch:
* <pre>{@code $ beam {module.name} {module.args}}</pre>
*
* @return module name
*/
String name();

/**
* Displays the usage/help for this module.
*
* @return help info
*/
String getHelpInfo();

/**
* Executes the module with the specified arguments. The
* arguments do not include the module name.
*
* @param args command line arguments
*/
void exec(String[] args);
}
Loading

2 comments on commit 8132b04

@hilmanIbnu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sir, how can I output the graph representation after convert it from smiles?

@johnmay
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by graph representation? Draw an image or just list the atoms at bonds?

Please sign in to comment.