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
评论列表
文章目录