diff --git a/base.go b/base.go index 98608aa..f0e0da1 100644 --- a/base.go +++ b/base.go @@ -121,8 +121,12 @@ func min(a, b int) int { } // median gets the median value of an array -func median(numbers []float64) float64 { +func median(s []float64) float64 { + // Make a sorted copy + numbers := make([]float64, len(s)) + copy(numbers, s) sort.Float64s(numbers) + middle := len(numbers) / 2 result := numbers[middle] if len(numbers)%2 == 0 { diff --git a/clm.go b/clm.go index 14ed43f..aeb69f2 100644 --- a/clm.go +++ b/clm.go @@ -11,7 +11,6 @@ package allhic import ( "bufio" - "fmt" "math" "os" "path" @@ -214,8 +213,10 @@ func (r *CLMFile) pruneByDensity() { invalid++ } } - log.Noticef("Inactivated %d tigs with log10_density < %.5f", - invalid, lb) + if invalid > 0 { + log.Noticef("Inactivated %d tigs with log10_density < %.5f", + invalid, lb) + } } // pruneBySize selects active contigs based on size @@ -227,8 +228,10 @@ func (r *CLMFile) pruneBySize() { invalid++ } } - log.Noticef("Inactivated %d tigs with size < %d", - invalid, MINSIZE) + if invalid > 0 { + log.Noticef("Inactivated %d tigs with size < %d", + invalid, MINSIZE) + } } // pruneTour test deleting each contig and check the delta_score @@ -238,7 +241,7 @@ func (r *CLMFile) pruneTour() { tour, newTour Tour ) - for phase := 1; phase < 3; phase++ { + for { tour = r.Tour tourScore := -tour.Evaluate() log.Noticef("Starting score: %.5f", tourScore) @@ -265,7 +268,7 @@ func (r *CLMFile) pruneTour() { } // Wait for all workers to finish wg.Wait() - fmt.Println(log10ds) + //fmt.Println(log10ds) // Identify outliers lb, ub := OutlierCutoff(log10ds) @@ -311,7 +314,7 @@ func (r *CLMFile) pruneTour() { func (r *CLMFile) Activate(shuffle bool) { r.reportActive() r.pruneByDensity() - r.pruneBySize() + //r.pruneBySize() r.reportActive() for _, tig := range r.Tigs { diff --git a/main/allhic.go b/cmd/allhic.go similarity index 100% rename from main/allhic.go rename to cmd/allhic.go diff --git a/evaluate.go b/evaluate.go index 25cfb05..af5185c 100644 --- a/evaluate.go +++ b/evaluate.go @@ -228,7 +228,7 @@ func (r *CLMFile) GARun(fwtour *os.File, npop, ngen int, mutrate float64, phase for ; ; gen++ { ga.Evolve() currentBest := -ga.HallOfFame[0].Fitness - if gen%npop == 0 { + if gen%(ngen/10) == 0 { fmt.Printf("Current iteration GA%d-%d: max_score=%.5f\n", phase, gen, currentBest) currentBestTour := ga.HallOfFame[0].Genome.(Tour) diff --git a/functional-tests.sh b/functional-tests.sh index 3252e67..e095115 100755 --- a/functional-tests.sh +++ b/functional-tests.sh @@ -5,7 +5,7 @@ test -e ssshtest || wget -q https://raw.githubusercontent.com/ryanlayer/ssshtest . ssshtest set -uo pipefail -go build -o allhic_test main/allhic.go +go build -o allhic_test cmd/allhic.go run test_optimize ./allhic_test optimize tests/test.clm assert_in_stderr "Success" diff --git a/optimize.go b/optimize.go index 70a4ad8..43bb807 100644 --- a/optimize.go +++ b/optimize.go @@ -52,7 +52,7 @@ func (r *Optimizer) Run() { // OptimizeOrdering changes the ordering of contigs by Genetic Algorithm func (r *CLMFile) OptimizeOrdering(fwtour *os.File, phase int) { - r.GARun(fwtour, 100, 2000, .2, phase) + r.GARun(fwtour, 100, 5000, .25, phase) r.pruneTour() }