コード例 #1
0
ファイル: genecall.py プロジェクト: ongkong/compbio
def findNeighbors(regiondb, genes):
    """Determine which genes in 'genes' are neighboring genes in the 
       chromosomes 'chroms'
       
       returns a clustering of the genes in clusters of neighboring streaks
    """

    geneset = set(genes)
    neighbors = util.Dict(dim=2)    
    
    for gene in genes:
        chrom = regiondb.species[gene.species][gene.seqname]
        ind = regionlib.findRegion(chrom, gene)
        
        # look for neighboring genes on same strand
        if ind > 0:
            left = chrom[ind-1]
            if left in geneset and left.strand == gene.strand:
                neighbors[gene][left] = 1
                neighbors[left][gene] = 1
        
        if ind < len(chrom)-1:
            right = chrom[ind+1]
            if right in geneset and right.strand == gene.strand:
                neighbors[gene][right] = 1
                neighbors[right][gene] = 1
    
    comps = graph.connectedComponents(genes, lambda x: neighbors[x].keys())
    
    # sort neighbors in order of appearance along strand
    for comp in comps:
        comp.sort(key=lambda x: x.start, 
                  reverse=(comp[0].strand == -1))
    
    return comps
コード例 #2
0
def unionPart(* partsList):
    """Finds the union of several partitions"""

    mat = part2graph(util.concat(* partsList))
    parts = graph.connectedComponents(mat.keys(), lambda x: mat[x].keys())

    # remove parition ids from partitioning
    parts = map(lambda part: filter(lambda x: type(x) != int, part), parts)

    return parts
コード例 #3
0
ファイル: cluster.py プロジェクト: ongkong/compbio
def unionPart(*partsList):
    """Finds the union of several partitions"""

    mat = part2graph(util.concat(*partsList))
    parts = graph.connectedComponents(mat.keys(), lambda x: mat[x].keys())

    # remove parition ids from partitioning
    parts = map(lambda part: filter(lambda x: type(x) != int, part), parts)

    return parts