database

package
v0.0.0-...-ac0af50 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Postgres = 0
)

The list of supported databases

Variables

View Source
var DefaultValues = struct {
	MassEpsilon float64
	Intensity   int64
	Limit       int64
}{0.1, 50, math.MaxInt64}

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	Database  DatabaseType
	DbUser    string
	DbPwd     string
	DbHost    string
	DbName    string
	DbPort    uint
	DbConnStr string
}

DBConfig is the abstract database configuration which should be used when working with MB3Database.

type DatabaseType

type DatabaseType int

DatabaseType is an enum containing the database type

type Filters

type Filters struct {
	InstrumentType *[]string
	Splash         string
	MsType         *[]massbank.MsType
	IonMode        massbank.IonMode
	CompoundName   string
	CompoundClass  string
	Mass           *float64
	MassEpsilon    *float64
	Formula        string
	Peaks          *[]float64
	NeutralLoss    *[]float64
	Inchi          string
	InchiKey       string
	Contributor    *[]string
	Intensity      *int64
}

Filters is the abstract description of filters used to find MassBank records in the database

type Index

type Index struct {
	IndexName string
	TableName string
	Columns   []string
}

type MB3Database

type MB3Database interface {

	// Connect to the database.
	Connect() error

	// Disconnect from the database.
	Disconnect() error

	Ping() error

	// Count MassBank records in the database.
	Count() (int64, error)

	// Initialises the database.
	Init() error

	// GetRecord gets a single MassBank record by the Accession string.
	// It should return nil and a [NotFoundError] if the record is not in the
	// database.
	GetRecord(*string) (*massbank.MassBank2, error)

	GetRecords(*[]string) (*[]string, error)

	// GetSimpleRecord gets a single simple MassBank record by the Accession string.
	// It should return nil and a [NotFoundError] if the record is not in the
	// database.
	GetSimpleRecord(*string) (*massbank.MassBank2, error)

	// GetSimpleRecords Get an array of MassBank records by filtering
	//
	// Will return an empty list if the filter does not match any records.
	GetSearchResults(filters Filters) (*[]string, *[]int32, error)

	// GetRecordsBySubstructure Get an array of MassBank accessions by filtering by substructure
	//
	// Will return an empty list if the filter does not match any records.
	GetAccessionsBySubstructure(substructure string) ([]string, []int32, error)

	GetAccessionsByFilterOptions(filters Filters) ([]string, []int32, error)

	NeutralLossSearch(neutralLoss *[]float64, tolerance *float64, minRelIntensity *int64) ([]string, []int32, map[string][]string, error)

	// GetRecordsBySubstructure Get an array of MassBank records by filtering by substructure
	//
	// Will return an empty list if the filter does not match any records.
	GetRecordsBySubstructure(substructure string) (*[]massbank.MassBank2, error)

	// GetUniqueValues is used to get the values for filter frontend
	GetUniqueValues(filters Filters) (MB3Values, error)

	GetMetadata() (*massbank.MbMetaData, error)
	// GetVersion returns the version of the MassBank PostGres database.
	GetVersion() (string, error)

	// UpdateMetadata updates the metadata describing the MassBank version.
	// Provides the database id of an existing entry if it is already in the
	// database.
	//
	// Returns the id of the database entry as string.
	UpdateMetadata(meta *massbank.MbMetaData) (string, error)

	// Set status
	SetStatus(param string, status string) error
	// Delete status
	DeleteStatus(param string) error
	// Get status
	GetStatus(param string) (string, error)

	// RemoveIndexes removes all indexes from the database.
	RemoveIndexes() error

	//AddIndexes adds indexes to the database.
	AddIndexes() error

	// AddRecord adds a new MassBank record to the database. If the Accession
	// id already exists it will return an error.
	//
	// The second parameter is the database id of the version information. You
	// can get it from [UpdateMetadata].
	AddRecord(record *massbank.MassBank2, metaDataId string, mb3RecordJson string) error

	// AddRecords adds a list of MassBank records given as an array to the
	// database. If one of the Accession ids  exists the  function should roll
	// back the transaction and return an error.
	//
	// The second parameter is the database id of the version information. You
	// can get it from [UpdateMetadata].
	AddRecords(records []*massbank.MassBank2, metaDataId string, mb3RecordJsons []string) error
}

MB3Database This is the Interface which has to be implemented for databases using MassBank3

Any database can be used as in the backend as long as it defines the interface.

func InitDb

func InitDb(dbConfig DBConfig) (MB3Database, error)

type MB3MetaData

type MB3MetaData struct {
	StoredMetadata MB3StoredMetaData
	SpectraCount   int
	CompoundCount  int
	IsomerCount    int
}

type MB3StoredMetaData

type MB3StoredMetaData struct {
	Version   string
	TimeStamp string
	GitCommit string
}

type MB3Values

type MB3Values struct {
	Contributor    []MBCountValues
	InstrumentType []MBCountValues
	MSType         []MBCountValues
	IonMode        []MBCountValues
	Intensity      MBMinMaxValues
	Mass           MBMinMaxValues
	Peak           MBMinMaxValues
}

type MBCountValues

type MBCountValues struct {
	Val   string
	Count int
}

type MBDatabaseError

type MBDatabaseError struct {
	InnerError error  // inner error mostly from the database backend
	Message    string // the error message
}

MBDatabaseError is an error type specific for the database interactions

func (*MBDatabaseError) Error

func (err *MBDatabaseError) Error() string

Implements the error interface for MBDatabaseError

type MBErrorType

type MBErrorType int

MBErrorType is an enum for the error types during database operations

const (
	DatabaseNotReady MBErrorType = iota
	CouldNotReachHost
	InternalError
	NotFoundError
	ConversionError
)

The list of error types

type MBMinMaxValues

type MBMinMaxValues struct {
	Min float64
	Max float64
}

type MSTypeAndIonMode

type MSTypeAndIonMode struct {
	MSType  []string
	IonMode []string
}

type PostgresSQLDB

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

PostgresSQLDB is a struct representing a postgres connection. This should implement the MB3Database interface.

func NewPostgresSQLDb

func NewPostgresSQLDb(config DBConfig) (*PostgresSQLDB, error)

NewPostgresSQLDb creates a postgres database handle implementing MB3Database from the configuration. It does test the connection or connect to the database. This should be done by [Connect()].

Returns an error if the connection data is not syntactically valid.

func (*PostgresSQLDB) AddIndexes

func (p *PostgresSQLDB) AddIndexes() error

AddIndexes see [MB3Database.AddIndexes]

func (*PostgresSQLDB) AddRecord

func (p *PostgresSQLDB) AddRecord(record *massbank.MassBank2, metaDataId string, mb3RecordJson string) error

AddRecord see [MB3Database.AddRecord]

func (*PostgresSQLDB) AddRecords

func (p *PostgresSQLDB) AddRecords(records []*massbank.MassBank2, metaDataId string, mb3RecordJsons []string) error

AddRecords see [MB3Database.AddRecords]

func (*PostgresSQLDB) BuildBrowseOptionsWhere

func (p *PostgresSQLDB) BuildBrowseOptionsWhere(filters Filters) (string, []string)

BuildSearchOptionsWhere to build the where clause within the browse_options table

func (*PostgresSQLDB) Connect

func (p *PostgresSQLDB) Connect() error

Connect see [MB3Database.Connect]

func (*PostgresSQLDB) Count

func (p *PostgresSQLDB) Count() (int64, error)

Count see [MB3Database.Count]

func (*PostgresSQLDB) CreateIndex

func (p *PostgresSQLDB) CreateIndex(i *Index) string

func (*PostgresSQLDB) DeleteStatus

func (p *PostgresSQLDB) DeleteStatus(name string) error

func (*PostgresSQLDB) Disconnect

func (p *PostgresSQLDB) Disconnect() error

Disconnect see [MB3Database.Disconnect]

func (*PostgresSQLDB) DropIndex

func (p *PostgresSQLDB) DropIndex(i *Index) string

func (*PostgresSQLDB) GetAccessionsByFilterOptions

func (p *PostgresSQLDB) GetAccessionsByFilterOptions(filters Filters) ([]string, []int32, error)

func (*PostgresSQLDB) GetAccessionsBySubstructure

func (p *PostgresSQLDB) GetAccessionsBySubstructure(substructure string) ([]string, []int32, error)

func (*PostgresSQLDB) GetContributors

func (p *PostgresSQLDB) GetContributors() ([]string, error)

func (*PostgresSQLDB) GetIndexes

func (db *PostgresSQLDB) GetIndexes() []Index

func (*PostgresSQLDB) GetInstrumentTypes

func (p *PostgresSQLDB) GetInstrumentTypes() ([]string, error)

func (*PostgresSQLDB) GetMetadata

func (p *PostgresSQLDB) GetMetadata() (*massbank.MbMetaData, error)

func (*PostgresSQLDB) GetMsTypeAndIonMode

func (p *PostgresSQLDB) GetMsTypeAndIonMode() (*MSTypeAndIonMode, error)

func (*PostgresSQLDB) GetRecord

func (p *PostgresSQLDB) GetRecord(s *string) (*massbank.MassBank2, error)

GetRecord see [MB3Database.GetRecord]

func (*PostgresSQLDB) GetRecords

func (p *PostgresSQLDB) GetRecords(s *[]string) (*[]string, error)

func (*PostgresSQLDB) GetRecordsBySubstructure

func (p *PostgresSQLDB) GetRecordsBySubstructure(substructure string) (*[]massbank.MassBank2, error)

GetRecordsBySubstructure see [MB3Database.GetRecordsBySubstructure]

func (*PostgresSQLDB) GetSearchResults

func (p *PostgresSQLDB) GetSearchResults(filters Filters) (*[]string, *[]int32, error)

GetSearchResults see [MB3Database.GetSearchResults]

func (*PostgresSQLDB) GetSimpleRecord

func (p *PostgresSQLDB) GetSimpleRecord(s *string) (*massbank.MassBank2, error)

GetSimpleRecord see [MB3Database.GetSimpleRecord]

func (*PostgresSQLDB) GetStatus

func (p *PostgresSQLDB) GetStatus(name string) (string, error)

func (*PostgresSQLDB) GetUniqueValues

func (p *PostgresSQLDB) GetUniqueValues(filters Filters) (MB3Values, error)

GetUniqueValues see [MB3Database.GetUniqueValues]

func (*PostgresSQLDB) GetVersion

func (p *PostgresSQLDB) GetVersion() (string, error)

func (*PostgresSQLDB) Init

func (p *PostgresSQLDB) Init() error

func (*PostgresSQLDB) IsEmpty

func (p *PostgresSQLDB) IsEmpty() (bool, error)

IsEmpty see [MB3Database.IsEmpty]

func (*PostgresSQLDB) NeutralLossSearch

func (p *PostgresSQLDB) NeutralLossSearch(neutralLoss *[]float64, tolerance *float64, minRelIntensity *int64) ([]string, []int32, map[string][]string, error)

func (*PostgresSQLDB) Ping

func (p *PostgresSQLDB) Ping() error

func (*PostgresSQLDB) RemoveIndexes

func (p *PostgresSQLDB) RemoveIndexes() error

RemoveIndexes see [MB3Database.RemoveIndexes]

func (*PostgresSQLDB) SetStatus

func (p *PostgresSQLDB) SetStatus(name string, value string) error

func (*PostgresSQLDB) UpdateMetadata

func (p *PostgresSQLDB) UpdateMetadata(meta *massbank.MbMetaData) (string, error)

UpdateMetadata see [MB3Database.UpdateMetadata]

Jump to

Keyboard shortcuts

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