diff --git a/cmd/cutdate.go b/cmd/cutdate.go index 53bce63..98d5824 100644 --- a/cmd/cutdate.go +++ b/cmd/cutdate.go @@ -21,7 +21,9 @@ var pruneDateCmd = &cobra.Command{ This command will extract part of the tree corresponding to >= min-date and <= max-date. If min-date falls on an internal branch, it will create a new root node and will extract a tree starting at this node. -If max-date falls on an internal branch, we do not take this part of the tree, and we remove branches that end into these cases. +If max-date is specified (>0) : It additionally removes all tips that are > maxdate + +This command considers the input tree as rooted `, RunE: func(cmd *cobra.Command, args []string) (err error) { diff --git a/docs/commands/cut.md b/docs/commands/cut.md new file mode 100644 index 0000000..ded243c --- /dev/null +++ b/docs/commands/cut.md @@ -0,0 +1,66 @@ +# Gotree: toolkit and api for phylogenetic tree manipulation + +## Commands + +### cut +Cut the input tree by keeping only parts in date window. + +It extracts parts of the tree corresponding to >= min-date and <= max-date. + +If min-date falls on an internal branch, it will create a new root node and will extract a tree starting at this node. +If max-date is specified (>0) : It removes all tips that are > maxdate + +This command considers the input tree as rooted. + +Dates are taken from the field [&date=] of the Nexus format. + +#### Usage + +``` +Usage: + gotree cut date [flags] + +Flags: + -h, --help help for date + -i, --input string Input tree(s) file (default "stdin") + --max-date float Maximum date to cut the tree (0=no max date) + --min-date float Minimum date to cut the tree + -o, --output string Forest output file (default "stdout") + +Global Flags: + --format string Input tree format (newick, nexus, phyloxml, or nextstrain) (default "newick") +``` + +#### Example + + +Initial tree: +``` ++-------------------- A[&date="2000"] +[&date="1990"] +| +------------ B[&date="2008"] ++------------------------|[&date="2002"] + | +----- C[&date="2010"] + +----------|[&date="2007"] + +------- D[&date="2011"] +``` + +If we cut it between 2003 and 2009: +``` +echo '(A[&date="2000"]:10,(B[&date="2008"]:6,(C[&date="2010"]:3,D[&date="2011"]:4)[&date="2007"]:5)[&date="2002"]:12)[&date="1990"];' | ./gotree cut date --min-date 2003 --max-date 2009 + +(B[&date="2008"]:5)[&date="2003.000000"]; +``` + +- There is only one hanging branch left + +If we cut it between 2003 and 2020: + +``` +echo '(A[&date="2000"]:10,(B[&date="2008"]:6,(C[&date="2010"]:3,D[&date="2011"]:4)[&date="2007"]:5)[&date="2002"]:12)[&date="1990"];' | ./gotree cut date --min-date 2003 --max-date 2020 + +(B[&date="2008"]:5)[&date="2003.000000"]; +((C[&date="2010"]:3,D[&date="2011"]:4)[&date="2007"]:4)[&date="2003.000000"]; +``` + +- There are two trees: 1) only one hanging branch, and 2) two tips left diff --git a/docs/index.md b/docs/index.md index 56ce934..fb9501b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -64,6 +64,7 @@ Command | Subcommand -- | edgetrees | Writes one output tree per branch of the input tree, with only one branch -- | support classical | Computes classical bootstrap supports -- | support booster | Computes booster bootstrap supports +[cut](commands/cut.md) | date | Cut the tree into specific time windows trees (if dated tree) [divide](commands/divide.md) | | Divides an input tree file into several tree files [download](commands/download.md) ([api](api/download.md)) | | Downloads trees from a server -- | itol | Downloads a tree image from iTOL, with given image options diff --git a/test.sh b/test.sh index 0a89462..985494f 100755 --- a/test.sh +++ b/test.sh @@ -2251,3 +2251,20 @@ EOF echo '(((A[&date="2024"]:1,B[&date="2024"]:1)[&date="2023"]:1,C[&date="2024"]:2)[&date="2022"]:3,(D[&date="2024"]:4,(E[&date="2024"]:3,((F[&date="2024"]:1.5,G[&date="2024"]:1.5)[&date="2022.5"]:0.5,H[&date="2024"]:2)[&date="2022"]:1)[&date="2021"]:1)[&date="2020"]:1)[&date="2019"];' | $GOTREE ltt > result diff -q -b expected result rm -f expected result + + +echo "->gotree cut date" +cat > expected < result +diff -q -b expected result +rm -f expected result + +cat > expected < result +diff -q -b expected result +rm -f expected result