Skip to content

Commit

Permalink
[allhic] Make a copy before sort in median()
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jan 7, 2018
1 parent 6fe21e7 commit 87989d3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 11 additions & 8 deletions clm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package allhic

import (
"bufio"
"fmt"
"math"
"os"
"path"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit 87989d3

Please sign in to comment.