api

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2016 License: MIT Imports: 12 Imported by: 0

README

api

-- import "github.com/brentp/vcfanno/api"

Usage

const BOTH = "both_"
const INTERVAL = ""
const LEFT = "left_"
const RIGHT = "right_"
var Reducers = map[string]Reducer{
	"self":   Reducer(self),
	"mean":   Reducer(mean),
	"max":    Reducer(max),
	"min":    Reducer(min),
	"concat": Reducer(concat),
	"count":  Reducer(count),
	"uniq":   Reducer(uniq),
	"first":  Reducer(first),
	"flag":   Reducer(vflag),
}
type Annotator
type Annotator struct {
	Sources []*Source
	Strict  bool // require a variant to have same ref and share at least 1 alt
	Ends    bool // annotate the ends of the variant in addition to the interval itself.
}

Annotator holds the information to annotate a file.

func NewAnnotator
func NewAnnotator(sources []*Source, js string, ends bool, strict bool) *Annotator

NewAnnotator returns an Annotator with the sources, seeded with some javascript. If ends is true, it will annotate the 1 base ends of the interval as well as the interval itself. If strict is true, when overlapping variants, they must share the ref allele and at least 1 alt allele.

func (*Annotator) AnnotateEnds
func (a *Annotator) AnnotateEnds(r interfaces.Relatable, ends string) error

AnnotatedEnds makes a new 1-base interval for the left and one for the right end so that it can use the same machinery to annotate the ends and the entire interval. Output into the info field is prefixed with "left_" or "right_".

func (*Annotator) AnnotateOne
func (a *Annotator) AnnotateOne(r interfaces.Relatable, strict bool, end ...string) error

AnnotateOne annotates a relatable with the Sources in an Annotator. In most cases, no need to specify end (it should always be a single arugment indicting LEFT, RIGHT, or INTERVAL, used from AnnotateEnds

func (*Annotator) SetupStreams
func (a *Annotator) SetupStreams() ([]string, error)

SetupStreams takes the query stream and sets everything up for annotation.

func (*Annotator) UpdateHeader
func (a *Annotator) UpdateHeader(r HeaderUpdater)

UpdateHeader adds to the Infos in the vcf Header so that the annotations will be reported in the header. func (a *Annotator) UpdateHeader(h HeaderUpdater) {

type HeaderUpdater
type HeaderUpdater interface {
	AddInfoToHeader(id string, itype string, number string, description string)
}
type Reducer
type Reducer func([]interface{}) interface{}
type Source
type Source struct {
	File string
	Op   string
	Name string
	// column number in bed file or ...
	Column int
	// info name in VCF. (can also be ID).
	Field string
	// 0-based index of the file order this source is from.
	Index int

	Js *otto.Script
	Vm *otto.Otto
}

Source holds the information for a single annotation to be added to a query. Many sources can come from the same file, but each must have their own Source.

func (*Source) AnnotateOne
func (src *Source) AnnotateOne(v interfaces.IVariant, vals []interface{}, prefix string)
func (*Source) IsNumber
func (s *Source) IsNumber() bool

IsNumber indicates that we expect the Source to return a number given the op

func (*Source) JsOp
func (s *Source) JsOp(v interfaces.IVariant, js *otto.Script, vals []interface{}) string

JsOp uses Otto to run a javascript snippet on a list of values and return a single value. It makes the chrom, start, end, and values available to the js interpreter.

func (*Source) UpdateHeader
func (src *Source) UpdateHeader(r HeaderUpdater, ends bool)

func (src *Source) UpdateHeader(h HeaderUpdater, ends bool) {

Documentation

Index

Constants

View Source
const BOTH = "both_"
View Source
const INTERVAL = ""
View Source
const LEFT = "left_"
View Source
const RIGHT = "right_"

Variables

View Source
var Reducers = map[string]Reducer{
	"self":   Reducer(self),
	"mean":   Reducer(mean),
	"max":    Reducer(max),
	"min":    Reducer(min),
	"concat": Reducer(concat),
	"count":  Reducer(count),
	"uniq":   Reducer(uniq),
	"first":  Reducer(first),
	"flag":   Reducer(vflag),
	"div2":   Reducer(div2),
}

Functions

This section is empty.

Types

type Annotator

type Annotator struct {
	Sources   []*Source
	Strict    bool // require a variant to have same ref and share at least 1 alt
	Ends      bool // annotate the ends of the variant in addition to the interval itself.
	PostAnnos []*PostAnnotation
}

Annotator holds the information to annotate a file.

func NewAnnotator

func NewAnnotator(sources []*Source, lua string, ends bool, strict bool, postannos []PostAnnotation) *Annotator

NewAnnotator returns an Annotator with the sources, seeded with some javascript. If ends is true, it will annotate the 1 base ends of the interval as well as the interval itself. If strict is true, when overlapping variants, they must share the ref allele and at least 1 alt allele.

func (*Annotator) AnnotateEnds

func (a *Annotator) AnnotateEnds(v interfaces.Relatable, ends string) error

AnnotatedEnds makes a new 1-base interval for the left and one for the right end so that it can use the same machinery to annotate the ends and the entire interval. Output into the info field is prefixed with "left_" or "right_".

func (*Annotator) AnnotateOne

func (a *Annotator) AnnotateOne(r interfaces.Relatable, strict bool, end ...string) error

AnnotateOne annotates a relatable with the Sources in an Annotator. In most cases, no need to specify end (it should always be a single arugment indicting LEFT, RIGHT, or INTERVAL, used from AnnotateEnds

func (*Annotator) PostAnnotate added in v0.0.9

func (a *Annotator) PostAnnotate(info interfaces.Info) error

func (*Annotator) Setup added in v0.0.9

func (a *Annotator) Setup(query HeaderUpdater) ([]interfaces.Queryable, error)

type HeaderTyped added in v0.0.9

type HeaderTyped interface {
	GetHeaderType(field string) string
}

type HeaderUpdater added in v0.0.8

type HeaderUpdater interface {
	AddInfoToHeader(id string, itype string, number string, description string)
}

type PostAnnotation added in v0.0.9

type PostAnnotation struct {
	Fields []string
	Op     string
	Name   string
	Type   string

	Vm *goluaez.State
	// contains filtered or unexported fields
}

type Reducer

type Reducer func([]interface{}) interface{}

type Source

type Source struct {
	File string
	Op   string
	Name string
	// column number in bed file or ...
	Column int
	// info name in VCF. (can also be ID).
	Field string
	// 0-based index of the file order this source is from.
	Index int

	Vm *goluaez.State
	// contains filtered or unexported fields
}

Source holds the information for a single annotation to be added to a query. Many sources can come from the same file, but each must have their own Source.

func (*Source) AnnotateOne added in v0.0.6

func (src *Source) AnnotateOne(v interfaces.IVariant, vals []interface{}, prefix string)

func (*Source) IsNumber

func (s *Source) IsNumber() bool

IsNumber indicates that we expect the Source to return a number given the op

func (*Source) LuaOp added in v0.0.9

func (s *Source) LuaOp(v interfaces.IVariant, code string, vals []interface{}) string

LuaOp uses go-lua to run a lua snippet on a list of values and return a single value. It makes the chrom, start, end, and values available to the lua interpreter.

func (*Source) UpdateHeader added in v0.0.6

func (src *Source) UpdateHeader(r HeaderUpdater, ends bool, htype string)

func (src *Source) UpdateHeader(h HeaderUpdater, ends bool) {

Jump to

Keyboard shortcuts

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