Skip to content

Commit aec402a

Browse files
authored
Merge pull request #23 from BrunoMeyer/NewickString
branch #15: Add toNewickString method on Cluster class
2 parents 30389e0 + 172e9aa commit aec402a

File tree

1 file changed

+33
-0
lines changed
  • src/main/java/com/apporiented/algorithm/clustering

1 file changed

+33
-0
lines changed

src/main/java/com/apporiented/algorithm/clustering/Cluster.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,39 @@ public void toConsole(int indent)
196196
child.toConsole(indent + 1);
197197
}
198198
}
199+
200+
public String toNewickString(int indent)
201+
{
202+
String cdtString = "";
203+
if(!isLeaf()) cdtString+="(";
204+
205+
for (int i = 0; i < indent; i++) cdtString+=" ";
206+
207+
208+
if(isLeaf()) {
209+
cdtString+=getName();
210+
}
211+
212+
List<Cluster> children = getChildren();
213+
214+
boolean firstChild = true;
215+
for (Cluster child : children)
216+
{
217+
cdtString+=child.toNewickString(indent);
218+
String distanceString = distance.getDistance().toString().replace(",", ".");
219+
String weightString = distance.getWeight().toString().replace(",", ".");
220+
if(firstChild) cdtString+=":"+distanceString+",";
221+
else cdtString+=":"+weightString;
222+
223+
firstChild=false;
224+
}
225+
226+
for (int i = 0; i < indent; i++) cdtString+=" ";
227+
228+
if(!isLeaf()) cdtString+=")";
229+
230+
return cdtString;
231+
}
199232

200233
public double getTotalDistance()
201234
{

0 commit comments

Comments
 (0)