Beispiel #1
0
func main() {
	flag.Parse()

	if *cpuProfile != "" {
		f, err := os.Create(*cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	stream, _ := os.Open(flag.Arg(0))
	input, _ := ioutil.ReadAll(stream)

	var output string
	var w wookie.Wookie
	for i := 0; i < *count; i++ {
		w = wookie.NewWookie(string(input))
		err := w.Compute()
		if err != nil {
			log.Fatal(err)
		}
		output = w.Genome.String()
	}

	// only print latest output
	if *graphviz {
		fmt.Println(w.Graphviz())
	} else {
		fmt.Println(output)
	}
}
Beispiel #2
0
func main() {
	stream, _ := os.Open(os.Args[1])
	input, _ := ioutil.ReadAll(stream)
	wookie := wookie.NewWookie(strings.Split(strings.TrimSpace(string(input)), "\n"))
	wookie.Compute()
	fmt.Println(wookie.Genome.String())
}
Beispiel #3
0
func handler(w http.ResponseWriter, r *http.Request) {
	decoder := json.NewDecoder(r.Body)
	var resolveRequest ResolveRequest
	err := decoder.Decode(&resolveRequest)

	if err != nil {
		fmt.Fprintf(w, "POST parsing error: %v\n", err)
		return
	}
	wook := wookie.NewWookie(resolveRequest.Sequences)

	// Timeout
	timeout := make(chan bool, 1)
	go func() {
		time.Sleep(time.Second * 3)
		timeout <- true
	}()

	computed := make(chan bool, 1)
	go func() {
		err = wook.Compute()
		if err != nil {
			fmt.Fprintf(w, "%v", err)
		} else {
			fmt.Fprintf(w, "%s", wook.Genome.String())
		}
		computed <- true
	}()

	select {
	case <-computed:
		// compute finished
	case <-timeout:
		fmt.Fprintf(w, "%s", "Timeout, this webapp times out after 3 seconds.\nUse the CLI version if you need to compute bigger genomes.\n\n    https://github.com/moul/wookie\n")
	}
}