def rwcd(fName,tx='6',g='/24'): #random walk community detection print 'Walktrap walk length: '+tx wDir=os.getcwd()+"/CSV/WalkTrap/"+fName if not os.path.exists(wDir): print 'Please prepare files for walktrap using walktrapFile(fName)' return else: for un1,un2,u3 in os.walk(wDir): wtf=[xx for xx in u3 if ('.w' in xx)] break print 'Random walk length parameter: '+tx if os.path.exists(os.getcwd()+"/Model/"+fName): print 'Error: ' +fName+' Model already exists, delete to rerun' return else: os.mkdir(os.getcwd()+"/Model/"+fName) lll=len(wtf) for j,w in enumerate(wtf): print '---------------- '+str(j+1) +' / '+str(lll) +' -----------------------' print 'Prefix: '+w.replace('.w','').replace('s','/') qq = 'WalkTrap/walktrap '+wDir+'/'+w+ " -t"+tx+" -b -d1 -s |grep community| cut -d'=' -f2 > "+ wDir+'/'+w.replace('.w','.C') os.system(qq) #~ communityGraph(fName,w.replace('.w','')) C = UoSM_input(fName,w.replace('.w','')) print 'No. of Clusters: '+str(len(C)) print 'Cluster to subnet conversion...' if len(C)>0: uos = cluster2sub(C,g) with open('Model/' + fName + '/'+w.replace('.w','.uos'), 'w') as f: f.write(str(uos)) print '-------------------------------------------------'
def rwcd(prefix,tx='4',g='/24'): #random walk community detection w=prefix.replace('/','s') f=open('Debug/'+w+'.uos','w') print 'Prefix: '+prefix fn='Debug/'+w+'.w' qq = 'WalkTrap/walktrap '+fn+ " -t"+tx+" -b -d1 -s |grep community| cut -d'=' -f2 > Debug/"+w+'.C' os.system(qq) #~ communityGraph(fName,w.replace('.w','')) C = UoSM_input(prefix) print 'No. of Clusters: '+str(len(C)) print 'Cluster to subnet conversion...' if len(C)>0: uos = cluster2sub(C,g) with open('Debug/'+w+'.uos', 'w') as f: f.write(str(uos)) print '-------------------------------------------------'
def rwcd(fName, tx="6", g="/24"): # random walk community detection print "Walktrap walk length: " + tx wDir = os.getcwd() + "/CSV/WalkTrap/" + fName if not os.path.exists(wDir): print "Please prepare files for walktrap using walktrapFile(fName)" return else: for un1, un2, u3 in os.walk(wDir): wtf = [xx for xx in u3 if (".w" in xx)] break print "Random walk length parameter: " + tx if os.path.exists(os.getcwd() + "/Model/uos-" + fName + ".pk"): print "Error: " + fName + " Model already exists, delete to rerun" return lll = len(wtf) A = {} for j, w in enumerate(wtf): print "---------------- " + str(j + 1) + " / " + str(lll) + " -----------------------" prefix = w.replace(".w", "").replace("s", "/") print "Prefix: " + prefix qq = ( "WalkTrap/walktrap " + wDir + "/" + w + " -t" + tx + " -b -d1 -s |grep community| cut -d'=' -f2 > " + wDir + "/" + w.replace(".w", ".C") ) os.system(qq) # ~ communityGraph(fName,w.replace('.w','')) C = UoSM_input(fName, w.replace(".w", "")) print "No. of Clusters: " + str(len(C)) print "Cluster to subnet conversion..." if len(C) > 0: uos = cluster2sub(C, g) A[prefix] = uos with open("Model/uos-" + fName + ".pk", "w") as f: pk.dump(A, f)
def parse_args(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.add_option("-g", "--gap", dest="g", default="/24", help="Optional: threshold to split brackets") parser.add_option("-f", "--fileName", dest="fName", default=None, help="Required: filename for data") parser.add_option("-p", "--prefix", dest="prefix", default=None, help="Required: filename for data") if len(sys.argv) == 1: parser.print_help() sys.exit(1) options, args = parser.parse_args() if options.fName is None or options.prefix is None: print "Error: Please provide --filename to read data \n (do not include .G suffix)" sys.exit(1) return (options, args) if __name__ == "__main__": options, args = parse_args() fName = options.fName prefix = options.prefix g = options.g walktrapFile(fName) qq = "WalkTrap/walktrap CSV/" + fName + ".walktrap -b -d1 -s |grep community| cut -d'=' -f2 > CSV/" + fName + ".C" os.system(qq) C = UoSM_input(fName) uos = cluster2sub(C, g) with open("CSV/" + fName + ".net", "a+b") as f: f.write(prefix + "," + str(uos) + "\n")