def test_fast5_info__clean(self): self.assertEqual(_clean(1), 1) self.assertEqual(_clean('str'), 'str') self.assertTrue(isinstance(_clean('str'), str)) test_str = array('Hello!', dtype=str) self.assertEqual(type(test_str), ndarray) self.assertEqual(_clean(test_str), 'Hello!') self.assertEqual(_clean(array([1, 2, 3])), [1, 2, 3])
def get_tracking_id(self): """ Returns a dictionary of tracking-id key/value pairs. """ self.assert_open() tracking = self.handle[self.global_key + 'tracking_id'].attrs.items() tracking = {key: _clean(value) for key, value in tracking} return tracking
def _parse_attribute_tree(self, group): data = {} folders = self.handle[group].keys() for folder in folders: path = '{}/{}'.format(group, folder) attr = self.handle[path].attrs.items() data[folder] = {key: _clean(value) for key, value in attr} return data
def get_context_tags(self): """ Returns a dictionary of context tag key/value pairs. """ self.assert_open() if self.has_context_tags: tags = self.handle[self.global_key + 'context_tags'].attrs.items() return {key: _clean(value) for key, value in tags} return {}
def get_channel_info(self): """ Returns a dictionary of channel information key/value pairs. """ self.assert_open() channel_info = self.handle['UniqueGlobalKey/channel_id'].attrs.items() channel_info = {key: _clean(value) for key, value in channel_info} channel_info['channel_number'] = int(channel_info['channel_number']) return channel_info
def get_context_tags(self): """ Returns a dictionary of context tag key/value pairs. """ self.assert_open() tags = {} if 'context_tags' in self.handle['UniqueGlobalKey']: tags = self.handle['UniqueGlobalKey/context_tags'].attrs.items() tags = {key: _clean(value) for key, value in tags} return tags
def check_file_type(f5_file): try: return _clean(f5_file.handle.attrs['file_type']) except KeyError: if len(f5_file.handle) == 0: return 1 if len([read for read in f5_file.handle if read.startswith('read_')]) != 0: return 1 if 'UniqueGlobalKey' in f5_file.handle: return 0 raise TypeError('file can not be indetified as single- or multi- read.\n' 'File path: {}'.format(f5_file.filename))
def get_analysis_attributes(self, group_name): """ Returns the attributes for the specified group or dataset. :param group_name: The path of the group or dataset, relative to the "Analyses" group. :returns: A dictionary representing the attributes (if any). """ self.assert_open() group = 'Analyses/{}'.format(group_name) attr = None if group in self.handle: attr = self.handle[group].attrs.items() attr = {key: _clean(value) for key, value in attr} return attr
def check_file_type(f5_file): try: return _clean(f5_file.handle.attrs['file_type']) except KeyError: # On older files we don't have the 'file_type' attribute so check groups explicitly if len(f5_file.handle) == 0: # If there are no top-level groups we default to MultiRead return MULTI_READ if len([read for read in f5_file.handle if read.startswith('read_')]) != 0: # If there are any read_xxx groups we're definitely MultiRead return MULTI_READ if "UniqueGlobalKey" in f5_file.handle: # This group indicates a single read return SINGLE_READ raise TypeError("Fast5 file type could not be identified as single- or multi-read. " "\nFilepath: {}".format(f5_file.filename))
def list_analyses(self, component=None): """ Provides a list of all analyses groups. :param component: Optional component name. If provided, only analyses of that component will be returned. :returns: A list of component-name/group-name pairs (tuples). """ self.assert_open() analyses = [] if 'Analyses' not in self.handle: return analyses ana_groups = self.handle['Analyses'].keys() for group_name in ana_groups: group_attrs = self.handle['Analyses/{}'.format(group_name)].attrs if 'component' in group_attrs: comp = _clean(group_attrs['component']) elif group_name[:-4] in LEGACY_COMPONENT_NAMES: comp = LEGACY_COMPONENT_NAMES[group_name[:-4]] else: # We don't know anything about this component! comp = None if comp is not None and (component is None or comp == component): analyses.append((comp, group_name)) return analyses
def test_fast5_info__clean_py3(self): # _clean should convert byte strings into python3 utf-8 ones test_str = array(b'Hello!', dtype=bytes) self.assertEqual(type(test_str), ndarray) self.assertEqual(_clean(test_str), 'Hello!')