1515InnerTree <- R6Class(
1616 " InnerTree" ,
1717 public = list (
18- initialize = function (outer , mod , prefix = ' P' , p.index = 1 ) {
18+ initialize = function (outer , prefix = ' P' , p.index = 1 ) {
1919 private $ inner.log <- data.frame (
2020 time = numeric (), # time of event
2121 event = character (), # type of event, e.g., coalescence
@@ -27,7 +27,7 @@ InnerTree <- R6Class(
2727 pathogen2 = character ()
2828 )
2929
30- private $ mod <- mod
30+ private $ mod <- outer $ get.model() # inherits model from OuterTree
3131 private $ prefix <- prefix
3232 private $ p.index <- p.index
3333
@@ -40,7 +40,6 @@ InnerTree <- R6Class(
4040
4141 # inactive Hosts are part of the transmission history
4242 private $ inactive <- HostSet $ new()
43- private $ inactive $ add.host(index.case $ clone())
4443 private $ sampled <- HostSet $ new()
4544
4645 # note there is overlap between `retired` and `sampled` HostSets
@@ -54,6 +53,13 @@ InnerTree <- R6Class(
5453 }
5554 }
5655
56+ # handle index case
57+ if (index.case $ get.name() %in% sampled $ get.names()) {
58+ private $ sampled $ add.host(index.case $ clone())
59+ } else {
60+ private $ inactive $ add.host(index.case $ clone())
61+ }
62+
5763 # track Hosts with active Pathogen lineages
5864 private $ active <- HostSet $ new()
5965
@@ -117,7 +123,7 @@ as.phylo.InnerTree <- function(obj) {
117123 events <- obj $ get.log()
118124 events $ time <- as.numeric(events $ time )
119125
120- active <- inner $ get.active()
126+ active <- obj $ get.active()
121127 if (active $ count.type() != 1 ) {
122128 stop(" Error, expected only one Host in active HostSet" )
123129 }
@@ -179,7 +185,8 @@ as.phylo.InnerTree <- function(obj) {
179185 Nnode = length(node.label ), edge = edge ,
180186 edge.length = as.numeric(edge.list $ length ),
181187 event = events $ event [match(nodes , events $ pathogen2 )],
182- compartment = edge.list $ compartment
188+ compartment = edge.list $ compartment ,
189+ host = events $ from.host [match(nodes , events $ pathogen2 )]
183190 )
184191 attr(phy , ' class' ) <- ' phylo'
185192 phy
@@ -236,7 +243,7 @@ as.phylo.InnerTree <- function(obj) {
236243# ' @param node: character, Pathogen name
237244# ' @param order: character, 'preorder' or 'postorder'
238245# ' @param result: character, vector to append results by recursive calls
239- # ' @result character, Pathogen names ordered by tree traversal
246+ # ' @return character, Pathogen names ordered by tree traversal
240247# '
241248# ' @keywords internal
242249# ' @noRd
@@ -253,3 +260,17 @@ as.phylo.InnerTree <- function(obj) {
253260 }
254261 return (result )
255262}
263+
264+
265+ # ' Generic print function for R6 objects of class `InnerTree`
266+ # ' @export
267+ # ' @noRd
268+ print.InnerTree <- function (obj ) {
269+ cat(" twt InnerTree\n " ) # bold color!
270+ cat(" " , obj $ get.sampled()$ count.type(), " sampled Pathogens\n " )
271+ cat(" " , obj $ get.active()$ count.type(), " active Pathogens\n " )
272+ cat(" " , obj $ get.inactive()$ count.type(), " inactive Pathogens\n " )
273+ events <- obj $ get.log()
274+ cat(" " , nrow(events ), " events in inner log: " )
275+ print(table(events $ event ))
276+ }
0 commit comments