func main() { db := util.OpenBowDB(util.Arg(0)) out := util.CreateFile(util.Arg(1)) printf := func(format string, v ...interface{}) { fmt.Fprintf(out, format, v...) } // Set our search options. bowOpts := bowdb.SearchDefault bowOpts.Limit = -1 printf("QueryID\tResultID\tCosine\tEuclid\n") entries, err := db.ReadAll() util.Assert(err, "Could not read BOW database entries") for _, entry := range entries { results := db.Search(bowOpts, entry) for _, result := range results { printf("%s\t%s\t%0.4f\t%0.4f\n", entry.Id, result.Bowed.Id, result.Cosine, result.Euclid) } printf("\n") } util.Assert(out.Close()) util.Assert(db.Close()) }
func search(c *command) { c.assertLeastNArg(2) // Some search options don't translate directly to command line parameters // specified by the flag package. if flagSearchDesc { flagSearchOpts.Order = bowdb.OrderDesc } switch flagSearchSort { case "cosine": flagSearchOpts.SortBy = bowdb.SortByCosine case "euclid": flagSearchOpts.SortBy = bowdb.SortByEuclid default: util.Fatalf("Unknown sort field '%s'.", flagSearchSort) } db := util.OpenBowDB(c.flags.Arg(0)) bowPaths := c.flags.Args()[1:] _, err := db.ReadAll() util.Assert(err, "Could not read BOW database entries") // always hide the progress bar here. bows := util.ProcessBowers(bowPaths, db.Lib, false, flagCpu, true) out, outDone := outputter() // launch goroutines to search queries in parallel wgSearch := new(sync.WaitGroup) for i := 0; i < flagCpu; i++ { wgSearch.Add(1) go func() { defer wgSearch.Done() for b := range bows { sr := db.Search(flagSearchOpts, b) out <- searchResult{b, sr} } }() } wgSearch.Wait() close(out) <-outDone util.Assert(db.Close()) }
func main() { dbPath := util.Arg(0) fragLibDir := util.Arg(1) pdbFiles := flag.Args()[2:] util.Assert(createBowDb(dbPath, fragLibDir, pdbFiles)) db := util.OpenBowDB(dbPath) _, err := db.ReadAll() util.Assert(err, "Could not read BOW database entries") bowOpts := bowdb.SearchDefault bowOpts.Limit = 200 mattOpts := matt.DefaultConfig mattOpts.Verbose = false chains := createChains(pdbFiles) mattArgs := createMattArgs(chains) tabw := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0) header := []byte( "BOW entry\t" + "BOW chain\t" + "BOW dist\t" + "Matt entry\t" + "Matt chain\t" + "Matt dist\n") for i, chain := range chains { marg := mattArgs[i] bowOrdered := getBowOrdering(db, bowOpts, bow.BowerFromChain(chain)) mattOrdered := getMattOrdering(mattOpts, marg, mattArgs) fmt.Printf("Ordering for %s (chain %c)\n", chain.Entry.IdCode, chain.Ident) compared := comparison([2]ordering{bowOrdered, mattOrdered}) tabw.Write(header) tabw.Write([]byte(compared.String())) tabw.Flush() fmt.Println("\n") } util.Assert(db.Close()) }
func main() { if len(util.FlagCpuProf) > 0 { f := util.CreateFile(util.FlagCpuProf) pprof.StartCPUProfile(f) defer f.Close() defer pprof.StopCPUProfile() } // Read all CATH domains, the best-of-all matrix, and the matrix for // each aligner. domains := readDomains(util.Arg(0)) boa := readMatrix(domains, util.Arg(1)) aligners := make([]aligner, 0) flibs := make([]flib, 0) for i := 2; i < util.NArg(); i += 2 { fpath := util.Arg(i) if path.Ext(fpath) == ".bowdb" { db := util.OpenBowDB(fpath) records, err := db.ReadAll() util.Assert(err) bowed := make([]bow.Bowed, domains.in.Len()) for _, b := range records { if !domains.in.Exists(b.Id) { util.Fatalf("Found ID in bowdb that isn't in the list "+ "of CATH domains provided: %s", b.Id) } bowed[domains.in.Atom(b.Id)] = b } flibs = append(flibs, flib{db, bowed, util.Arg(i + 1)}) } else { aligners = append(aligners, aligner{ readMatrix(domains, fpath), util.Arg(i + 1), }) } } // Now remove CATH domains that don't have a corresponding structure file. // We don't do this initially since the matrix files are indexed with // respect to all CATH domains (includings ones without structure). // This is an artifact of the fact that the matrices were generated with // a very old version of CATH. domains.removeOldDomains() if a := matrixAuc(domains, boa, boa, flagThreshold); a != 1.0 { util.Fatalf("Something is wrong. The AUC of the best-of-all matrix "+ "with respect to itself is %f, but it should be 1.0.", a) } if len(aligners) > 0 { fmt.Println("Computing AUC for aligners...") writeAuc := func(aligner aligner) struct{} { w := util.CreateFile(aligner.outpath) a := matrixAuc(domains, boa, aligner.matrix, flagThreshold) fmt.Fprintf(w, "%f\n", a) return struct{}{} } fun.ParMap(writeAuc, aligners) } if len(flibs) > 0 { fmt.Println("Computing AUC for bowdbs...") writeAuc := func(flib flib) struct{} { w := util.CreateFile(flib.outpath) a := flibAuc(domains, boa, flib, flagThreshold) fmt.Fprintf(w, "%f\n", a) return struct{}{} } fun.ParMap(writeAuc, flibs) } }