Пример #1
0
func (d *DiversityFilter) findGenome(r *sam.Record, env *lmdb.Env, dbname string) (val []byte, err error) {
	fn := func(txn *lmdb.Txn) error {
		dbi, err := txn.OpenDBI(dbname, 0)
		if err != nil {
			return err
		}
		key := []byte(r.Ref.Name())
		val, err = txn.Get(dbi, key)
		val = bytes.ToUpper(val)
		return err
	}
	err = env.View(fn)
	return
}
Пример #2
0
func setVersionLMDB(env *lmdb.Env, metadbi lmdb.DBI, version int64) error {
	return env.Update(func(tx *lmdb.Txn) error {
		buf := new(bytes.Buffer)
		err := binary.Write(buf, binary.LittleEndian, version)
		if err != nil {
			glog.Errorf("Couldn't convert version!")
			return err
		}
		werr := tx.Put(metadbi, []byte("version"), buf.Bytes(), 0)
		if werr != nil {
			glog.Error("Couldn't write version!")
			return werr
		}
		return nil
	})
}
Пример #3
0
func createDBI(env *lmdb.Env, name string) error {
	fn := func(txn *lmdb.Txn) error {
		var dbi lmdb.DBI
		var err error
		var del bool = false

		if dbi, err = txn.CreateDBI(name); err != nil {
			return err
		}

		if err = txn.Drop(dbi, del); err != nil {
			return err
		}

		return nil
	}

	err := env.Update(fn)
	return err
}
Пример #4
0
func getAllCr(env *lmdb.Env, dbname string) chan KeyValue {
	ch := make(chan KeyValue)
	go func() {
		defer close(ch)
		fn := func(txn *lmdb.Txn) error {
			dbi, err := txn.OpenDBI(dbname, 0)
			if err != nil {
				return err
			}

			cur, err := txn.OpenCursor(dbi)
			if err != nil {
				return err
			}

			for {
				k, v, err := cur.Get(nil, nil, lmdb.Next)
				if lmdb.IsNotFound(err) {
					break
				}

				if err != nil {
					return err
				}

				ch <- KeyValue{Key: k, Value: v}
			}
			return nil
		}

		err := env.View(fn)
		if err != nil {
			if *debug {
				log.Panicln(err)
			} else {
				log.Fatalln(err)
			}
		}
	}()
	return ch
}
Пример #5
0
func getAllSNPs(env *lmdb.Env) chan SNPArr {
	ch := make(chan SNPArr)
	fn := func(tx *lmdb.Txn) error {
		dbi, err := tx.OpenDBI("gene", 0)
		if err != nil {
			return err
		}

		cur, err := tx.OpenCursor(dbi)
		if err != nil {
			return err
		}
		defer cur.Close()

		for {
			k, v, err := cur.Get(nil, nil, lmdb.Next)
			if lmdb.IsNotFound(err) {
				return nil
			} else if err != nil {
				return err
			}

			arr := []pileup.SNP{}
			if err := msgpack.Unmarshal(v, &arr); err != nil {
				return err
			}

			ch <- SNPArr{Key: k, Arr: arr}
		}
	}

	go func() {
		defer close(ch)
		env.View(fn)
	}()

	return ch
}