build_splicegraph.py 文件源码

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

项目:exfi 作者: jlanga 项目源码 文件源码
def build_splicegraph(exon_index):
    """Build the splicegraph from a dict of SeqRecords

    Splicegraph is a directed graph, whose nodes
        - are exon_ids,
        - attributes are
            - coordinates [(transcript1, start, end), ..., (transcriptN, start, end)]
            - sequence in str format
    and whose edges
        - are connected exons in any way
        - attributes are the overlap between them:
            - positive means there is an overlap of that number of bases
            - zero means no overlap
            - negative means a gap of that number of bases
    """
    # Initialize grpah
    splice_graph = nx.DiGraph()

    # Add nodes
    splice_graph.add_nodes_from(exon_index.keys())
    nx.set_node_attributes(
        G=splice_graph,
        name='coordinates',
        values= exon_to_coordinates(exon_index)
    )
    nx.set_node_attributes(
        G=splice_graph,
        name='sequence',
        values={exon.id : str(exon.seq) for exon in exon_index.values()}
    )

    # Edges
    transcript2path = transcript_to_path(exons_to_df(exon_index))
    for path in transcript2path.values():
        splice_graph.add_path(path)

    nx.set_edge_attributes(
        G=splice_graph,
        name='overlap',
        values = compute_edge_overlaps(splice_graph)
    )

    return splice_graph
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号