Commit 087cd190 authored by aknecht2's avatar aknecht2
Browse files

Added some helper functions to db / result.

parent 3c5bee77
......@@ -39,20 +39,22 @@ class MongoDB(object):
self.gfs = gridfs.GridFS(self.db)
return
def delete_result(self, result_id):
def delete_result(self, result, genome):
"""
:param result_id: ID of result to delete
:type result_id: ObjectId
:param result: The result to delete
:type result: :py:class:~chipathlon.result.Result
:param genome: The genome to find information from.
:type genome: :py:meth:~chipathlon.genome.Genome
Deletes a result and it's corresponding gridfs entry.
"""
result_id = self.get_reuslt_id(result, genome)
cursor = self.db.results.find({
"_id": result_id
})
if cursor.count() == 1:
result = cursor.next()
self.gfs.delete(result["gridfs_id"])
self.db[result["result_type"]].delete_many({"result_id": result["_id"]})
self.db.results.delete_one({"_id": result["_id"]})
else:
print "result_id %s doesn't exist." % (result_id,)
......@@ -98,6 +100,22 @@ class MongoDB(object):
print "Error checking result [%s]: %s" % (file_name, e)
return False
def get_result_id(self, result, genome):
"""
:param result: The result to check.
:type result: :py:meth:~chipathlon.result.Result
:param genome: The genome to find information from.
:type genome: :py:meth:~chipathlon.genome.Genome
Get the id of a result.
"""
try:
cursor = self.db.results.find(self._get_result_query(result, genome))
if cursor.count() == 1:
return cursor._id
except pymongo.errors.OperationFailure as e:
print "Error getting result id [%s]: %s" % (file_name, e)
return None
def get_result(self, result, genome):
"""
......
......@@ -157,6 +157,17 @@ class Result(object):
"""
return mdb.get_result(self, genome)
def delete_from_db(self, mdb, genome):
"""
:param mdb: MongoDB instance to check metadata.
:type mdb: MongoDB
:param genome: The genome class containing genomic information
:type genome: Genome
Checks whether or not the result exists in the database.
"""
return mdb.delete_result(self, genome)
def save_to_db(self, mdb, dax, master_files, master_jobs, genome, save_job, base_path):
"""
:param mdb: MongoDB instance to save to.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment