Commit 23cc2a3a authored by aknecht2's avatar aknecht2
Browse files

Added new method to fetch samples, and used it in the run class.

parent 941577bb
......@@ -303,6 +303,33 @@ class MongoDB(object):
else:
return True
def get_sample(self, accession, file_type):
"""
:param accession: The accession number of the target sample
:type accession: string
:param file_type: The file type of the target sample should be [fastq|bam]
:type file_type: string
Gets the associated sample based on accession number and file_type
"""
valid = True
msg = ""
data = {}
cursor = self.db.samples.find({
"accession": accession,
"file_type": file_type
})
if cursor.count() == 1:
data = cursor.next()
else:
valid = False
msg = "Found %s files with accession: %s, file_type: %s. Should only be 1." % (
cursor.count(),
accession,
file_type
)
return (valid, msg, data)
def get_samples(self, experiment_id):
valid = True
msg = ""
......
......@@ -61,11 +61,12 @@ class Run(object):
self.errors.append("Run defined by %s is invalid. Idr can only be run if signal2 AND control2 are defined." % (self,))
for accession in [signal1, signal2, control1, control2]:
if accession is not None:
valid, msg, sample = self.mdb.get_sample(accession)
valid, msg, sample = self.mdb.get_sample(accession, self.file_type)
if valid:
self.samples[accession] = sample
else:
self.errors.append("Run defined by %s is invalid. Database error: %s." % (self, msg)
self.errors.append("Run defined by %s is invalid. Database error: %s." % (self, msg))
return
def is_valid(self):
"""
......
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