本文整理汇总了Golang中github.com/TuftsBCB/tools/util.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Assert函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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())
}
示例2: main
func main() {
if len(util.FlagCpuProf) > 0 {
f := util.CreateFile(util.FlagCpuProf)
pprof.StartCPUProfile(f)
defer f.Close()
defer pprof.StopCPUProfile()
}
if len(flagGobIt) > 0 {
astralDir := util.Arg(0)
dists := readAlignmentDists(astralDir)
enc := gob.NewEncoder(util.CreateFile(flagGobIt))
util.Assert(enc.Encode(dists), "Could not GOB encode distances")
return
}
var dists *intern.Table
if util.IsDir(util.Arg(0)) {
dists = readAlignmentDists(util.Arg(0))
} else {
dec := gob.NewDecoder(util.OpenFile(util.Arg(0)))
util.Assert(dec.Decode(&dists), "Could not GOB decode distances")
}
treeFile := util.Arg(1)
outPath := util.Arg(2)
treeReader := newick.NewReader(util.OpenFile(treeFile))
tree, err := treeReader.ReadTree()
util.Assert(err, "Could not read newick tree")
csvw := csv.NewWriter(util.CreateFile(outPath))
clusters := treeClusters(flagThreshold, dists, tree)
util.Assert(csvw.WriteAll(clusters))
}
示例3: mkStructure
func mkStructure(c *command) {
c.assertNArg(2)
brkFile := c.flags.Arg(0)
saveto := c.flags.Arg(1)
util.AssertOverwritable(saveto, flagOverwrite)
brkContents, err := ioutil.ReadAll(util.OpenFile(c.flags.Arg(0)))
util.Assert(err)
pdbFragments := bytes.Split(brkContents, []byte("TER"))
fragments := make([][]structure.Coords, 0)
for i, pdbFrag := range pdbFragments {
pdbFrag = bytes.TrimSpace(pdbFrag)
if len(pdbFrag) == 0 {
continue
}
fragments = append(fragments, coords(i, pdbFrag))
}
libName := stripExt(path.Base(brkFile))
lib, err := fragbag.NewStructureAtoms(libName, fragments)
util.Assert(err)
fragbag.Save(util.CreateFile(saveto), lib)
}
示例4: mkPaired
func mkPaired(c *command) {
c.assertNArg(2)
in := util.Library(c.flags.Arg(0))
outPath := c.flags.Arg(1)
util.AssertOverwritable(outPath, flagOverwrite)
if _, ok := in.(fragbag.WeightedLibrary); ok {
util.Fatalf("%s is a weighted library (not allowed)", in.Name())
}
name := fmt.Sprintf("paired-%s", in.Name())
if fragbag.IsStructure(in) {
var pairs [][]structure.Coords
lib := in.(fragbag.StructureLibrary)
nfrags := lib.Size()
for i := 0; i < nfrags; i++ {
for j := 0; j < nfrags; j++ {
if i == j {
continue
}
f1, f2 := lib.Atoms(i), lib.Atoms(j)
pairs = append(pairs, append(f1, f2...))
}
}
pairLib, err := fragbag.NewStructureAtoms(name, pairs)
util.Assert(err)
fragbag.Save(util.CreateFile(outPath), pairLib)
} else if strings.Contains(in.Tag(), "hmm") {
var pairs []*seq.HMM
lib := in.(fragbag.SequenceLibrary)
nfrags := lib.Size()
for i := 0; i < nfrags; i++ {
for j := 0; j < nfrags; j++ {
if i == j {
continue
}
f1, f2 := lib.Fragment(i).(*seq.HMM), lib.Fragment(j).(*seq.HMM)
pairs = append(pairs, seq.HMMCat(f1, f2))
}
}
pairLib, err := fragbag.NewSequenceHMM(name, pairs)
util.Assert(err)
fragbag.Save(util.CreateFile(outPath), pairLib)
} else if strings.Contains(in.Tag(), "profile") {
util.Fatalf("Sequence profiles not implemented.")
} else {
util.Fatalf("Unrecognized fragment library: %s", in.Tag())
}
}
示例5: search
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())
}
示例6: mkBowDb
func mkBowDb(c *command) {
c.assertLeastNArg(3)
dbPath := c.flags.Arg(0)
flib := util.Library(c.flags.Arg(1))
bowPaths := c.flags.Args()[2:]
util.AssertOverwritable(dbPath, flagOverwrite)
db, err := bowdb.Create(flib, dbPath)
util.Assert(err)
bows := util.ProcessBowers(bowPaths, flib, false, flagCpu, util.FlagQuiet)
for b := range bows {
db.Add(b)
}
util.Assert(db.Close())
}
示例7: coords
func coords(num int, atomRecords []byte) []structure.Coords {
r := bytes.NewReader(atomRecords)
name := fmt.Sprintf("fragment %d", num)
entry, err := pdb.Read(r, name)
util.Assert(err, "Fragment contents could not be read in PDB format")
atoms := entry.OneChain().CaAtoms()
if len(atoms) == 0 {
util.Fatalf("Fragment %d has no ATOM coordinates.", num)
}
return atoms
}
示例8: readVectors
func readVectors(fpath string) map[string]bow.Bow {
f := util.OpenFile(fpath)
defer f.Close()
bows := make(map[string]bow.Bow, 5000)
for _, line := range util.ReadLines(f) {
fields := strings.Fields(line)
b := bow.NewBow(len(fields[1:]))
for _, sfreq := range fields[1:] {
freq, err := strconv.ParseFloat(sfreq, 32)
util.Assert(err)
b.Freqs = append(b.Freqs, float32(freq))
}
bows[fields[0]] = b
}
return bows
}
示例9: readDomains
func readDomains(fpath string) *inDomains {
domains := &inDomains{
intern.NewInterner(),
make([]string, 0, 2000),
make([]intern.Atom, 0, 2000),
}
scanner := bufio.NewScanner(util.OpenFile(fpath))
for scanner.Scan() {
d := strings.Fields(scanner.Text())[0]
d = stripExt(path.Base(util.CathPath(d)))
a := domains.in.Atom(d)
domains.ids = append(domains.ids, d)
domains.atoms = append(domains.atoms, a)
}
util.Assert(scanner.Err())
return domains
}
示例10: readMatrix
func readMatrix(domains *inDomains, fpath string) *intern.Table {
var (
err error
fval float64
sval string
)
tab := intern.NewTableInterner(domains.in)
scanner := bufio.NewScanner(util.OpenFile(fpath))
for i := 0; scanner.Scan(); i++ {
// It'd be much simpler to use Split here, but let's be quicker.
// In particular, avoid allocating.
// Also, we're dealing with the line as a string since it's quicker
// than using bytes and converting each number to a string for
// strconv.ParseFloat.
line := scanner.Text()
bstart, j := 0, -1
for bend, b := range scanner.Text() {
// This actually skips the very last element in the table, but
// it's OK because the value at [k, k] is always 0.
switch {
case b == ' ' || b == '\n' || bend+1 == len(line):
sval = line[bstart:bend]
bstart = bend + 1
j++
// falls down to process this value
default:
continue
}
if j > i && len(sval) > 0 { // upper triangular
fval, err = strconv.ParseFloat(sval, 64)
if err != nil {
panic(err)
}
tab.Set(domains.atoms[i], domains.atoms[j], fval)
}
}
}
util.Assert(scanner.Err())
return tab
}
示例11: readAlignmentDists
func readAlignmentDists(dir string) *intern.Table {
dists := intern.NewTable(11000)
threads := util.FlagCpu
addDists := make(chan []pair)
alignFile := make(chan string)
done := make(chan struct{})
go func() {
for fileDists := range addDists {
for _, pair := range fileDists {
a1, a2 := dists.Atom(pair.key[0]), dists.Atom(pair.key[1])
dists.Set(a1, a2, pair.dist)
}
}
done <- struct{}{}
}()
wg := new(sync.WaitGroup)
for i := 0; i < threads; i++ {
wg.Add(1)
go func() {
for fpath := range alignFile {
log.Printf("Reading %s (%s)", fpath, time.Now())
f := util.OpenFile(fpath)
defer f.Close()
csvr := csv.NewReader(f)
csvr.Comma = '\t'
csvr.TrimLeadingSpace = true
csvr.FieldsPerRecord = -1 // data is poorly formatted
records, err := csvr.ReadAll()
util.Assert(err, "[%s]", fpath)
fileDists := make([]pair, 0, 100000)
for _, record := range records {
if len(record) != 9 {
continue
}
p := recordToDist(record)
fileDists = append(fileDists, p)
}
addDists <- fileDists
}
wg.Done()
}()
}
for _, fpath := range util.RecursiveFiles(dir) {
if strings.HasPrefix(path.Base(fpath), ".") {
continue
}
alignFile <- fpath
}
close(alignFile)
wg.Wait()
close(addDists)
<-done
return dists
}
示例12: readFloat
func readFloat(s string) float64 {
num, err := strconv.ParseFloat(s, 64)
util.Assert(err, "Expected float, but got '%s'.", s)
return num
}
示例13: mkSeqHMM
func mkSeqHMM(c *command) {
c.assertLeastNArg(3)
structLib := util.StructureLibrary(c.flags.Arg(0))
outPath := c.flags.Arg(1)
entries := c.flags.Args()[2:]
util.AssertOverwritable(outPath, flagOverwrite)
saveto := util.CreateFile(outPath)
// Stores intermediate files produced by hhmake.
tempDir, err := ioutil.TempDir("", "mk-seqlib-hmm")
util.Assert(err, "Could not create temporary directory.")
defer os.RemoveAll(tempDir)
// Initialize a MSA for each structural fragment.
var msas []seq.MSA
var msaChans []chan seq.Sequence
for i := 0; i < structLib.Size(); i++ {
msa := seq.NewMSA()
msa.SetLen(structLib.FragmentSize())
msas = append(msas, msa)
msaChans = append(msaChans, make(chan seq.Sequence))
}
// Now spin up a goroutine for each fragment that is responsible for
// adding a sequence slice to itself.
for i := 0; i < structLib.Size(); i++ {
addToMSA(msaChans[i], &msas[i])
}
// Create a channel that sends the PDB entries given.
entryChan := make(chan string)
go func() {
for _, fp := range entries {
entryChan <- fp
}
close(entryChan)
}()
progress := util.NewProgress(len(entries))
for i := 0; i < flagCpu; i++ {
wgPDBChains.Add(1)
go func() {
for entryPath := range entryChan {
_, chains, err := util.PDBOpen(entryPath)
progress.JobDone(err)
if err != nil {
continue
}
for _, chain := range chains {
structureToSequence(structLib, chain, nil, msaChans)
}
}
wgPDBChains.Done()
}()
}
wgPDBChains.Wait()
progress.Close()
// We've finishing reading all the PDB inputs. Now close the channels
// and let the sequence fragments finish.
for i := 0; i < structLib.Size(); i++ {
close(msaChans[i])
}
wgSeqFragments.Wait()
util.Verbosef("Building profile HMMs from MSAs...")
// Finally, add the sequence fragments to a new sequence fragment
// library and save.
hmms := make([]*seq.HMM, structLib.Size())
hhmake := func(i int) struct{} {
fname := path.Join(tempDir, fmt.Sprintf("%d.fasta", i))
f := util.CreateFile(fname)
util.Assert(msa.WriteFasta(f, msas[i]))
hhm, err := hhsuite.HHMakePseudo.Run(fname)
util.Assert(err)
hmms[i] = hhm.HMM
return struct{}{} // my unifier sucks, i guess
}
fun.ParMap(hhmake, fun.Range(0, structLib.Size()))
lib, err := fragbag.NewSequenceHMM(structLib.Name(), hmms)
util.Assert(err)
util.Assert(fragbag.Save(saveto, lib))
}
示例14: mkSeqProfile
func mkSeqProfile(c *command) {
c.assertLeastNArg(3)
structLib := util.StructureLibrary(c.flags.Arg(0))
outPath := c.flags.Arg(1)
entries := c.flags.Args()[2:]
util.AssertOverwritable(outPath, flagOverwrite)
saveto := util.CreateFile(outPath)
// Initialize a frequency and null profile for each structural fragment.
var freqProfiles []*seq.FrequencyProfile
var fpChans []chan seq.Sequence
for i := 0; i < structLib.Size(); i++ {
fp := seq.NewFrequencyProfile(structLib.FragmentSize())
freqProfiles = append(freqProfiles, fp)
fpChans = append(fpChans, make(chan seq.Sequence))
}
// Now spin up a goroutine for each fragment that is responsible for
// adding a sequence slice to itself.
nullChan, nullProfile := addToNull()
for i := 0; i < structLib.Size(); i++ {
addToProfile(fpChans[i], freqProfiles[i])
}
// Create a channel that sends the PDB entries given.
entryChan := make(chan string)
go func() {
for _, fp := range entries {
entryChan <- fp
}
close(entryChan)
}()
progress := util.NewProgress(len(entries))
for i := 0; i < flagCpu; i++ {
wgPDBChains.Add(1)
go func() {
for entryPath := range entryChan {
_, chains, err := util.PDBOpen(entryPath)
progress.JobDone(err)
if err != nil {
continue
}
for _, chain := range chains {
structureToSequence(structLib, chain, nullChan, fpChans)
}
}
wgPDBChains.Done()
}()
}
wgPDBChains.Wait()
progress.Close()
// We've finishing reading all the PDB inputs. Now close the channels
// and let the sequence fragments finish.
close(nullChan)
for i := 0; i < structLib.Size(); i++ {
close(fpChans[i])
}
wgSeqFragments.Wait()
// Finally, add the sequence fragments to a new sequence fragment
// library and save.
profs := make([]*seq.Profile, structLib.Size())
for i := 0; i < structLib.Size(); i++ {
profs[i] = freqProfiles[i].Profile(nullProfile)
}
lib, err := fragbag.NewSequenceProfile(structLib.Name(), profs)
util.Assert(err)
util.Assert(fragbag.Save(saveto, lib))
}