Exemple #1
0
func kmerFreq(filename string, localFreq map[int]int32, kmer_len int) {
	genome := readGenome(os.Args[1] + "/" + filename)
	var wg sync.WaitGroup
	numCores := runtime.NumCPU()
	result := make(chan int, numCores)

	for i := 0; i < numCores; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			start := len(genome) * i / numCores
			end := len(genome) * (i + 1) / numCores
			if start != 0 {
				start = start - kmer_len + 1
			}
			kmers.Slide(genome, kmer_len, start, end, result)
		}(i)
	}
	go func() {
		wg.Wait()
		close(result)
	}()
	for k := range result {
		localFreq[k]++
	}
}
Exemple #2
0
func main() {
	if len(os.Args) != 2 {
		panic("must provide sequence folder file.")
	}

	files, _ := ioutil.ReadDir(os.Args[1])
	gsm := make(map[int]int)

	numCores := runtime.NumCPU()
	runtime.GOMAXPROCS(numCores)

	kmer_len := 14
	for index, file := range files {
		genome := readGenome(os.Args[1] + "/" + file.Name())
		var wg sync.WaitGroup
		result := make(chan int, numCores)

		for i := 0; i < numCores; i++ {
			wg.Add(1)
			go func(i int) {
				defer wg.Done()
				start := len(genome) * i / numCores
				end := len(genome) * (i + 1) / numCores
				if start != 0 {
					start = start - kmer_len
				}
				fmt.Println(start, end)
				kmers.Slide(genome, kmer_len, start, end, result)
			}(i)
		}

		go func() {
			wg.Wait()
			close(result)
		}()
		for k := range result {
			if gsm[k] == 0 {
				gsm[k] = index + 1
			} else if gsm[k] == index+1 {

			} else {
				gsm[k] = -1
			}
		}
	}

	var keys []int
	for k := range gsm {
		keys = append(keys, k)
	}

	sort.Ints(keys)
	for _, k := range keys {
		fmt.Println("Key:", kmers.NumToKmer(k, kmer_len), k, "Value:", gsm[k], "end")
	}
}