From b324e738b1ac3e3bb1945f50fb40132a9fbc2b5b Mon Sep 17 00:00:00 2001 From: Frederic Lemoine Date: Mon, 26 Feb 2024 23:28:08 +0100 Subject: [PATCH] Added options min-len and max-len to gotree brlen setrand --- cmd/randbrlen.go | 11 ++++++++++- docs/commands/brlen.md | 16 ++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cmd/randbrlen.go b/cmd/randbrlen.go index 94c6832..e58b4f8 100644 --- a/cmd/randbrlen.go +++ b/cmd/randbrlen.go @@ -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{ @@ -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 @@ -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)) } } @@ -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") } diff --git a/docs/commands/brlen.md b/docs/commands/brlen.md index 229cbc0..a41360f 100644 --- a/docs/commands/brlen.md +++ b/docs/commands/brlen.md @@ -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