示例#1
0
func Consumer(limit int, inChan <-chan Task) {
	for i := 0; i < limit; i++ {
		for s := range inChan {
			fmt.Println(nm.PrettyPrint(nm.Nmw(s.a, s.b, s.sm)))
		}
	}
}
示例#2
0
func main() {
	var stdinContent string
	stdinContent = repeat()
	var allA, allB []nm.Sequence
	allA, allB = splitOnMarker(stdinContent, "")

	//fmt.Println(stdinContent)

	//allA = FastaReader{file:fastaFileA}.getSequences()
	//allB = FastaReader{file:fastaFileB}.getSequences()
	//allA = FastaReaderStd{inputString: stdinContent}.getSequences()
	//allB = FastaReaderStd{inputString: stdinContent}.getSequences()
	eblosum62 := nm.MakeSubstitutionMatrix("EBLOSUM62")
	eblosum62.SetMap("EBLOSUM62")

	var maxCPU int = runtime.NumCPU()
	var wg sync.WaitGroup
	tasks := make(chan Task, 10000)
	var resultStr []string

	if len(allA)*len(allB) < maxCPU {
		maxCPU = len(allA) * len(allB)
	}

	for i := 0; i < maxCPU; i++ {
		wg.Add(1)
		go func() {
			for t := range tasks {
				resultStr = append(resultStr, nm.PrettyPrint(nm.Nmw(t.a, t.b, t.sm)))
			}
			wg.Done()
		}()
	}
	var seen map[string]bool
	seen = make(map[string]bool)
	var ok bool
	var tmpkey string
	for _, a := range allA {
		if a.GetSequence() == "" {
			continue
		}
		for _, b := range allB {
			if b.GetSequence() == "" {
				continue
			}
			tmpkey = b.GetHeader() + a.GetHeader()
			ok = seen[tmpkey]
			if ok {
				continue
			}
			tmpkey = a.GetHeader() + b.GetHeader()
			ok = seen[tmpkey]
			if ok {
				continue
			}
			seen[a.GetHeader()+b.GetHeader()] = true
			seen[b.GetHeader()+a.GetHeader()] = true
			tasks <- Task{a: a, b: b, sm: eblosum62}

		}
	}
	close(tasks)
	wg.Wait()

	for _, v := range resultStr {
		fmt.Print(v)
	}
}