Reads gbasis-formatted file data and converts it to a dictionary with the
       usual BSE fields

       Note that the gbasis format does not store all the fields we
       have, so some fields are left blank
970980
def read_gbasis(basis_lines, fname):
    '''
    '''

    skipchars = '!#'
    basis_lines = [l for l in basis_lines if l and not l[0] in skipchars]

    bs_data = create_skel('component')

    i = 0
    bs_name = None
    while i < len(basis_lines):
        line = basis_lines[i]
        lsplt = line.split(':')
        elementsym = lsplt[0]

        if bs_name is None:
            bs_name = lsplt[1]
        elif lsplt[1] != bs_name:
            raise RuntimeError("Multiple basis sets in a file")

        element_Z = lut.element_Z_from_sym(elementsym)
        element_Z = str(element_Z)

        if not element_Z in bs_data['elements']:
            bs_data['elements'][element_Z] = {}

        element_data = bs_data['elements'][element_Z]

        if not 'electron_shells' in element_data:
            element_data['electron_shells'] = []

        i += 1

        max_am = int(basis_lines[i].strip())
        i += 1

        for am in range(0, max_am + 1):
            lsplt = basis_lines[i].split()
            shell_am = lut.amchar_to_int(lsplt[0])
            nprim = int(lsplt[1])
            ngen = int(lsplt[2])

            if shell_am[0] != am:
                raise RuntimeError("AM out of order in gbasis?")

            if max(shell_am) <= 1:
                func_type = 'gto'
            else:
                func_type = 'gto_spherical'


            shell = {
                'function_type': func_type,
                'region': '',
                'angular_momentum': shell_am
            }

            exponents = []
            coefficients = []

            i += 1
            for j in range(nprim):
                line = basis_lines[i].replace('D', 'E')
                line = line.replace('d', 'E')
                lsplt = line.split()

                if len(lsplt) != (ngen + 1):
                    raise RuntimeError("Incorrect number of general contractions in gbasis")

                exponents.append(lsplt[0])
                coefficients.append(lsplt[1:])
                i += 1

            shell['exponents'] = exponents

            # We need to transpose the coefficient matrix
            # (we store a matrix with primitives being the column index and
            # general contraction being the row index)
            shell['coefficients'] = list(map(list, zip(*coefficients)))

            element_data['electron_shells'].append(shell)

    return bs_data
629770
def read_meminfo():
    
    data = {}
    with open("/proc/meminfo", "rb") as meminfo_file:
        for row in meminfo_file:
            fields = row.split()
            # Example content:
            # MemTotal:                3801016 kB
            # MemFree:                 1840972 kB
            # MemAvailable:        3287752 kB
            # HugePages_Total:             0
            data[fields[0].decode("ascii")[:-1]] = int(fields[1]) * 1024
    return data
714993
def to_dict(self):
        '''
        '''
        try:
            name = self.file.name
        except AttributeError:
            name = None

        try:
            size = self.size()
        except OSError:
            size = None

        return {
            'filename': name,
            'length': size,
            'content_size': size,
        }
683986
def parse_s2bs(s2bs):
    
    s2b = {}
    for s in s2bs:
        for line in open(s):
            line = line.strip().split('\t')
            s, b = line[0], line[1]
            s2b[s] = b
    return s2b
54637
def _parse_memory(s):
    
    units = {'g': 1024, 'm': 1, 't': 1 << 20, 'k': 1.0 / 1024}
    if s[-1].lower() not in units:
        raise ValueError("invalid format: " + s)
    return int(float(s[:-1]) * units[s[-1].lower()])
95621
def to_dict(self, remove_nones=False):
        

        d = super().to_dict(remove_nones=remove_nones)

        d.update({
            'read': self.read,
            'create': self.create,
            'update': self.update
        })

        return d
545742
def read_header(filename):
    '''  '''
    header = {}
    in_header = False
    data = nl.universal_read(filename)
    lines = [x.strip() for x in data.split('\n')]
    for line in lines:
        if line=="*** Header Start ***":
            in_header=True
            continue
        if line=="*** Header End ***":
            return header
        fields = line.split(": ")
        if len(fields)==2:
            header[fields[0]] = fields[1]
1103728
def serialisasi(self):
        

        return {
            "kelas": self.kelas,
            "submakna": self.submakna,
            "info": self.info,
            "contoh": self.contoh
        }
303452
def parse_to_dict(self):
        
        lst = []
        with open(self.fname, 'r') as f:
            hdr = f.readline()
            self.hdrs = hdr.split(',')
            #print("self.hdrs = ", self.hdrs)
            for line in f:
                cols = line.split(',')
                if len(cols) == len(self.hdrs):
                    #print(cols)
                    d = {}
                    for ndx, col_header in enumerate(self.hdrs):
                        #d[self.hdrs[ndx].strip('\n').strip()] = cols[ndx].strip('\n').strip()
                        d[col_header.strip('\n').strip()] = cols[ndx].strip('\n').strip()
                        
                    lst.append(d)
                else:
                    print("Error parsing " + self.fname + " line : " + line)
        return lst
1152581
def to_dict(self):
        
        return {
            'pvalues': self.pvalues(),
            'resid': self.resid(),
            'order': self.order,
            'seasonal_order': self.seasonal_order,
            'oob': self.oob(),
            'aic': self.aic(),
            'aicc': self.aicc(),
            'bic': self.bic(),
            'bse': self.bse(),
            'params': self.params()
        }
638295
def _deserialize_dict(cls, data):
        '''
        
        '''
        return cPickle.loads(zlib.decompress(b64decode(data.encode())))
678023
def to_bytes(s):
    
    if sys.version_info < (3,):
        return "".join(map(chr, s))
    else:
        return bytes(s)
1231099
def getMemoryUse(self):
        
        info_dict = {}
        try:
            fp = open(meminfoFile, 'r')
            data = fp.read()
            fp.close()
        except:
            raise IOError('Failed reading stats from file: %s' % meminfoFile)
        for line in data.splitlines():
            mobj = re.match('^(.+):\s*(\d+)\s*(\w+|)\s*$', line)
            if mobj:
                if mobj.group(3).lower() == 'kb':
                    mult = 1024
                else:
                    mult = 1
                info_dict[mobj.group(1)] = int(mobj.group(2)) * mult
        return info_dict
1300734
def _deserialize(self, data: dict, silent=True) -> dict:
        '''  '''
        deserialized_data = {}
        for name, field in self._fields.items():
            if field._readonly is False and name in data:
                deserialized_data[name] = data.get(name)
        return deserialized_data
303184
def to_tsv(self, include_readonly=True):
        '''
        
        '''
        data = self.__dict__
        fields = self.fields(writable=not include_readonly)
        return '\t'.join(field.to_db_string(data[name], quote=False) for name, field in iteritems(fields))
579624
def read_key(pysam_alignment_record):
    '''
    
    '''
    return (
        pysam_alignment_record.query_name,
        pysam_alignment_record.is_duplicate,
        pysam_alignment_record.is_read1,
        pysam_alignment_record.is_read2,
    )
295592
def parse_s2bins(s2bins):
    
    s2b = {}
    b2s = {}
    for line in s2bins:
        line = line.strip().split()
        s, b = line[0], line[1]
        if 'UNK' in b:
            continue
        if len(line) > 2:
            g = ' '.join(line[2:])
        else:
            g = 'n/a'
        b = '%s\t%s' % (b, g)
        s2b[s] = b 
        if b not in b2s:
           b2s[b] = []
        b2s[b].append(s)
    return s2b, b2s