1
$\begingroup$

I have read other questions related to TreeGraph but couldn't find something similar to my problem.

I have a list of geometric properties of the bronchial tree, where each bronchus is represented by an ID as follows:

1: trachea

11: sub-trachea left

12: sub-trachea right

111: left bronchus of sub-trachea left

112: right bronchus of sub-trachea left

etc.

Looks straightforward, but I can't manage to create a TreeGraph from these data. I'have tried to sum up the values to create a path for TreeGraph but as several paths can have the same added values, this obviously doesn't work.

Here is my code (not optimized yet) for extraction and sorting of the data, struggling for the next steps.

dataraw=Import["http://mae.engr.ucdavis.edu/wexler/lungs/LF53-Raabe/id18.htm","Data"];
data=Transpose[dataraw];
(* Manipulation of data, formatting etc. *)
namesraw=Table[ToString[data[[j]][[1]]],{j,1,Length[dataraw[[1]]]}];
namestojoin=StringSplit [Table[namesraw[[i]]//ToLowerCase//StringTrim//StringSplit//StringJoin//StringTrim ,{i,1,Length[dataraw[[1]]]}],Except[WordCharacter]];
names=Table[StringJoin[namestojoin[[i]]],{i,1,Length[dataraw[[1]]]}]
dataok=Table[Table[ToExpression[StringTrim[ToString[data[[j]][[i]]]]],{i,2,Length[data[[1]]]} ],{j,1,Length[dataraw[[1]]]}];
listdata=Table[Symbol[names[[j]]]->Table[dataok[[j]][[i]],{i,1,Length[data[[1]]]-1}],{j,1,Length[dataraw[[1]]]}];
listbranchid=Sort@IntegerDigits@Table[listdata[[8]][[2]][[i]],{i,1,Length[listdata[[8]][[2]]] }];
(* Placing data in cluster aka generations *)
Table[clusterbranchid[j]={},{j,1,Max@Table[Length@listbranchid[[i]],{i,1,Length[listdata[[8]][[2]]]}]} ]; 
Table[Table
[If[Length[listbranchid[[i]]]==j,clusterbranchid[j]=Join[clusterbranchid [j],{listbranchid[[i]]}]],{j,1,Max@Table[Length@listbranchid[[i]],{i,1,Length[listdata[[8]][[2]]]}]}],{i,1,Length[listdata[[8]][[2]]]}];
(* Clusters visualisation *)
clusterbranchid[1]
clusterbranchid[2]
clusterbranchid[3]
clusterbranchid[4]
clusterbranchid[5]
$\endgroup$

1 Answer 1

4
$\begingroup$

Try this:

ids = ToExpression@dataraw[[2 ;;, 8]];

G = TreeGraph[
  DirectedEdge @@@ Transpose[{
     Lookup[
      AssociationThread[ids -> Range[Length[ids]]],
      FromDigits@*Most@*IntegerDigits /@ Rest[ids]
      ],
     Range[2, Length[ids]]
     }],
  GraphLayout -> "LayeredEmbedding"
  ]

enter image description here

$\endgroup$
2
  • $\begingroup$ This is great, thanks! $\endgroup$
    – Valacar
    Jul 12, 2018 at 18:26
  • $\begingroup$ You're welcome! $\endgroup$ Jul 12, 2018 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.