Пример #1
0
    def add_gpcrdb_categories(self):

        resep = re.compile(r'[- /\(\),]+')

        gpcrdb_categories = []

        if self._resource_categories['gpcrdb']:

            self.ensure_annotdb()

            gpcrdb = self.annotdb['GPCRdb']

            fields = gpcrdb.get_names()

            for i in range(1, len(fields) + 1):

                combinations = {
                    a[:i]
                    for entity, annots in iteritems(gpcrdb.annot)
                    for a in annots
                }

                for values in combinations:

                    if not values[0]:

                        continue

                    this_fields = fields[:i]
                    this_values = values[:i]

                    args = dict(zip(
                        this_fields,
                        this_values,
                    ))

                    members = gpcrdb.select(**args)

                    if not members:

                        continue

                    name = '_'.join(
                        resep.sub('_', val).lower().strip('_')
                        for val in
                        this_values
                    )
                    name = name.replace('_receptors', '')

                    gpcrdb_categories.append(
                        af.AnnotDef(
                            name = name,
                            resource = 'GPCRdb',
                            args = args,
                            parent = 'receptor',
                        )
                    )

            self._class_definitions_provided += tuple(gpcrdb_categories)
Пример #2
0
    def add_baccin_categories(self):

        if self._resource_categories['baccin']:

            self.ensure_annotdb()
            baccin_categories = []
            baccin = self.annotdb.annots['Baccin2019']
            fields = baccin.get_names()
            locations = {
                'surface': {'membrane', 'both'},
                'secreted': {'secreted', 'both', 'ecm'},
            }

            subclasses = baccin.get_values('subclass') - {'other', None}

            this_fields = fields[1:]

            for subclass in subclasses:

                receptor = 'receptor' in subclass

                args = {'subclass': subclass}

                for location in ('surface', 'secreted'):

                    if receptor and location == 'secreted':

                        continue

                    if not receptor:

                        args['location'] = location

                    members = baccin.select(**args)

                    if not members:

                        continue

                    parent = ('receptor' if receptor else
                              ('cell_surface_ligand'
                               if location == 'surface' else 'ligand'))

                    name = subclass.replace('_receptor', '')

                    baccin_categories.append(
                        af.AnnotDef(
                            name=name,
                            parent=parent,
                            resource='Baccin2019',
                            args=args,
                        ))

            self._class_definitions_provided += tuple(baccin_categories)
Пример #3
0
    def add_surfaceome_categories(self):

        resep = re.compile(r'[- /\(\),\.]+')
        recls = re.compile(r'_(?:transporters|receptors|ion_channels)')

        mainclasses = {
            'Receptors': 'receptor',
            'Transporters': 'transporter',
            'Enzymes': 'surface_enzyme',
        }

        if self._resource_categories['surfaceome']:

            self.ensure_annotdb()
            surfaceome = self.annotdb['Surfaceome']
            surfaceome_categories = []

            for mainclass, parent in iteritems(mainclasses):

                subclasses = {
                    sc
                    for annots in surfaceome.annot.values() for a in annots
                    for sc in (a.subclasses or ())
                    if (a.mainclass == mainclass and sc is not None
                        and not sc[0].isdigit())
                }

                for subclass in subclasses:

                    if subclass.startswith('Other'):

                        continue

                    name = '%s_%s' % (
                        resep.sub('_', subclass).lower().strip('_'),
                        mainclass.lower(),
                    )
                    _parent = ('ion_channel'
                               if 'ion_channel' in name else parent)
                    name = recls.sub('', name)

                    surfaceome_categories.append(
                        af.AnnotDef(
                            name=name,
                            resource='Surfaceome',
                            args={
                                'mainclass': mainclass,
                                'subclasses': subclass,
                            },
                            parent=_parent,
                        ))

            self._class_definitions_provided += tuple(surfaceome_categories)
Пример #4
0
    def add_icellnet_categories(self):

        icellnet_categories = []

        if self._resource_categories['icellnet']:

            self.ensure_annotdb()

            icellnet = self.annotdb['ICELLNET']

            names = icellnet.get_names()[:3]

            combinations = {
                a[:3]
                for aa in icellnet.annot.values() for a in aa
            }

            for values in combinations:

                for l in (2, 3):

                    _fields = names[:l]
                    _values = values[:l]

                    if _values[-1] is None:

                        continue

                    args = dict(zip(_fields, _values))

                    members = icellnet.select(**args)

                    if not members:

                        continue

                    name = '_'.join(
                        val.lower().replace('.', '').replace(' ', '_')
                        for val in _values[1:] if val is not None)

                    icellnet_categories.append(
                        af.AnnotDef(
                            name=name,
                            resource='ICELLNET',
                            args=args,
                            parent=values[0],
                        ))

            self._class_definitions_provided += tuple(icellnet_categories)
Пример #5
0
    def add_cellphonedb_categories(self):

        if self._resource_categories['cellphonedb']:

            self.ensure_annotdb()

            cellphonedb_categories = []

            for mainclass in ('receptor', 'secreted'):

                cpdb = self.annotdb.annots['CellPhoneDB']
                attr = '%s_class' % mainclass

                categories = set(
                    itertools.chain(*(
                        getattr(c, attr)
                        for cc in cpdb.annot.values()
                        for c in cc
                    ))
                )

                for category in categories:

                    if category in {'secreted', 'receptor'}:

                        continue

                    parent = (
                        'receptor'
                            if category == 'receptor' else
                        'ligand'
                    )

                    cellphonedb_categories.append(
                        af.AnnotDef(
                            name = category,
                            parent = parent,
                            resource = 'CellPhoneDB',
                            args = {attr: category},
                        )
                    )

            self._class_definitions_provided += tuple(cellphonedb_categories)
Пример #6
0
    def add_hpmr_categories(self):

        resep = re.compile(r'[- /\(\),]+')

        hpmr_categories = []

        if self._resource_categories['hpmr']:

            self.ensure_annotdb()

            hpmr = self.annotdb['HPMR']

            fields = hpmr.get_names()

            for i in range(2, len(fields) + 1):

                combinations = {
                    a[:i]
                    for entity, annots in iteritems(hpmr.annot) for a in annots
                }

                for values in combinations:

                    if not values[0]:

                        continue

                    this_fields = fields[1:i]
                    this_values = values[1:i]

                    if not this_values[-1]:

                        continue

                    args = dict(zip(
                        this_fields,
                        this_values,
                    ))

                    members = hpmr.select(**args)
                    parent = values[0].lower()

                    if not members:

                        continue

                    name_parts = (this_values[1:]
                                  if len(this_values) > 1 else this_values)

                    name = '_'.join(
                        name_part.strip('_').replace('_receptors', '')
                        for name_part in (
                            resep.sub('_', val).lower() if val else None
                            for val in reversed(name_parts)) if name_part)

                    hpmr_categories.append(
                        af.AnnotDef(
                            name=name,
                            resource='HPMR',
                            args=args,
                            parent=parent,
                        ))

            self._class_definitions_provided += tuple(hpmr_categories)