logger = logging.getLogger(__name__)
+DAF_VARIABLE_NAMES = ("variables", "extraVariables")
+VARIABLES_TERM_NAME = 'variables'
class ModelException(RuntimeError):
"""Assumptions about the RDF model failed"""
view_name = None
view_attributes = {}
state = DAF_HEADER
- elif state == DAF_HEADER and name == 'variables':
+ elif state == DAF_HEADER and name in DAF_VARIABLE_NAMES:
attributes[name] = [x.strip() for x in value.split(',')]
elif state == DAF_HEADER and name == 'view':
view_name = value
The statements are attached to the provided subject node
"""
+ variables_term = dafTermOntology[VARIABLES_TERM_NAME]
statements = []
for daf_key in attributes:
predicate = dafTermOntology[daf_key]
statements.extend(_views_to_statements(subject,
dafTermOntology,
attributes[daf_key]))
- elif daf_key == 'variables':
- #predicate = ddfNS['variables']
- for var in attributes.get('variables', []):
+ elif daf_key in DAF_VARIABLE_NAMES:
+ for var in attributes.get(daf_key, []):
obj = toTypedNode(var)
- statements.append(RDF.Statement(subject, predicate, obj))
+ statements.append(RDF.Statement(subject, variables_term, obj))
else:
value = attributes[daf_key]
obj = toTypedNode(value)
def get_daf_variables(self):
"""Returns simple variables names that to include in the ddf
"""
- variableTerm = dafTermOntology['variables']
+ variables_term = dafTermOntology[VARIABLES_TERM_NAME]
results = ['view']
if self.need_replicate():
results.append('replicate')
- for obj in self.model.get_targets(self.submissionSet, variableTerm):
+ for obj in self.model.get_targets(self.submissionSet, variables_term):
value = str(fromTypedNode(obj))
results.append(value)
results.append('labVersion')
required no
"""
+test_daf_extra = """# Lab and general info
+grant Hardison
+lab Caltech-m
+dataType ChipSeq
+variables cell,antibody,sex,age,strain
+extraVariables controlId,treatment
+compositeSuffix CaltechHistone
+assembly mm9
+dafVersion 2.0
+validationSettings validateFiles.bam:mismatches=2,bamPercent=99.9;validateFiles.fastq:quick=1000
+
+# Track/view definition
+view FastqRd1
+longLabelPrefix Caltech Fastq Read 1
+type fastq
+hasReplicates no
+required no
+"""
+
+
class TestDAF(unittest.TestCase):
def test_parse(self):
self.failUnlessEqual(signal['longLabelPrefix'],
'Caltech Histone Signal')
+
def test_rdf(self):
parsed = daf.fromstring(test_daf)
turtle = writer.serialize_model_to_string(model)
print turtle
+
class TestDAFMapper(unittest.TestCase):
def test_create_mapper_add_pattern(self):
name = 'testsub'
self.failUnlessEqual(daf_mapper.need_replicate(), False)
self.failUnless('replicate' not in daf_mapper.get_daf_variables())
+ def test_daf_with_extra(self):
+ daf_mapper = load_daf_mapper('test_rep',test_daf=test_daf_extra)
+ variables = daf_mapper.get_daf_variables()
+ self.assertEqual(len(variables), 9)
+ self.failUnless('treatment' in variables)
+ self.failUnless('controlId' in variables)
+
+
@contextmanager
def mktempdir(prefix='tmp'):
d = tempfile.mkdtemp(prefix=prefix)
- print "made", d
yield d
shutil.rmtree(d)
- print "unmade", d
+
@contextmanager
def mktempfile(suffix='', prefix='tmp', dir=None):
fd, pathname = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir)
yield pathname
- print "made", pathname
os.close(fd)
os.unlink(pathname)
- print "unmade", pathname
def suite():