// create personal graph in memory
// (Lomikel is a groovy class for accesss and manipulation of graphs)
graph1 = Lomikel.myGraph()
// create (or access) named graph "test" in the master HBase
// it is also possible to create graph in another HBase
//graph1 = Lomikel.myGraph('test')
// get access to this graph
g1 = graph1.traversal()
// you may want to define a schema for some elements in g1
// for example, if those elements have array types (List or Set)
// or if you want create an index on them
mgmt1 = graph1.openManagement()
PCA = mgmt1.makeVertexLabel('PCA').make()
pca00 = mgmt1.makePropertyKey('pca00').dataType(Double.class).cardinality(Cardinality.SINGLE).make() 
mgmt1.addProperties(PCA, pca00)
mgmt1.commit()
// create an instance of GremlinRecipies - a class with usefull methods for operations on graphs
gr = new GremlinRecipies(g)
// get any Vertex (10 * source)
// clone that vertex from the master graph (g) to personal graph (g1)
// last two (integer) arguments specify how far up/down should cloning go
// cloning doesn't clone loops, up goes all the way up (without going down), down goes just down 
// -1 means clone everything (it may be dangerous)
g.V().has('lbl', 'source').limit(10).each {source ->
  gr.gimme(source, g1, -1, -1)
  }
// commit new structure
graph1.tx().commit()
// Get GremlinRecipies for the private graph 'g1'
gr1 = new GremlinRecipies(g1)
// drop all '
Lomikel.drop(graph, 'distance', 100)
// scan all PCAs
// compute difference bewtween 'pca00' (that can be any formula using Vertex properties, giving double)
// if the result <= 0.5 then add an Edge with name 'distance' and a property 'difference' with the result value,
// do it only for 5 distances with the minimal value
// (commit after each Integer.MAX_VALUE new Edges, so do not commit)
// note: g1 does not have schema and indexes - so used variables should be specified 
gr1.structurise(g1.V().has('lbl', 'PCA'), 'pca00[0]-pca00[1]', 'pca00', 0.5, 5, 'distance', 'difference', Integer.MAX_VALUE)
// get some statistics about new Edges
g1.E().has('lbl', 'distance').values('difference').union(min(), max(), sum(), mean(), count())
// get the closest sources 
g1.E().has('lbl', 'distance').order().by('difference').limit(1).bothV().in().has('lbl', 'source').values('objectId')
// get all clusters containing at least 10 PCAs which are closer then 1.5
FinkBrowser.findPCAClusters(g1, 'distance', 'difference', 10, 1.5);[]

// write your new Graph into a file
graph1.io(IoCore.gryo()).writeGraph('myfile.kryo')
// to read it later (maybe into another graph)
graph2.io(IoCore.gryo()).readGraph('myfile.kryo')

