import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
f=open('D:\MalwareDetectionProject\Graphs\Auth_citrix_module.gdl','r');
G=nx.DiGraph();
print 'hello';
count=0;
for line in f.readlines():
	if line.split()[0] == 'node:':
		if len(line.split()) > 6:
			G.add_node(line.split()[3]+' '+line.split()[5]+' '+line.split()[7]);
		else:
			G.add_node(line.split()[3]+' '+'null'+' '+'null');
	elif line.split()[0] == 'edge:':
		G.add_edge(int(line.split()[3].replace('"','')),int(line.split()[5].replace('"','')));

	#	print G.edges();
l=list(G.in_degree_iter());
arr=np.array(l);
d=dict();
for i in range(0,arr.shape[0]):
	key=arr[i][1];
	if key not in d:
		d[key]=1;
	else:	
		d[key] = d[key]+1;

x=d.keys();
y=d.values();
prob=np.multiply(np.array(y),1.0/G.number_of_nodes());

print x
print y
print prob;
print G.number_of_nodes();
plt.scatter(x,prob);


l=list(G.out_degree_iter());
arr=np.array(l);
d=dict();
for i in range(0,arr.shape[0]):
	key=arr[i][1];
	if key not in d:
		d[key]=1;
	else:	
		d[key] = d[key]+1;

x=d.keys();
y=d.values();
prob=np.multiply(np.array(y),1.0/G.number_of_nodes());

print x
print y
print prob;
print G.number_of_nodes();
plt.scatter(x,prob);
plt.show();


