madbot_cli.associations
The data associations of a node: paired reads, an assembly and its reads, others.
A node of the deposit file gives associations, a list of rules. Each rule
makes associations of one type from the data of the node:
pattern: the data whose name matches, grouped by thegroupof the pattern, one association per group of two data or more;list: associations given one by one, each by itsnameand the names of its data;suggested: true: the associations madbot suggests, as the web application shows them.
An association is identified by its data: the one of madbot holding exactly
the data of a group is that group’s. The fields of its type (TYPE_FIELDS)
take their values from the metadata of the rule, and per group from
by_group. Apply creates the associations and writes those values; it never
changes the type of an association, nor removes one.
Attributes
| Name | Description |
|---|---|
ASSOCIATION_TYPES | The types of an association. |
CREATE | No description. |
TYPE_FIELDS | The madbot metadata fields of each type of association, by slug. |
UNCHANGED | No description. |
UPDATE | No description. |
Classes
| Name | Description |
|---|---|
Candidates | The data of a node an association can take, linked or about to be. |
Functions
| Name | Description |
|---|---|
apply_associations | Create the associations of a plan and write the values of their fields. |
check_value | Check a value against the schema of its field. |
create_association | Create an association of data. |
field_slugs | List the fields the associations of some rules may have. |
group_by_pattern | Group data by the group of a pattern searched in their name. |
label_of | Name an association for a person. |
list_association_metadata | Read the metadata of an association, by field slug. |
list_data_associations | List the associations of a data that hold data of a node. |
list_node_associations | List the associations of the data of a node, each once. |
list_suggestions | List the associations madbot suggests for the data of a node. |
merged_values | Return the values a rule gives to the fields of one of its associations. |
plan_associations | Plan the associations of a node from the rules of the file. |
plan_values | Plan the values of the fields of one association, in place. |
read_fields | Read the madbot fields of some slugs, each with its JSON Schema. |
set_association_metadata | Give a value to a field of an association. |
variant_of | Choose the variant of a oneOf schema a value names by a constant. |
ASSOCIATION_TYPESattributemodule attribute#
ASSOCIATION_TYPES = ('paired', 'assembly', 'other')The types of an association.
CREATEattributemodule attribute#
CREATE = 'create'TYPE_FIELDSattributemodule attribute#
TYPE_FIELDS: dict[str, tuple[str, ...]] = {'paired': ('library_layout'), 'assembly': ('assembly'), 'other': ()}The madbot metadata fields of each type of association, by slug.
As the API binds them (DataAssociation.TYPE_FIELD_SLUGS): madbot gives
every association of a type these fields, and they are the only ones a file
fills on an association.
UNCHANGEDattributemodule attribute#
UNCHANGED = 'unchanged'UPDATEattributemodule attribute#
UPDATE = 'update'Candidatesclass#
class Candidates(items: Iterable[Mapping], connections: Mapping[str, Mapping])The data of a node an association can take, linked or about to be.
source is the key of the source of a data still to link; the
connection of a source, by key, is found in connections once it
exists.
connectionsattributeinstance attribute#
connections = connectionsitemsattributeinstance attribute#
items = sorted(({: item} for item in items), key=lambda item: item['name'])by_namemethod#
def by_name(name: str, key: str | None) -> list[dict]Return the data of a name, of one source of the file when given.
in_sourcemethod#
def in_source(item: Mapping, key: str) -> boolSay whether a data comes from a source of the file.
of_sourcesmethod#
def of_sources(keys: Iterable[str] | None) -> list[dict]Return the data of some sources of the file; all when None.
apply_associationsfunction#
def apply_associations(client: Client, plan: Mapping, fields: Mapping[str, Mapping], log: op.Log = _silent) -> dictCreate the associations of a plan and write the values of their fields.
A failure is reported and the next association is handled.
Parameters
Returns
dictcreatedandupdatedcounts, and thefailures, each{association, error}.
check_valuefunction#
def check_value(schema: Mapping | None, value: Any) -> str | NoneCheck a value against the schema of its field.
Parameters
create_associationfunction#
def create_association(client: Client, kind: str, data_ids: list[str]) -> dictCreate an association of data.
Parameters
Returns
dict- The association. madbot answers with the one already holding exactly these data when there is one, its type left as it is.
field_slugsfunction#
def field_slugs(rules: Iterable[Mapping]) -> set[str]List the fields the associations of some rules may have.
Parameters
| Name | Type | Description |
|---|---|---|
rules | iterable of mapping | The associations of a node. |
Returns
set of str- The slugs of the fields of their types.
group_by_patternfunction#
def group_by_pattern(items: Iterable[Mapping], pattern: str) -> tuple[OrderedDict[str, list[dict]], list[str]]Group data by the group of a pattern searched in their name.
Parameters
| Name | Type | Description |
|---|---|---|
items | iterable of mapping | The data, each with its name. |
pattern | str | A regular expression with a group group. |
Returns
tuple- The data of each group, by group, in the order of the names; and the names that match no group.
label_offunction#
def label_of(association: Mapping) -> strName an association for a person.
Parameters
| Name | Type | Description |
|---|---|---|
association | mapping | A planned association, or one of madbot. |
Returns
str- Its type, its group when it has one, and its data.
list_association_metadatafunction#
def list_association_metadata(client: Client, data_id: str, association_id: str) -> dict[str, dict]Read the metadata of an association, by field slug.
Parameters
Returns
dict- For each field slug,
{id, field, value}: the metadata, the identifier of the field and the value of the association, None when empty.
list_data_associationsfunction#
def list_data_associations(client: Client, data_id: str, node_id: str) -> list[dict]List the associations of a data that hold data of a node.
Parameters
Returns
list of dict- The associations as the API lists them.
list_node_associationsfunction#
def list_node_associations(client: Client, node_id: str, datalinks: Iterable[Mapping]) -> list[dict]List the associations of the data of a node, each once.
Parameters
Returns
list of dict- Each association as
{id, type, data, names, members}: its identifier, its type, the identifiers of its data as a frozenset, their names, and each data as{name, data}, by name.
list_suggestionsfunction#
def list_suggestions(client: Client, node_id: str) -> list[dict]List the associations madbot suggests for the data of a node.
The data already together in an association are left out by madbot.
Returns
list of dict- Each suggestion as
{type, data: [{id, name, datalink}]}.
merged_valuesfunction#
def merged_values(rule: Mapping, group: str | None) -> dict[str, Any]Return the values a rule gives to the fields of one of its associations.
Parameters
Returns
dict- By field slug: the value of
metadata, completed by the one ofby_groupfor the group (key by key when both are objects).
plan_associationsfunction#
def plan_associations(label: str, rules: list[Mapping], candidates: Iterable[Mapping], existing: list[dict], suggestions: list[dict], connections: Mapping[str, Mapping], fields: Mapping[str, Mapping], current: Mapping[str, Mapping[str, Mapping]] | None = None, complete: bool = True) -> dictPlan the associations of a node from the rules of the file.
Nothing is read nor written: the inputs come from the API.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
label | str | required | The path of the node, for the messages. |
rules | list of mapping | required | The associations of the node in the file. |
candidates | iterable of mapping | required | The data of the node, each {name, data, connection, source?};
data is None for a data still to link, which gives the key of its
source. |
existing | list of dict | required | The associations of madbot, as list_node_associations gives them. |
suggestions | list of dict | required | The suggestions of madbot, as list_suggestions gives them. |
connections | mapping | required | The plan of the connection of each source of the file, by key. |
fields | mapping | required | The madbot fields of the types, by slug. |
current | mapping | None | The metadata of each existing association, by its identifier. |
complete | bool | True | Whether every data of the node is known; when not, a name of a
list not found yet waits for the data instead of being an error. |
Returns
dictlater: some associations wait for data still to be found;associations: each planned one,{rule, type, group, names, data, id, exists, action, values, writes, missing};untracked: the associations of madbot no rule designates;ignored: the names no pattern matches;errorsandwarnings.
plan_valuesfunction#
def plan_values(entry: dict, current: Mapping[str, Mapping], fields: Mapping[str, Mapping]) -> NonePlan the values of the fields of one association, in place.
Parameters
| Name | Type | Description |
|---|---|---|
entry | dict | A planned association, with its values from the file. |
current | mapping | Its metadata in madbot, by field slug, as list_association_metadata
gives them; empty when it does not exist yet. |
fields | mapping | The madbot fields, by slug. |
Only | ||
file |
read_fieldsfunction#
def read_fields(client: Client, slugs: Iterable[str]) -> dict[str, dict]Read the madbot fields of some slugs, each with its JSON Schema.
Parameters
| Name | Type | Description |
|---|---|---|
client | Client | The client. |
slugs | iterable of str | The slugs of the fields. |
Returns
dict- Each field as the API gives it, by slug, its
schemaread from its address; the fields the instance does not have are left out.
set_association_metadatafunction#
def set_association_metadata(client: Client, data_id: str, association_id: str, field_id: str, value: Any, metadata_id: str | None = None) -> NoneGive a value to a field of an association.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
client | Client | required | The client, with its workspace set. |
data_id | str | required | A data of the association. |
association_id | str | required | The association. |
field_id | str | required | The madbot metadata field. |
value | Any | required | The value. |
metadata_id | str | None | The metadata of the association for that field, when it has one. |
variant_offunction#
def variant_of(schema: Mapping, value: Any) -> MappingChoose the variant of a oneOf schema a value names by a constant.
The value of a library layout names its variant by library_layout: PAIRED: its errors are those of that variant, not of the others.
Parameters
| Name | Type | Description |
|---|---|---|
schema | mapping | A JSON Schema. |
value | Any | A value. |
Returns
mapping- The schema with the variant the value names in place of
oneOf; the schema itself when no variant or several match.

