Beispiel #1
0
func init() {
	flag.StringVar(&flagChain, "chain", flagChain,
		"This may be set to one or more chain identifiers. Only amino acids "+
			"belonging to a chain specified will be included.")
	flag.StringVar(&flagSplit, "split", flagSplit,
		"When set, each FASTA entry produced will be written to a file in the "+
			"specified directory with the PDB id code and chain identifier as "+
			"the name.")

	util.FlagParse("in-pdb-file [out-fasta-file]", "")

	if util.NArg() != 1 && util.NArg() != 2 {
		util.Usage()
	}
}
Beispiel #2
0
func main() {
	lib = util.StructureLibrary(util.Arg(0))
	pdbEntry := util.PDBRead(util.Arg(1))

	if util.NArg() == 2 {
		for _, chain := range pdbEntry.Chains {
			atoms := chain.CaAtoms()
			bestFragsForRegion(chain, atoms, 0, len(atoms))
		}
	} else {
		chainId := util.Arg(2)
		chain := pdbEntry.Chain(chainId[0])
		if chain == nil || !chain.IsProtein() {
			util.Fatalf("Could not find protein chain with id '%c'.", chainId)
		}
		atoms := chain.CaAtoms()

		if util.NArg() == 3 {
			bestFragsForRegion(chain, atoms, 0, len(atoms))
		} else {
			if util.NArg() != 5 {
				log.Println("Both a start and end must be provided.")
				util.Usage()
			}

			s, e := util.Arg(3), util.Arg(4)
			sn, en := util.ParseInt(s)-1, util.ParseInt(e)
			if en-sn < lib.FragmentSize() {
				util.Fatalf("The range [%s, %s] specifies %d alpha-carbon "+
					"atoms while at least %d alpha-carbon atoms are required "+
					"for the given fragment library.",
					s, e, en-sn, lib.FragmentSize())
			}
			bestFragsForRegion(chain, atoms, sn, en)
		}
	}
}
Beispiel #3
0
func init() {
	flag.Float64Var(&flagThreshold, "threshold", flagThreshold,
		"Set the distance threshold to use when computing AUC.")
	util.FlagUse("cpu", "cpuprof")
	util.FlagParse(
		"cath-domain-labels best-of-all-matrix"+
			"(bowdb | matrix-file) out-file "+
			"[ (bowdb | matrix-file) out-file ... ]",
		"Computes the AUC of each aligner matrix (or BOW database) given\n"+
			"with respect to the 'best-of-all' matrix given. Each AUC is\n"+
			"written to a separate out-file. The sizes of all matrices must\n"+
			"be exactly equivalent.\n"+
			"Files are interpreted as BOW databases if they have a '.bowdb'\n"+
			"file extension.")
	util.AssertLeastNArg(4)
	if util.NArg()%2 != 0 {
		util.Fatalf("There must be an out file for each matrix or bowdb file.")
	}
}
Beispiel #4
0
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)
	}
}
Beispiel #5
0
func main() {
	libFile := util.Arg(0)
	brkFile := util.Arg(1)
	lib := util.StructureLibrary(libFile)

	stderrf("Loading PDB files into memory...\n")
	entries := make([]*pdb.Entry, util.NArg()-2)
	for i, pdbfile := range flag.Args()[2:] {
		entries[i] = util.PDBRead(pdbfile)
	}

	stderrf("Comparing the results of old fragbag and new fragbag on " +
		"each PDB file...\n")
	for _, entry := range entries {
		stderrf("Testing %s...\n", entry.Path)
		fmt.Printf("Testing %s\n", entry.Path)

		// Try to run old fragbag first. The output is an old-style BOW.
		oldBowStr, err := runOldFragbag(brkFile, entry.Path, lib.Size(),
			lib.FragmentSize())
		if err != nil {
			fmt.Println(err)
			fmt.Printf("The output was:\n%s\n", oldBowStr)
			divider()
			continue
		}

		oldBow, err := bow.NewOldStyleBow(lib.Size(), oldBowStr)
		if err != nil {
			fmt.Printf("Could not parse the following as an old style "+
				"BOW:\n%s\n", oldBowStr)
			fmt.Printf("%s\n", err)
			divider()
			continue
		}

		// Now use package fragbag to compute a BOW.
		var newBow bow.Bow
		if flagOldStyle {
			newBow = oldStyle{entry}.StructureBow(lib)
		} else {
			newBow = newStyle{entry}.StructureBow(lib)
		}

		// Create a diff and check if they are the same. If so, we passed.
		// Otherwise, print an error report.
		diff := bow.NewBowDiff(oldBow, newBow)
		if diff.IsSame() {
			fmt.Println("PASSED.")
			divider()
			continue
		}

		// Ruh roh...
		fmt.Println("FAILED.")
		fmt.Printf("\nOld BOW:\n%s\n\nNew BOW:\n%s\n", oldBow, newBow)
		fmt.Printf("\nDiff:\n%s\n", diff)
		divider()
	}
	stderrf("Done!\n")
}