Пример #1
0
 def eq(self, a, b):
     if a._anomer != b._anomer:
         return False
     if a._config != b._config:
         return False
     if a._stem != b._stem:
         return False
     if a._superclass != b._superclass:
         return False
     if a._ring_start != b._ring_start:
         return False
     if a._ring_end != b._ring_end:
         return False
     if a._mods != b._mods:
         return False
     any = False
     for ii, jj in itermatchings(
             a.substituent_links(), b.substituent_links(),
             lambda i, j: self.sublinkeq(i, j) and self.substeq(
                 i.child(), j.child())):
         any = True
         break
     if not any:
         return False
     return True
Пример #2
0
 def eq(self, a, b):
     # Remove anomer, anything else?
     if a._config != b._config:
         return False
     if a._stem != b._stem:
         return False
     if a._superclass != b._superclass:
         return False
     if a._ring_start != b._ring_start:
         return False
     if a._ring_end != b._ring_end:
         return False
     # Should mods be checked without positions?
     if a._mods != b._mods:
         return False
     any = False
     for ii, jj in itermatchings(
             a.substituent_links(), b.substituent_links(),
             lambda i, j: self.sublinkeq(i, j) and self.substeq(
                 i.child(), j.child())):
         any = True
         break
     if not any:
         return False
     return True
Пример #3
0
    def leq(self, m, g):
        if m._anomer and m._anomer != g._anomer:
            return False
        if m._config and m._config != g._config:
            return False
        if m._stem and m._stem != g._stem:
            return False
        if m._superclass != g._superclass:
            return False
        if m._ring_start and m._ring_start != g._ring_start:
            return False
        if m._ring_end and m._ring_end != g._ring_end:
            return False
        if m._mods != g._mods:
            return False

        any = False
        for ii, jj in itermatchings(
                m.substituent_links(), g.substituent_links(),
                lambda i, j: self.sublinkeq(i, j) and self.substeq(
                    i.child(), j.child())):
            any = True
            break
        if not any:
            return False

        return True
Пример #4
0
    def monosaccharide_match(self, a, b):

        if not self.monoeq(a, b):
            return False
        if len(a.parent_links()) != len(b.parent_links()):
            return False
        if len(a.links(instantiated_only=True)) != len(
                b.links(instantiated_only=True)):
            return False
        if len(a.links(instantiated_only=False)) != len(
                b.links(instantiated_only=False)):
            return False

        assert self.adist and self.bdist
        if self.adist[0].get(a.id()) != self.bdist[0].get(b.id()):
            return False
        if self.adist[1].get(a.id()) != self.bdist[1].get(b.id()):
            return False

        child_links_match = False
        for ii, jj in itermatchings(
                a.links(instantiated_only=False),
                b.links(instantiated_only=False), lambda i, j: self.linkeq(
                    i, j) and self.monoeq(i.child(), j.child())):
            child_links_match = True
            break
        return child_links_match
Пример #5
0
 def leq(self, a, b):
     if not self._leq_(a._anomer, b._anomer):
         return False
     if not self._leq_(a._config, b._config):
         return False
     if not self._leq_(a._stem, b._stem):
         return False
     if not self._leq_(a._superclass, b._superclass):
         return False
     if not self._leq_(a._ring_start, b._ring_start):
         return False
     if not self._leq_(a._ring_end, b._ring_end):
         return False
     if a._mods != b._mods:
         return False
     any = False
     for ii, jj in itermatchings(
             a.substituent_links(), b.substituent_links(),
             lambda i, j: self.sublinkleq(i, j) and self.substeq(
                 i.child(), j.child())):
         any = True
         break
     if not any:
         return False
     return True
Пример #6
0
 def monosaccharide_match(a, b):
     # print a
     # print b
     if not a.equals(b):
         return False
     # parent_links_match = False
     # for ii,jj in itermatchings(a.parent_links(),b.parent_links(),
     #                            lambda i,j: i.equals(j) and i.parent().equals(j.parent())):
     #     parent_links_match = True
     #     break
     # if not parent_links_match:
     #     return False
     if len(a.parent_links()) != len(b.parent_links()):
         return False
     if len(a.links(instantiated_only=True)) != len(
             b.links(instantiated_only=True)):
         return False
     if len(a.links(instantiated_only=False)) != len(
             b.links(instantiated_only=False)):
         return False
     child_links_match = False
     for ii, jj in itermatchings(
             a.links(instantiated_only=False),
             b.links(instantiated_only=False),
             lambda i, j: i.equals(j) and i.child().equals(j.child())):
         child_links_match = True
         break
     return child_links_match
Пример #7
0
    def subtree_leq(self, a, b, root=True):

        if root:
            if not self.rootmonoleq(a, b):
                return False
        else:
            if not self.monoleq(a, b):
                return False

        for ii, jj in itermatchings(
                a.links(), b.links(), lambda i, j: self.linkleq(i, j) and self.
                subtree_leq(i.child(), j.child(), root=False)):
            return True

        return False
Пример #8
0
    def subtree_leq(self, m, tg, root=True):

        if root:
            if not self.rootmonoleq(m, tg):
                return False
        else:
            if not self.monoleq(m, tg):
                return False

        for tg_linkset in choose(tg.links(), len(m.links())):
            for ii, jj in itermatchings(
                    m.links(), tg_linkset, lambda i, j: self.linkleq(i, j) and
                    self.subtree_leq(i.child(), j.child(), root=False)):
                return True

        return False
Пример #9
0
    def subtree_equals(self,m,mapids=True):

        if not self.equals(m):
            return False
        
        if mapids:
            m.set_id(self.id())

        for ii,jj in itermatchings(self.links(),m.links(),
                                   lambda i,j: i.equals(j) and i.child().subtree_equals(j.child(),mapids=mapids)):
            return True

        if mapids:
            m.unset_id()

        return False
Пример #10
0
    def subtree_eq(self, a, b, root=True, mapids=False):

        if root:
            if not self.rootmonoeq(a, b):
                return False
        else:
            if not self.monoeq(a, b):
                return False

        if mapids:
            b.set_id(a.id())

        for ii, jj in itermatchings(
                a.links(), b.links(), lambda i, j: self.linkeq(i, j) and self.
                subtree_eq(i.child(), j.child(), root=False, mapids=mapids)):
            return True

        if mapids:
            b.unset_id()

        return False
Пример #11
0
 def anysubstmatching(self, m):
     for ii, jj in itermatchings(
             self.substituent_links(), m.substituent_links(),
             lambda i, j: i.equals(j) and i.child().equals(j.child())):
         return True
     return False