Skip to content

Commit

Permalink
Merge pull request #7 from CIDARLAB/LookupTable
Browse files Browse the repository at this point in the history
Lookup table
shamseen authored Jul 24, 2017
2 parents 7504f9a + c52764b commit c7b0e75
Showing 7 changed files with 1,220 additions and 769 deletions.
302 changes: 151 additions & 151 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,194 +1,194 @@
<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">
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">

<modelVersion>4.0.0</modelVersion>
<groupId>org.cidarlab</groupId>
<artifactId>eugene</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<groupId>org.cidarlab</groupId>
<artifactId>eugene</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
<resources>
<build>
<resources>

<!-- Rule-files for JBoss Drools ``Sparrow'' -->
<resource>
<directory>src/main/rules</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<!-- Rule-files for JBoss Drools ``Sparrow'' -->
<resource>
<directory>src/main/rules</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>


<plugins>
<plugins>

<!-- Packing Eugene v2.0 including all dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.cidarlab.eugene.Eugene</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Packing Eugene v2.0 including all dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.cidarlab.eugene.Eugene</mainClass>
</manifest>
</archive>
</configuration>
</plugin>


<!-- Packaging Eugene v2.0 w/o dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.cidarlab.eugene.Eugene</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Packaging Eugene v2.0 w/o dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.cidarlab.eugene.Eugene</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<!-- Maven - Java compiler - Java7 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Maven - Java compiler - Java7 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

</plugins>
</build>
</plugins>
</build>


<!-- REPOSITORIES for downloading dependencies
on libSBOLj and BioJava
-->
<repositories>
on libSBOLj and BioJava
-->
<repositories>
<repository>
<id>Sonatype OSS Snapshot Repository</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<repository>
<id>biojava-maven-repo</id>
<name>BioJava repository</name>
<url>http://www.biojava.org/download/maven/</url>
</repository>
<id>biojava-maven-repo</id>
<name>BioJava repository</name>
<url>http://www.biojava.org/download/maven/</url>
</repository>
</repositories>


<!-- DEPENDENCIES -->
<dependencies>
<dependencies>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>uk.com.robust-it</groupId>
<artifactId>cloning</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>uk.com.robust-it</groupId>
<artifactId>cloning</artifactId>
<version>1.7.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

<!-- JUNit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<!-- JUNit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>

<!-- DROOLS dependencies -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-templates</artifactId>
<version>5.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
<version>5.6.0.Final</version>
</dependency>
<!-- DROOLS dependencies -->
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-templates</artifactId>
<version>5.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>knowledge-api</artifactId>
<version>5.6.0.Final</version>
</dependency>

<!-- ALL HAIL SBOL -->
<dependency>
<!-- ALL HAIL SBOL -->
<dependency>
<groupId>org.sbolstandard</groupId>
<artifactId>libSBOLj</artifactId>
<version>0.7.0-SNAPSHOT</version>
</dependency>


<!-- miniEugene-core dependency -->
<dependency>
<groupId>org.cidarlab</groupId>
<artifactId>miniEugene-core</artifactId>
<version>1.0</version>
</dependency>
<!-- miniEugene-core dependency -->
<dependency>
<groupId>org.cidarlab</groupId>
<artifactId>miniEugene-core</artifactId>
<version>1.0</version>
</dependency>

<!-- JaCoP Constraint Solver -->
<dependency>
<groupId>org.jacop</groupId>
<artifactId>jacop</artifactId>
<version>4.4.0</version>
</dependency>
<!-- JaCoP Constraint Solver -->
<dependency>
<groupId>org.jacop</groupId>
<artifactId>jacop</artifactId>
<version>4.4.0</version>
</dependency>

<!-- BioJava -->
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava3-core</artifactId>
<version>3.0</version>
</dependency>
<!-- BioJava -->
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava3-core</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>org.biojava</groupId>
<artifactId>core</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>core</artifactId>
<version>1.9.0</version>
</dependency>

<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>

</dependencies>
<!-- MongoDB driver for mLab -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
</project>
893 changes: 465 additions & 428 deletions src/main/java/org/cidarlab/eugene/data/sbol/mapping/Eugene2SBOL.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.cidarlab.eugene.data.sbol.mapping.sbolConversionAPI;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import org.bson.Document;

/**
*
* @author Shamseen Rahman <shamseen at bu.edu>
*/
public class MongoConnection {

private MongoClient client;
private MongoDatabase db;

public MongoConnection() {
}

// TO DO: ERROR HANDLING ------------------------------------------------------
public MongoCollection getCollection(String colName) {
MongoCollection<Document> collection = db.getCollection(colName);
return collection;
}

public MongoIterable<String> getCollectionNames() {
// Document retVal = db.runCommand(new Document("listCollections", 1));
MongoIterable<String> retVal = db.listCollectionNames();

return retVal;
}

public void login(String user, String pw) throws Exception {
if (user == null || pw == null) {
}
// To connect to mongodb server
String uri = String.format("mongodb://%s:%s@ds153412.mlab.com:53412/lookuptables", user, pw);

MongoCredential mongoCredential = MongoCredential.createScramSha1Credential("admin", "admin",
"admin123".toCharArray());
MongoClientURI connectionString = new MongoClientURI(uri);
client = new MongoClient(connectionString);
db = client.getDatabase("lookuptables");
System.out.println("Connected to database successfully!");
//boolean auth = db.authenticate(myUserName, myPassword);
//System.out.println("Authentication: "+auth);

}

public void logout() {
client.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.cidarlab.eugene.data.sbol.mapping.sbolConversionAPI;

/**
*
* @author Shamseen Rahman <shamseen at bu.edu>
*/
public class SBOLConversionController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.cidarlab.eugene.data.sbol.mapping.sbolConversionAPI;

// MongoDB imports
import org.junit.After;
import org.junit.Before;
import com.mongodb.client.MongoCollection;
import static com.mongodb.client.model.Filters.eq;
import org.bson.Document;

// Java imports
import java.util.ArrayList;
import java.util.Arrays;

/**
* SBOLConversionDataLayer connects to the LookupTables database (MongoDB) at
* https://mlab.com/databases/lookuptables .
*
* Performs two-way data exchange with the SBOL2Conversion collection.
*
* @author Shamseen Rahman <shamseen at bu.edu>
*/
public class SBOLConversionDataLayer {

private MongoConnection _instance;
private MongoCollection collection;
private Document doc;

public SBOLConversionDataLayer() {
setUp();
}

public ArrayList<String> getEugenePartNames(String so) {
ArrayList<String> names = new ArrayList<>();

if (findDocument(so)) {
names = (ArrayList) doc.get("eugenePartNames");
}

return names;
}

public void UpsertEugenePartName(String so, String name) {
if (findDocument(so)) {
updateSOTerm(so, name, true);
return;
}

Document d = new Document("sequenceOntologyNumber", so)
.append("eugenePartNames", Arrays.asList(name));

collection.insertOne(d);
}

public boolean removeEugenePartName(String so, String name) {
boolean retVal = true;

if (findDocument(so)) {
updateSOTerm(so, name, false);
}

return retVal;
}

private void updateSOTerm(String so, String name, boolean addName) {
ArrayList<String> names = (ArrayList) doc.get("eugenePartNames");

if (addName == names.contains(name)) {
return;
}

if (addName) {
names.add(name);
} else {
names.remove(name);
}

collection.updateOne(eq("sequenceOntologyNumber", so),
new Document("$set", new Document("eugenePartNames", names)));
}

private boolean findDocument(String so) {

doc = (Document) collection.find(eq("sequenceOntologyNumber", so)).first();

boolean retVal = doc != null;

return retVal;
}

@Before
private void setUp() {
_instance = new MongoConnection();

try {
_instance.login("shamseen", "lcp");
collection = _instance.getCollection("SBOL2Conversions");

} catch (Exception e) {
e.printStackTrace();
}
}

@After
private void tearDown() {
_instance.logout();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.cidarlab.eugene.data.sbol.mapping.sbolConversionAPI;

import java.net.URI;
import java.util.List;
import org.sbolstandard.core.util.SequenceOntology;

/**
*
* @author Shamseen Rahman <shamseen at bu.edu>
*/
public class SBOLConversionLogicLayer {

private SBOLConversionDataLayer _dataLayer;
private List<String> names;
private int uriIndex;
private String _so;

// TO DO: Error handling
public SBOLConversionLogicLayer() {
_dataLayer = new SBOLConversionDataLayer();
String uri = SequenceOntology.NAMESPACE.toString() + "SO_";
uriIndex = uri.length();
}

public void AddOrUpdateSO(String so, String name) {
takeSONumberFromURI(so);
insertOrUpdate(name);
}

public boolean DeleteEugenePartName(String so, String name) {
takeSONumberFromURI(so);
return deleteEugenePartName(name);
}

public List<String> GetEugeneNames(String so) {
takeSONumberFromURI(so);
getEugeneNames();
return names;
}

private boolean deleteEugenePartName(String name) {
boolean retVal = _dataLayer.removeEugenePartName(_so, name);
return retVal;
}

private void getEugeneNames() {
names = _dataLayer.getEugenePartNames(_so);
}

private void insertOrUpdate(String name) {
_dataLayer.UpsertEugenePartName(_so, name);
}

private void takeSONumberFromURI(String so) {
if (so.length() > uriIndex) {
so = so.substring(uriIndex);
}

_so = so;
}

}
544 changes: 354 additions & 190 deletions src/test/java/org/cidarlab/eugene/units/data/SBOLTest.java

Large diffs are not rendered by default.

0 comments on commit c7b0e75

Please sign in to comment.