BiodbFactory: A class for constructing biodb objects.

BiodbFactoryR Documentation

A class for constructing biodb objects.

Description

A class for constructing biodb objects.

A class for constructing biodb objects.

Details

This class is responsible for the creation of database connectors and database entries. You must go through the single instance of this class to create and get connectors, as well as instantiate entries. To get the single instance of this class, call the getFactory() method of class BiodbMain.

Methods

Public methods


Method new()

New instance initializer. The BiodbFactory class must not be instantiated directly. Instead, call the getFactory() method from the BiodbMain instance.

Usage
BiodbFactory$new(bdb)
Arguments
bdb

The BiodbMain instance.

Returns

Nothing.


Method getBiodb()

Returns the biodb main class instance to which this object is attached.

Usage
BiodbFactory$getBiodb()
Returns

The main biodb instance.


Method createConn()

Creates a connector to a database.

Usage
BiodbFactory$createConn(
  db.class,
  url = NULL,
  token = NA_character_,
  fail.if.exists = TRUE,
  get.existing.conn = TRUE,
  conn.id = NULL,
  cache.id = NULL
)
Arguments
db.class

The type of a database. The list of types can be obtained from the class BiodbDbsInfo.

url

An URL to the database for which to create a connection. Each database connector is configured with a default URL, but some allow you to change it.

token

A security access token for the database. Some database require such a token for all or some of their webservices. Usually you obtain the token through your account on the database website.

fail.if.exists

If set to TRUE, the method will fail if a connector for

get.existing.conn

This argument will be used only if fail.if.exists is set to FALSE and an identical connector already exists. If it set to TRUE, the existing connector instance will be returned, otherwise NULL will be returned.

conn.id

If set, this identifier will be used for the new connector. An error will be raised in case another connector already exists with this identifier.

cache.id

If set, this ID will be used as the cache ID for the new connector. An error will be raised in case another connector already exists with this cache identifier.

Returns

An instance of the requested connector class.


Method connExists()

Tests if a connector exists.

Usage
BiodbFactory$connExists(conn.id)
Arguments
conn.id

A connector ID.

Returns

TRUE if a connector with this ID exists, FALSE otherwise.


Method deleteConn()

Deletes an existing connector.

Usage
BiodbFactory$deleteConn(conn)
Arguments
conn

A connector instance or a connector ID.

Returns

Nothing.


Method deleteConnByClass()

Deletes all existing connectors from a same class.

Usage
BiodbFactory$deleteConnByClass(db.class)
Arguments
db.class

The type of a database. All connectors of this database type will be deleted.

Returns

Nothing.


Method getAllConnectors()

Gets all connectors.

Usage
BiodbFactory$getAllConnectors()
Returns

A list of all created connectors.


Method deleteAllConnectors()

Deletes all connectors.

Usage
BiodbFactory$deleteAllConnectors()
Returns

Nothing.


Method getConn()

Gets an instantiated connector instance, or create a new one.

Usage
BiodbFactory$getConn(conn.id, class = TRUE, create = TRUE)
Arguments
conn.id

An existing connector ID.

class

If set to TRUE, and \"conn.id\" does not correspond to any instantiated connector, then interpret \"conn.id\" as a database class and looks for the first instantiated connector of that class.

create

If set to TRUE, and \"class\" is also set to TRUE, and no suitable instantiated connector was found, then creates a new connector instance of the class specified by \"conn.id\".

Returns

The connector instance corresponding to the connector ID or to the database ID submitted (if class \"parameter\" is set to TRUE).


Method getEntry()

Retrieves database entry objects from IDs (accession numbers), for the specified connector.

Usage
BiodbFactory$getEntry(conn.id, id, drop = TRUE, no.null = FALSE, limit = 0)
Arguments
conn.id

An existing connector ID.

id

A character vector containing database entry IDs (accession numbers).

drop

If set to TRUE and the list of entries contains only one element, then returns this element instead of the list. If set to FALSE, then returns always a list.

no.null

Set to TRUE to remove NULL entries.

limit

Set to a positive value to limit the number of entries returned.

Returns

A list of BiodbEntry objects, the same length as id. A NULL value is put into the list for each invalid ID of id.


Method createNewEntry()

Creates a new empty entry object from scratch. This entry is not stored in cache, and is directly attached to the factory instance instead of a particular connector.

Usage
BiodbFactory$createNewEntry(db.class)
Arguments
db.class

A database ID.

Returns

A new BiodbEntry object.


Method createEntryFromContent()

Creates an entry instance from a content.

Usage
BiodbFactory$createEntryFromContent(conn.id, content, drop = TRUE)
Arguments
conn.id

A valid BiodbConn identifier.

content

A list or character vector of contents to parse to create the entries.

drop

If set to TRUE

Returns

A list of new BiodbEntry objects.


Method getAllCacheEntries()

For a connector, gets all entries stored in the cache.

Usage
BiodbFactory$getAllCacheEntries(conn.id)
Arguments
conn.id

A connector ID.

Returns

A list of BiodbEntry objects.


Method deleteAllEntriesFromVolatileCache()

Deletes all entries stored in the cache of the given connector. This method is deprecated, please use deleteAllEntriesFromVolatileCache() instead.

Usage
BiodbFactory$deleteAllEntriesFromVolatileCache(conn.id)
Arguments
conn.id

A connector ID.

Returns

Nothing.


Method deleteAllCacheEntries()

Deletes all entries stored in the cache of the given connector.

Usage
BiodbFactory$deleteAllCacheEntries(conn.id)
Arguments
conn.id

A connector ID.

Returns

Nothing.


Method print()

Prints information about this instance.

Usage
BiodbFactory$print()
Returns

Nothing.


Method clone()

The objects of this class are cloneable with this method.

Usage
BiodbFactory$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

BiodbMain, BiodbConn and BiodbEntry.

Examples

# Create a BiodbMain instance with default settings:
mybiodb <- biodb::newInst()

# Obtain the factory instance:
factory <- mybiodb$getFactory()

# Get a compound CSV file database
chebi.tsv <- system.file("extdata", "chebi_extract.tsv", package='biodb')

# Create a connector:
conn <- mybiodb$getFactory()$createConn('comp.csv.file', url=chebi.tsv)

# Get a database entry:
entry <- conn$getEntry(conn$getEntryIds(1))

# Terminate instance.
mybiodb$terminate()


pkrog/biodb documentation built on Nov. 29, 2022, 4:24 a.m.