BiodbEntry: The mother abstract class of all database entry classes.

BiodbEntryR Documentation

The mother abstract class of all database entry classes.

Description

The mother abstract class of all database entry classes.

The mother abstract class of all database entry classes.

Details

An entry is an element of a database, identifiable by its accession number. Each contains a list of fields defined by a name and a value. The details of all fields that can be set into an entry are defined inside the class BiodbEntryFields. From this class are derived other abstract classes for different types of entry contents: BiodbTxtEntry, BiodbXmlEntry, BiodbCsvEntry, BiodbJsonEntry and BiodbHtmlEntry. Then concrete classes are derived for each database: CompCsvEntry, MassCsvEntry, etc. For biodb users, there is no need to know this hierarchy; the knowledge of this class and its methods is sufficient.

Methods

Public methods


Method new()

New instance initializer. Entry objects must not be created directly. Instead, they are retrieved through the connector instances.

Usage
BiodbEntry$new(parent)
Arguments
parent

A valid BiodbConn instance.

Returns

Nothing.


Method parentIsAConnector()

Tests if the parent of this entry is a connector instance.

Usage
BiodbEntry$parentIsAConnector()
Returns

TRUE if this entry belongs to a connector, FALSE otherwise.


Method getParent()

Returns the parent instance (A BiodbConn or BiodbFactory object) to which this object is attached.

Usage
BiodbEntry$getParent()
Returns

A BiodbConn instance or a BiodbFactory object.


Method getBiodb()

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

Usage
BiodbEntry$getBiodb()
Returns

The main biodb instance.


Method cloneInstance()

Clones this entry.

Usage
BiodbEntry$cloneInstance(db.class = NULL)
Arguments
db.class

The database class (the Biodb database ID) of the clone. By setting this parameter, you can specify a different database for the clone, so you may clone an entry into another database if you wish. By default the class of the clone will be the same as the original entry.

Returns

The clone, as a new BiodbEntry instance.


Method getId()

Gets the entry ID.

Usage
BiodbEntry$getId()
Returns

the entry ID, which is the value if the accession field.


Method isNew()

Tests if this entry is new.

Usage
BiodbEntry$isNew()
Returns

TRUE if this entry was newly created, FALSE otherwise.


Method getDbClass()

Gets the ID of the database associated with this entry.

Usage
BiodbEntry$getDbClass()
Returns

The name of the database class associated with this entry.


Method setFieldValue()

Sets the value of a field. If the field is not already set for this entry, then the field will be created. See BiodbEntryFields for a list of possible fields in biodb.

Usage
BiodbEntry$setFieldValue(field, value)
Arguments
field

The name of a field.

value

The value to set.

Returns

Nothing.


Method appendFieldValue()

Appends a value to an existing field. If the field is not defined for this entry, then the field will be created and set to this value. Only fields with a cardinality greater than one can accept multiple values.

Usage
BiodbEntry$appendFieldValue(field, value)
Arguments
field

The name of a field.

value

The value to append.

Returns

Nothing.


Method getFieldNames()

Gets a list of all fields defined for this entry.

Usage
BiodbEntry$getFieldNames()
Returns

A character vector containing all field names defined in this entry.


Method hasField()

Tests if a field is defined in this entry.

Usage
BiodbEntry$hasField(field)
Arguments
field

The name of a field.

Returns

TRUE if the specified field is defined in this entry, FALSE otherwise.


Method removeField()

Removes the specified field from this entry.

Usage
BiodbEntry$removeField(field)
Arguments
field

The name of a field.

Returns

Nothing.


Method getFieldValue()

Gets the value of the specified field.

Usage
BiodbEntry$getFieldValue(
  field,
  compute = TRUE,
  flatten = FALSE,
  last = FALSE,
  limit = 0,
  withNa = TRUE,
  duplicatedValues = TRUE
)
Arguments
field

The name of a field.

compute

If set to TRUE and a field is not defined, try to compute it using internal defined computing rules. If set to FALSE, let the field undefined.

flatten

If set to TRUE and a field's value is a vector of more than one element, then export the field's value as a single string composed of the field's value concatenated and separated by the character defined in the 'multival.field.sep' config key. If set to FALSE or the field contains only one value, changes nothing.

last

If set to TRUE and a field's value is a vector of more than one element, then export only the last value. If set to FALSE, changes nothing.

limit

The maximum number of values to get in case the field contains more than one value.

withNa

If set to TRUE, keep NA values. Otherwise filter out NAs values in vectors.

duplicatedValues

If set to TRUE, keeps duplicated values.

Returns

The value of the field.


Method getFieldsByType()

Gets the fields of this entry that have the specified type.

Usage
BiodbEntry$getFieldsByType(type)
Arguments
type

The type of fields to retrieve.

Returns

A character vector containing the field names.


Method getFieldsAsDataframe()

Converts this entry into a data frame.

Usage
BiodbEntry$getFieldsAsDataframe(
  only.atomic = TRUE,
  compute = TRUE,
  fields = NULL,
  fields.type = NULL,
  flatten = TRUE,
  limit = 0,
  only.card.one = FALSE,
  own.id = TRUE,
  duplicate.rows = TRUE,
  sort = FALSE,
  virtualFields = FALSE
)
Arguments
only.atomic

If set to TRUE, only export field's values that are atomic

compute

If set to TRUE and a field is not defined, try to compute it using internal defined computing rules. If set to FALSE, let the field undefined.

fields

Set to character vector of field names in order to restrict execution to this set of fields.

fields.type

If set, output all the fields of the specified type.

flatten

If set to TRUE and a field's value is a vector of more than one element, then export the field's value as a single string composed of the field's value concatenated and separated by the character defined in the 'multival.field.sep' config key. If set to FALSE or the field contains only one value, changes nothing.

limit

The maximum number of field values to write into new columns. Used for fields that can contain more than one value.

only.card.one

If set to TRUE, only fields with a cardinality of one will be extracted.

own.id

If set to TRUE includes the database id field named <database_name>.id whose values are the same as the accession field.

duplicate.rows

If set to TRUE and merging field values with cardinality greater than one, values will be duplicated.

sort

If set to TRUE sort the order of columns alphabetically, otherwise do not sort.

virtualFields

If set to TRUE includes also virtual fields, otherwise excludes them.

(i.e.

of type vector).

Returns

A data frame containg the values of the fields.


Method getFieldsAsJson()

Converts this entry into a JSON string.

Usage
BiodbEntry$getFieldsAsJson(compute = TRUE)
Arguments
compute

If set to TRUE and a field is not defined, try to compute it using internal defined computing rules. If set to FALSE, let the field undefined.

Returns

A JSON object from jsonlite package.


Method parseContent()

Parses content string and set values accordingly for this entry's fields. This method is called automatically and should be run directly by users.

Usage
BiodbEntry$parseContent(content)
Arguments
content

A character string containing definition for an entry and

obtained

from a database. The format can be CSV, HTML, JSON, XML, or just text.

Returns

Nothing.


Method computeFields()

Computes fields. Look at all missing fields, and try to compute them using references to other databases, if a rule exists.

Usage
BiodbEntry$computeFields(fields = NULL)
Arguments
fields

A list of fields to review for computing. By default all fields will be reviewed.

Returns

TRUE if at least one field was computed successfully, FALSE otherwise.


Method print()

Displays short information about this instance.

Usage
BiodbEntry$print()
Returns

Nothing.


Method getName()

Gets a short text describing this entry instance.

Usage
BiodbEntry$getName()
Returns

A character value concatenating the connector name with the entry accession.


Method makesRefToEntry()

Tests if this entry makes reference to another entry.

Usage
BiodbEntry$makesRefToEntry(db, oid, recurse = FALSE)
Arguments
db

Another database connector.

oid

A entry ID from database db.

recurse

If set to TRUE, the algorithm will follow all references to entries from other databases, to see if it can establish an indirect link to oid.

Returns

TRUE if this entry makes reference to the entry oid from database db, FALSE otherwise.


Method getField()

DEPRECATED. Gets the value of a field.

Usage
BiodbEntry$getField(field)
Arguments
field

The name of the field.

Returns

The value of the field.


Method setField()

DEPRECATED. Sets the value of a field.

Usage
BiodbEntry$setField(field, value)
Arguments
field

The name of the field.

value

The new value of the field.

Returns

Nothing.


Method getFieldClass()

Gets the class of a field.

Usage
BiodbEntry$getFieldClass(field)
Arguments
field

The name of the field.

Returns

The class of the field.


Method getFieldDef()

Gets the definition of an entry field.

Usage
BiodbEntry$getFieldDef(field)
Arguments
field

The name of the field.

Returns

An object BiodbEntryField which defines the field.


Method getFieldCardinality()

Gets the cardinality of the field.

Usage
BiodbEntry$getFieldCardinality(field)
Arguments
field

The name of the field.

Returns

The cardinality of the field.


Method fieldHasBasicClass()

DEPRECATED. Use BiodbEntryField::isVector() instead.

Usage
BiodbEntry$fieldHasBasicClass(field)
Arguments
field

The name of the field.

Returns

TRUE if the field as a basic type (logical, numeric, character, ...).


Method clone()

The objects of this class are cloneable with this method.

Usage
BiodbEntry$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

BiodbFactory, BiodbConn, BiodbEntryFields.

Examples

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

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

# Get the connector of a compound database
conn <- mybiodb$getFactory()$createConn('comp.csv.file', url=chebi.tsv)

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

# Get all defined fields:
entry$getFieldNames()

# Get a field value:
accession <- entry$getFieldValue('accession')

# Test if a field is defined:
if (entry$hasField('name'))
  print(paste("The entry's name is ", entry$getFieldValue('name'),
  '.', sep=''))

# Export an entry as a data frame:
df <- entry$getFieldsAsDataframe()

# You can set or reset a field's value:
entry$setFieldValue('mass', 1893.1883)

# Terminate instance.
mybiodb$terminate()


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