Models

Module contents

Creates Model and Manager subclasses to represent and manage all the different parts of an analysis pipeline.

For an illustration of the app’s models, see the Overview.

Submodules

django_analyses.models.analysis module

Definition of the Analysis class.

class django_analyses.models.analysis.Analysis(*args, **kwargs)

Bases: django_extensions.db.models.TitleDescriptionModel, django_extensions.db.models.TimeStampedModel

A Model representing a single analysis in the database.

category

A Category instance associated with this analysis.

inputspecification_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <django_analyses.models.managers.analysis.AnalysisManager object>
outputspecification_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

version_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

django_analyses.models.analysis_version module

Definition of the AnalysisVersion class.

class django_analyses.models.analysis_version.AnalysisVersion(*args, **kwargs)

Bases: django_extensions.db.models.TitleDescriptionModel, django_extensions.db.models.TimeStampedModel

A Model representing a single analysis version in the database.

Each AnalysisVersion instance should be assigned an interface through the project’s ANALYSIS_INTERFACES setting (for more information see Interface Integration and Integration Customization).

analysis

The Analysis instance to which this analysis version belongs.

extract_results(results: Any) → dict

Extracts a results dictionary from an arbitrary results object in case the nested_results_attribute is not None.

Parameters:results (Any) – Arbitrary results object
Returns:Results dictionary
Return type:dict
fixed_run_method_kwargs

Any “fixed” keyword arguments that should always be passed to the interface’s run method at execution.

get_interface() → object

Queries the project’s settings to locate the instance’s interface. For more information see Interface Integration.

Returns:Interface class used to run this version of the analysis
Return type:object
Raises:NotImplementedError – No interface could be found for this analysis
get_interface_initialization_kwargs(**kwargs) → dict

Returns the parameters required at the interface’s class initialization.

Returns:Initialization parameters as a keyword arguments dict
Return type:dict
get_run_method_kwargs(**kwargs) → dict

Returns the parameters required when calling the interface’s run() method.

Returns:run() method parameters as a keyword arguments dict
Return type:dict
input_definitions

Returns the associated instance’s InputDefinition subclasses as defined in its input_specification.

Returns:InputDefinition subclasses
Return type:QuerySet
input_specification

The InputSpecification instance specifying the InputDefinition subclasses associated with this analysis version.

interface

Returns the associated interface for this instance.

Returns:Analysis interface class
Return type:type
max_parallel

Maximal number of parallel executions that may be run using Celery. This attribute is used in execute_node() to chunk an iterable of node inputs in case it is longer than this value. For more information see Celery’s Chunks documentation.

nested_results_attribute

Analysis interfaces are expected to return a dictionary of the results. In case this analysis version’s interface returns some object which conatins the desired dictionary, this field allows specifying the attribute or method that may be used to retrieve it.

Example

Nipype’s interfaces generally return some kind of InterfaceResults object with an outputs attribute that may be used to create a dictionary of the results by calling the get_traitsfree() method. In order to integrate smoothly with Nipype’s interfaces, we could simply specify nested_results_attribute=”outputs.get_traitsfree” when creating the appropriate analysis versions.

nested_results_parts

Splits the nested_results_attribute at “.” indices in case of a deeply nested attribute.

Returns:Listed parts of nested result dictionary location
Return type:list
node_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <django_analyses.models.managers.analysis_version.AnalysisVersionManager object>
output_definitions

Returns the associated instance’s OutputDefinition subclasses as defined in its output_specification.

Returns:OutputDefinition subclasses
Return type:QuerySet
output_specification

The OutputSpecification instance specifying the OutputDefinition subclasses associated with this analysis version.

run(**kwargs) → dict

Runs the interface safely by validating the input according to the instance’s input_specification and applying any special integration customizations (for more information see Integration Customization).

Returns:Results dictionary
Return type:dict
run_interface(**kwargs) → dict

Call the interface class’s run() method with the given keyword arguments.

Returns:Dictionary of results
Return type:dict
run_method_key

Custom run method name for the interface. Each analysis version is expected to have some class associated with it and used as an interface for running the analysis. This field determines the name of the method that will be called (default value is “run”).

run_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

update_input_with_defaults(configuration: dict) → dict

Updates a configuration specified as keyword arguments with the instance’s input_specification defaults.

Parameters:configuration (dict) – Input configuration (excluding default values)
Returns:Configuration updated with default values
Return type:dict

django_analyses.models.category module

Definition of the Category class.

class django_analyses.models.category.Category(*args, **kwargs)

Bases: django_extensions.db.models.TitleDescriptionModel, django_extensions.db.models.TimeStampedModel

A Model representing a category of analyses in the databse.

analysis_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <django.db.models.manager.Manager object>
parent

If this is a nested category, this field holds the association with the parent.

subcategories

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

django_analyses.models.run module

Definition of the Run model.

class django_analyses.models.run.Run(*args, **kwargs)

Bases: django_extensions.db.models.TimeStampedModel

Model representing a single analysis version’s run in the database.

analysis_version

The AnalysisVersion that was run.

base_input_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

base_output_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

check_null_configuration() → bool

Checks whether this run’s configuration is equivalent to the input specification’s default settings.

Returns:Whether this run has only default configuration settings
Return type:bool
duration

Returns the time delta between this instance’s end_time and start_time. If end_time isn’t set yet returns time since start_time.

Returns:Run duration
Return type:datetime.timedelta
end_time

Run end time.

fix_input_value(inpt) → Any

Reverts changes that may have been made to a given input in order to return the “raw” input configuration of this run (i.e. the input as it was passed by the user).

Parameters:inpt (Input) – An input of this run
Returns:The “raw” input value
Return type:Any
get_input(key: str) → Any

Returns a particular output created in this run according to its definition’s key field.

Parameters:key (str) – The desired Input’s associated definition keyword
Returns:Input value
Return type:Any
get_input_configuration(include_non_configuration: bool = True, include_defaults: bool = True) → dict

Returns the input configuration of this run.

Parameters:
  • include_non_configuration (bool) – Whether to include inputs for which the associated definition’s is_configuration attribute is set to False, default is True
  • include_defaults (bool) – Whether to include default input configuration values, default is True
Returns:

Input configuration

Return type:

dict

get_input_set() → model_utils.managers.InheritanceQuerySet

Returns the Input subclasses’ instances created for this execution of the analysis_version.

Returns:This run’s inputs
Return type:InheritanceQuerySet
get_output(key: str) → Any

Returns a particular output created in this run according to its definition’s key field.

Parameters:key (str) – The desired Output’s associated definition keyword
Returns:Output value
Return type:Any
get_output_configuration() → dict

Returns the output configuration of this run.

Returns:Output configuration
Return type:dict
get_output_parser() → object
get_output_set() → model_utils.managers.InheritanceQuerySet

Returns the Output subclasses’ instances created on this execution of the analysis_version.

Returns:This run’s outputs
Return type:InheritanceQuerySet
get_raw_input_configuration() → dict

Returns the “raw” configuration of this run. As some inputs may have been transformed, this method is used to reverse these changes in case this run’s parameters are compared in the future to new input parameters.

Returns:Raw input configuration as provided by the user
Return type:dict
get_results_json() → dict

Returns a JSON serializable dictionary of the results.

Returns:JSON serializable output dictionary
Return type:dict
get_status_display(*, field=<django.db.models.fields.CharField: status>)
get_visualizer(provider: str = None) → callable
input_configuration

Returns a dictionary with the full input configuration of this run.

Returns:Full input configuration
Return type:dict
input_defaults

Returns the default configuration parameters according to this instance’s InputSpecification’s default_configuration property.

Returns:This analysis version’s default input configuration
Return type:dict
input_set

Returns the Input subclasses’ instances created for this run.

Returns:This run’s inputs
Return type:QuerySet

See also

objects = <django_analyses.models.managers.run.RunManager object>
output_configuration

Returns a dictionary of the output configuration of this run.

Returns:Output configuration
Return type:dict
output_parser
output_set

Returns the Output subclasses’ instances created by this run.

Returns:This run’s outputs
Return type:QuerySet

See also

parse_output()
path

Retruns the default Path for any artifacts created by this run.

Returns:Run artifacts directory under MEDIA_ROOT.
Return type:pathlib.Path
raw_input_configuration

Returns a dictionary of this run’s raw input configuration.

Returns:This run’s raw input configuration
Return type:dict
start_time

Run start time.

status

The status of this run.

task_result

The TaskResult instance associated with this run.

task_result_id
traceback

Traceback saved in case of run failure.

user

The user who created this run.

visualize() → None