func main() { giMapper, err := giTaxid.Load(dictfile, true) if err != nil { log.Fatalf("Problem reading dict file: %s\n", err) } taxid, err := giMapper.GiTaxid(gi) if err != nil { log.Fatalf("Problem retrieving taxid from dict: %s\n", err) } fmt.Printf("%d\n", taxid) }
// New creates a new NCBI taxonomy representation from the options given in opts // returns the newly created taxonomy or any error it may encounter in the process func New(nodesfn, namesfn, dictfn string, savemem bool) (*Taxonomy, error) { // T : taxtree => tax t := &Taxonomy{} fmt.Fprintf(os.Stderr, "Creating new taxonomy tree ... ") s1 := time.Now() maxNodes, ewcl := wcl.FromFile(nodesfn) if ewcl != nil { return nil, ewcl } nodesf, eopen := os.OpenFile(nodesfn, os.O_RDONLY, 0644) if eopen != nil { return nil, eopen } nodesbuf := bufio.NewReader(io.Reader(nodesf)) tax, dict, ee := newTaxonomy(nodesbuf, maxNodes) if ee != nil { return nil, ee } s2 := time.Now() dur := s2.Sub(s1) fmt.Fprintf(os.Stderr, "Done (%.3f sec)\n", dur.Seconds()) // T.Name(s) fmt.Fprintf(os.Stderr, "Filling names in taxonomy tree ... ") s1 = time.Now() err := tax.loadNames(namesfn, dict) if err != nil { return nil, err } s2 = time.Now() dur = s2.Sub(s1) fmt.Fprintf(os.Stderr, "Done (%.3f sec)\n", dur.Seconds()) // E, L, H fmt.Fprintf(os.Stderr, "Creating indexes ... ") s1 = time.Now() E := make([]int, 0, maxNodes*2) L := make([]int, 0, maxNodes*2) H := make([]int, maxNodes) tax.elh(1, 0, &E, &L, &H) s2 = time.Now() dur = s2.Sub(s1) fmt.Fprintf(os.Stderr, "Done (%.3f sec)\n", dur.Seconds()) // M fmt.Fprintf(os.Stderr, "Preprocessing RMQ ... ") s1 = time.Now() M := makeMatrix(maxNodes) rmqPrep(&M, L[:len(L)-1], maxNodes) s2 = time.Now() dur = s2.Sub(s1) fmt.Fprintf(os.Stderr, "Done (%.3f sec)\n", dur.Seconds()) fmt.Fprintf(os.Stderr, "Combining data ... ") s1 = time.Now() t.T = tax t.D = dict // t.E = make([]int, len(E)) // copy(t.E, E) t.E = E // t.L = make([]int, len(L)) // copy(t.L, L) t.L = L // t.H = make([]int, len(H)) // copy(t.H, H) t.H = H // t.M = make([][]int, len(M)) // for i := 0; i < len(M); i++ { // t.M[i] = make([]int, len(M[0])) // } // copy(t.M, M) t.M = M s2 = time.Now() dur = s2.Sub(s1) fmt.Fprintf(os.Stderr, "Done (%.3f sec)\n", dur.Seconds()) t.G, err = giTaxid.Load(dictfn, savemem) if err != nil { return nil, err } return t, nil }