コード例 #1
0
ファイル: remote.go プロジェクト: shenwei356/gtaxon
func remoteQueryGi2TaxidByFile(host string, port int, dataType string, dataFile string, chunkSize int, threads int) {
	if chunkSize <= 0 {
		chunkSize = 1000
	}
	fn := func(line string) (interface{}, bool, error) {
		line = strings.TrimSpace(strings.TrimRight(line, "\n"))
		if line == "" {
			return "", false, nil
		}
		return line, true, nil
	}
	reader, err := breader.NewBufferedReader(dataFile, threads, chunkSize, fn)
	checkError(err)

	chResults := make(chan taxon.MessageGI2TaxidMap, threads)

	// receive result and print
	chDone := make(chan int)
	go func() {
		for msg := range chResults {
			if msg.Status != "OK" {
				log.Error(msg.Message)
			}
			for gi, taxid := range msg.Taxids {
				fmt.Printf("%s\t%s\n", gi, taxid)
			}
		}
		chDone <- 1
	}()

	// querying
	var wg sync.WaitGroup
	tokens := make(chan int, threads)
	for chunk := range reader.Ch {
		tokens <- 1
		wg.Add(1)

		gis := make([]string, len(chunk.Data))
		for i, data := range chunk.Data {
			gis[i] = data.(string)
		}

		go func(gis []string) {
			defer func() {
				wg.Done()
				<-tokens
			}()

			msg := taxon.RemoteQueryGi2Taxid(host, port, dataType, gis)
			checkError(err)
			chResults <- msg
		}(gis)
	}
	wg.Wait()
	close(chResults)
	<-chDone
}
コード例 #2
0
ファイル: remote.go プロジェクト: shenwei356/gtaxon
func remoteQueryGi2Taxid(host string, port int, dataType string, gis []string) {
	msg := taxon.RemoteQueryGi2Taxid(host, port, dataType, gis)
	if msg.Status != "OK" {
		log.Error(msg.Message)
	}
	for gi, taxid := range msg.Taxids {
		fmt.Printf("%s\t%s\n", gi, taxid)
	}
}