def create_class(s):
    return factory.getOWLClass(IRI.create(s))
    
def add_anno(resource, prop, cont):
    anno = factory.getOWLAnnotation(factory.getOWLAnnotationProperty(prop.getIRI()), factory.getOWLLiteral(cont))
    axiom = factory.getOWLAnnotationAssertionAxiom(resource.getIRI(), anno)
    manager.addAxiom(ontology, axiom)
    
# Subclasses of 'cellular location'
print "Finding subclasses of cellular location..."
progressMonitor = ConsoleProgressMonitor();
config = SimpleConfiguration(progressMonitor);
reasoner = ElkReasonerFactory().createReasoner(ontology, config);
loc_cls = create_class("http://purl.obolibrary.org/obo/GO_0005575")
loc_nodeset = reasoner.getSubClasses(loc_cls, False).getFlattened()
print loc_nodeset
print "... done."
    
genericProteinNames = dict()
proteinCounter = 0

# Initiate a queue of all ttl files to be read.
queue = Queue()
for tfile in os.listdir(input_directory):
    queue.put(tfile)
print "Queue built. There are %d files to be read from %s." % (queue._qsize(), input_directory)

def readFiles(i, q):
    while True:
        tfile = q.get()
    print "Start timer..."
    reasoner = ElkReasonerFactory().createReasoner(ontology)
    reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY)
    end = time.clock()
    total_time += (end - start)
    print "Classification time: %d seconds." % (end - start)
print "Average classification time: %d seconds" % (total_time / repeats)


#### Query 1

total_time1, total_time2 = 0, 0
repeats = 1000

go_reasoner = ElkReasonerFactory().createReasoner(go)
go_top_set = go_reasoner.getSubClasses(thing, False).getFlattened()
go_top_list = []
for x in go_top_set:
    go_top_list.append(x)
print "%d GO classes" % len(go_top_list)

ncbi_reasoner = ElkReasonerFactory().createReasoner(ncbi)
ncbi_top_set = ncbi_reasoner.getSubClasses(thing, False).getFlattened()
ncbi_top_list = []
for x in ncbi_top_set:
    ncbi_top_list.append(x)
print "%d NCBI classes" % len(ncbi_top_list)

# Cellular location
loc_cls = create_class("http://purl.obolibrary.org/obo/GO_0005575")
loc_nodeset = reasoner.getSubClasses(loc_cls, False).getFlattened()