enrichment.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:gamtools 作者: pombo-lab 项目源码 文件源码
def get_feature_summary(pairwise_interactions, window_classes):
    """
    Count the number of pairwise interactions between different window classes.

    :param pairwise_interactions: Table of pairwise interactions.
    :type pairwise_interactions: :class:`pandas.DataFrame`
    :param window_classes: Table of windows and their classifications
    :type window_classes: :class:`pandas.DataFrame`
    :returns: A list of tuples of the form (first class, second class, count).

    >>> pairwise_interactions = pd.DataFrame([('chr1', 10, 20, 0.75),
    ...                                        ('chr2', 10, 20, 0.5),
    ...                                        ('chr1', 10, 30, 0.4)],
    ...                                      columns=['chrom', 'Pos_A', 'Pos_B',
    ...                                               'interaction'])
    >>> pairwise_interactions
      chrom  Pos_A  Pos_B  interaction
    0  chr1     10     20         0.75
    1  chr2     10     20         0.50
    2  chr1     10     30         0.40
    >>> window_classification = pd.DataFrame([('chr1', 10, True, False),
    ...                                       ('chr1', 20, False, True),
    ...                                       ('chr2', 20, True, False),
    ...                                       ('chr2', 30, False, True)],
    ...                                      columns=['chrom', 'i', 'Enhancer', 'Gene'])
    >>> window_classification
      chrom   i Enhancer   Gene
    0  chr1  10     True  False
    1  chr1  20    False   True
    2  chr2  20     True  False
    3  chr2  30    False   True
    >>> enrichment.get_feature_summary(pairwise_interactions, window_classification)
    [('Enhancer', 'Enhancer', 0), ('Enhancer', 'Gene', 1), ('Gene', 'Gene', 0)]
    """

    results = []
    feature_classes = [col for col in window_classes.columns
                       if not col in ['chrom', 'start', 'stop', 'i']]

    for feat1, feat2 in itertools.combinations_with_replacement(
            feature_classes, 2):

        feat_values = feature_pair_values(
            pairwise_interactions, window_classes, feat1, feat2)

        results.append((feat1, feat2, len(feat_values)))

    return results
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号