Beispiel #1
0
    def is_positioned_compatibly(self, other):
        """ Are these InwardsPointingCodingBlockGraph positioned compatibly? """
        mutualorgs = self.mutual_organisms(other)
        analyses = []
        for (pacbpkey, nodeQ, nodeS), pacbporf in self.pacbps.iteritems():
            orgQ = self.organism_by_node(nodeQ)
            orgS = self.organism_by_node(nodeS)
            if not orgQ in mutualorgs or not orgS in mutualorgs: continue
            for (_pacbpkey, _nodeQ,
                 _nodeS), _pacbporf in other.pacbps.iteritems():
                _orgQ = other.organism_by_node(_nodeQ)
                _orgS = other.organism_by_node(_nodeS)
                if _orgQ != orgQ or _orgS != orgS: continue
                pos = pacbporf.relatively_positioned_towards(_pacbporf)
                (q1, s1) = relpos2binaryrelpos(pos['Q1'], pos['S1'])
                (q2, s2) = relpos2binaryrelpos(pos['Q2'], pos['S2'])
                # check positioning
                if q1 != s1: analyses.append([False, None])
                elif q2 != s2: analyses.append([False, None])
                else: analyses.append([True, q1[0] == 1])

        # Have closer look on the (True,...) tuples.
        # The orientation self->other or other->self is stored in the 2th value
        # These orientations must therefor be identical
        cnt_false = [a for a, b in analyses].count(False)
        cnt_ab = [b for a, b in analyses].count(True)
        cnt_ba = [b for a, b in analyses].count(False)
        return_list = []
        for pos in range(0, cnt_false):
            return_list.append(False)
        if cnt_ab > cnt_ba:
            for pos in range(0, cnt_ba):
                return_list.append(False)
            for pos in range(0, cnt_ab):
                return_list.append(True)
        elif cnt_ab < cnt_ba:
            for pos in range(0, cnt_ab):
                return_list.append(False)
            for pos in range(0, cnt_ba):
                return_list.append(True)
        else:
            # identical in size
            for pos in range(0, cnt_ab):
                return_list.append(False)
            for pos in range(0, cnt_ba):
                return_list.append(True)
        # return the return_list outcome
        return return_list
def relatively_positioned_towards(cbg1, cbg2):
    """
    """
    # get union of organisms between two CBGs
    allorgs = cbg1.organism_set().union(cbg2.organism_set())
    posRel = []
    posBin = []
    orfIdent = []
    # get overall minimal spanning range data structures for comparison
    omsrCbg1 = cbg1.overall_minimal_spanning_range()
    omsrCbg2 = cbg2.overall_minimal_spanning_range()
    for org in allorgs:
        if org in cbg1.organism_set() and org in cbg2.organism_set():
            nodeCbg1 = cbg1.node_by_organism(org)
            nodeCbg2 = cbg2.node_by_organism(org)
            if len(omsrCbg1[nodeCbg1]) == 0 or len(omsrCbg2[nodeCbg2]) == 0:
                continue
            # get relative positioning of the OMSRs
            (a1, a2, a3), (b1, b2, b3) = rel_pos_sets(
                omsrCbg1[nodeCbg1],
                omsrCbg2[nodeCbg2],
            )
            # get binary relative positioning of the OMSRs
            (Ba1, Ba2, Ba3), (Bb1, Bb2, Bb3) = relpos2binaryrelpos(
                (a1, a2, a3), (b1, b2, b3))
            posRel.append(((a1, a2, a3), (b1, b2, b3)))
            posBin.append(((Ba1, Ba2, Ba3), (Bb1, Bb2, Bb3)))
            # check if the orfs are identical
            orfCbg1 = cbg1.get_orfs_of_graph(organism=org)[0]
            orfCbg2 = cbg2.get_orfs_of_graph(organism=org)[0]
            orfIdent.append(orfCbg1.id == orfCbg2.id)

    # make summed binary tuples
    summedPosBin = ([0, 0, 0], [0, 0, 0])
    for i in range(0, 2):
        for j in range(0, 3):
            summedPosBin[i][j] = sum([item[i][j] for item in posBin])
    # and make binary tuples of this one
    (binPosCbg1,
     binPosCbg2) = relpos2binaryrelpos(summedPosBin[0],
                                       summedPosBin[1],
                                       overlap_offset=0,
                                       percentual_overlap_offset=0.0)

    # return summed tuples, binary tuples and orfIdent for cbg1 and cbg2
    return summedPosBin[0], summedPosBin[
        1], binPosCbg1, binPosCbg2, orfIdent, posRel, posBin
Beispiel #3
0
def relatively_positioned_towards(cbg1,cbg2):
    """
    """
    # get union of organisms between two CBGs
    allorgs = cbg1.organism_set().union( cbg2.organism_set() )
    posRel  = []
    posBin  = []
    orfIdent= []
    # get overall minimal spanning range data structures for comparison
    omsrCbg1 = cbg1.overall_minimal_spanning_range()
    omsrCbg2 = cbg2.overall_minimal_spanning_range()
    for org in allorgs:
        if org in cbg1.organism_set() and org in cbg2.organism_set():
            nodeCbg1 = cbg1.node_by_organism(org)
            nodeCbg2 = cbg2.node_by_organism(org)
            if len(omsrCbg1[nodeCbg1]) == 0 or len(omsrCbg2[nodeCbg2]) == 0:
                continue
            # get relative positioning of the OMSRs
            (a1,a2,a3), (b1,b2,b3) = rel_pos_sets(
                    omsrCbg1[nodeCbg1],
                    omsrCbg2[nodeCbg2],
                    )
            # get binary relative positioning of the OMSRs
            (Ba1,Ba2,Ba3), (Bb1,Bb2,Bb3) = relpos2binaryrelpos( (a1,a2,a3), (b1,b2,b3) )
            posRel.append( ( (a1,a2,a3), (b1,b2,b3) ) )
            posBin.append( ( (Ba1,Ba2,Ba3), (Bb1,Bb2,Bb3) ) )
            # check if the orfs are identical
            orfCbg1 = cbg1.get_orfs_of_graph(organism=org)[0]
            orfCbg2 = cbg2.get_orfs_of_graph(organism=org)[0]
            orfIdent.append( orfCbg1.id == orfCbg2.id )

    # make summed binary tuples
    summedPosBin = ( [0,0,0], [0,0,0] )
    for i in range(0,2):
        for j in range(0,3):
            summedPosBin[i][j] = sum([ item[i][j] for item in posBin ] )
    # and make binary tuples of this one
    ( binPosCbg1, binPosCbg2 ) = relpos2binaryrelpos(
            summedPosBin[0],
            summedPosBin[1],
            overlap_offset = 0,
            percentual_overlap_offset = 0.0
            )

    # return summed tuples, binary tuples and orfIdent for cbg1 and cbg2
    return summedPosBin[0], summedPosBin[1], binPosCbg1, binPosCbg2, orfIdent, posRel, posBin
    def is_positioned_compatibly(self,other):
        """ Are these InwardsPointingCodingBlockGraph positioned compatibly? """
        mutualorgs = self.mutual_organisms(other)
        analyses = []
        for (pacbpkey,nodeQ,nodeS),pacbporf in self.pacbps.iteritems():
            orgQ = self.organism_by_node(nodeQ)
            orgS = self.organism_by_node(nodeS)
            if not orgQ in mutualorgs or not orgS in mutualorgs: continue
            for (_pacbpkey,_nodeQ,_nodeS),_pacbporf in other.pacbps.iteritems():
                _orgQ = other.organism_by_node(_nodeQ)
                _orgS = other.organism_by_node(_nodeS)
                if _orgQ != orgQ or _orgS != orgS: continue
                pos = pacbporf.relatively_positioned_towards(_pacbporf)
                (q1,s1) = relpos2binaryrelpos(pos['Q1'],pos['S1'])
                (q2,s2) = relpos2binaryrelpos(pos['Q2'],pos['S2'])
                # check positioning
                if q1 != s1:   analyses.append( [ False, None ] )
                elif q2 != s2: analyses.append( [ False, None ] )
                else:          analyses.append( [ True, q1[0]==1 ] )

        # Have closer look on the (True,...) tuples.
        # The orientation self->other or other->self is stored in the 2th value
        # These orientations must therefor be identical
        cnt_false = [ a for a,b in analyses ].count(False)
        cnt_ab    = [ b for a,b in analyses ].count(True)
        cnt_ba    = [ b for a,b in analyses ].count(False)
        return_list = []
        for pos in range(0,cnt_false): return_list.append(False)
        if cnt_ab > cnt_ba:
            for pos in range(0,cnt_ba): return_list.append(False)
            for pos in range(0,cnt_ab): return_list.append(True)
        elif cnt_ab < cnt_ba:
            for pos in range(0,cnt_ab): return_list.append(False)
            for pos in range(0,cnt_ba): return_list.append(True)
        else:
            # identical in size
            for pos in range(0,cnt_ab): return_list.append(False)
            for pos in range(0,cnt_ba): return_list.append(True)
        # return the return_list outcome
        return return_list