File size: 1,765 Bytes
07fcdfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
Export PPI with all genes in LINCS (those that overlap)
'''

#Generate a subset of the PPI
#First checks the overlap between genes in PPI (BRIOGRID) and genes in LINCS
#Removes all genes from PPI that are *not* in LINCS (no GE data available for them)


import networkx as nx
import csrgraph as cg
from collections import Counter
import pandas as pd
import os
import os.path as osp

path_edge_list = '../../raw/ppi/2022-03-PPI/processed/ppi_edgelist.txt'
log_handle = open('log_ppi_all_genes.txt', 'w')


#Loads dataset PPI (BIOGRID)
ppi = nx.read_edgelist(path_edge_list)
#Loads gene info LINCS
gene_info = pd.read_csv('../../raw/lincs/2022-02-LINCS_Level3/data/geneinfo_beta.txt', sep="\t", low_memory=False)



log_handle.write('Overlap of genes from LINCS to PPI:{}/{}\n'.format(len(set(ppi.nodes()).intersection(set(gene_info['gene_symbol']))), len(gene_info)))

#Filter nodes from PPI to keep only the ones in LINCS
ppi = ppi.subgraph(gene_info['gene_symbol'].tolist())
log_handle.write('Keeping only PPI nodes that are in LINCS:{}\n'.format(ppi.number_of_nodes()))

ccs = [len(c) for c in sorted(nx.connected_components(ppi), key=len, reverse=True)]
log_handle.write('Number of connected componens:\t{}\n'.format(len(ccs)))
Gcc = sorted(nx.connected_components(ppi), key=len, reverse=True)
ppi = ppi.subgraph(Gcc[0])
log_handle.write('After keeping only biggest CC:\n')
log_handle.write('stats: {} nodes, {} edges, {} density, {} diameter\n\n\n'.format(ppi.number_of_nodes(), ppi.number_of_edges(), nx.density(ppi), nx.diameter(ppi)))

#Saves ppi
outdir = '../../processed/ppi'
os.makedirs(outdir, exist_ok=True)
ppi_f = osp.join(outdir, 'ppi_all_genes_edgelist.txt')

nx.write_edgelist(ppi, ppi_f, data=False) 




log_handle.close()