Skip to content

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 the group of the pattern, one association per group of two data or more;
  • list: associations given one by one, each by its name and 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

NameDescription
ASSOCIATION_TYPESThe types of an association.
CREATENo description.
TYPE_FIELDSThe madbot metadata fields of each type of association, by slug.
UNCHANGEDNo description.
UPDATENo description.

Classes

NameDescription
CandidatesThe data of a node an association can take, linked or about to be.

Functions

NameDescription
apply_associationsCreate the associations of a plan and write the values of their fields.
check_valueCheck a value against the schema of its field.
create_associationCreate an association of data.
field_slugsList the fields the associations of some rules may have.
group_by_patternGroup data by the group of a pattern searched in their name.
label_ofName an association for a person.
list_association_metadataRead the metadata of an association, by field slug.
list_data_associationsList the associations of a data that hold data of a node.
list_node_associationsList the associations of the data of a node, each once.
list_suggestionsList the associations madbot suggests for the data of a node.
merged_valuesReturn the values a rule gives to the fields of one of its associations.
plan_associationsPlan the associations of a node from the rules of the file.
plan_valuesPlan the values of the fields of one association, in place.
read_fieldsRead the madbot fields of some slugs, each with its JSON Schema.
set_association_metadataGive a value to a field of an association.
variant_ofChoose 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 = connections

itemsattributeinstance 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) -> bool

Say 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) -> dict

Create the associations of a plan and write the values of their fields.

A failure is reported and the next association is handled.

Parameters

NameTypeDefaultDescription
clientClientrequiredThe client, with its workspace set.
planmappingrequiredThe plan made by plan_associations, every data linked.
fieldsmappingrequiredThe madbot fields, by slug.
logcallable_silentCalled with a message for each change; the failures are returned.

Returns

dict
created and updated counts, and the failures, each {association, error}.

check_valuefunction#

def check_value(schema: Mapping | None, value: Any) -> str | None

Check a value against the schema of its field.

Parameters

NameTypeDescription
schemamapping or NoneThe JSON Schema of the field; no check when None.
valueAnyThe value; None when there is none.

Returns

str or None
What is wrong, None when the value is valid.

create_associationfunction#

def create_association(client: Client, kind: str, data_ids: list[str]) -> dict

Create an association of data.

Parameters

NameTypeDescription
clientClientThe client, with its workspace set.
kindstrIts type, one of ASSOCIATION_TYPES.
data_idslist of strIts data, two or more.

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

NameTypeDescription
rulesiterable of mappingThe 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

NameTypeDescription
itemsiterable of mappingThe data, each with its name.
patternstrA 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) -> str

Name an association for a person.

Parameters

NameTypeDescription
associationmappingA 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

NameTypeDescription
clientClientThe client, with its workspace set.
data_idstrA data of the association.
association_idstrThe association.

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

NameTypeDescription
clientClientThe client, with its workspace set.
data_idstrThe data.
node_idstrThe node.

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

NameTypeDescription
clientClientThe client, with its workspace set.
node_idstrThe node.
datalinksiterable of mappingThe datalinks of the node.

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.

Parameters

NameTypeDescription
clientClientThe client, with its workspace set.
node_idstrThe node.

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

NameTypeDescription
rulemappingThe rule, from the file.
groupstr or NoneThe group of the association.

Returns

dict
By field slug: the value of metadata, completed by the one of by_group for 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) -> dict

Plan the associations of a node from the rules of the file.

Nothing is read nor written: the inputs come from the API.

Parameters

NameTypeDefaultDescription
labelstrrequiredThe path of the node, for the messages.
ruleslist of mappingrequiredThe associations of the node in the file.
candidatesiterable of mappingrequiredThe 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.
existinglist of dictrequiredThe associations of madbot, as list_node_associations gives them.
suggestionslist of dictrequiredThe suggestions of madbot, as list_suggestions gives them.
connectionsmappingrequiredThe plan of the connection of each source of the file, by key.
fieldsmappingrequiredThe madbot fields of the types, by slug.
currentmappingNoneThe metadata of each existing association, by its identifier.
completeboolTrueWhether 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

dict
later: 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; errors and warnings.

plan_valuesfunction#

def plan_values(entry: dict, current: Mapping[str, Mapping], fields: Mapping[str, Mapping]) -> None

Plan the values of the fields of one association, in place.

Parameters

NameTypeDescription
entrydictA planned association, with its values from the file.
currentmappingIts metadata in madbot, by field slug, as list_association_metadata gives them; empty when it does not exist yet.
fieldsmappingThe 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

NameTypeDescription
clientClientThe client.
slugsiterable of strThe slugs of the fields.

Returns

dict
Each field as the API gives it, by slug, its schema read 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) -> None

Give a value to a field of an association.

Parameters

NameTypeDefaultDescription
clientClientrequiredThe client, with its workspace set.
data_idstrrequiredA data of the association.
association_idstrrequiredThe association.
field_idstrrequiredThe madbot metadata field.
valueAnyrequiredThe value.
metadata_idstrNoneThe metadata of the association for that field, when it has one.

variant_offunction#

def variant_of(schema: Mapping, value: Any) -> Mapping

Choose 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

NameTypeDescription
schemamappingA JSON Schema.
valueAnyA value.

Returns

mapping
The schema with the variant the value names in place of oneOf; the schema itself when no variant or several match.