-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimization read.mcmctree #60
Merged
GuangchuangYu
merged 7 commits into
YuLab-SMU:master
from
xiangpin:optimization_read.mcmctree
Jun 9, 2021
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dd850ca
optimizing read.mcmctree
xiangpin 8046a33
check ultrametric with two methods
xiangpin 69263fe
fix the check of ultrametric
xiangpin 0a21a72
Merge branch 'master' into optimization_read.mcmctree
xiangpin b67d8ff
Update MCMCTree.R
GuangchuangYu 1ba1f9f
typo for as.ultrametric
xiangpin cc2d2dd
Merge remote-tracking branch 'origin/optimization_read.mcmctree' into…
xiangpin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' @title as.ultrametric | ||
#' @param tree tree object | ||
#' @param ... additional parameters | ||
#' @return treedata or phylo object | ||
#' @export | ||
as.ultrametric <- function(tree, ...){ | ||
UseMethod("as.ultrametric") | ||
} | ||
|
||
#' @method as.ultrametric phylo | ||
#' @export | ||
## reference | ||
## https://github.com/PuttickMacroevolution/MCMCtreeR/blob/master/R/readMCMCTree.R | ||
as.ultrametric.phylo <- function(tree, ...){ | ||
outer <- tree$edge[, 2] | ||
inner <- tree$edge[, 1] | ||
ntip <- Ntip(tree) | ||
totalPath <- c() | ||
tipindx <- which(outer <= ntip) | ||
for (i in tipindx) { | ||
start <- i | ||
end <- inner[start] | ||
edgeTimes <- tree$edge.length[start] | ||
while (end != inner[1]) { | ||
start <- which(outer == end) | ||
end <- inner[start] | ||
edgeTimes <- c(edgeTimes, tree$edge.length[start]) | ||
} | ||
totalPath <- c(totalPath, sum(edgeTimes)) | ||
} | ||
addLength <- max(totalPath) - totalPath | ||
tree$edge.length[tipindx] <- tree$edge.length[tipindx] + addLength | ||
return (tree) | ||
} | ||
|
||
#' @method as.ultrametric treedata | ||
#' @export | ||
as.ultrametric.treedata <- function(tree, ...){ | ||
tree@phylo <- as.ultrametric(tree=tree@phylo,...) | ||
return (tree) | ||
} | ||
|
||
#' @method as.ultrametric tbl_tree | ||
as.ultrametric.tbl_tree <- function(tree, ...){ | ||
tree <- as.treedata(tree) | ||
tree <- as.ultrametric(tree) | ||
return(tree) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot find the
force.ultrametric
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, It should be
as.ultrametric