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
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
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