def parse_genome_property_longform_file(longform_file): """ Parses longform genome properties assignment files. :param longform_file: A longform genome properties assignment file handle object. :return: An assignment cache object. """ property_id = '' step_number = '' assignment_cache = AssignmentCache(sample_name=splitext(basename(longform_file.name))[0]) for line in longform_file: if 'PROPERTY:' in line: property_id = line.split(':')[1].strip() elif 'STEP NUMBER:' in line: step_number = int(line.split(':')[1].strip()) elif 'RESULT:' in line: assignment = line.split(':')[1].strip().upper() if 'STEP' in line: assignment_cache.cache_step_assignment(property_id, step_number, assignment) else: assignment_cache.cache_property_assignment(property_id, assignment) else: continue return assignment_cache
def test_get_identifiers(self): """Test that we can get the correct assignment identifiers from the cache.""" test_cache = AssignmentCache() test_cache.cache_property_assignment('GenProp0067', 'YES') test_cache.cache_property_assignment('GenProp0092', 'NO') identifiers = test_cache.genome_property_identifiers identifiers.sort() self.assertEqual(identifiers, ['GenProp0067', 'GenProp0092'])
def test_assignment_cache_synchronization(self): """Test that the assignment file can be properly synchronized.""" test_cache = AssignmentCache() test_tree = self.test_tree test_cache.cache_property_assignment('GenProp0456', 'YES') test_cache.cache_property_assignment('GenProp0710', 'YES') sanitized_cache = create_synchronized_assignment_cache(test_cache, test_tree) self.assertEqual(len(sanitized_cache.property_assignments), 1) self.assertEqual(sanitized_cache.get_property_assignment('GenProp0710'), 'YES')
def test_cache_flush(self): """Test that the cache can be properly flushed.""" test_cache = AssignmentCache() test_cache.cache_property_assignment('GenProp0067', 'YES') test_cache.cache_property_assignment('GenProp0092', 'NO') test_cache.cache_step_assignment('GenProp0067', 1, 'YES') test_cache.cache_step_assignment('GenProp0092', 1, 'NO') test_cache.flush_property_from_cache('GenProp0067') self.assertEqual(test_cache.get_property_assignment("GenProp0067"), None) self.assertEqual(test_cache.get_step_assignment("GenProp0067", 1), None) self.assertEqual(len(test_cache.property_assignments), 1) self.assertEqual(len(test_cache.step_assignments), 1)
def setUpClass(cls): """Set up testing data for testing.""" prebuilt_cache = AssignmentCache() prebuilt_cache.cache_property_assignment('GenProp0053', 'YES') prebuilt_cache.cache_property_assignment('GenProp0052', 'NO') prebuilt_cache.cache_property_assignment('GenProp0051', 'PARTIAL') prebuilt_cache.cache_step_assignment('GenProp0053', 1, 'YES') prebuilt_cache.cache_step_assignment('GenProp0053', 2, 'NO') prebuilt_cache.cache_step_assignment('GenProp0053', 3, 'YES') cls.cache = prebuilt_cache """ Test Properties Rooted DAG Structure: --> GenProp0089 GenProp0066 --> GenProp0092 """ property_rows_one = [('AC', 'GenProp0066'), ('DE', 'Coenzyme F420 utilization'), ('TP', 'GUILD'), ('--', ''), ('SN', '1'), ('ID', 'Selfish genetic elements'), ('RQ', '0'), ('EV', 'GenProp0089;'), ('--', ''), ('SN', '2'), ('ID', 'Selfish genetic elements'), ('RQ', '0'), ('EV', 'GenProp0092;')] property_rows_two = [('AC', 'GenProp0089'), ('DE', 'Coenzyme F420 utilization'), ('TP', 'GUILD'), ('--', ''), ('SN', '1'), ('ID', 'LLM-family F420-associated subfamilies'), ('RQ', '0'), ('EV', 'IPR019910; TIGR03564; sufficient;')] property_rows_three = [('AC', 'GenProp0092'), ('DE', 'Coenzyme F420 utilization'), ('TP', 'GUILD'), ('--', ''), ('SN', '1'), ('ID', 'LLM-family F420-associated subfamilies'), ('RQ', '0'), ('EV', 'IPR019910; TIGR03565; sufficient;')] property_one = parse_genome_property(property_rows_one) property_two = parse_genome_property(property_rows_two) property_three = parse_genome_property(property_rows_three) raw_properties = [property_one, property_two, property_three] cls.tree = GenomePropertiesTree(*raw_properties)