def prepareClsuterData(self, graph, Timestep, syllable):
print "Cluster Time ",Timestep, "Syllable:",syllable
self.Timestep = Timestep
distances = copy.deepcopy(nx.to_numpy_matrix(graph))
samples = [x for x in xrange(len(distances))]
self.ParsedData = ConsensusClster.DataModel.ParseNormal(distances, samples)
idlist = [ x.sample_id for x in self.ParsedData.samples ]
if len(dict.fromkeys(idlist)) != len(idlist):
raise ValueError, 'One or more Sample IDs are not unique!\n\n\nHere is the data'+str(len(dict.fromkeys(idlist)))+'len'+str(len(idlist))
if not self.pca_only:
self._postprocess()
kwds = []
self.GlobalCDF = dict()
self.partition1 = dict()
self.deltaArea = dict()
self.area = dict()
self.newKValues = [2,3,4,5,6,7]
for i in self.newKValues:
self.partition1[i] = self.run_cluster(i, self.subsamples, self.subsample_fraction, self.norm_var, kwds)
k = self.createDeltaArea(self.kvalues)
if Timestep == 62:
ChangeInDeltaArea = "ConsensusData/DeltaAreaChange"+str(self.graphWidget.Syllable)+str(4)+"Heatmap.tsv"
AllClusterData = "ConsensusData/AllClusterings"+str(self.graphWidget.Syllable)+str(4)+"Heatmap.tsv"
with open(ChangeInDeltaArea, 'w') as outfile:
kValues = 'day' #K-values
timeSteps = 'hour' #hour
value = 'value'
outfile.write("{}\t{}\t{}\n".format(timeSteps,kValues,value))
for i,j in self.DeltaAreaTimestep.iteritems():
KDict = j
# print i, KDict
for k,value in KDict.iteritems():
outfile.write("{}\t{}\t{}\n".format(i,k,value))
outfile.close()
with open(AllClusterData, 'w') as outfile:
pickle.dump(self.FinalPartiction, outfile)
print AllClusterData, "is the file name for all data", "look at the K value data and choose Wisely:)"
if k == 1:
partition = dict()
for i in range(len(distances)):
partition[i] = 0
self.partition1[1] = partition
self.FinalPartiction[self.Timestep] = self.partition1
return self.partition1[k]
communityDetectionEngine.py 文件源码
python
阅读 31
收藏 0
点赞 0
评论 0
评论列表
文章目录