-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunFileConnectClusters.m
More file actions
135 lines (127 loc) · 4.56 KB
/
Copy pathRunFileConnectClusters.m
File metadata and controls
135 lines (127 loc) · 4.56 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
clc
clear
%%Load Input Data
clusterData=load('ClusterData.txt'); % Input cluster data
Species=load('SpeciesData.txt'); % input speciecis avaialbility data
NumClu=4; % prvide number of clusters
NumSpe=3; % provide number of species in the system
%%%%%%% Do not change below %%%%%%%%%%%%%%%
[m,n]=size(clusterData);
Label=1;
k=1;
Data=[]; ExtraSpecies=[];
for i=1:m
for j=1:n
if (clusterData(i,j)==1)
clusterData(i,j)=0;
end
end
end
clusterData;
for p=1:NumClu
CurrentCluster=zeros(m,n);
for i=1:m
for j=1:n
if (clusterData(i,j)==p+1)
CurrentCluster(i,j)=1;
end
end
end
Data=[Data;CurrentCluster];
end
Data;
for p=1:NumClu
CurrentClu=Data((p-1)*n+1:p*n,:);
MultiData(:,:,p)=CurrentClu;
end
% for Species
for p=1:NumSpe
CurrentSpe=Species((p-1)*n+1:p*n,:);
AllSpe(:,:,p)=CurrentSpe;
end
[speciescount,Occurrence]=get_SpeciesCount(Species,NumClu,MultiData,NumSpe,m,n);
dlmwrite('C:\CompactConnect2020\speciescount.txt',speciescount,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\Occurrence.txt',Occurrence,'delimiter','\t');
AllSpe;
MultiData;
while (NumClu~=1)
Data;
NumClu;
for p=1:NumClu
CurrentClu=Data((p-1)*n+1:p*n,:);
MultiData(:,:,p)=CurrentClu;
end
OldData=MultiData;
MultiData;
Label=1;
[AlterPath,AllList,LevelSize,Label]=To_JoinCluctersAlternatives(MultiData, m,n,Label,NumClu);
AlterPath;
%CL1cell meeting place of the first cluster with the cluster number and
%level
%CL2cell meeting place of the second cluster with the cluster number and
%level
%AllList Need tp trace back to get the paths
% dlmwrite('C:\CompactConnect2020\AllList.txt',AllList,'delimiter','\t');
MeetingLevel=Label;
UnmodifiedMD=MultiData;
AlterPath=Clean_AlterPath(AlterPath,MeetingLevel); % need this to remove duplicates
AlterPath ;% All meeting places with the same lengths
[NumPath,~]=size(AlterPath);
counter=0; AllConnectors=[];IndCov=[];
NumPath;
while (NumPath>0)
NumPath;
CL1cell=AlterPath(2*counter+1,:);% Intersection of First Clsuter
CL2cel2=AlterPath(2*counter+2,:);% Intersection of Second Clsuter
clus1= CL1cell(3);% First Clsuter
clus2= CL2cel2(3);% First Clsuter
MeetingLevel=[CL1cell(4)+1,CL2cel2(4)+1];
[FinalPath,IndividualCoverage]=get_Coridors(clus1,clus2,AllList,CL1cell,CL2cel2,LevelSize,NumClu,MeetingLevel,UnmodifiedMD,AllSpe,NumSpe,m,n) ;
FinalPath;
[numfinalPath,~]=size(FinalPath);
AddClus1=clus1*ones(numfinalPath,1);
AddClus2=clus2*ones(numfinalPath,1);
counter=counter+1;
NumPath=NumPath-2;
AllConnectors=[AllConnectors;AddClus1,AddClus2,FinalPath];
IndCov=[IndCov;IndividualCoverage];
end
AllConnectors;
[numPath,~]=size(AllConnectors);
[BestPath,AdditionalC]=Get_BestPath(AllConnectors);
clus1=BestPath(1);
clus2=BestPath(2);
BestPath=BestPath(3:end);
MultiData(:,:,clus1);
MultiData(:,:,clus2);
[MergeCluster,clusterData]=Get_CombinedSystem(BestPath,clus1,clus2,MultiData,m,n,NumClu,clusterData);
MergeCluster;
clusterData;
ExtraSpecies=[ExtraSpecies,AdditionalC];
UpdateMultiData=[MergeCluster]; % UpdateMultiData contains the Clus 1 and Clus 2 data
for i=1:NumClu
if(i ~=clus1 && i~=clus2)
UpdateMultiData=[UpdateMultiData;OldData(:,:,i)];
end
end
UpdateMultiData;
IndCov;
[numpath,~]=size(AllConnectors);
dlmwrite('C:\CompactConnect2020\AllConnectors.txt',AllConnectors,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\Allindividual coverage.txt',IndCov,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\ClusterStep.txt',clusterData,'delimiter','\t');
Data=UpdateMultiData;
MultiData=[];
Label=1;
NumClu=NumClu-1;
end
AllConnectors;
ExtraSpecies;
MergeCluster;
[Newspeciescount,Occurrence]=get_SpeciesCount(Species,NumClu,MergeCluster,NumSpe,m,n)
Coridorcoverage=Newspeciescount-speciescount
SP=[Newspeciescount;speciescount;Coridorcoverage]
dlmwrite('C:\CompactConnect2020\SpeciesAnalysis.txt',SP,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\ClustermultiData.txt',clusterData,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\multiData.txt',MergeCluster,'delimiter','\t');
dlmwrite('C:\CompactConnect2020\AllConnectors.txt',AllConnectors,'delimiter','\t');