コード例 #1
0
ファイル: Blat.py プロジェクト: BioXiao/cgat
def getComponents(matches, max_distance=0, min_overlap=0, by_query=False):
    """return overlapping matches.

    max_distance
       allow reads to be joined if they are # residues apart. 
       Adjacent reads are 1 residue apart, overlapping reads are 0 residues
       apart
    min_overlap
       require at least # residues to be overlapping

    """

    addAlignments(matches, by_query=by_query)

    components = Components.IComponents()

    for x in range(0, len(matches)):
        components.add(x, x)

    if min_overlap > 0 and max_distance > 0:
        raise ValueError(
            "both min_overlap (%i) and max_distance (%i) > 0" % (min_overlap, max_distance))

    if by_query:
        if min_overlap > 0:
            f = lambda x, y: alignlib_lite.py_getAlignmentOverlap(
                matches[x].mMapQuery2Target,
                matches[y].mMapQuery2Target,
                alignlib_lite.py_RR) >= min_overlap
        else:
            f = lambda x, y: alignlib_lite.py_getAlignmentShortestDistance(
                matches[x].mMapQuery2Target,
                matches[y].mMapQuery2Target,
                alignlib_lite.py_RR) <= max_distance
    else:
        if min_overlap > 0:
            f = lambda x, y: alignlib_lite.py_getAlignmentOverlap(
                matches[x].mMapTarget2Query,
                matches[y].mMapTarget2Query,
                alignlib_lite.py_RR) >= min_overlap
        else:
            f = lambda x, y: alignlib_lite.py_getAlignmentShortestDistance(
                matches[x].mMapTarget2Query,
                matches[y].mMapTarget2Query,
                alignlib_lite.py_RR) <= max_distance

    for x in range(len(matches)):
        for y in range(0, x):
            if f(x, y):
                components.add(x, y)

    return components.getComponents()
コード例 #2
0
def getComponents(matches, max_distance=0, min_overlap=0, by_query=False):
    """return overlapping matches.

    max_distance
       allow reads to be joined if they are # residues apart. 
       Adjacent reads are 1 residue apart, overlapping reads are 0 residues
       apart
    min_overlap
       require at least # residues to be overlapping

    """

    addAlignments(matches, by_query=by_query)

    components = Components.IComponents()

    for x in range(0, len(matches)):
        components.add(x, x)

    if min_overlap > 0 and max_distance > 0:
        raise ValueError(
            "both min_overlap (%i) and max_distance (%i) > 0" % (min_overlap, max_distance))

    if by_query:
        if min_overlap > 0:
            f = lambda x, y: alignlib_lite.py_getAlignmentOverlap(
                matches[x].mMapQuery2Target,
                matches[y].mMapQuery2Target,
                alignlib_lite.py_RR) >= min_overlap
        else:
            f = lambda x, y: alignlib_lite.py_getAlignmentShortestDistance(
                matches[x].mMapQuery2Target,
                matches[y].mMapQuery2Target,
                alignlib_lite.py_RR) <= max_distance
    else:
        if min_overlap > 0:
            f = lambda x, y: alignlib_lite.py_getAlignmentOverlap(
                matches[x].mMapTarget2Query,
                matches[y].mMapTarget2Query,
                alignlib_lite.py_RR) >= min_overlap
        else:
            f = lambda x, y: alignlib_lite.py_getAlignmentShortestDistance(
                matches[x].mMapTarget2Query,
                matches[y].mMapTarget2Query,
                alignlib_lite.py_RR) <= max_distance

    for x in range(len(matches)):
        for y in range(0, x):
            if f(x, y):
                components.add(x, y)

    return components.getComponents()
コード例 #3
0
def compareChains( pairs1, pairs2 ):
    '''compare chains in pairs1 versus those in pairs2'''
    
    result = {}
    for key1, chain1 in pairs1.iteritems():
        E.debug( "comparing %s" % str(key1) )

        ntotal = chain1.getNumAligned()

        if key1 not in pairs2:
            result[ key1 ] = DiffResult._make( (ntotal, 0, 0, ntotal) )
            continue

        chain2 = pairs2[key1]
        nsame = alignlib_lite.py_getAlignmentIdentity( chain1, chain2, alignlib_lite.py_RR )
        noverlap = alignlib_lite.py_getAlignmentOverlap( chain1, chain2, alignlib_lite.py_RR )
        ndifferent = noverlap - nsame
        nunique = ntotal - noverlap

        result[ key1 ] = DiffResult._make( (ntotal, nsame, ndifferent, nunique ) )

    return result
コード例 #4
0
ファイル: diff_chains.py プロジェクト: yangjl/cgat
def compareChains(pairs1, pairs2):
    '''compare chains in pairs1 versus those in pairs2'''

    result = {}
    for key1, chain1 in pairs1.iteritems():
        E.debug("comparing %s" % str(key1))

        ntotal = chain1.getNumAligned()

        if key1 not in pairs2:
            result[key1] = DiffResult._make((ntotal, 0, 0, ntotal))
            continue

        chain2 = pairs2[key1]
        nsame = alignlib_lite.py_getAlignmentIdentity(chain1, chain2,
                                                      alignlib_lite.py_RR)
        noverlap = alignlib_lite.py_getAlignmentOverlap(
            chain1, chain2, alignlib_lite.py_RR)
        ndifferent = noverlap - nsame
        nunique = ntotal - noverlap

        result[key1] = DiffResult._make((ntotal, nsame, ndifferent, nunique))

    return result