datasafe.loi module

Lab Object Identifiers (LOIs)

Accessing objects in a laboratory via unique identifiers (here: a Lab Object Identifier, LOI) is a key concept of the LabInform framework. “Object” may be thought of in a very broad and general way, ranging from (physically existing) samples via datasets represented as files on a computer storage system to abstract concepts such as projects.

Currently, the classes implemented in this module can check a LOI for consistency and compliance to the LOI scheme developed so far.

Todo

structure of the LOI that is implemented in this module needs to be described.

Note

This module should probably eventually be moved to a separate subpackage dealing with LOIs. See the LabInform documentation containing already hints of such a subpackage of the LabInform package for details.

class datasafe.loi.LoiMixin[source]

Bases: object

Define basic properties for LOIs.

Every class handling LOIs should inherit/mixin this class.

separator

Character that separates different parts of the LOI. Defaults to /.

Type:

str

root

Number identifying a LOI; default: 42

Type:

str

root_issuer_separator

Character separating root and issuer; default: .

Type:

str

class datasafe.loi.AbstractChecker[source]

Bases: object

Base class for different types of checkers.

A given string is analysed using basic checkers that look for specific elements or patterns.

Derived classes should implement the concrete and private method check(). This method returns a Boolean value depending on the test results.

check(string)[source]

Return result of private method _check()

Parameters:

string (str) – string to check

Returns:

Bool True if string fulfills criteria.

Return type:

bool

class datasafe.loi.InListChecker[source]

Bases: AbstractChecker

Check whether the given string is contained in a given list.

list

List of strings that are possible options for the given string.

Type:

list

class datasafe.loi.StartsWithChecker[source]

Bases: AbstractChecker

Check whether a string starts with the given string.

string

Pattern the string should start with

Type:

str

class datasafe.loi.IsPatternChecker[source]

Bases: AbstractChecker

Check whether a string matches the given pattern.

pattern

Pattern the string should match

Type:

str

class datasafe.loi.IsNumberChecker[source]

Bases: IsPatternChecker

Check whether a string contains only numbers.

pattern

Pattern defining numbers: “d+”

Type:

str

class datasafe.loi.IsDateChecker[source]

Bases: IsPatternChecker

Check for date in given form (YYYY-MM-DD).

Note that currently, the checker doesn’t validate if the date is valid date.

class datasafe.loi.IsFriendlyStringChecker[source]

Bases: IsPatternChecker

Check whether the string contains only “friendly” characters.

class datasafe.loi.AbstractLoiChecker[source]

Bases: LoiMixin

Abstract checker class to check if LOI is supposed to exist.

The Laboratory Object Identifier (LOI) is a persistent identifier or handle to identify various samples, objects and projects that are linked to a laboratory and its working group. The aim of it is a unique connection between those objects and actions performed on or with them. The LOI is part of the LabInform framework. For more information see https://www.labinform.de/

The checker works recursive-like: If the attribute next_checker is given in the respective class, checking continues.

This class contains the public method check() which calls the private method _check() that is to be overwritten in derived checkers.

property ignore_check

Check that should be ignored.

property next_checker

Next checker class that should be called.

check(string)[source]

Split string, check first part, give the rest over to next checker.

Initiates checking cascade by checking the first part of the LOI and pass the following string to the next checker (if given) which performs the next checking step in a recursive-like way. Key element of the LOI validating cascade.

Parameters:

string (str) – Part of the LOI to check.

Returns:

result – Returns true if part of the string is valid.

Return type:

bool

class datasafe.loi.LoiChecker[source]

Bases: AbstractLoiChecker

Check a lab object identifier (LOI) to conform to scheme.

A user only needs to instantiate this class for checking a LOI.

Begin of the cascading chain to validate a given LOI. Checking starts with the first part of the LOI that should start with 42. Following, the data type will be surveyed and depending on the result, further downstream checkers will be involved. Returns True if string is valid LOI.

class datasafe.loi.LoiStartsWithCorrectRootChecker[source]

Bases: AbstractLoiChecker

Check root of LOI.

class datasafe.loi.LoiTypeChecker[source]

Bases: AbstractLoiChecker

Check type of LOI.

class datasafe.loi.LoiRecChecker[source]

Bases: AbstractLoiChecker

Check rec type of LOI.

class datasafe.loi.LoiDsChecker[source]

Bases: AbstractLoiChecker

Check ds type of LOI.

class datasafe.loi.LoiExpChecker[source]

Bases: AbstractLoiChecker

Check exp type of LOI.

class datasafe.loi.BaSaChecker[source]

Bases: AbstractLoiChecker

Check ba/sa of LOI.

class datasafe.loi.BaSaNumberChecker[source]

Bases: AbstractLoiChecker

Check ba/sa number type of LOI.

class datasafe.loi.LoiExpMethodChecker[source]

Bases: AbstractLoiChecker

Check experimental method of LOI.

class datasafe.loi.LoiMeasurementNumberChecker[source]

Bases: AbstractLoiChecker

Check measurement number of LOI.

class datasafe.loi.LoiCalcChecker[source]

Bases: AbstractLoiChecker

Check calc of LOI.

class datasafe.loi.LoiCalcObjectNumberChecker[source]

Bases: AbstractLoiChecker

Check calc object number of LOI.

class datasafe.loi.LoiImgChecker[source]

Bases: AbstractLoiChecker

Check img of LOI.

class datasafe.loi.LoiInfoChecker[source]

Bases: AbstractLoiChecker

Check info of LOI.

class datasafe.loi.LoiInfoKindChecker[source]

Bases: AbstractLoiChecker

Check info kind of LOI.

class datasafe.loi.LoiInfoOtherKindChecker[source]

Bases: AbstractLoiChecker

Check info other kind of LOI.

class datasafe.loi.LoiInfoProjectChecker[source]

Bases: LoiInfoOtherKindChecker

Check info project of LOI.

class datasafe.loi.LoiInfoPublicationChecker[source]

Bases: LoiInfoOtherKindChecker

Check info publication of LOI.

class datasafe.loi.LoiInfoGrantChecker[source]

Bases: LoiInfoOtherKindChecker

Check info grant of LOI.

class datasafe.loi.LoiInfoDeviceChecker[source]

Bases: LoiInfoOtherKindChecker

Check info device of LOI.

class datasafe.loi.LoiInfoChemicalChecker[source]

Bases: LoiInfoOtherKindChecker

Check info chemical of LOI.

class datasafe.loi.LoiInfoPersonChecker[source]

Bases: LoiInfoOtherKindChecker

Check info person of LOI.

class datasafe.loi.LoiInfoSampleChecker[source]

Bases: AbstractLoiChecker

Check info sample of LOI.

class datasafe.loi.LoiInfoCalculationChecker[source]

Bases: AbstractLoiChecker

Check info calculation of LOI.

class datasafe.loi.Parser[source]

Bases: LoiMixin

Parse LOIs, allowing to handle different parts correctly.

A LOI consists of four parts:

  • root

  • issuer

  • type

  • id

Generally, a LOI could be written like this:

<root>.<issuer>/<type>/<id>

Typically, root is fixed for LOIs (42) and issuer is a number. Type is a single string, and id usually consists of several parts separated by a “/”.

For general aspects of LOIs, such as root and separator(s), refer to the LoiMixin class.

parse(loi='')[source]

Parse given LOI and create dict with the four parts described above.

Parameters:

loi (str) – LOI to parse.

Returns:

parser_dict – Dict with parts of the LOI as key:value pairs.

Return type:

dict

Raises:
  • datasafe.loi.MissingLoiError – Raised if no LOI is provided.

  • datasafe.loi.InvalidLoiError – Raised if given string is not a valid LOI.

split_id()[source]

Split id part of LOI at separator and return list of components.

Returns:

id_parts – List (of strings) with parts of ID split at separator

Empty list if no LOI has been parsed

Return type:

list