Skip to content

Commit

Permalink
Added options min-len and max-len to gotree brlen setrand
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericlemoine committed Feb 26, 2024
1 parent df34e91 commit b324e73
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 10 additions & 1 deletion cmd/randbrlen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
var setlengthmean float64
var setlengthmeanMin float64
var setlengthmeanMax float64
var setlengthMinLen float64
var setlengthMaxLen float64

// randbrlenCmd represents the randbrlen command
var randbrlenCmd = &cobra.Command{
Expand All @@ -31,6 +33,9 @@ Two possibilities for the mean:
if --internal=false is given, it won't apply to internal branches (only external)
if --external=false is given, it won't apply to external branches (only internal)
if --min-len > 0, it will apply only to branches with length >= min-len
if --max-len > 0, it will apply only to branches with length <= max-len
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
var f *os.File
Expand Down Expand Up @@ -61,7 +66,9 @@ if --external=false is given, it won't apply to external branches (only internal
}

for _, e := range tr.Tree.Edges() {
if (e.Right().Tip() && brlenexternal) || (!e.Right().Tip() && brleninternal) {
if ((e.Right().Tip() && brlenexternal) || (!e.Right().Tip() && brleninternal)) &&
(setlengthMinLen == -1 || e.Length() >= setlengthMinLen) &&
(setlengthMaxLen == -1 || e.Length() <= setlengthMaxLen) {
e.SetLength(gostats.Exp(1.0 / lmean))
}
}
Expand All @@ -78,5 +85,7 @@ func init() {
randbrlenCmd.Flags().Float64VarP(&setlengthmean, "mean", "m", 0.1, "Mean of the exponential distribution of branch lengths")
randbrlenCmd.Flags().Float64Var(&setlengthmeanMin, "min-mean", 0.001, "Mean of the exponential distribution of branch lengths will be drawn uniformly in the interval [min-mean,max-mean]")
randbrlenCmd.Flags().Float64Var(&setlengthmeanMax, "max-mean", 0.05, "Mean of the exponential distribution of branch lengths will be drawn uniformly in the interval [min-mean,max-mean]")
randbrlenCmd.Flags().Float64Var(&setlengthMinLen, "min-len", -1, "Applies only to branches having length >= min-length (taken into account iff > 0)")
randbrlenCmd.Flags().Float64Var(&setlengthMaxLen, "max-len", -1, "Applies only to branches having length <= max-length (taken into account iff > 0)")
randbrlenCmd.PersistentFlags().StringVarP(&outtreefile, "output", "o", "stdout", "Random length output tree file")
}
16 changes: 10 additions & 6 deletions docs/commands/brlen.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ Usage:
gotree brlen setrand [flags]
Flags:
-h, --help help for setrand
-m, --mean float Mean of the exponential distribution of branch lengths (default 0.1)
-o, --output string Random length output tree file (default "stdout")
-h, --help help for setrand
--max-len float Applies only to branches having length <= max-length (taken into account iff > 0) (default -1)
--max-mean float Mean of the exponential distribution of branch lengths will be drawn uniformly in the interval [min-mean,max-mean] (default 0.05)
-m, --mean float Mean of the exponential distribution of branch lengths (default 0.1)
--min-len float Applies only to branches having length >= min-length (taken into account iff > 0) (default -1)
--min-mean float Mean of the exponential distribution of branch lengths will be drawn uniformly in the interval [min-mean,max-mean] (default 0.001)
-o, --output string Random length output tree file (default "stdout")
Global Flags:
--external Applies to external branches (default true)
--format string Input tree format (newick, nexus, phyloxml, or nextstrain) (default "newick")
-i, --input string Input tree (default "stdin")
--seed int Random Seed: -1 = nano seconds since 1970/01/01 00:00:00 (default -1)
```

--internal Applies to internal branches (default true)
#### Examples
1. Removing branch lengths from a set of 10 trees
Expand Down

0 comments on commit b324e73

Please sign in to comment.