Skip to content

Commit cdb9295

Browse files
Added option to change moving taxa cutoff
1 parent 2acdbff commit cdb9295

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

Diff for: cmd/booster.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
var boosterSeed int64
1414
var boosterPrintMovedTaxa bool
15+
var boosterDistanceCutoff float64
1516

1617
// boosterCmd represents the booster command
1718
var boosterCmd = &cobra.Command{
@@ -22,7 +23,7 @@ var boosterCmd = &cobra.Command{
2223
Run: func(cmd *cobra.Command, args []string) {
2324
writeLogBooster()
2425
rand.Seed(boosterSeed)
25-
t, err := support.Booster(supportIntree, supportBoottrees, supportLog, supportSilent, boosterPrintMovedTaxa, rootCpus)
26+
t, err := support.Booster(supportIntree, supportBoottrees, supportLog, supportSilent, boosterPrintMovedTaxa, boosterDistanceCutoff, rootCpus)
2627
if err != nil {
2728
io.ExitWithMessage(err)
2829
}
@@ -34,6 +35,7 @@ var boosterCmd = &cobra.Command{
3435
func init() {
3536
supportCmd.AddCommand(boosterCmd)
3637
boosterCmd.PersistentFlags().BoolVar(&boosterPrintMovedTaxa, "moved-taxa", false, "If true, will print in log file (-l) taxa that move the most around branches")
38+
boosterCmd.PersistentFlags().Float64Var(&boosterDistanceCutoff, "dist-cutoff", 0.05, "If --moved-taxa, then this is the distance cutoff to consider a branch for moving taxa computation. It is the normalized distance to the current bootstrap tree (e.g. 0.05). Must be between 0 and 1, otherwise set to 0")
3739
boosterCmd.PersistentFlags().Int64VarP(&boosterSeed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed if empirical is ON")
3840
}
3941

Diff for: support/booster.go

+38-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"errors"
66
"fmt"
7+
"math"
78
"os"
89
"sync"
910

@@ -12,13 +13,36 @@ import (
1213
)
1314

1415
type BoosterSupporter struct {
15-
expected_rand_val []float64
16-
distribution_rand_val [][]float64
17-
currentTree int
18-
mutex *sync.RWMutex
19-
stop bool
20-
silent bool
21-
computeMovedSpecies bool
16+
currentTree int
17+
mutex *sync.RWMutex
18+
stop bool
19+
silent bool
20+
computeMovedSpecies bool
21+
/* Cutoff for considering a branch : ok if norm distance to current
22+
bootstrap tree < cutoff (ex=0.05) => allows to compute a minimum depth also:
23+
norm_dist = distance / (p-1)
24+
=> If we want at least one species that moves (distance=1) at a given norm_dist cutoff, we need a depth p :
25+
p=(1/norm_dist)+1
26+
*/
27+
movedSpeciesCutoff float64
28+
}
29+
30+
func NewBoosterSupporter(silent bool, computeMovedSpecies bool, movedSpeciesCutoff float64) *BoosterSupporter {
31+
if movedSpeciesCutoff < 0 {
32+
movedSpeciesCutoff = 1.0
33+
}
34+
if movedSpeciesCutoff > 1 {
35+
movedSpeciesCutoff = 1.0
36+
}
37+
38+
return &BoosterSupporter{
39+
currentTree: 0,
40+
mutex: &sync.RWMutex{},
41+
stop: false,
42+
silent: silent,
43+
computeMovedSpecies: computeMovedSpecies,
44+
movedSpeciesCutoff: movedSpeciesCutoff,
45+
}
2246
}
2347

2448
func (supporter *BoosterSupporter) ExpectedRandValues(depth int) float64 {
@@ -272,8 +296,9 @@ func (supporter *BoosterSupporter) ComputeValue(refTree *tree.Tree, cpu int, edg
272296
return err
273297
}
274298
be := bootEdges[min_dist_edge[i]]
275-
norm := 1.0 - float64(vals[i])/(float64(td)-1.0)
276-
if norm > 0.95 && td >= 21 {
299+
norm := float64(vals[i]) / (float64(td) - 1.0)
300+
mindepth := int(math.Ceil(1.0/supporter.movedSpeciesCutoff + 1.0))
301+
if norm <= supporter.movedSpeciesCutoff && td >= mindepth {
277302
if sm, er := speciesToMove(e, be, vals[i]); er != nil {
278303
io.LogError(er)
279304
return err
@@ -309,16 +334,12 @@ func (supporter *BoosterSupporter) ComputeValue(refTree *tree.Tree, cpu int, edg
309334
return nil
310335
}
311336

312-
func Booster(reftreefile, boottreefile string, logfile *os.File, silent bool, computeMovedSpecies bool, cpus int) (*tree.Tree, error) {
313-
var supporter *BoosterSupporter = &BoosterSupporter{}
314-
supporter.silent = silent
315-
supporter.computeMovedSpecies = computeMovedSpecies
337+
func Booster(reftreefile, boottreefile string, logfile *os.File, silent bool, computeMovedSpecies bool, movedSpeciedCutoff float64, cpus int) (*tree.Tree, error) {
338+
var supporter *BoosterSupporter = NewBoosterSupporter(silent, computeMovedSpecies, movedSpeciedCutoff)
316339
return ComputeSupport(reftreefile, boottreefile, logfile, cpus, supporter)
317340
}
318-
func BoosterFile(reftreefile, boottreefile *bufio.Reader, logfile *os.File, silent bool, computeMovedSpecies bool, cpus int) (*tree.Tree, error) {
319-
var supporter *BoosterSupporter = &BoosterSupporter{}
320-
supporter.silent = silent
321-
supporter.computeMovedSpecies = computeMovedSpecies
341+
func BoosterFile(reftreefile, boottreefile *bufio.Reader, logfile *os.File, silent bool, computeMovedSpecies bool, movedSpeciedCutoff float64, cpus int) (*tree.Tree, error) {
342+
var supporter *BoosterSupporter = NewBoosterSupporter(silent, computeMovedSpecies, movedSpeciedCutoff)
322343
return ComputeSupportFile(reftreefile, boottreefile, logfile, cpus, supporter)
323344
}
324345

0 commit comments

Comments
 (0)