예제 #1
0
def is_poly_subtree_hemiplasy(root, leaves):
    """
    Returns True if the polymorphic subtree shows hemiplasy
    """

    extincts = [node.data["freq"] == 0.0 for node in leaves]
    return not util.equal(* extincts)
예제 #2
0
파일: phylo.py 프로젝트: sarab609/scraps
 def walk(node):
     if not node.isLeaf():
         counts = []
         for child in node.children:
             walk(child)
             counts.append(child.data['genes'] 
                           - child.data['appear']
                           - child.data['dup'] 
                           + child.data['loss'])
         assert util.equal(* counts), str(counts)
         node.data['genes'] = counts[0]
예제 #3
0
    def walk(node):
        if node in leaves:
            colors[node] = phylo.hash_tree(node, gene2species)
        else:
            # recurse
            for child in node.children:
                walk(child)

            childHashes = util.mget(colors, node.children)
            if len(childHashes) > 1 and util.equal(*childHashes):
                nmirrors[0] += 1

            childHashes.sort()
            colors[node] = phylo.hash_tree_compose(childHashes)
예제 #4
0
    def walk(node):
        if node in leaves:
            colors[node] = phylo.hash_tree(node, gene2species)
        else:
            # recurse
            for child in node.children:
                walk(child)

            childHashes = util.mget(colors, node.children)
            if len(childHashes) > 1 and util.equal(*childHashes):
                nmirrors[0] += 1

            childHashes.sort()
            colors[node] = phylo.hash_tree_compose(childHashes)
예제 #5
0
파일: stats.py 프로젝트: mdrasmus/spimap
def chiSquare(rows, expected=None, nparams=0):
    # ex: rows = [[1,2,3],[1,4,5]]
    assert (util.equal(map(len, rows)))

    if 0 in map(sum, rows): return 0, 1.0
    cols = zip(*rows)
    if 0 in map(sum, cols): return 0, 1.0

    if not expected:
        expected = make_expected(rows)

    chisq = 0
    for obss, exps in zip(rows, expected):
        for obs, exp in zip(obss, exps):
            chisq += ((obs - exp)**2) / exp

    df = max(len(rows) - 1, 1) * max(len(rows[0]) - 1, 1) - nparams

    p = chi_square_lookup(chisq, df)

    return chisq, p
예제 #6
0
파일: stats.py 프로젝트: jeffhsu3/argweaver
def chiSquare(rows, expected=None, nparams=0):
    # ex: rows = [[1,2,3],[1,4,5]]
    assert util.equal(map(len, rows))

    if 0 in map(sum,rows): return 0,1.0
    cols = zip(* rows)
    if 0 in map(sum,cols): return 0,1.0

    if not expected:
        expected = make_expected(rows)

    chisq = 0
    for obss,exps in zip(rows,expected):
        for obs, exp in zip(obss, exps):
            chisq += ((obs-exp)**2)/exp

    df = max(len(rows)-1, 1)*max(len(rows[0])-1, 1) - nparams

    p = chi_square_lookup(chisq,df)

    return chisq,p
예제 #7
0
def is_contig(db, genes):
    """Returns True if genes are contiguous along chromosome"""
    
    if len(genes) > 1:
        pos = [db.get_region_pos_full(i) for i in genes if i in db.regions]

        # ensure hits are on same chromosome
        if not util.equal(* util.cget(pos, 1)):
            return False

        ind = util.cget(pos, 2)
        ind.sort()

        # check that each position is present
        i = ind[0]
        for j in ind[1:]:
            if j != i+1:
                return False
            i += 1

    return True
def is_contig(db, genes):
    """Returns True if genes are contiguous along chromosome"""

    if len(genes) > 1:
        pos = [db.get_region_pos_full(i) for i in genes if i in db.regions]

        # ensure hits are on same chromosome
        if not util.equal(*util.cget(pos, 1)):
            return False

        ind = util.cget(pos, 2)
        ind.sort()

        # check that each position is present
        i = ind[0]
        for j in ind[1:]:
            if j != i + 1:
                return False
            i += 1

    return True
예제 #9
0
def validate_seqs(seqs):
    """Ensures sequences are all same size"""

    sizes = map(len, seqs.values())
    assert util.equal(*sizes), "sequences are not same length"
예제 #10
0
def validate_seqs(seqs):
    """Ensures sequences are all same size"""
    
    sizes = map(len, seqs.values())
    assert util.equal(* sizes), "sequences are not same length"