Skip to content

Commit

Permalink
Merge pull request #453 from ISA-tools/DomModelRefactor
Browse files Browse the repository at this point in the history
Dom model refactor
  • Loading branch information
terazus authored Jul 21, 2022
2 parents 0341f8e + 50c693f commit 4d3c82a
Show file tree
Hide file tree
Showing 98 changed files with 10,700 additions and 7,896 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/buildandtestpython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with python unittests
- name: Test with python unittest
run: |
behave --no-capture --no-capture-stderr --format=progress features/isa-file-handler.feature
coverage run -m unittest discover -s tests/
Expand Down
10 changes: 5 additions & 5 deletions isatools/create/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2222,8 +2222,8 @@ def _generate_samples_and_assays(self, sources_map, sampling_protocol, performer
derives_from=[source],
comments=[is_treatment_comment]
)
if sample_type not in characteristic_categories:
characteristic_categories.append(sample_type)
if sample_type.category not in characteristic_categories:
characteristic_categories.append(sample_type.category)

sample_batches[sample_node].append(sample)
sample_count += 1
Expand Down Expand Up @@ -2320,8 +2320,8 @@ def _generate_isa_elements_from_node(
other_materials.append(item)
# characteristic_categories.append(item.characteristics)
for charx in item.characteristics:
if charx not in characteristic_categories:
characteristic_categories.append(charx)
if charx.category not in characteristic_categories:
characteristic_categories.append(charx.category)

elif isinstance(item, DataFile):
data_files.append(item)
Expand Down Expand Up @@ -2570,7 +2570,7 @@ def generate_isa_study(self, identifier=None):

# setting the `characteristic_categories` associated to study and required for isajson loading
# study_charac_categories = []
study.characteristic_categories.append(DEFAULT_SOURCE_TYPE)
study.characteristic_categories.append(DEFAULT_SOURCE_TYPE.category)
study.factors, new_protocols, study.samples, study_charac_categories, study.assays, study.process_sequence, \
study.ontology_source_references = \
self._generate_samples_and_assays(
Expand Down
1,996 changes: 0 additions & 1,996 deletions isatools/isajson.py

This file was deleted.

9 changes: 9 additions & 0 deletions isatools/isajson/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Functions for reading, writing and validating ISA-JSON.
Don't forget to read the ISA-JSON spec:
https://isa-specs.readthedocs.io/en/latest/isajson.html
"""

from isatools.isajson.load import load
from isatools.isajson.dump import ISAJSONEncoder
from isatools.isajson.validate import validate, batch_validate, default_config_dir, load_config
10 changes: 10 additions & 0 deletions isatools/isajson/dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from json import JSONEncoder


class ISAJSONEncoder(JSONEncoder):
def default(self, o):
if hasattr(o, 'to_dict'):
method = getattr(o, 'to_dict')
if callable(method):
return o.to_dict()
return JSONEncoder.default(self, o)
15 changes: 15 additions & 0 deletions isatools/isajson/load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json

from isatools.model import Investigation


def load(fp):
"""Loads an ISA-JSON file and returns an Investigation object.
:param fp: A file-like object or a string containing the JSON data.
:return: An Investigation object.
"""
investigation_json = json.load(fp)
investigation = Investigation()
investigation.from_dict(investigation_json)
return investigation
Loading

0 comments on commit 4d3c82a

Please sign in to comment.