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

Updated savers object creation to bulk save #64

Draft
wants to merge 1 commit into
base: arango-port
Choose a base branch
from
Draft
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 pyGeno/backends/arangodb/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def prompt_setup(self):
args = {
"username": "root",
"password": "root",
"arangoURL": "http://localhost:8529/"
"arangoURL": "http://127.0.0.1:8529/"
}
print("## ArangoDB backend setup")
for key, value in args.items():
Expand Down
26 changes: 16 additions & 10 deletions pyGeno/backends/arangodb/savers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ..backend_abs import GenomeSaver_ABS
from pyGeno.configuration import system_message
from .objects import schemas

import pyArango
class GenomeSaver(GenomeSaver_ABS):
"""
Saves genome into database
Expand All @@ -14,24 +14,30 @@ def __init__(self, database_configuration):
def init_db(self):
for col in schemas.ALL_COLLECTIONS:
colname = col.__name__
if colname not in self.db:
if not self.db.hasCollection(str(colname)):
self.db.createCollection(colname)
else :
print("TRUNCATING (temporary for tests, should be removed)", colname)
self.db[colname].truncate()

def create_objects(self):
for colname, objs in self.data.items():
i = 0
c = 0
docs = []
doc = {}
for key, obj in objs.items():
try :
doc = self.db[colname][key]
except :
doc = self.db[colname].createDocument()
doc["_key"] = key
doc.set(obj)
doc = self.db[colname].createDocument_(obj)
doc['_key'] = key
if colname in self.accepted_contigs:
doc["contig"] = self.get_subsequence(doc["seqname"], doc["start"], doc["end"])
doc.save()
docs.append(doc)
i = i + 1
c = c + 1
if i == len(objs) or i == 1000 or c + i == len(objs):
self.db[colname].bulkSave(docs, onDuplicate='ignore')
docs = []
i = 0

def create_links(self):
def _get_collection(from_type, to_type):
Expand All @@ -56,4 +62,4 @@ def _get_collection(from_type, to_type):
def save(self) :
self.init_db()
self.create_objects()
self.create_links()
#self.create_links()