Skip to content

Commit

Permalink
fix trait reporting bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jjustison committed Aug 22, 2024
1 parent 08d0b23 commit 811b8bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/NetworkSim.R
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ handleTipsTaxa<-function(phy,complete,target_ntaxa,current_n){
phy<-deleteTips(phy,deltips)

if(has_traits){
trait_inds<-match(phy$tip.label,old_tip_states) ##how the tips of the new phy mapped to the old one
phy$tip.states<-old_tip_states[tip_inds] ##Use the mapping to keep and order the appropriate trait values
trait_inds<-match(phy$tip.label,old_tip_names) ##how the tips of the new phy mapped to the old one
phy$tip.states<-old_tip_states[trait_inds] ##Use the mapping to keep and order the appropriate trait values
}

}
Expand Down
13 changes: 9 additions & 4 deletions R/sim.bdh.age.help.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ sim2.bdh.origin <- function(m=0,n=0,age,lambda,mu,nu,hyb.inher.fxn,hybprops,hyb.
extinct_tips<-rep(NA,length(extinct)) ##record all extinct tips
timecreation_order<-rep(NA,length(timecreation)) ##reorder timecreation so node numbers and creation match
Nextinct<-1

if(!is_null_trait){
tip_states<-c()
}

for (j in (1:num_nodes)){
inleaves <- (leaves %in% (-j))
inextinct<- (extinct %in% (-j))
Expand All @@ -417,14 +422,14 @@ sim2.bdh.origin <- function(m=0,n=0,age,lambda,mu,nu,hyb.inher.fxn,hybprops,hyb.
} else { ## We are at a tip of some sort (extant,extinct, or hybrid)

if(!is_null_trait){##if a trait model
tip_states<-c()

#record the trait value of the leaf we are at

##determine if we are at an extant or extinct tip
if(any(inleaves)){ #we are in an extant leaf
trait_value <- trait_states[which(-j==leaves)]
trait_value <- trait_state[which(-j==leaves)]
}else{ ##we are extinct leaf
trait_value <- ext_trait_states[which(-j==extinct)]
trait_value <- ext_trait_state[which(-j==extinct)]
}
tip_states<-c(tip_states,trait_value)
}
Expand Down Expand Up @@ -459,7 +464,7 @@ sim2.bdh.origin <- function(m=0,n=0,age,lambda,mu,nu,hyb.inher.fxn,hybprops,hyb.
if(!is_null_trait){
phy$tip.states<-tip_states
}

if(n!=0){ ##we use these for GSA
phy$timecreation <- timecreation_order
if(is.null(time_in_n)){
Expand Down

0 comments on commit 811b8bb

Please sign in to comment.