<jupyter_start><jupyter_text>Loading TCGA Data<jupyter_code>tcga_folder_path = ROOT_DIR + "/data/tcga-assembler/LUAD/"
external_path = "/home/jonny_admin/PycharmProjects/nuclei-segmentation/data/external"

luad_data = MultiOmicsData(cancer_type="LUAD", tcga_data_path=tcga_folder_path, external_data_path=external_path,
                           modalities=["GE", "MIR", "LNC"])
luad_data.GE.get_genes_info().index =  luad_data.GE.get_genes_info()["Gene symbol"]
luad_data.GE.get_genes_info()
# Number of overlapping genes between Gene Expressions, microRNAs, and lncRNAs
len(set(luad_data.GE.get_genes_list()) & set(luad_data.MIR.get_genes_list()) & set(luad_data.LNC.get_genes_list()))<jupyter_output><empty_output><jupyter_text>Load miRNA-target interactions network from TargetScan<jupyter_code>mirna_target_interactions = luad_data.MIR.get_miRNA_target_interaction_context().copy()
mirna_target_interactions["weighted context++ score percentile"] = \
    mirna_target_interactions["weighted context++ score percentile"].apply(func=lambda x: x/100.0)
mirna_target_interactions.rename(columns={"weighted context++ score percentile": "weight",
                                         "MiRBase ID": "MIR",
                                         "Gene Symbol": "GE"}, inplace=True)
mirna_target_interactions
import networkx as nx
miRNA_target_g = nx.from_pandas_dataframe(mirna_target_interactions, 
                         source="MIR", target="GE", edge_attr="weight",
                         create_using=nx.DiGraph())
miRNA_target_g.number_of_nodes()
import sys
sys.getsizeof(nx.adjacency_matrix(miRNA_target_g, weight='weight'))
# len(miRNA_target_g.edges())
nx.adjacency_matrix(miRNA_target_g, weight='weight')
d = tf.constant([[1, 1, 1], 
             [2, 2, 2],
             [3, 3, 3],
             [4, 4, 4],                 
             [5, 5, 5], 
             [6, 6, 6]])
tf.slice(d,begin=[6,6], size=[6,1])<jupyter_output><empty_output><jupyter_text>Import PPI network<jupyter_code>import pandas as pd
import numpy as np
import networkx as nx

ppi = pd.read_table("./gem/data/BINARY_PROTEIN_PROTEIN_INTERACTIONS.txt", header=None)
ppi.filter([0,3])
np.savetxt(r'gem/data/ppi.edgelist', ppi.filter([0,3]).values, fmt='%s')
G = nx.read_edgelist('gem/data/ppi.edgelist', create_using=nx.DiGraph())
G = nx.relabel.convert_node_labels_to_integers(G)<jupyter_output><empty_output><jupyter_text>Import Graph Embedding Methods<jupyter_code>import matplotlib.pyplot as plt
import networkx as nx

from gem.utils import graph_util, plot_util
from gem.evaluation import visualize_embedding as viz
from gem.evaluation import evaluate_graph_reconstruction as gr
from gem.evaluation.evaluate_link_prediction import evaluateStaticLinkPrediction

from time import time

from gem.embedding.gf       import GraphFactorization
from gem.embedding.hope     import HOPE
from gem.embedding.lap      import LaplacianEigenmaps
from gem.embedding.lle      import LocallyLinearEmbedding
from gem.embedding.node2vec import node2vec
from gem.embedding.sdne     import SDNE

# File that contains the edges. Format: source target
# Optionally, you can add weights as third column: source target weight

# Specify whether the edges are directed
isDirected = True

# Load graph
# G = graph_util.loadGraphFromEdgeListTxt(edge_f, directed=isDirected)
# G = G.to_directed()

# G = nx.read_edgelist('gem/data/ppi.edgelist', create_using=nx.DiGraph())
G = miRNA_target_g
G = nx.convert_node_labels_to_integers(G)

G
models = []
# You can comment out the methods you don't want to run
models.append(GraphFactorization(d=100, max_iter=10000, eta=1*10**-4, regu=1.0))
models.append(HOPE(d=100, beta=0.01))
# models.append(LaplacianEigenmaps(d=2))
# models.append(LocallyLinearEmbedding(d=2))
# models.append(node2vec(d=100, max_iter=1, walk_len=80, num_walks=10, con_size=10, ret_p=1, inout_p=1))
models.append(SDNE(d=100, beta=5, alpha=1e-5, nu1=1e-6, nu2=1e-6, 
                   K=3, n_units=[50, 15,], rho=0.3, 
                   n_iter=50, xeta=0.01, n_batch=500))

print ('Num nodes: %d, num edges: %d' % (G.number_of_nodes(), G.number_of_edges()))
for embedding in models:
    try:
        print("\n", embedding.get_method_name(), embedding.get_method_summary())
        t1 = time()
    #     Learn embedding - accepts a networkx graph or file with edge list
#         Y, t = embedding.learn_embedding(graph=G, edge_f=None, is_weighted=True, no_python=True)
#         print (embedding._method_name+':\n\tTraining time: %f' % (time() - t1))

        # Evaluate on graph reconstruction
    #     MAP, prec_curv, err, err_baseline = gr.evaluateStaticGraphReconstruction(G, embedding, Y, None)
    #     print ("Graph Reconstruction. MAP:", MAP, ". Prec_curv", prec_curv)

    #     # Evaluate on link prediction
        MAP, prec_curv = evaluateStaticLinkPrediction(G, embedding,
                                     train_ratio=0.8,
                                     is_undirected=False)
        print ("Link Prediction. MAP:", MAP)
        print (embedding._method_name+':\n\tTraining time: %f' % (time() - t1))

        # Visualize
    #     viz.plot_embedding2D(embedding.get_embedding(), di_graph=G, node_colors=None)
    #     plt.show()
    except Exception:
        print("could not run", embedding)<jupyter_output>Num nodes: 12261, num edges: 157643

 graph_factor_sgd graph_factor_sgd_100
		Iter id: 0, Objective: 86096.4, f1: 85978.7, f2: 117.702
Link Prediction. MAP: 0.013560448448284633
graph_factor_sgd:
	Training time: 8424.707361

 hope_gsvd hope_gsvd_100
SVD error (low rank): 1.653647
Link Prediction. MAP: 0.3517557417729534
hope_gsvd:
	Training time: 453.409168

 sdne sdne_100
WARNING:tensorflow:From /opt/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1044: calling reduce_sum (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From /opt/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1123: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNI[...]
{'fraction_non_alphanumeric': 0.11385589865399842, 'fraction_numerical': 0.03436262866191607, 'mean_word_length': 4.143322475570033, 'pattern_counts': {'":': 3, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '314997', 'license': 'FTL', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2140, 'n_words': 453, 'path': 'notebooks/graph embedding tests.ipynb', 'repo_name': 'JonnyTran/nuclei-segmentation', 'size': '6315'}