api

package
v0.0.0-...-a23d55b Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Overview

Package api implements the back-end for PharmacoDB.

For more information about the API, visit https://github.com/bhklab/PharmacoDB

Index

Constants

View Source
const (
	DebugMode   string = "debug"   // for development
	ReleaseMode string = "release" // for production
	TestMode    string = "test"    // for testing
)

API server environment modes.

View Source
const (
	GET    string = "GET"
	HEAD   string = "HEAD"
	POST   string = "POST"
	PUT    string = "PUT"
	DELETE string = "DELETE"
	OPTION string = "OPTION"
	PATCH  string = "PATCH"
)

HTTP methods.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, description interface{})

BadRequest responds with error status code 400, Bad Request.

func CellCompoundIntersection

func CellCompoundIntersection(c *gin.Context)

CellCompoundIntersection returns a list of experiments where a cell line and a compound have been tested. Handles GET requests for /intersections/{id}/{cell_id}/{compound_id}.

func CellCompounds

func CellCompounds(c *gin.Context)

CellCompounds returns all distinct compounds where a cell line of interest has been tested. Handles GET requests for /cell_lines/{id}/compounds.

func CellDatasetIntersection

func CellDatasetIntersection(c *gin.Context)

CellDatasetIntersection returns a list of experiments where a cell line has been tested in a dataset. Handles GET requests for /intersections/{id}/{cell_id}/{dataset_id}.

func CompoundCells

func CompoundCells(c *gin.Context)

CompoundCells returns all cell lines tested with compound. Handles GET requests for /compounds/{id}/cell_lines.

func CompoundTissues

func CompoundTissues(c *gin.Context)

CompoundTissues returns all tissues tested with compound. Handles GET requests for /compounds/{id}/tissues.

func Count

func Count(table string) (int, error)

Count returns the total number of records in table.

func Database

func Database() (*sql.DB, error)

Database creates a new database connection.

func DatasetCells

func DatasetCells(c *gin.Context)

DatasetCells returns a list of cell lines tested in dataset. Handles GET requests for /datasets/{id}/cell_lines.

func DatasetCompounds

func DatasetCompounds(c *gin.Context)

DatasetCompounds returns a list of compounds tested in dataset. Handles GET requests for /datasets/{id}/compounds.

func DatasetTissues

func DatasetTissues(c *gin.Context)

DatasetTissues returns a list of tissues tested in dataset. Handles GET requests for /datasets/{id}/tissues.

func GetEnvMode

func GetEnvMode() string

GetEnvMode gets api mode from environment variable MODE.

func GetEnvPort

func GetEnvPort() string

GetEnvPort gets api port from environment variable PORT.

func GetEnvVersion

func GetEnvVersion() string

GetEnvVersion gets api version from environment variable VERSION.

func IndexCells

func IndexCells(c *gin.Context)

IndexCells returns a list of cell lines. Handles GET requests for /cell_lines.

func IndexCellsHEAD

func IndexCellsHEAD(c *gin.Context)

IndexCellsHEAD returns header info for cell lines. Handles HEAD requests for /cell_lines.

func IndexCompounds

func IndexCompounds(c *gin.Context)

IndexCompounds returns a list of compounds. Handles GET requests for /compounds.

func IndexDatasets

func IndexDatasets(c *gin.Context)

IndexDatasets returns a list of datasets. Handles GET requests for /datasets.

func IndexExperiments

func IndexExperiments(c *gin.Context)

IndexExperiments returns a list of experiments. Handles GET requests for /experiments.

func IndexIntersections

func IndexIntersections(c *gin.Context)

IndexIntersections returns a list of all intersections. Handles GET requests for /intersections.

func IndexTissues

func IndexTissues(c *gin.Context)

IndexTissues returns a list of tissues. Handles GET requests for /tissues.

func Init

func Init(config *Config)

Init server.

func InternalServerError

func InternalServerError(c *gin.Context, description interface{})

InternalServerError responds with error status code 500, Internal Server Error.

func LogSentry

func LogSentry(err error)

LogSentry submits private errors to sentry.

func NotFound

func NotFound(c *gin.Context, description interface{})

NotFound responds with error status code 404, Not Found.

func RenderJSON

func RenderJSON(c *gin.Context, indent bool, obj interface{})

RenderJSON returns an indented, or non-indented, JSON output.

func RenderJSONwithMeta

func RenderJSONwithMeta(c *gin.Context, indent bool, page int, limit int, total int, include string, obj interface{})

RenderJSONwithMeta adds metadata to response body.

func RootHandler

func RootHandler(c *gin.Context)

RootHandler handles GET requests for root endpoint.

func SetDB

func SetDB(version string)

SetDB updates DB using environment settings.

func SetVersion

func SetVersion(version string)

SetVersion sets global api version.

func ShowCell

func ShowCell(c *gin.Context)

ShowCell returns a single cell line using id/name. Handles GET requests for /cell_lines/{id}.

func ShowCompound

func ShowCompound(c *gin.Context)

ShowCompound returns a single compound. Handles GET requests for /compounds/{id}.

func ShowDataset

func ShowDataset(c *gin.Context)

ShowDataset returns a single dataset. Handles GET requests for /datasets/{id}.

func ShowExperiment

func ShowExperiment(c *gin.Context)

ShowExperiment returns a single experiment. Handles GET requests for /experiments/{id}.

func ShowTissue

func ShowTissue(c *gin.Context)

ShowTissue returns a single tissue. Handles GET requests for /tissues/{id}.

func StatDatasetsCells

func StatDatasetsCells(c *gin.Context)

StatDatasetsCells returns a list of datasets, and the number of cell lines tested in each dataset. Handles GET requests for /stats/datasets/cell_lines.

func StatDatasetsCellsCompounds

func StatDatasetsCellsCompounds(c *gin.Context)

StatDatasetsCellsCompounds returns a list of datasets, and the number of compounds tested with a cell line per dataset. Handles GET requests for /stats/datasets/compounds/cell_lines/:id.

func StatDatasetsCompounds

func StatDatasetsCompounds(c *gin.Context)

StatDatasetsCompounds returns a list of datasets, and the number of compounds tested in each dataset. Handles GET requests for /stats/datasets/compounds.

func StatDatasetsCompoundsCells

func StatDatasetsCompoundsCells(c *gin.Context)

StatDatasetsCompoundsCells returns a list of datasets, and the number of cell lines tested with a drug per dataset. Handles GET requests for /stats/datasets/cell_lines/compounds/{id}.

func StatDatasetsCompoundsTissues

func StatDatasetsCompoundsTissues(c *gin.Context)

StatDatasetsCompoundsTissues returns a list of datasets, and the number of tissues tested with a compound per dataset. Handles GET requests for /stats/datasets/tissues/compounds/{id}.

func StatDatasetsExperiments

func StatDatasetsExperiments(c *gin.Context)

StatDatasetsExperiments returns a list of datasets, and the number of experiments carried out in each dataset. Handles GET requests for /stats/datasets/experiments.

func StatDatasetsTissues

func StatDatasetsTissues(c *gin.Context)

StatDatasetsTissues returns a list of datasets, and the number of tissues tested in each dataset. Handles GET requests for /stats/datasets/tissues.

func StatDatasetsTissuesCells

func StatDatasetsTissuesCells(c *gin.Context)

StatDatasetsTissuesCells returns a list of datasets, and the number of cell lines in a tissue per dataset. Handles GET requests for /stats/datasets/cell_lines/tissues/{id}.

func StatDatasetsTissuesCompounds

func StatDatasetsTissuesCompounds(c *gin.Context)

StatDatasetsTissuesCompounds returns a list of datasets, and the number of compounds tested with a tissue per dataset. Handles GET requests for /stats/datasets/compounds/tissues/{id}.

func StatTissuesCells

func StatTissuesCells(c *gin.Context)

StatTissuesCells returns a list of tissues, and the number of cell lines per tissue. Handles GET requests for /stats/tissues/cell_lines.

func TissueCells

func TissueCells(c *gin.Context)

TissueCells returns all cell lines of a tissue type. Handles GET requests for /tissues/{id}/cell_lines.

func TissueCompounds

func TissueCompounds(c *gin.Context)

TissueCompounds returns all compounds tested with tissue. Handles GET requests for /tissues/{id}/compounds.

func Version

func Version() string

Version returns the current api version.

func WriteHeader

func WriteHeader(c *gin.Context, endpoint string, page int, limit int, total int)

WriteHeader writes metadata to response header.

Types

type Annotation

type Annotation struct {
	Name     string   `json:"name"`
	Datasets []string `json:"datasets"`
}

Annotation models the name used by datasets for a resource item.

type Annotations

type Annotations []Annotation

Annotations is a collection of Annotation.

type Cell

type Cell struct {
	ID          int         `json:"id"`
	ACC         *string     `json:"accession_id,omitempty"`
	Name        string      `json:"name"`
	Tissue      *Tissue     `json:"tissue,omitempty"`
	Annotations Annotations `json:"annotations,omitempty"`
}

Cell is a resource model for cell_lines.

func (*Cell) Annotate

func (cell *Cell) Annotate() error

Annotate adds annotations to cell.

func (*Cell) Compounds

func (cell *Cell) Compounds(page int, limit int) (Comps, int, error)

Compounds updates cell with a list of distinct compounds tested with cell line.

func (*Cell) Find

func (cell *Cell) Find(id string, typ string) error

Find updates receiver with a record for a single cell line.

type Cells

type Cells []Cell

Cells is a collection of Cell.

func (*Cells) List

func (cells *Cells) List() error

List returns a list of all cell lines, without pagination.

func (*Cells) ListPaginated

func (cells *Cells) ListPaginated(page int, limit int) error

ListPaginated returns a list of cell lines with pagination.

type Comp

type Comp struct {
	Compound Compound `json:"compound"`
	Datasets []string `json:"datasets"`
	Count    int      `json:"experiment_count"`
}

Comp models experiment data for a compound-resource pair test.

type Compound

type Compound struct {
	ID          int         `json:"id"`
	Name        string      `json:"name"`
	Annotations Annotations `json:"annotations,omitempty"`
}

Compound is a resource model for compounds.

func (*Compound) Annotate

func (compound *Compound) Annotate() error

Annotate adds annotations to compound.

func (*Compound) Cells

func (compound *Compound) Cells(page int, limit int) (DCS, int, error)

Cells returns a paginated list of all distinct cell lines which have been tested with drug, along with experiments count and an array of datasets that tested each cell/drug combination.

func (*Compound) Find

func (compound *Compound) Find(id string, typ string) error

Find updates receiver with a record for a single compound.

func (*Compound) Tissues

func (compound *Compound) Tissues(page int, limit int) (DTS, int, error)

Tissues returns a paginated list of all distinct tissues which have been tested with drug, along with experiments count and an array of datasets that tested each cell/drug combination.

type Compounds

type Compounds []Compound

Compounds is a collection of Drug.

func (*Compounds) List

func (compounds *Compounds) List() error

List updates receiver with a list of all compounds without pagination.

func (*Compounds) ListPaginated

func (compounds *Compounds) ListPaginated(page int, limit int) error

ListPaginated updates receiver with a list of compounds using pagination.

type Comps

type Comps []Comp

Comps is a collection of Comp.

type Config

type Config struct {
	Mode    string
	Port    string
	Version string
}

Config is an API configuration struct.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default API configuration setting.

func (*Config) SetMode

func (c *Config) SetMode(mode string)

SetMode sets api mode.

func (*Config) SetPort

func (c *Config) SetPort(port string)

SetPort sets api port.

func (*Config) SetVersion

func (c *Config) SetVersion(version string)

SetVersion sets api version.

type DBAuthInfo

type DBAuthInfo struct {
	User string // local mysql user
	Pass string // local mysql password
	Name string // database name
	Host string // mysql host
}

DBAuthInfo contains local mysql username, password, and database name.

var DB DBAuthInfo

DB is a global datastore for database connection information.

type DC

type DC struct {
	Cell     Cell     `json:"cell_line"`
	Datasets []string `json:"datasets"`
	Count    int      `json:"experiment_count"`
}

DC models experiment data for a compound and a cell line.

type DCS

type DCS []DC

DCS is a collection of DCT.

type DT

type DT struct {
	Tissue   Tissue   `json:"tissue"`
	Datasets []string `json:"datasets"`
	Count    int      `json:"experiment_count"`
}

DT models experiment data for a compound and a tissue.

type DTS

type DTS []DT

DTS is a collection of DT.

type Dataset

type Dataset struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Dataset is a resource model for datasets.

func (*Dataset) Cells

func (dataset *Dataset) Cells(page int, limit int) (Cells, int, error)

Cells returns a paginated list of all cell lines tested in a dataset.

func (*Dataset) Compounds

func (dataset *Dataset) Compounds(page int, limit int) (Compounds, int, error)

Compounds returns a paginated list of all drugs tested in dataset.

func (*Dataset) Find

func (dataset *Dataset) Find(id string, typ string) error

Find updates receiver with a record for a single dataset.

func (*Dataset) Tissues

func (dataset *Dataset) Tissues(page int, limit int) (Tissues, int, error)

Tissues returns a paginated list of all tissues tested in dataset.

type DatasetCount

type DatasetCount struct {
	Dataset Dataset `json:"dataset"`
	Count   int     `json:"compounds_count"`
}

DatasetCount models the number of compounds tested per dataset.

type DatasetCounts

type DatasetCounts []DatasetCount

DatasetCounts is a collection of DatasetCount.

func CountItemsPerDataset

func CountItemsPerDataset(query string) (DatasetCounts, error)

CountItemsPerDataset returns a list of all datasets, along with the number of required item tested in each dataset.

type Datasets

type Datasets []Dataset

Datasets is a collection of Dataset.

func (*Datasets) List

func (datasets *Datasets) List() error

List updates receiver with a list of all datasets without pagination.

func (*Datasets) ListPaginated

func (datasets *Datasets) ListPaginated(page int, limit int) error

ListPaginated updates receiver with a list of datasets using pagination.

type DoseResponse

type DoseResponse struct {
	Dose     float64 `json:"dose"`
	Response float64 `json:"response"`
}

DoseResponse is a model for a dose/response data pair.

type DoseResponses

type DoseResponses []DoseResponse

DoseResponses is a collection of DoseResponse.

type Error

type Error struct {
	Code        int         `json:"code"`
	Message     string      `json:"message"`
	Description interface{} `json:"description,omitempty"`
}

Error is a public error implementation.

type Experiment

type Experiment struct {
	ID            int           `json:"experiment_id"`
	Cell          Cell          `json:"cell_line"`
	Tissue        Tissue        `json:"tissue"`
	Compound      Compound      `json:"compound"`
	Dataset       Dataset       `json:"dataset"`
	DoseResponses DoseResponses `json:"dose_responses,omitempty"`
}

Experiment is a resource model for experiments.

func (*Experiment) DoseResponse

func (experiment *Experiment) DoseResponse() error

DoseResponse updates receiver experiment with its corresponding dose/response data.

func (*Experiment) Find

func (experiment *Experiment) Find(id string) error

Find updates receiver with a record for a single experiment.

type Experiments

type Experiments []Experiment

Experiments is a collection of Experiment.

func (*Experiments) CellCompoundCombination

func (experiments *Experiments) CellCompoundCombination(cellID string, compoundID string, typ string) error

CellCompoundCombination updates receiver with a list of all experiments where a cell line and a drug have been tested.

func (*Experiments) CellDatasetCombination

func (experiments *Experiments) CellDatasetCombination(cellID string, datasetID string, typ string) error

CellDatasetCombination updates receiver with a list of all experiments where a cell line and dataset have been tested.

func (*Experiments) ListPaginated

func (experiments *Experiments) ListPaginated(page int, limit int) error

ListPaginated updates receiver with a list of experiments using pagination.

type Intersection

type Intersection struct {
	ID      int      `json:"id"`
	ResComb []string `json:"resources_combined"`
	Path    string   `json:"template_path"`
	Ex      string   `json:"example_path"`
}

Intersection is a combination query model.

type Intersections

type Intersections []Intersection

Intersections is a collection of Intersection.

func (*Intersections) List

func (intersections *Intersections) List()

List lists all possible intersections.

type Route

type Route struct {
	Endpoint string
	Handler  gin.HandlerFunc
}

Route is a routing model.

type Routes

type Routes []Route

Routes is a collection of Route.

type Tissue

type Tissue struct {
	ID          int         `json:"id"`
	Name        *string     `json:"name,omitempty"`
	Annotations Annotations `json:"annotations,omitempty"`
}

Tissue is a resource model for tissues.

func (*Tissue) Annotate

func (tissue *Tissue) Annotate() error

Annotate adds annotations to tissue.

func (*Tissue) Cells

func (tissue *Tissue) Cells(page int, limit int) (Cells, int, error)

Cells returns a paginated list of all cell lines of tissue type.

func (*Tissue) Compounds

func (tissue *Tissue) Compounds(page int, limit int) (Comps, int, error)

Compounds returns a paginated list of all distinct compounds that have been tested with tissue.

func (*Tissue) Find

func (tissue *Tissue) Find(id string, typ string) error

Find updates receiver with a record for a single tissue.

type TissueCount

type TissueCount struct {
	Tissue Tissue `json:"tissue"`
	Count  int    `json:"cell_lines_count"`
}

TissueCount models the number of cell lines per tissue.

type TissueCounts

type TissueCounts []TissueCount

TissueCounts is a collection of TissueCount.

func CountCellsPerTissue

func CountCellsPerTissue() (TissueCounts, error)

CountCellsPerTissue returns a list of all tissues, along with the number of cell lines of each tissue type.

type Tissues

type Tissues []Tissue

Tissues is a collection of Tissue.

func (*Tissues) List

func (tissues *Tissues) List() error

List updates receiver with a list of all tissues without pagination.

func (*Tissues) ListPaginated

func (tissues *Tissues) ListPaginated(page int, limit int) error

ListPaginated updates receiver with a list of tissues using pagination.

Directories

Path Synopsis
This module is used for tranforming front-end database to back-end database, modifying/adding/dropping tables as needed.
This module is used for tranforming front-end database to back-end database, modifying/adding/dropping tables as needed.

Jump to

Keyboard shortcuts

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