'To plot PPI (Protein-Protein interaction graph) and calculate PPI distance in python
I want to plot the PPI graph and then calculate the PPI minimum distance in igraph. I am running this code in Jupyter notebook and I am getting no error but the distancee matrix is also not generated.
My input file "PPI_links.tsv" looks like (header)
ARF5 ACTR10
ARF5 ACTR1A
ARF5 ANK1
ARF5 ANK2
ARF5 ANK3
Here is my code:
import igraph
import pandad as pd
#import input file
ppi_file = pd.read_csv("PPI_links.tsv", sep="\t", header=None)
#define edges
edges = [line.strip().split("\t") for line in open("PPI_links.tsv")]
vertices = list(set(edge[0] for edge in edges))
edges = [(edge[0], edge[1]) for edge in edges if edge[0] < edge[1]]
# Build graph with graph
graph = igraph.Graph(directed=False)
graph.add_vertices(vertices)
graph.add_edges(edges)
return graph.simplify(combine_edges="max")
# Compute PPI distances (the minimum distances calculated between the target gene and featured genes)
graph = get_PPI_graph("PPI_links.tsv")
genes = list(set(gene_feature_info.index.unique()).intersection(set(graph.vs["name"])))
feature_genes = list(set(gene_feature_info["Feature Gene"].dropna().unique()).intersection(set(graph.vs["name"])))
distance_matrix = graph.shortest_paths(source=feature_genes, target=genes)
distances = dict(
(feature_gene, dict((gene, distance) for gene, distance in zip(genes, distances)))
for feature_gene, distances in zip(feature_genes, distance_matrix)
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
