Source code for bripipetools.io.sexcheck

"""
Class for reading and parsing sex check validation files.
"""
import logging

logger = logging.getLogger(__name__)


[docs]class SexcheckFile(object): """ Parser to read tables of metrics generated by custom Tophat Stats PE tool, stored in a tab-delimited text file. """ def __init__(self, path): self.path = path self.data = {}
[docs] def _read_file(self): """ Read file into list of raw strings. """ logger.debug("reading file '{}' to raw string list".format(self.path)) with open(self.path) as f: self.data['raw'] = f.readlines()
[docs] def _parse_lines(self): """ Get key-value pairs from text lines and return dictionary. """ rows = [l.rstrip().split(',') for l in self.data['raw']] self.data['table'] = dict(list(zip(rows[0], rows[1])))
[docs] def parse(self): """ Parse metrics table and return dictionary. """ self._read_file() self._parse_lines() return self.data['table']