BiodbEntry | R Documentation |
The mother abstract class of all database entry classes.
The mother abstract class of all database entry classes.
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.
new()
New instance initializer. Entry objects must not be created directly. Instead, they are retrieved through the connector instances.
BiodbEntry$new(parent)
parent
A valid BiodbConn instance.
Nothing.
parentIsAConnector()
Tests if the parent of this entry is a connector instance.
BiodbEntry$parentIsAConnector()
TRUE if this entry belongs to a connector, FALSE otherwise.
getParent()
Returns the parent instance (A BiodbConn or BiodbFactory object) to which this object is attached.
BiodbEntry$getParent()
A BiodbConn instance or a BiodbFactory object.
getBiodb()
Returns the biodb main class instance to which this object is attached.
BiodbEntry$getBiodb()
The main biodb instance.
cloneInstance()
Clones this entry.
BiodbEntry$cloneInstance(db.class = NULL)
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.
The clone, as a new BiodbEntry instance.
getId()
Gets the entry ID.
BiodbEntry$getId()
the entry ID, which is the value if the accession
field.
isNew()
Tests if this entry is new.
BiodbEntry$isNew()
TRUE if this entry was newly created, FALSE otherwise.
getDbClass()
Gets the ID of the database associated with this entry.
BiodbEntry$getDbClass()
The name of the database class associated with this entry.
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.
BiodbEntry$setFieldValue(field, value)
field
The name of a field.
value
The value to set.
Nothing.
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.
BiodbEntry$appendFieldValue(field, value)
field
The name of a field.
value
The value to append.
Nothing.
getFieldNames()
Gets a list of all fields defined for this entry.
BiodbEntry$getFieldNames()
A character vector containing all field names defined in this entry.
hasField()
Tests if a field is defined in this entry.
BiodbEntry$hasField(field)
field
The name of a field.
TRUE if the specified field is defined in this entry, FALSE otherwise.
removeField()
Removes the specified field from this entry.
BiodbEntry$removeField(field)
field
The name of a field.
Nothing.
getFieldValue()
Gets the value of the specified field.
BiodbEntry$getFieldValue( field, compute = TRUE, flatten = FALSE, last = FALSE, limit = 0, withNa = TRUE, duplicatedValues = TRUE )
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.
The value of the field.
getFieldsByType()
Gets the fields of this entry that have the specified type.
BiodbEntry$getFieldsByType(type)
type
The type of fields to retrieve.
A character vector containing the field names.
getFieldsAsDataframe()
Converts this entry into a data frame.
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 )
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).
A data frame containg the values of the fields.
getFieldsAsJson()
Converts this entry into a JSON string.
BiodbEntry$getFieldsAsJson(compute = TRUE)
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.
A JSON object from jsonlite package.
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.
BiodbEntry$parseContent(content)
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.
Nothing.
computeFields()
Computes fields. Look at all missing fields, and try to compute them using references to other databases, if a rule exists.
BiodbEntry$computeFields(fields = NULL)
fields
A list of fields to review for computing. By default all fields will be reviewed.
TRUE if at least one field was computed successfully, FALSE otherwise.
print()
Displays short information about this instance.
BiodbEntry$print()
Nothing.
getName()
Gets a short text describing this entry instance.
BiodbEntry$getName()
A character value concatenating the connector name with the entry accession.
makesRefToEntry()
Tests if this entry makes reference to another entry.
BiodbEntry$makesRefToEntry(db, oid, recurse = FALSE)
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
.
TRUE if this entry makes reference to the entry oid from database db, FALSE otherwise.
getField()
DEPRECATED. Gets the value of a field.
BiodbEntry$getField(field)
field
The name of the field.
The value of the field.
setField()
DEPRECATED. Sets the value of a field.
BiodbEntry$setField(field, value)
field
The name of the field.
value
The new value of the field.
Nothing.
getFieldClass()
Gets the class of a field.
BiodbEntry$getFieldClass(field)
field
The name of the field.
The class of the field.
getFieldDef()
Gets the definition of an entry field.
BiodbEntry$getFieldDef(field)
field
The name of the field.
An object BiodbEntryField which defines the field.
getFieldCardinality()
Gets the cardinality of the field.
BiodbEntry$getFieldCardinality(field)
field
The name of the field.
The cardinality of the field.
fieldHasBasicClass()
DEPRECATED. Use BiodbEntryField::isVector() instead.
BiodbEntry$fieldHasBasicClass(field)
field
The name of the field.
TRUE if the field as a basic type (logical, numeric, character, ...).
clone()
The objects of this class are cloneable with this method.
BiodbEntry$clone(deep = FALSE)
deep
Whether to make a deep clone.
BiodbFactory
, BiodbConn
,
BiodbEntryFields
.
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.