gochado

package module
v0.0.0-...-8f2270e Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2014 License: GPL-2.0 Imports: 13 Imported by: 0

README

gochado

Command line tool for exporting and importing biological data from chado database.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMD5Hash

func GetMD5Hash(text string) string

Returns MD5 hash of string

func ParseConfig

func ParseConfig(buffer *bytes.Buffer) map[string]string

Parse ini content from a buffer

Types

type ChadoHelper

type ChadoHelper struct {
	*Database
	// contains filtered or unexported fields
}

Helper for finding and creating cv, cvterm , db and dbxrefs in chado database.

func NewChadoHelper

func NewChadoHelper(dbh *sqlx.DB) *ChadoHelper

Gets a new instance

func (*ChadoHelper) CreateCvtermId

func (helper *ChadoHelper) CreateCvtermId(params map[string]string) (int, error)

Creates a cvterm record from cvterm, cv, dbxref and db parameters and return a primary key of cvterm table(cvterm_id). The parameters are passed through a map structure with the following keys

cv :    manadatory
cvterm: manadatory
dbxref: mandatory. If dbxref has Db:Id structure the Db and Id are split before
        storing
db:     optional. By default internal is used.

func (*ChadoHelper) FindCvtermId

func (helper *ChadoHelper) FindCvtermId(cv, cvt string) (int, error)

func (*ChadoHelper) FindOrCreateCvId

func (helper *ChadoHelper) FindOrCreateCvId(cv string) (int, error)

Given a cv namespace returns its primary key identifier. The lookup is done on the cache first and if absent retrieved from cv table.

func (*ChadoHelper) FindOrCreateDbId

func (helper *ChadoHelper) FindOrCreateDbId(db string) (int, error)

Given a db name returns its primary key identifier. The lookup is done on the cache first and if absent retrieved from db table.

func (*ChadoHelper) NormaLizeId

func (helper *ChadoHelper) NormaLizeId(dbxref string) (int, string, error)

Given a dbxref returns its db_id and accession. Accepts both Db:Dbxref and Dbxref form. Create the Db entry if absent in the database. In case of without specific Db, *internal* is used

type ChadoLoader

type ChadoLoader interface {
	// To prepare involved chado tables for bulk load, such as
	// disabling indexes and/or foreign keys if needed
	AlterTables()
	// Primarilly to complement the AlterTables method, put back the chaged tables
	// in its pristine states. Could also be used to re-calcualate statistics
	// on tables that has inserts after bulk load.
	ResetTables()
	// Actual data loading by running a series of sql statements that transfers
	// data from staging tables.
	BulkLoad()
}

Interface for making a chado loader from staging tables

type Cv

type Cv struct {
	CvId       int64 `primary_key:"cv_id"`
	Name       string
	Definition string
	Cvterms    []Cvterm
}

type Cvterm

type Cvterm struct {
	CvtermId           int64 `primary_key:"cvterm_id"`
	Name               string
	Definition         string
	IsObsolete         bool
	IsRelationshiptype bool

	//Foreign keys
	CvId     int64
	Cv       Cv
	DbxrefId int64
	Dbxref   Dbxref
}

type DataBucket

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

A simple way to hold bucket of data primarilly for inserting in batch to a relational backend. It is a simple slice of maps container where each will have values keyed by a column name. Ultimately, each of this map will be transformed into a row in the database.

func NewDataBucket

func NewDataBucket() *DataBucket

func (*DataBucket) Clear

func (b *DataBucket) Clear()

func (*DataBucket) Count

func (b *DataBucket) Count() int

func (*DataBucket) Elements

func (b *DataBucket) Elements() []map[string]interface{}

func (*DataBucket) GetByPosition

func (b *DataBucket) GetByPosition(pos int) map[string]interface{}

func (*DataBucket) Push

func (b *DataBucket) Push(m map[string]interface{})

type DataCache

type DataCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A simple thread safe cache for holding key(string) value(int). This is a typical use case for working with chado database where db,dbxref, cv and cvterm entries are shared as foreign keys between most of the tables. Caching those foreign keys with a unique name reduces redundant database lookups.

func NewDataCache

func NewDataCache() *DataCache

New instance of Datacache

func (*DataCache) Clear

func (dc *DataCache) Clear()

Removes all entries from cache

func (*DataCache) Get

func (dc *DataCache) Get(key string) (id int)

Retrieve an entry from the cache. However, it is advisable to run *Has* method before retrieving the entry.

func (*DataCache) Has

func (dc *DataCache) Has(key string) bool

Check for the presence of an entry

func (*DataCache) Remove

func (dc *DataCache) Remove(key string)

Remove an entry

func (*DataCache) Set

func (dc *DataCache) Set(key string, id int)

Add an entry to the cache

type Database

type Database struct {
	ChadoHandler *sqlx.DB
}

Type to hold an active chado database handler. It is expected to be embedded in other type structure that requires an active chado connection.

type Db

type Db struct {
	DbId        int64 `primary_key:"db_id"`
	Name        string
	Description string
	Urlprefix   string
	Url         string
	// has_many relations
	Dbxrefs []Dbxref
}

type Dbxref

type Dbxref struct {
	DbxrefId    int64 `primary_key:"dbxref_id"`
	Accession   string
	Version     string
	Description string
	//Foreign key
	DbId int64
	// Embedded struct belongs_to relation
	Db Db
	//has_many relations
	FeatureDbxrefs []FeatureDbxref
}

type Feature

type Feature struct {
	FeatureId        int64 `primary_key:"feature_id"`
	Name             string
	Uniquename       string
	Residues         string
	Seqlen           int64
	Md5checksum      string
	IsAnalysis       bool
	IsObsolete       bool
	Timeaccessioned  time.Time
	Timelastmodified time.Time

	//foreign keys
	OrganismId int64
	Organism   Organism
	DbxrefId   int64
	Dbxref     Dbxref
	TypeId     int64
	Type       Cvterm

	//has_many relations
	FeatureCvterms []FeatureCvterm
	FeatureDbxrefs []FeatureDbxref
}

type FeatureCvterm

type FeatureCvterm struct {
	FeatureCvtermId int64 `primary_key:"feature_cvterm_id"`
	IsNot           bool
	Rank            int64
	//foreign keys
	FeatureId int64
	Feature   Feature
	CvtermId  int64
	Cvterm    Cvterm
	PubId     int64
	Pub       Pub
}

type FeatureDbxref

type FeatureDbxref struct {
	FeatureDbxrefId int64 `primary_key:"feature_dbxref_id"`
	FeatureId       int64
	DbxrefId        int64
	Feature         Feature
	Dbxref          Dbxref
}

type GpadFixtureLoader

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

func NewGpadFixtureLoader

func NewGpadFixtureLoader(tc testchado.DBManager) *GpadFixtureLoader

func (*GpadFixtureLoader) LoadGenes

func (f *GpadFixtureLoader) LoadGenes(genes []string) []Feature

func (*GpadFixtureLoader) LoadGoIds

func (f *GpadFixtureLoader) LoadGoIds(ids map[string][]string) []Cvterm

func (*GpadFixtureLoader) LoadMiscCvterms

func (f *GpadFixtureLoader) LoadMiscCvterms(cv string) []Cvterm

func (*GpadFixtureLoader) LoadPubIds

func (f *GpadFixtureLoader) LoadPubIds(ids []string) []Pub

type Organism

type Organism struct {
	OrganismId   int64 `primary_key:"organism_id"`
	Abbreviation string
	Genus        string
	Species      string
	CommonName   string
	Comment      string
	Features     []Feature
}

type Pub

type Pub struct {
	PubId       int64 `primary_key:"pub_id"`
	Title       string
	Volumetitle string
	Volume      string
	SeriesName  string
	Issue       string
	Pyear       string
	Pages       string
	Miniref     string
	Uniquename  string
	Publisher   string
	Pubplace    string
	IsObsolete  bool
	//foreign key
	TypeId int64
	Type   Cvterm
}

type SqlParser

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

Parsing sql statements from ini style config file. Each ini section expects to have a sql statement

In caboose.ini file

[create_bag] CREATE TABLE bag (

id INTEGER PRIMARY KEY NOT NULL,
name TEXT

);

[select_bag] SELECT id FROM bag WHERE name = ?

[insert_bag] INSERT INTO bag(name) VALUES(?)

.......

parser := NewSqlParserFromFile("caboose.ini")
for _, section := range parser.Sections() {
    fmt.Printf("section:%s\nvalue:%s\n\n",section,parser.GetSection(section))
}

func NewSqlParserFromFile

func NewSqlParserFromFile(file string) *SqlParser

Parse ini sql content from a file and returns a new instance

func NewSqlParserFromString

func NewSqlParserFromString(content string) *SqlParser

Parse ini sql content from a string and returns a new instance

func (*SqlParser) GetSection

func (ini *SqlParser) GetSection(key string) string

Value of a particular section

func (*SqlParser) Sections

func (ini *SqlParser) Sections() []string

List of ini section

type StagingLoader

type StagingLoader interface {
	// Add a row of unprocessed data to the staging cache
	AddDataRow(string)
	// Create temporary staging tables
	CreateTables()
	// Drop the staging tables
	DropTables()
	// Alteration in the staging tables, for example creating indexes
	AlterTables()
	// Bulk upload data from staging cache to the staging tables
	BulkLoad()
}

Interface for making a loader for staging tables

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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