-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new executable module for beam command line utils.
- Loading branch information
Showing
12 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.
8132b04
There was a problem hiding this comment.
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?
8132b04
There was a problem hiding this comment.
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?