snakeobjects package

This is snakeobject python package.

Project class

class Project(directory=None)

Each objects of the Project class represents a snakeobject project.

The project directory is given as the directory parameter. If directory is none, the find_so_project_directory() function is used to determine the project directory.

A snakeobject project attributes are:

directory: str

the project directory

parameters: dict[str, str]

a key value dictionary for global project level parameters

parent_projects: dict[str, Project]

a key value dictionary for parent project names

objectGraph: ObjectGraph

the objectGraph for the project

Project useful functions are:

get_object_directory(object_instance)

returns directory of object

get_object_path(type_name, object_name)

returns path to the object of type type_name, and object name object_name

get_pipeline_directory

returns path to the project pipeline directory

get_parameter(name, parent_project_id=None)

If parent_project_id is given returns the value of parameter in that project, otherwise, if name is in project parameters, returns its value. Finally, if name is not in the project parameters, returns the value of named parameters in the first project recursively folowing parent projects.

Pipeline class

class Pipeline

Each objects of the Pipeline class represents a snakeobject pipeline.

get_definition() str
Definitions is a string of the form:

“directory:<dir>” OR “package:<package>” OR “<dir>” which is equivallent to “directory:<dir>”

DirectoryPipeline class

class DirectoryPipeline(definition_dir: str)

Subclass of the Pipeline class defined by directory path.

A snakeobject DirectoryPipeline attributes are:

definition_dir: str
snakefile_directory: str

DirecoryPipeline useful functions are:

get_snakefile_directory

returns directory of Snakefile

get_main_snakefile_path

returns path to the Snakefile

get_environment_variables

returns dictionary with keys PATH, PYTHPONPATH, etc.

build_object_graph(proj: Project, args: List[str])

returns instance of and ObjectGraph

get_definition() str
Definitions is a string of the form:

“directory:<dir>” OR “package:<package>” OR “<dir>” which is equivallent to “directory:<dir>”

PackagePipeline class

class PackagePipeline(definition_package: str)

Subclass of Pipeline class defined by python package.

A snakeobject PackagePipeline attributes are:

definition_package: str
snake_file_dir: str

PackagePipeline useful functions are:

get_snakefile_directory

returns directory of Snakefile

get_main_snakefile_path

returns path to the Snakefile

get_environment_variables

returns dictionary with keys PATH, PYTHPONPATH, etc.

build_object_graph(proj: Project, args: List[str])

returns instance of and ObjectGraph

get_definition() str
Definitions is a string of the form:

“directory:<dir>” OR “package:<package>” OR “<dir>” which is equivallent to “directory:<dir>”

ObjectGraph class

class ObjectGraph

The class representing the directed acyclic graph representing the relationships among the snakeobjects’ objects. Each object is defined by a set an object type and by object id.

__getitem__(key)

Query objects in the object graph.

Parameters

key (oType or (oType,oOid)) – the object query

The graph (G) indexing has two forms depending of the key parameter:

  1. G[oType] returns the list of the objects of type oType;

  2. G[oType,oId] returns the object with object id oId and object type type oType.

Return type

list(OGO) if form 1 is used or OGO if form 2 is used

add(oType, oId, params=None, deps=None)

Adds a new object to the object graph.

Parameters
  • oType (str) – the object type of the new object.

  • oId (str) – the object id of the new object.

  • params (dict[str,str]) – the parameters of the new object. If None, the new object is assigned with no parameters.

  • deps (list[OGO]) – list objects the new object depends on. If None, the new object depends on no other objects. The objects included in deps should already be part of the ObjectGraph.

Returns

the newly created object.

Return type

OGO

get_object_types()

The object types used in the ObjectGraph

save(outFile)

Save the object graph in a json file outFile.

class OGO(oType, oId, params=None, deps=None)

The class represents the objects in an ObjectGraph. Each object has the following attributes:

oType: str

the object type of the object

oId: str

the object id of the object

params: dict[str, str]

the key-value parameters of the object

deps: list[OGO]

the list of the dependency objects (other objects this object depends on)

find_project_directory function

find_so_project_directory()

Determines the directory for the current snakeobjects project.

Several approaches are attempted and the first suitable directory found is returned. If everything fails, the current working directory is returned.

  1. If the SO_PROJECT environment variable exits, its values is returned.

  2. If the current working directory contains a file named so_project.yaml, the current working directory is returned.

  3. The parents of the current working directory are examined recursively and the first one containing so_project.yaml file is returned.

load_object_graph function

load_object_graph(fname)