Ejemplo n.º 1
0
func remoteQueryLCAByFile(host string, port int, dataFile string, chunkSize int, threads int) {
	if chunkSize <= 0 {
		chunkSize = 1000
	}
	fn := func(line string) (interface{}, bool, error) {
		line = 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.MessageLCAMap, threads)

	// receive result and print
	chDone := make(chan int)
	go func() {
		for msg := range chResults {
			if msg.Status != "OK" {
				log.Error(msg.Message)
			}
			for query, taxon := range msg.LCA {
				fmt.Printf("Query TaxIDs: %s\n", query)
				bs, err := json.MarshalIndent(taxon, "", "  ")
				checkError(err)
				fmt.Printf("Taxon: %s\n\n", string(bs))
			}
		}
		chDone <- 1
	}()

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

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

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

			msg := taxon.RemoteQueryLCA(host, port, queries)
			checkError(err)
			chResults <- msg
		}(queries)
	}
	wg.Wait()
	close(chResults)
	<-chDone
}
Ejemplo n.º 2
0
func remoteQueryLCA(host string, port int, queries []string) {
	msg := taxon.RemoteQueryLCA(host, port, queries)
	if msg.Status != "OK" {
		log.Error(msg.Message)
	}

	for query, taxon := range msg.LCA {
		fmt.Printf("Query TaxIDs: %s\n", query)
		bs, err := json.MarshalIndent(taxon, "", "  ")
		checkError(err)
		fmt.Printf("Taxon: %s\n\n", string(bs))
	}
}