Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating repo so that classes extend/implement those defined at bio4j main repository #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description := "Neo4jdb implementation of the Bio4j model"
bucketSuffix := "era7.com"

libraryDependencies ++= Seq(
"bio4j" % "bio4j" % "0.11.0",
"bio4j" % "bio4j" % "0.12.0-SNAPSHOT",
"org.neo4j" % "neo4j" % "1.9.6",
"com.amazonaws" % "aws-java-sdk" % "1.6.12",
"org.apache.httpcomponents" % "httpclient" % "4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bio4j/neo4j/BasicRelationship.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author ppareja
*/
public abstract class BasicRelationship implements RelationshipType{
public abstract class BasicRelationship implements RelationshipType {

protected Relationship relationship = null;

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/bio4j/neo4j/Bio4jRelationshipType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bio4j.neo4jdb;

import org.neo4j.graphdb.RelationshipType;

public enum Bio4jRelationshipType implements RelationshipType {

NewTaxonParentRel
// add all rel types here
}
110 changes: 110 additions & 0 deletions src/main/java/com/bio4j/neo4j/Neo4jNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.bio4j.neo4jdb;

import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.ReturnableEvaluator;
import org.neo4j.graphdb.StopEvaluator;
import org.neo4j.graphdb.Traverser;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.kernel.Traversal;

public class Neo4jNode extends Neo4jPropertyContainer implements TypedNeo4jNode, com.bio4j.model.Node {

/*
The wrapped Neo4j node
*/
protected final Node wrapped;
public Node getNode(){ return wrapped; }

protected Neo4jNode(Node n, String type) { wrapped = n; this.setType(type); }

private void setType(String type) { this.setProperty(this.NODE_TYPE_PROPERTY, type); }
@Override
public String getType() { return String.valueOf(getProperty(NODE_TYPE_PROPERTY)); }

public long getId() {
return wrapped.getId();
}
public void delete() {
wrapped.delete();
}
public Iterable<Relationship> getRelationships() {
return wrapped.getRelationships();
}
public boolean hasRelationship() {
return wrapped.hasRelationship();
}
public Iterable<Relationship> getRelationships( RelationshipType... types ) {
return wrapped.getRelationships(types);
}
public Iterable<Relationship> getRelationships( Direction direction, RelationshipType... types ) {
return wrapped.getRelationships(direction, types);
}
public boolean hasRelationship( RelationshipType... types ) {
return wrapped.hasRelationship(types);
}
public boolean hasRelationship( Direction direction, RelationshipType... types ) {
return wrapped.hasRelationship(direction, types);
}
public Iterable<Relationship> getRelationships( Direction dir ) {
return wrapped.getRelationships(dir);
}
public boolean hasRelationship( Direction dir ) {
return wrapped.hasRelationship(dir);
}
public Iterable<Relationship> getRelationships( RelationshipType type, Direction dir ) {
return wrapped.getRelationships(type, dir);
}
public boolean hasRelationship( RelationshipType type, Direction dir ) {
return wrapped.hasRelationship(type, dir);
}
public Relationship getSingleRelationship( RelationshipType type, Direction dir ) {
return wrapped.getSingleRelationship(type, dir);
}
public Relationship createRelationshipTo( Node otherNode, RelationshipType type ) {
return wrapped.createRelationshipTo(otherNode, type);
}
@Deprecated
public Traverser traverse(
Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
RelationshipType relationshipType, Direction direction
) {
return wrapped.traverse(traversalOrder, stopEvaluator, returnableEvaluator, relationshipType, direction);
}
@Deprecated
public Traverser traverse(
Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
RelationshipType firstRelationshipType, Direction firstDirection,
RelationshipType secondRelationshipType, Direction secondDirection
) {
return wrapped.traverse(
traversalOrder,
stopEvaluator,
returnableEvaluator,
firstRelationshipType,
firstDirection,
secondRelationshipType,
secondDirection
);
}
@Deprecated
public Traverser traverse(
Traverser.Order traversalOrder,
StopEvaluator stopEvaluator,
ReturnableEvaluator returnableEvaluator,
Object... relationshipTypesAndDirections
) {
return wrapped.traverse(
traversalOrder,
stopEvaluator,
returnableEvaluator,
relationshipTypesAndDirections
);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/bio4j/neo4j/Neo4jPropertyContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bio4j.neo4jdb;

import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.GraphDatabaseService;

public abstract class Neo4jPropertyContainer implements PropertyContainer {

protected PropertyContainer wrapped;

public GraphDatabaseService getGraphDatabase() { return wrapped.getGraphDatabase(); }
public boolean hasProperty( String key ) { return wrapped.hasProperty(key); }
public Object getProperty( String key ){ return wrapped.getProperty(key); }
public Object getProperty( String key, Object defaultValue ) { return wrapped.getProperty(key, defaultValue); }
public void setProperty( String key, Object value ) { wrapped.setProperty(key, value); }
public Object removeProperty( String key ) { return wrapped.removeProperty(key); }
public Iterable<String> getPropertyKeys() { return wrapped.getPropertyKeys(); }
@Deprecated
public Iterable<Object> getPropertyValues() { return wrapped.getPropertyValues(); }
}
35 changes: 35 additions & 0 deletions src/main/java/com/bio4j/neo4j/Neo4jRelationship.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.bio4j.neo4jdb;

import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Node;

/*
*
* @author Eduardo Pareja-Tobes <@[email protected]>
*/
public abstract class Neo4jRelationship extends Neo4jPropertyContainer implements
com.bio4j.model.Relationship, org.neo4j.graphdb.Relationship {

/*
The relationship type should be accessible from the class
*/
public static Bio4jRelationshipType type;

protected final Relationship wrapped;

protected Neo4jRelationship(Relationship r) { wrapped = r; }

// Neo4j rel
public long getId() { return wrapped.getId(); }
public void delete() { wrapped.delete(); }
public Node getStartNode() { return wrapped.getStartNode(); }
public Node getEndNode() { return wrapped.getEndNode(); }
public Node getOtherNode( Node node ) { return wrapped.getOtherNode(node); }
public Node[] getNodes() { return wrapped.getNodes(); }
public RelationshipType getType() { return wrapped.getType(); }
public boolean isType( RelationshipType type ) { return wrapped.isType(type); }

// Bio4j model rel
public String type() { return wrapped.getType().toString(); }
}
8 changes: 8 additions & 0 deletions src/main/java/com/bio4j/neo4j/TypedNeo4jNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bio4j.neo4jdb;

public interface TypedNeo4jNode extends org.neo4j.graphdb.Node, com.bio4j.model.Node {

public static final String NODE_TYPE_PROPERTY = "nodeType";
// public String getNodeType();

}
2 changes: 1 addition & 1 deletion src/main/java/com/bio4j/neo4j/model/nodes/CityNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Just nodes representing different cities of the world
* @author Pablo Pareja Tobes <[email protected]>
*/
public class CityNode extends BasicEntity{
public class CityNode extends BasicEntity {

public static final String NODE_TYPE = CityNode.class.getCanonicalName();
public static final String CITY_NAME_INDEX = "city_name_index";
Expand Down
121 changes: 121 additions & 0 deletions src/main/java/com/bio4j/neo4j/model/nodes/NewTaxonNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.bio4j.neo4jdb.model.nodes;

import com.bio4j.neo4jdb.Neo4jNode;
import com.bio4j.neo4jdb.TypedNeo4jNode;

import com.bio4j.neo4jdb.model.relationships.NewTaxonParentRel;
import com.bio4j.model.nodes.Taxon;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

/**
* Uniprot taxonomy taxon
* @author Pablo Pareja Tobes <[email protected]>
*/
public final class NewTaxonNode extends Neo4jNode implements com.bio4j.model.nodes.Taxon {

// node type
public static final String NODE_TYPE = NewTaxonNode.class.getCanonicalName();

// properties and their getters/setters
public static final String NAME_PROPERTY = "taxon_name";
public String getName(){ return String.valueOf(getProperty(NAME_PROPERTY)); }
public void setName(String value){ setProperty(NAME_PROPERTY, value); }

// indexes
public static final String TAXON_NAME_INDEX = "taxon_name_index";


public NewTaxonNode(Node n){ super(n, NODE_TYPE); }

// methods
public NewTaxonNode getParent() {

NewTaxonNode parent = null;

Iterator<Relationship> iterator =
getRelationships(NewTaxonParentRel.type, Direction.INCOMING).iterator();

if(iterator.hasNext()){

parent = new NewTaxonNode(iterator.next().getStartNode());
}

return parent;
}

/**
*
* @return A list holding the taxon children of the current node
*/
public List<NewTaxonNode> getChildren() {

List<NewTaxonNode> list = new ArrayList<NewTaxonNode>();

Iterator<Relationship> iterator =
getRelationships(NewTaxonParentRel.type, Direction.OUTGOING).iterator();

while(iterator.hasNext()) {

Node tempNode = iterator.next().getEndNode();

if(tempNode.getProperty(TypedNeo4jNode.NODE_TYPE_PROPERTY).equals(NewTaxonNode.NODE_TYPE)) {

list.add( new NewTaxonNode(tempNode) );
}
}

return list;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// modify accordingly /////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*
* @return The organisms associated to the current node
*/
public List<OrganismNode> getOrganisms(){

List<OrganismNode> list = new ArrayList<OrganismNode>();

Iterator<Relationship> iterator = getRelationships(NewTaxonParentRel.type, Direction.OUTGOING).iterator();

while(iterator.hasNext()){
Node tempNode = iterator.next().getEndNode();
if(tempNode.getProperty(com.bio4j.neo4jdb.BasicEntity.NODE_TYPE_PROPERTY).equals(OrganismNode.NODE_TYPE)){
list.add(new OrganismNode(tempNode));
}
}

return list;
}
@Override
public int hashCode(){
return super.hashCode();
}

@Override
public boolean equals(Object obj) {

if(obj instanceof NewTaxonNode){
NewTaxonNode other = (NewTaxonNode) obj;
return this.wrapped.equals(other.wrapped);
} else {
return false;
}
}

@Override
public String toString(){
return "name = " + getName();
}

}
3 changes: 1 addition & 2 deletions src/main/java/com/bio4j/neo4j/model/nodes/TaxonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public TaxonNode(Node n){
super(n);
}


public String getName(){ return String.valueOf(node.getProperty(NAME_PROPERTY));}
public String getName(){ return String.valueOf(node.getProperty(NAME_PROPERTY));}


public void setName(String value){ node.setProperty(NAME_PROPERTY, value);}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bio4j.neo4jdb.model.relationships;

import com.bio4j.neo4jdb.Neo4jRelationship;
import org.neo4j.graphdb.Relationship;
import com.bio4j.neo4jdb.Bio4jRelationshipType;

import com.bio4j.model.relationships.TaxonParent;

/**
*
* @author Pablo Pareja Tobes <[email protected]>
*/
public class NewTaxonParentRel extends Neo4jRelationship implements TaxonParent {

public static Bio4jRelationshipType type = Bio4jRelationshipType.NewTaxonParentRel;
// public static final String NAME = "TAXON_PARENT";

public NewTaxonParentRel(Relationship rel){
super(rel);
}

}
4 changes: 0 additions & 4 deletions src/main/java/com/bio4j/neo4j/model/util/Bio4jManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.bio4j.neo4jdb.model.util;

import com.bio4j.neo4jdb.model.nodes.*;
Expand Down