htsdb

package module
v0.0.0-...-ba125ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2017 License: MIT Imports: 4 Imported by: 0

README

htsdb: library and tools to handle Hith Throughput Sequencing data stored in SQLite database.

Given a database table with a schema similar to a SAM file this library provides a convenient interface to iterate over the records in the database and perform custom queries. For usage examples see available tools.

Note: The API is in early alpha and therefore very unstable. Things change frequently.

To install go get github.com/mnsmar/htsdb/...

Documentation

Overview

Package htsdb wraps a database connection to provide a convenient loop interface for reading database records. Successive calls to the Next method will step through the records of the database. Iteration stops unrecoverably when records are exhausted or at the first error.

type Record struct {
	Strand  int `db:"strand_field"`
	Start   int
}

db, err := sql.Open("foo", "bar")

r, err := NewReader(db, "foo", &Record{}, "SELECT * FROM FOO")

for r.Next() {
    rec, ok := r.Record().(*Record)
    fmt.Println(rec)
}
if r.Error() !=  nil {
	panic(r.Error)
}

Index

Constants

This section is empty.

Variables

View Source
var CountBuilder = squirrel.Select().
	Column(squirrel.Alias(squirrel.Expr("COUNT(*)"), "count"))

CountBuilder is a squirrel select builder to count entries.

View Source
var FeatureBuilder = RangeBuilder.Column("rname")

FeatureBuilder is a squirrel select builder whose columns match Feature fields.

View Source
var OrientedFeatureBuilder = FeatureBuilder.Column("strand")

OrientedFeatureBuilder is a squirrel select builder whose columns match OrientedFeature fields.

View Source
var RangeBuilder = squirrel.Select("start", "stop", "copy_number")

RangeBuilder is a squirrel select builder whose columns match Range fields.

View Source
var ReferenceBuilder = squirrel.Select("rname").
	Column(squirrel.Alias(squirrel.Expr("MAX(stop)+1"), "length")).
	GroupBy("rname")

ReferenceBuilder is a squirrel select builder whose structure matches that of Reference and that knows how to properly extract references from htsdb.

View Source
var SamRecordBuilder = squirrel.Select("qname", "flag", "rname", "pos",
	"mapq", "cigar", "rnext", "pnext", "tlen", "seq", "qual", "tags")

SamRecordBuilder is a squirrel select builder whose columns match SamRecord fields.

Functions

func Head(r feat.Range, o feat.Orientation) int

Head returns the head coordinate of r depending on orientation.

func Tail

func Tail(r feat.Range, o feat.Orientation) int

Tail returns the tail coordinate of r depending on orientation.

Types

type Feature

type Feature struct {
	Rname string `db:"rname"`
	Range
}

Feature is part of an htsdb record that wraps Range and the name of the reference.

func (*Feature) Description

func (e *Feature) Description() string

Description returns an empty string.

func (*Feature) Location

func (e *Feature) Location() feat.Feature

Location returns the location of Feature.

func (*Feature) Name

func (e *Feature) Name() string

Name returns an empty string.

type OrientedFeature

type OrientedFeature struct {
	Orient feat.Orientation `db:"strand"`
	Feature
}

OrientedFeature is part of an htsdb record that wraps Feature and has orientation.

func (*OrientedFeature) Orientation

func (e *OrientedFeature) Orientation() feat.Orientation

Orientation returns the orientation of OrientedFeature.

type Range

type Range struct {
	StartPos   int `db:"start"`
	StopPos    int `db:"stop"`
	CopyNumber int `db:"copy_number"`
}

Range is part of an htsdb record that wraps the alignment coordinates.

func (*Range) CopyNum

func (e *Range) CopyNum() int

CopyNum returns the copy number of Range.

func (*Range) End

func (e *Range) End() int

End returns the end position of Range.

func (*Range) Len

func (e *Range) Len() int

Len returns the length of Range.

func (*Range) Start

func (e *Range) Start() int

Start returns the start position of Range.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader encapsulates a connection to a database and acts as an iterator for the records. Internally the reader maps each database row to dest.

func NewReader

func NewReader(db *sql.DB, driverName string, dest interface{}, query string,
) (*Reader, error)

NewReader returns a new reader that reads from db by runs the given query and maps rows into dest.

func (*Reader) Close

func (r *Reader) Close()

Close closes the database connection.

func (*Reader) Error

func (r *Reader) Error() error

Error returns the error that was encountered by the iterator.

func (*Reader) Next

func (r *Reader) Next() bool

Next advances the iterator past the next record, which will then be available through Record(). It returns false when the iteration stops, either by reaching the end of the input or an error. After Next returns false, the Error method will return any error that occurred during iteration.

func (*Reader) Record

func (r *Reader) Record() interface{}

Record returns the most recent record read by a call to Next.

type Reference

type Reference struct {
	Chrom  string `db:"rname"`
	Length int    `db:"length"`
}

Reference is a reference feature on which reads align.

func SelectReferences

func SelectReferences(db *sqlx.DB, b squirrel.SelectBuilder) ([]Reference, error)

SelectReferences selects the reference sequences from db using squirrel.SelectBuilder. It will return an error if it encounters one.

e.g. refs, err := SelectReferences(db, ReferenceBuilder)

func (*Reference) Description

func (c *Reference) Description() string

Description returns the description of the reference.

func (*Reference) End

func (c *Reference) End() int

End returns the end of the reference.

func (*Reference) Len

func (c *Reference) Len() int

Len returns the length of the reference.

func (*Reference) Location

func (c *Reference) Location() feat.Feature

Description returns nil.

func (*Reference) Name

func (c *Reference) Name() string

Name returns the name of the reference.

func (*Reference) Start

func (c *Reference) Start() int

Start returns 0.

type SamRecord

type SamRecord struct {
	Qname string
	Flag  int
	Rname string
	Pos   int
	Mapq  int
	Cigar string
	Rnext string
	Pnext int
	Tlen  int
	Seq   string
	Qual  string
	Tags  string
}

SamRecord is part of an htsdb record that wraps the fields of a SAM file.

func (*SamRecord) Name

func (s *SamRecord) Name() string

Name returns the SAM qname.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL