Skip to content

Commit

Permalink
file extension support for Product Nodes #378
Browse files Browse the repository at this point in the history
  • Loading branch information
Zigur committed Dec 15, 2020
1 parent 75d864a commit 17de888
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions isatools/create/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PRODUCT_NODE_NAME_ERROR = 'ProductNode name must be a string, {0} supplied of type {1}'
SIZE_ERROR = 'ProductNode size must be a natural number, i.e integer >= 0'
CHARACTERISTIC_TYPE_ERROR = 'A characteristic must be either a string or a Characteristic, {0} supplied'
PRODUCT_NODE_EXTENSION_ERROR = 'ProductNode extension must be either a string or an OntologyAnnotation.'

# ERROR MESSAGES: QC SAMPLE (QUALITY CONTROL)
QC_SAMPLE_TYPE_ERROR = 'qc_sample_type must be one of {0}'
Expand Down
30 changes: 27 additions & 3 deletions isatools/create/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,21 +770,35 @@ class ProductNode(SequenceNode):
"""
ALLOWED_TYPES = {SOURCE, SAMPLE, EXTRACT, LABELED_EXTRACT, DATA_FILE}

def __init__(self, id_=str(uuid.uuid4()), node_type=SOURCE, name='', characteristics=[], size=0):
def __init__(self, id_=str(uuid.uuid4()), node_type=SOURCE, name='', characteristics=[], size=0, extension=None):
"""
ProductNode constructor method
:param id_: an identifier for the ProductNode
:param node_type: str - the type of ProductNode. Must be one of the allowed types.
:param name: str - the name of the ProductNone
:param characteristics: list<Characteristics> - characteristics of the node
:param size: int
:param extension: str/OntologyAnnotation - an extension to be appended to the elements generated from this
ProductNode. It can be used to specify file extensions to a DATA_FILE node
"""
super().__init__()
self.__id = id_
self.__type = None
self.__name = None
self.__characteristics = []
self.__size = None
self.__extension = None
self.type = node_type
self.name = name
self.characteristics = characteristics
self.size = size
if extension:
self.extension = extension

def __repr__(self):
return '{0}.{1}(id={2.id}, type={2.type}, name={2.name}, ' \
'characteristics={2.characteristics}, size={2.size})'.format(
'characteristics={2.characteristics}, size={2.size}, ' \
'extension={2.extension})'.format(
self.__class__.__module__, self.__class__.__name__, self)

def __str__(self):
Expand All @@ -802,7 +816,7 @@ def __hash__(self):
def __eq__(self, other):
return isinstance(other, ProductNode) and self.id == other.id and self.type == other.type \
and self.name == other.name and self.characteristics == other.characteristics \
and self.size == other.size
and self.size == other.size and self.extension == other.extension

def __ne__(self, other):
return not self == other
Expand Down Expand Up @@ -862,6 +876,16 @@ def size(self, size):
raise AttributeError(errors.SIZE_ERROR)
self.__size = size

@property
def extension(self):
return self.__extension

@extension.setter
def extension(self, extension):
if not isinstance(extension, (str, OntologyAnnotation)):
raise AttributeError(errors.PRODUCT_NODE_EXTENSION_ERROR)
self.__extension = extension


class QualityControlSource(Source):
pass
Expand Down

0 comments on commit 17de888

Please sign in to comment.