BiodbEntry-class {biodb} | R Documentation

## The mother abstract class of all database entry classes.

### Description

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

`appendFieldValue(field, value)`

  :

  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.

  field: The name of a field.

  value: The value to append.

  Returned value: None.

`clone(db.class = NULL)`

  :

  Clones this entry.

  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.

  Returned value: The clone, as a new BiodbEntry instance.

`computeFields(fields = NULL)`

  :

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

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

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

`getDbClass()`

  :

  Gets the ID of the database associated with this entry.

  Returned value: The name of the database class associated with this entry.

`getFieldDef(field)`

  :

  Gets the definition of an entry field.

  field: The name of the field.

  return: A object BiodbEntryField which defines the field.

`getFieldNames()`

  :

  Gets a list of all fields defined for this entry.

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

`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 )`

  :

  Converts this entry into a data frame.

  only.atomic: If set to TRUE, only export field's values that are atomic (i.e.: of type vector).

  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.

  Returned value: A data frame containg the values of the fields.

`getFieldsAsJson(compute = TRUE)`

  :

  Converts this entry into a JSON string.

  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.

  Returned value: A JSON object from jsonlite package.

`getFieldsByType(type)`

  :

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

  Returned value: A character vector containing the field names.

`getFieldValue( field, compute = TRUE, flatten = FALSE, last = FALSE, limit = 0, withNa = TRUE, duplicatedValues = TRUE )`

  :

  Gets the value of the specified field.

  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.

  Returned value: The value of the field.

`getId()`

  :

  Gets the entry ID.

  Returned value: the entry ID, which is the value if the 'accession' field.

`getName()`

  :

  Gets a short text describing this entry instance.

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

`hasField(field)`

  :

  Tests if a field is defined in this entry.

  field: The name of a field.

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

`isNew()`

  :

  Tests if this entry is new.

  Returned value: TRUE if this entry was newly created, FALSE otherwise.

`makesRefToEntry(db, oid, recurse = FALSE)`

  :

  Tests if this entry makes reference to another entry.

  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'.

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

`parentIsAConnector()`

  :

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

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

`parseContent(content)`

  :

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

  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.

  Returned value: None.

`removeField(field)`

  :

  Removes the specified field from this entry.

  field: The name of a field.

  Returned value: None.

`setFieldValue(field, value)`

  :

  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.

  field: The name of a field.

  value: The value to set.

  Returned value: None.

### 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()

[Package biodb version 1.0.4 Index]