ua_clarity_tools
index
c:\users\ryanj\desktop\github\work\ua-clarity-tools\ua_clarity_tools\ua_clarity_tools.py

Tools that interact with Clarity's REST database.

 
Modules
       
argparse
os
re
requests
ua_clarity_api.ua_clarity_api

 
Classes
       
builtins.object
Artifact
ClarityExceptions
ClarityTools
Process
Sample
StepTools
builtins.tuple(builtins.object)
PreviousStepArtifact

 
class Artifact(builtins.object)
    Artifact(name: str = None, uri: str = None, art_type: str = None, sample_uri: str = None, container_uri: str = None, container_name: str = None, container_type: str = None, location: str = None, parent_process: str = None, reagent_label: str = None, udf: dict = <factory>) -> None
 
Stores the fields of an Artifact.
 
  Methods defined here:
__eq__(self, other)
__init__(self, name: str = None, uri: str = None, art_type: str = None, sample_uri: str = None, container_uri: str = None, container_name: str = None, container_type: str = None, location: str = None, parent_process: str = None, reagent_label: str = None, udf: dict = <factory>) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'art_type': <class 'str'>, 'container_name': <class 'str'>, 'container_type': <class 'str'>, 'container_uri': <class 'str'>, 'location': <class 'str'>, 'name': <class 'str'>, 'parent_process': <class 'str'>, 'reagent_label': <class 'str'>, 'sample_uri': <class 'str'>, 'udf': <class 'dict'>, ...}
__dataclass_fields__ = {'art_type': Field(name='art_type',type=<class 'str'>,default...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'container_name': Field(name='container_name',type=<class 'str'>,d...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'container_type': Field(name='container_type',type=<class 'str'>,d...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'container_uri': Field(name='container_uri',type=<class 'str'>,de...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'location': Field(name='location',type=<class 'str'>,default...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default=Non...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'parent_process': Field(name='parent_process',type=<class 'str'>,d...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'reagent_label': Field(name='reagent_label',type=<class 'str'>,de...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'sample_uri': Field(name='sample_uri',type=<class 'str'>,defau...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'udf': Field(name='udf',type=<class 'dict'>,default=<da...rue,metadata=mappingproxy({}),_field_type=_FIELD), ...}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
art_type = None
container_name = None
container_type = None
container_uri = None
location = None
name = None
parent_process = None
reagent_label = None
sample_uri = None
uri = None

 
class ClarityExceptions(builtins.object)
    Holds custom Clarity Exceptions.
 
  Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
CallError = <class 'ua_clarity_tools.ClarityExceptions.CallError'>
This method call wasn't well-formed.
EPPError = <class 'ua_clarity_tools.ClarityExceptions.EPPError'>
The EPP script provided is not correct.
TechnicianError = <class 'ua_clarity_tools.ClarityExceptions.TechnicianError'>
A Clarity user technician has made a mistake.

 
class ClarityTools(builtins.object)
    ClarityTools(host, username, password)
 
Tools that interact with Clarity without a step. These tools are general
use functions for when caller is not attached to a step and knows the
endpoints they want to perform work on. These methods are not limited by
the requirement to have a step uri.
 
  Methods defined here:
__init__(self, host, username, password)
Initializes a ClarityAPI object for use within method calls.
 
username and password should be strings representing your creds in the
    clarity environment.
host should be a string representing the url of your clarity api
    endpoint.
get_arts_from_samples(self, sample_uris)
Map sample uris to their respective artifact uris from clarity.
 
Arguments:
    sample_uris (list): A list of sample uris. All sample uris given
        must have at least one artifact uri in clarity.
 
Returns:
    smp_art_uris (dict): The sample uri mapped to the artifact uri.
get_samples(self, uris)
Returns a list of Sample data classes with data populated from the
get responses of given clarity sample URIs.
 
Arguments:
    uris (list): List of Sample URIs harvested from the clarity env.
 
Returns:
    samples (list): Returns a list of Sample data classes.
get_udfs(self, target)
Find all of the udfs with attach-to-name: target attributes.
 
Arguments:
    target (str): A string representation of what attach-to-name
        attributes to harvest.
 
Returns:
    target_udfs (list): A list of all udf names for specified target.
 
Raises:
    ClarityExceptions.CallError: If there are no target udfs found.
set_reagent_label(self, limsid_label)
Set reagent-label of all artifact limsid keys to their mapped value.
 
Arguments:
    limsid_label (dict {str: str}): maps limsid's to
        reagent-label information. If a value is Falsey, then all
        labels will be removed.
 
Side Effects:
    If successful, this method will add a reagent-label to each
        artifact.
    Overwrites the original reagent-label if it existed.
 
Raises:
    RuntimeError: If there was an exception raised while POSTing.
step_router(self, wf_name, dest_stage_name, art_uris, action='assign')
Assign/unassign artifacts from current step to a destination step.
    Assigning will move the artifacts to the given destination step.
    Unassigning will remove the artifact from the step/queue, but does
    not remove the artifact from the clarity environment
 
Arguments:
    wf_name (string): The workflow name in which the destination
        step is.
    dest_stage_name (string): The step name that is the destination
        for the artifacts.
    art_uris (list): The list of artifact_uris to route to the
        destination step.
    action (string): Either 'assign' or 'unassign', determining which
        action to perform.
 
Side Effects:
    If successful, assigns or unassigns the artifacts to the
        destination step in Clarity.
 
Raises:
    ClarityExceptions.CallError: If that workflow or stage isn't found.
    RuntimeError: If there was an exception raised while POSTing.
    RuntimeError: If for some other, unknown reason the artifact was
        not routed.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class PreviousStepArtifact(builtins.tuple)
    PreviousStepArtifact(uri, art_type, generation_type)
 
PreviousStepArtifact(uri, art_type, generation_type)
 
 
Method resolution order:
PreviousStepArtifact
builtins.tuple
builtins.object

Methods defined here:
__getnewargs__(self)
Return self as a plain tuple.  Used by copy and pickle.
__repr__(self)
Return a nicely formatted representation string
_asdict(self)
Return a new OrderedDict which maps field names to their values.
_replace(_self, **kwds)
Return a new PreviousStepArtifact object replacing specified fields with new values

Class methods defined here:
_make(iterable) from builtins.type
Make a new PreviousStepArtifact object from a sequence or iterable

Static methods defined here:
__new__(_cls, uri, art_type, generation_type)
Create new instance of PreviousStepArtifact(uri, art_type, generation_type)

Data descriptors defined here:
uri
Alias for field number 0
art_type
Alias for field number 1
generation_type
Alias for field number 2

Data and other attributes defined here:
_field_defaults = {}
_fields = ('uri', 'art_type', 'generation_type')
_fields_defaults = {}

Methods inherited from builtins.tuple:
__add__(self, value, /)
Return self+value.
__contains__(self, key, /)
Return key in self.
__eq__(self, value, /)
Return self==value.
__ge__(self, value, /)
Return self>=value.
__getattribute__(self, name, /)
Return getattr(self, name).
__getitem__(self, key, /)
Return self[key].
__gt__(self, value, /)
Return self>value.
__hash__(self, /)
Return hash(self).
__iter__(self, /)
Implement iter(self).
__le__(self, value, /)
Return self<=value.
__len__(self, /)
Return len(self).
__lt__(self, value, /)
Return self<value.
__mul__(self, value, /)
Return self*value.
__ne__(self, value, /)
Return self!=value.
__rmul__(self, value, /)
Return value*self.
count(self, value, /)
Return number of occurrences of value.
index(self, value, start=0, stop=9223372036854775807, /)
Return first index of value.
 
Raises ValueError if the value is not present.

 
class Process(builtins.object)
    Process(uri: str = None, technician: str = 'None', udf: dict = &lt;factory&gt;) -&gt; None
 
Stores the fields of a Process.
 
  Methods defined here:
__eq__(self, other)
__init__(self, uri: str = None, technician: str = 'None', udf: dict = <factory>) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'technician': <class 'str'>, 'udf': <class 'dict'>, 'uri': <class 'str'>}
__dataclass_fields__ = {'technician': Field(name='technician',type=<class 'str'>,defau...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'udf': Field(name='udf',type=<class 'dict'>,default=<da...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'uri': Field(name='uri',type=<class 'str'>,default=None...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
technician = 'None'
uri = None

 
class Sample(builtins.object)
    Sample(name: str = '', uri: str = None, date_received: str = None, project_uri: str = None, project_name: str = None, artifact_uri: str = None, udf: dict = &lt;factory&gt;) -&gt; None
 
Stores the fields of a Sample.
 
  Methods defined here:
__eq__(self, other)
__init__(self, name: str = '', uri: str = None, date_received: str = None, project_uri: str = None, project_name: str = None, artifact_uri: str = None, udf: dict = <factory>) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'artifact_uri': <class 'str'>, 'date_received': <class 'str'>, 'name': <class 'str'>, 'project_name': <class 'str'>, 'project_uri': <class 'str'>, 'udf': <class 'dict'>, 'uri': <class 'str'>}
__dataclass_fields__ = {'artifact_uri': Field(name='artifact_uri',type=<class 'str'>,def...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'date_received': Field(name='date_received',type=<class 'str'>,de...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default='',...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'project_name': Field(name='project_name',type=<class 'str'>,def...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'project_uri': Field(name='project_uri',type=<class 'str'>,defa...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'udf': Field(name='udf',type=<class 'dict'>,default=<da...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'uri': Field(name='uri',type=<class 'str'>,default=None...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
artifact_uri = None
date_received = None
name = ''
project_name = None
project_uri = None
uri = None

 
class StepTools(builtins.object)
    StepTools(username=None, password=None, step_uri=None)
 
Defines step specific methods which act upon a given step uri in
Clarity. This class can be instantiated directly or from a Clarity EPP
script.
 
  Methods defined here:
__init__(self, username=None, password=None, step_uri=None)
Initialize LimsTools with information to access step details.
 
username and password should be strings representing your creds in the
    clarity environment.
step_uri should be a string representing the step endpoint in your
    clarity environment that you wish to perform work on.
get_artifact_map(self, uri_only=False)
Returns a map of input artifacts to output artifacts, either as uris
    or as Artifact dataclasses. One input artifact can be mapped to a
    list of their multiple output artifacts.
 
Arguments:
    uri_only (boolean): This denotes whether to harvest this mapping as
        uris or as namedtuples.
 
Returns:
    artifact_map (dict {input artifact: [output_artifact]}):
        Returns a dict of input artifact : all output artifacts.
get_artifacts(self, stream, uri_only=False, container_info=False)
Return the artifact information as a list of Artifact data classes.
 
Arguments:
    stream (str): The source of the samples, either "input" or
        "output".
 
Returns:
    artifacts (list): Returns a list of Artifact data classes.
 
Notes:
    Does not include 'PerAllInputs' shared output files.
get_artifacts_previous_step(self, dest_step, stream, art_smp_uris, step_soup, results=None)
Return artifact uris mapped to ancestor artifacts from a target
    step.
 
Arguments:
    dest_step (str): The name of the step where the ancestor
        artifacts were created.
    stream (str): The source of the samples, either "input" or
        "output" in the dest_step.
    art_smp_uris (dict {str: str}): A dict that maps smp_uris to
        passed in art_uris.
    step_soup: The step details soup for initial step.
    results (dict): The empty dict that will eventually be returned
        with the desired artifacts from the dest_step.
 
Returns:
    results (dict {str: Artifact}): The dictionary that
        maps the art_uri to the artifact namedtuple. All of the
        'PerAllInputs' are stored in the results dict at
        results['shared']. If the art_uri does not have ancestors at
        that target, the art_uri will not be in the dictionary.
 
Exceptions:
    RuntimeError: If that target_step is not in any of the provided
        art_uri histories.
    RuntimeError: If there are targets that ran through the step at
        two or more different times. (The dest_step process id is not
        the same for all of the passed-in samples.)
 
Requirements:
    The targets to reroute must all have the same endpoint; if a sample
        went through the step separately from its fellows, this
        will not work.
get_process_data(self)
Retrieves Process data for the current step, including technician,
    uri, and udfs.
 
Returns:
    process: a Process dataclass representing the process of the
        current step.
set_artifact_udf(self, sample_values, stream)
Set UDF values for analytes in the current step based on given
    mapping.
 
Arguments:
    sample_values (dict {str: [namedtuple]}): Maps sample limsid's to
        a list of namedtuples called 'UDF' with the fields 'name',
        'value'.
 
    stream (str): The source of the samples, either "input" or
        "output".
 
Side Effects:
    Sets the samples' UDFs that were passed into the REST database.
        Overwrites the value that was in that UDF if it existed.
 
Raises:
    RuntimeError: If there was an exception raised while POSTing.
 
Requirements:
    The UDF Value's type must be in line with Clarity's
        initialization of that type.
setup_arguments(self)
Incorporate EPP arguments into your StepTools object.
 
Returns:
    (arguments): The object that holds all of the arguments that
        were parsed (at object.{dest}).

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Data
        __email__ = 'rjjohannesbland@email.arizona.edu'
__maintainer__ = 'Ryan Johannes-Bland'

 
Author
        ('Stephen Stern, Archer Morgan, Rafael Lopez,', 'Ryan Johannes-Bland, Etienne Thompson')