def read_lpb(self, f_name):

    def _get_general_info(name):
        unsats = [n[0] for n in name.split(':')[1:]]
        class_name = name.split('(')[0]
        if ('-' in class_name):
            name_split = name.split('(')
            name_split[0] = name.split('(')[0].replace('-', '')
            name = '('.join(name_split)
        acyl_lengths = name.split(':')
        acyl_lengths.pop()
        f_acyl_lengths = []
        for acl in acyl_lengths:
            try:
                if ('/' in acl):
                    f_acyl_lengths.append(acl.split('/')[1].replace('d', '').replace('methyl-', ''))
                elif ('-' in acl):
                    f_acyl_lengths.append(acl.split('-')[1].replace('d', '').replace('methyl-', ''))
                else:
                    f_acyl_lengths.append(acl.split('(')[1].replace('d', '').replace('methyl-', ''))
            except:
                logging.warning(('Could not format to get acyl lengths: %s' % name))
                return ([0], [0], '')
        try:
            f_acyl_lengths = list(map(int, f_acyl_lengths))
            unsats = list(map(int, unsats))
        except:
            logging.warning(('Could not format to get acyl lengths: %s' % name))
            return ([0], [0], '')
        return (f_acyl_lengths, unsats, class_name)

    def _simplify_name(class_name, acyls, unsats):
        simplified_name = ''
        simplified_name += class_name
        simplified_name += '('
        if (not self.aggregate_acyls):
            for (f, u) in zip(f_acyl_lengths, unsats):
                simplified_name += str(f)
                simplified_name += ':'
                simplified_name += str(u)
                simplified_name += '/'
            simplified_name = simplified_name[:(- 1)]
        else:
            simplified_name += str(sum(f_acyl_lengths))
            simplified_name += ':'
            simplified_name += str(sum(unsats))
        simplified_name += ')'
        return simplified_name

    def _get_chem_form(chem_form_native, ion):
        chem_form_ion = ''
        for (i, c) in enumerate(chem_form_native):
            if ((i + 1) >= len(chem_form_native)):
                if c.isdigit():
                    chem_form_ion += c
                else:
                    chem_form_ion += c
                    chem_form_ion += '1'
            elif c.isdigit():
                chem_form_ion += c
            elif (c.isupper() and chem_form_native[(i + 1)].isdigit()):
                chem_form_ion += c
            elif (c.isupper() and chem_form_native[(i + 1)].isupper()):
                chem_form_ion += c
                chem_form_ion += '1'
            elif chem_form_native[(i + 1)].isdigit():
                chem_form_ion += c
        list_chem = [''.join(g) for (_, g) in groupby(chem_form_ion, str.isalpha)]
        chem_form_ion = dict(zip(list_chem[::2], map(int, list_chem[1::2])))
        if ('+' not in ion):
            if ('[M-H]-' in ion):
                try:
                    chem_form_ion['H'] -= 1
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
            if ('[M-2H](2-)' in ion):
                try:
                    chem_form_ion['H'] -= 2
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
            if ('[M-Ac-H]-' in ion):
                try:
                    chem_form_ion['C'] += 2
                    chem_form_ion['H'] += 3
                    chem_form_ion['O'] += 2
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
        else:
            if ('[M+H]+' in ion):
                try:
                    chem_form_ion['H'] += 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+NH4]+' in ion):
                try:
                    if chem_form_ion.has_key('N'):
                        chem_form_ion['N'] += 1
                    else:
                        chem_form_ion['N'] = 1
                    chem_form_ion['H'] += 4
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+Na]+' in ion):
                try:
                    if chem_form_ion.has_key('Na'):
                        chem_form_ion['Na'] += 1
                    else:
                        chem_form_ion['Na'] = 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+Na2-H]+' in ion):
                try:
                    if chem_form_ion.has_key('Na'):
                        chem_form_ion['Na'] += 2
                    else:
                        chem_form_ion['Na'] = 2
                    chem_form_ion['H'] -= 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
        return ''.join([(atom + str(num_atom)) for (atom, num_atom) in sorted(chem_form_ion.items())])
    with open(f_name) as infile:
        fragments = []
        pre_c_mass = 0.0
        name = ''
        ion = ''
        for line in infile:
            line = line.strip()
            if (len(line) == 0):
                (f_acyl_lengths, unsats, class_name) = _get_general_info(name)
                f_acyl_lengths_error = [a for a in f_acyl_lengths if ((a < self.min_acyl_length) and (a != 0))]
                if ((len(class_name) == 0) or (ion_type not in self.include_ions) or (len([c for c in self.include_class if (c in name)]) == 0) or (self.exclude_lyso and ('/0:0' in name)) or (len(f_acyl_lengths_error) > 0)):
                    fragments = []
                    pre_c_mass = 0.0
                    name = ''
                    ion_type = ''
                    continue
                simplified_name = _simplify_name(class_name, f_acyl_lengths, unsats)
                new_entry = LipidBLAST_entry(name=name, ion=ion_type, mw=pre_c_mass, chem_form=chem_form_ion, num_ms2_peaks=num_peaks, ms2=fragments, f_acyl_lengths=f_acyl_lengths, unsats=unsats)
                self.lpb_dict[('%s|%s' % (simplified_name, ion_type))] = new_entry
                loc_dict = (int(pre_c_mass) - (int(pre_c_mass) % self.dalt_diff_lookup_bin))
                if (loc_dict in self.ms1_dict_lookup.keys()):
                    self.ms1_dict_lookup[loc_dict][('%s|%s' % (simplified_name, ion_type))] = new_entry
                else:
                    self.ms1_dict_lookup[loc_dict] = {}
                    self.ms1_dict_lookup[loc_dict][('%s|%s' % (simplified_name, ion_type))] = new_entry
                self.tot_entr_read += 1
                fragments = []
                pre_c_mass = 0.0
                name = ''
                ion_type = ''
            elif (':' in line):
                if line.startswith('PRECURSORMZ'):
                    pre_c_mass = float(line.split(': ')[1])
                if line.startswith('Name: '):
                    name = line.split('; ')[(- 1)]
                    ion_type = line.split('; ')[1]
                if line.startswith('Comment: '):
                    chem_form_native = line.split('; ')[(- 1)].replace(';', '')
                    chem_form_ion = _get_chem_form(chem_form_native, ion_type)
                if line.startswith('Num Peaks:'):
                    num_peaks = int(line.split(': ')[(- 1)])
            else:
                if (line == '\x1a'):
                    continue
                fragments.append([float(line.split(' ')[0]), float(line.split(' ')[1]), line.split(' ')[2].replace('"', '')])
def read_lpb(self, f_name):

    def _get_general_info(name):
        unsats = [n[0] for n in name.split(':')[1:]]
        class_name = name.split('(')[0]
        if ('-' in class_name):
            name_split = name.split('(')
            name_split[0] = name.split('(')[0].replace('-', )
            name = '('.join(name_split)
        acyl_lengths = name.split(':')
        acyl_lengths.pop()
        f_acyl_lengths = []
        for acl in acyl_lengths:
            try:
                if ('/' in acl):
                    f_acyl_lengths.append(acl.split('/')[1].replace('d', ).replace('methyl-', ))
                elif ('-' in acl):
                    f_acyl_lengths.append(acl.split('-')[1].replace('d', ).replace('methyl-', ))
                else:
                    f_acyl_lengths.append(acl.split('(')[1].replace('d', ).replace('methyl-', ))
            except:
                logging.warning(('Could not format to get acyl lengths: %s' % name))
                return ([0], [0], )
        try:
            f_acyl_lengths = list(map(int, f_acyl_lengths))
            unsats = list(map(int, unsats))
        except:
            logging.warning(('Could not format to get acyl lengths: %s' % name))
            return ([0], [0], )
        return (f_acyl_lengths, unsats, class_name)

    def _simplify_name(class_name, acyls, unsats):
        simplified_name = 
        simplified_name += class_name
        simplified_name += '('
        if (not self.aggregate_acyls):
            for (f, u) in zip(f_acyl_lengths, unsats):
                simplified_name += str(f)
                simplified_name += ':'
                simplified_name += str(u)
                simplified_name += '/'
            simplified_name = simplified_name[:(- 1)]
        else:
            simplified_name += str(sum(f_acyl_lengths))
            simplified_name += ':'
            simplified_name += str(sum(unsats))
        simplified_name += ')'
        return simplified_name

    def _get_chem_form(chem_form_native, ion):
        chem_form_ion = 
        for (i, c) in enumerate(chem_form_native):
            if ((i + 1) >= len(chem_form_native)):
                if c.isdigit():
                    chem_form_ion += c
                else:
                    chem_form_ion += c
                    chem_form_ion += '1'
            elif c.isdigit():
                chem_form_ion += c
            elif (c.isupper() and chem_form_native[(i + 1)].isdigit()):
                chem_form_ion += c
            elif (c.isupper() and chem_form_native[(i + 1)].isupper()):
                chem_form_ion += c
                chem_form_ion += '1'
            elif chem_form_native[(i + 1)].isdigit():
                chem_form_ion += c
        list_chem = [.join(g) for (_, g) in groupby(chem_form_ion, str.isalpha)]
        chem_form_ion = dict(zip(list_chem[::2], map(int, list_chem[1::2])))
        if ('+' not in ion):
            if ('[M-H]-' in ion):
                try:
                    chem_form_ion['H'] -= 1
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
            if ('[M-2H](2-)' in ion):
                try:
                    chem_form_ion['H'] -= 2
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
            if ('[M-Ac-H]-' in ion):
                try:
                    chem_form_ion['C'] += 2
                    chem_form_ion['H'] += 3
                    chem_form_ion['O'] += 2
                except KeyError:
                    logging.critical('ERROR: could not subtract atom when getting the ionized form from the molecule')
        else:
            if ('[M+H]+' in ion):
                try:
                    chem_form_ion['H'] += 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+NH4]+' in ion):
                try:
                    if chem_form_ion.has_key('N'):
                        chem_form_ion['N'] += 1
                    else:
                        chem_form_ion['N'] = 1
                    chem_form_ion['H'] += 4
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+Na]+' in ion):
                try:
                    if chem_form_ion.has_key('Na'):
                        chem_form_ion['Na'] += 1
                    else:
                        chem_form_ion['Na'] = 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
            if ('[M+Na2-H]+' in ion):
                try:
                    if chem_form_ion.has_key('Na'):
                        chem_form_ion['Na'] += 2
                    else:
                        chem_form_ion['Na'] = 2
                    chem_form_ion['H'] -= 1
                except KeyError:
                    logging.critical('ERROR: could not add atom when getting the ionized form from the molecule')
        return .join([(atom + str(num_atom)) for (atom, num_atom) in sorted(chem_form_ion.items())])
    with open(f_name) as infile:
        fragments = []
        pre_c_mass = 0.0
        name = 
        ion = 
        for line in infile:
            line = line.strip()
            if (len(line) == 0):
                (f_acyl_lengths, unsats, class_name) = _get_general_info(name)
                f_acyl_lengths_error = [a for a in f_acyl_lengths if ((a < self.min_acyl_length) and (a != 0))]
                if ((len(class_name) == 0) or (ion_type not in self.include_ions) or (len([c for c in self.include_class if (c in name)]) == 0) or (self.exclude_lyso and ('/0:0' in name)) or (len(f_acyl_lengths_error) > 0)):
                    fragments = []
                    pre_c_mass = 0.0
                    name = 
                    ion_type = 
                    continue
                simplified_name = _simplify_name(class_name, f_acyl_lengths, unsats)
                new_entry = LipidBLAST_entry(name=name, ion=ion_type, mw=pre_c_mass, chem_form=chem_form_ion, num_ms2_peaks=num_peaks, ms2=fragments, f_acyl_lengths=f_acyl_lengths, unsats=unsats)
                self.lpb_dict[('%s|%s' % (simplified_name, ion_type))] = new_entry
                loc_dict = (int(pre_c_mass) - (int(pre_c_mass) % self.dalt_diff_lookup_bin))
                if (loc_dict in self.ms1_dict_lookup.keys()):
                    self.ms1_dict_lookup[loc_dict][('%s|%s' % (simplified_name, ion_type))] = new_entry
                else:
                    self.ms1_dict_lookup[loc_dict] = {}
                    self.ms1_dict_lookup[loc_dict][('%s|%s' % (simplified_name, ion_type))] = new_entry
                self.tot_entr_read += 1
                fragments = []
                pre_c_mass = 0.0
                name = 
                ion_type = 
            elif (':' in line):
                if line.startswith('PRECURSORMZ'):
                    pre_c_mass = float(line.split(': ')[1])
                if line.startswith('Name: '):
                    name = line.split('; ')[(- 1)]
                    ion_type = line.split('; ')[1]
                if line.startswith('Comment: '):
                    chem_form_native = line.split('; ')[(- 1)].replace(';', )
                    chem_form_ion = _get_chem_form(chem_form_native, ion_type)
                if line.startswith('Num Peaks:'):
                    num_peaks = int(line.split(': ')[(- 1)])
            else:
                if (line == '\x1a'):
                    continue
                fragments.append([float(line.split(' ')[0]), float(line.split(' ')[1]), line.split(' ')[2].replace('"', )])