def main():
    PPI_Network = loader.load_graph('../Data/9606.protein.links.v11.0.txt')
    #ground_truth_files = ['../Data/MalaCard-protein-Endometriosis.diseasegenes.tsv', '../Data/MalaCard-protein-ischaemic-stroke.diseasegenes.tsv','../Data/MalaCard-protein-lymphoma.diseasegenes.tsv']
    file_paths = [
        '../Data/endometriosis-proteins.diseasegenes.tsv',
        '../Data/lymphoma-proteins.diseasegenes.tsv',
        '../Data/ischaemic-proteins.diseasegenes.tsv'
    ]
    names = [
        "endometriosis.graphml", "lymphoma.graphml", "ischaemic_stroke.graphml"
    ]
    # for i in range(3):
    #     nodes_in_subgraph =[]
    #     with open(file_paths[i], 'r') as input:
    #         input = input.readlines()
    #         for line in input:
    #             protein = line.rstrip('\n')
    #             nodes_in_subgraph.append(protein)
    #
    #             neighbors = list(PPI_Network.neighbors(protein))
    #             nodes_in_subgraph = nodes_in_subgraph + neighbors
    #
    #     subgraph = PPI_Network.subgraph(nodes_in_subgraph)
    #
    #     nx.write_graphml(subgraph, names[i])
    #     print("exported file named" + names[i])

    nodes_in_subgraph = []
    with open(file_paths[2], 'r') as input:
        input = input.readlines()
        for line in input:
            protein = line.rstrip('\n')
            nodes_in_subgraph.append(protein)

            neighbors = list(PPI_Network.neighbors(protein))
            nodes_in_subgraph = nodes_in_subgraph + neighbors

    subgraph = PPI_Network.subgraph(nodes_in_subgraph)

    nx.write_graphml(subgraph, names[2])
    print("exported file named" + names[2])
Exemplo n.º 2
0
if not kcross:
    torch.random.manual_seed(seed // 3)
    random.seed(seed // 3)
    np.random.seed(seed // 3)

cuda_is_available = torch.cuda.is_available()
print("Cuda: ", cuda_is_available)

if cuda_is_available and device_ == 'gpu':
    device = torch.device("cuda")
else:
    device = torch.device("cpu")

dataset_name = dataset
A, X, Y = load_graph(dataset_name)

D_inv = 1 / A.sum(axis=1).astype('float32')
P = np.dot(np.diag(D_inv), A)

A = torch.tensor(A)
P = torch.tensor(P)

feat_size = X.shape[1]


def train_dvna(A, P, verbose=False):
    n_epochs = 4000

    train_ones_indices, train, val, test = u.split_dataset(A, seed=seed)

def neighbourhood_all(g, depth):
	'''
	set neighbourhood of each node to BFS of depth "depth"
	todo: this should probably be in "graph.py"
	'''
	iteration = 0
	for auth_id, auth_t in g.authors.iteritems():
		if (iteration%250 == 0):
			print "computing neighbourhood %d out of %d"%(iteration, len(g.authors))
		iteration += 1
		pickle.dump(bfs.bfs(g, depth, auth_id), open("neighbourhood/%d"%auth_id, 'wb')) # we actually dump the neighbourhood to a file, can't save all of this in memory. It enables easy enough access from code, but not very efficient.


print "loading graph"
g = loader.load_graph()
g.authors[73317].edges[1200930] = 4
g.authors[1200930].edges[73317] = 4
print "noga alon projection"
noga_alon_projection(g, 3)
print "bounding degree to %d"%50
bound_degree(g, 50)
print "removing low degree nodes"
remove_low_degree(g, 3)
print "saving resultant graph to file"
pickle.dump(g, open("processed_graph.pickle", "wb"))
print "setting neighbourhood for all nodes"
neighbourhood_all(g, 3)
print "done"
Exemplo n.º 4
0
	set neighbourhood of each node to BFS of depth "depth"
	todo: this should probably be in "graph.py"
	'''
    iteration = 0
    for auth_id, auth_t in g.authors.iteritems():
        if (iteration % 250 == 0):
            print "computing neighbourhood %d out of %d" % (iteration,
                                                            len(g.authors))
        iteration += 1
        pickle.dump(
            bfs.bfs(g, depth, auth_id), open("neighbourhood/%d" % auth_id,
                                             'wb')
        )  # we actually dump the neighbourhood to a file, can't save all of this in memory. It enables easy enough access from code, but not very efficient.


print "loading graph"
g = loader.load_graph()
g.authors[73317].edges[1200930] = 4
g.authors[1200930].edges[73317] = 4
print "noga alon projection"
noga_alon_projection(g, 3)
print "bounding degree to %d" % 50
bound_degree(g, 50)
print "removing low degree nodes"
remove_low_degree(g, 3)
print "saving resultant graph to file"
pickle.dump(g, open("processed_graph.pickle", "wb"))
print "setting neighbourhood for all nodes"
neighbourhood_all(g, 3)
print "done"
#import plotly.express as px
import matplotlib.pyplot as plt
import networkx as nx
from loader import load_graph
import sys

if len(sys.argv) != 2:
    print("Usage: python3 plot-graph-degree-histogram.py path-to-ppi-network")
    sys.exit()

DATA_PATH = sys.argv[1]

ppi_graph = load_graph(DATA_PATH)
result = []
hist = nx.degree_histogram(ppi_graph)
for i, count in enumerate(hist):
    if count > 0:
        result.append((i, count))
print(result)
plt.hist(hist, nbins=50)
plt.show()