Commit 70ac44ef authored by aknecht2's avatar aknecht2
Browse files

Fixed database query to correctly reflect if sample arrays are empty. Return...

Fixed database query to correctly reflect if sample arrays are empty.  Return actual document instead of truthy value. Added output file name and timestamp to save_results.:
parent 0548f1fe
......@@ -5,6 +5,7 @@ import sys
import traceback
import os
import itertools
import time
import chipathlon.conf
from pprint import pprint
import hashlib
......@@ -38,18 +39,15 @@ class MongoDB(object):
print "result_id %s doesn't exist." % (result_id,)
return
def check_result(self, control_sample_ids, experiment_sample_ids, ref_genome, result_type, params):
def check_result(self, control_sample_ids, experiment_sample_ids, ref_genome, result_type, params, debug=False):
try:
query = {
"control_sample_ids": {
"$all": control_sample_ids
},
"experiment_sample_ids": {
"$all": experiment_sample_ids
},
"result_type": result_type,
"ref_genome": ref_genome
}
# In the case that there are 0 samples we just want to check for existence.
query["control_sample_ids"] = {"$all": control_sample_ids} if (len(control_sample_ids) > 0) else {"$exists": True}
query["experiment_sample_ids"] = {"$all": experiment_sample_ids} if (len(experiment_sample_ids) > 0) else {"$exists": True}
for job_name in params:
param_keys = params[job_name].keys()
if len(param_keys) == 0:
......@@ -58,11 +56,15 @@ class MongoDB(object):
for param_name in param_keys:
query[job_name + "." + param_name] = params[job_name][param_name]
cursor = self.db.results.find(query)
if cursor.count() == 1:
return True
if debug:
print "[DB.check_result] Query = %s" % (query,)
print "[DB.check_result] count = %s" % (cursor.count(),)
if cursor.count() > 0:
# Use the latest if available
return cursor.sort("timestamp", pymongo.DESCENDING).next()
except pymongo.errors.OperationFailure as e:
print "Error with experiment_id %s: %s" % (experiment_id, e)
return False
return None
def create_result(self, output_file, control_sample_ids, experiment_sample_ids, result_type, additional_data = {}, gfs_attributes = {}):
# Make sure output_file exists
......@@ -81,7 +83,9 @@ class MongoDB(object):
"gridfs_id": gridfs_id,
"control_sample_ids": control_sample_ids,
"experiment_sample_ids": experiment_sample_ids,
"result_type": result_type
"result_type": result_type,
"file_name": output_file,
"timestamp": time.time()
}
# Add additional attributes into the result_entry
result_entry.update(additional_data)
......
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