def communityGraph(fName,w,pos=None,s=1):
	#for the name of the graph add .G
	# for the name of communities add .C
	tit=w.replace('.G','').replace('s','/')
	gFile=os.getcwd()+'/CSV/Graphs/'+fName+'/'+w+'.G'
	pDir=os.getcwd()+'/PIC/'+fName
	wFile=os.getcwd()+'/CSV/WalkTrap/'+fName+'/'+w+'.C'
	if (not os.path.exists(gFile)) or (not os.path.exists(wFile)):
		print 'Error: '+gFile+' or '+wFile+' not found'
		return 101
		
	if (not os.path.exists(pDir)):
		os.mkdir(pDir)

	print '--------------------'
	G=nx.read_graphml(gFile)
	fn=wFile
	try:
		f=open(fn,'r')
	except IOError:
		print 'Could not open '+fn
		return
	a=sorted(G.nodes())
	#~ b=[str(xx) for xx in range(len(a))]
	#~ myDic=list2dic(b,a)
	C=0
	for k,line in enumerate(f):
		C=C+1
		t1=line.strip(' {}\t\n')
		t2=t1.split(',')
		cc = pickColor(k).strip()
		for ww in t2:
			#~ n=myDic[ww.strip()]
			n=a[int(ww)]
			#~ G.node[n[0].strip()]['color'] = cc
			G.node[n]['color'] = cc
	print w
	print "Number of communities: "+str(C)
	if C<1:
		lab=str(C)+' community'
	else:
		lab=str(C)+' communities'
	if pos is None:
		myDraw(G,pDir+"/"+w+".png",s)
	else:
		myDraw(G,pDir+"/"+w+".png",s,pos=pos,tit=tit+'\n'+lab)
	print '---------------------'
	f.close()
def drawC(cA,ax):
	xmin=float('inf')
	xmax=-xmin
	ymin=float('inf')
	ymax=-ymin
	for q,w in enumerate(cA):
		t1=w.c.x-w.r
		t2=w.c.x+w.r
		if t1<xmin:
			xmin=t1
		if t2>xmax:
			xmax=t2
		t1=w.c.y-w.r
		t2=w.c.y+w.r
		if t1<ymin:
			ymin=t1
		if t2>ymax: 
			ymax=t2
		circ=pl.Circle((w.c.x,w.c.y), radius=w.r,fc='none',lw=2,ec=pickColor(q))
		ax.add_artist(circ)
	ax.set_xlim([xmin,xmax])
	ax.set_ylim([ymin,ymax])