Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions isatools/database/models/assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Assay(Base):
def to_json(self):
characteristic_categories = get_characteristic_categories(self.characteristic_categories)
return {
"@id": str(self.assay_id),
"filename": self.filename,
"technologyPlatform": self.technology_platform,
"measurementType": self.measurement_type.to_json(),
Expand Down
2 changes: 1 addition & 1 deletion isatools/database/models/ontology_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def to_json(self):
return {
"@id": self.ontology_annotation_id,
"annotationValue": self.annotation_value,
"termSource": self.term_source_id if self.term_source_id else None,
"termSource": self.term_source.name if self.term_source else None,
"termAccession": self.term_accession,
"comments": [c.to_json() for c in self.comments],
}
Expand Down
6 changes: 3 additions & 3 deletions isatools/database/models/ontology_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def to_json(self) -> dict:
:return: The dictionary representation of the object taken from the database
"""
return {
"id": self.ontology_source_id,
"@id": self.ontology_source_id,
"name": self.name,
"file": self.file,
"version": self.version,
Expand All @@ -56,11 +56,11 @@ def to_sql(self, session) -> OntologySource:

:return: The SQLAlchemy object ready to be committed to the database session.
"""
ontology_source = session.get(OntologySource, self.name)
ontology_source = session.get(OntologySource, self.id)
if ontology_source:
return ontology_source
ontology_source = OntologySource(
ontology_source_id=self.name,
ontology_source_id=self.id,
name=self.name,
file=self.file,
version=self.version,
Expand Down
1 change: 1 addition & 0 deletions isatools/database/models/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def to_json(self) -> dict:
"""
characteristics_categories = get_characteristic_categories(self.characteristic_categories)
return {
"@id": str(self.study_id),
"title": self.title,
"filename": self.filename,
"identifier": self.identifier,
Expand Down
7 changes: 6 additions & 1 deletion isatools/model/assay.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from isatools.model.comments import Commentable
from isatools.model.datafile import DataFile
from isatools.model.identifiable import Identifiable
from isatools.model.loader_indexes import loader_states as indexes
from isatools.model.material import Material
from isatools.model.mixins import StudyAssayMixin
from isatools.model.ontology_annotation import OntologyAnnotation
from isatools.model.process import Process


class Assay(Commentable, StudyAssayMixin, object):
class Assay(Commentable, Identifiable, StudyAssayMixin, object):
"""An Assay represents a test performed either on material taken from a
subject or on a whole initial subject, producing qualitative or
quantitative
Expand Down Expand Up @@ -38,6 +39,7 @@ class Assay(Commentable, StudyAssayMixin, object):

def __init__(
self,
id_="",
measurement_type=None,
technology_type=None,
technology_platform="",
Expand Down Expand Up @@ -72,6 +74,7 @@ def __init__(
self.__technology_platform = technology_platform
self.data_files = data_files or []

self.id = id_
@property
def measurement_type(self):
""":obj:`OntologyAnnotation: an ontology annotation representing the
Expand Down Expand Up @@ -200,6 +203,7 @@ def __ne__(self, other):

def to_dict(self, ld=False):
assay = {
"@id": self.id,
"measurementType": self.measurement_type.to_dict(ld=ld) if self.measurement_type else "",
"technologyType": self.technology_type.to_dict(ld=ld) if self.technology_type else "",
"technologyPlatform": self.technology_platform,
Expand All @@ -217,6 +221,7 @@ def to_dict(self, ld=False):
return self.update_isa_object(assay, ld)

def from_dict(self, assay, isa_study):
self.id = assay.get("@id", "")
self.technology_platform = assay.get("technologyPlatform", "")
self.filename = assay.get("filename", "")
self.load_comments(assay.get("comments", []))
Expand Down
73 changes: 36 additions & 37 deletions isatools/model/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@


class MetadataMixin(metaclass=ABCMeta):
"""Abstract mixin class to contain metadata fields found in Investigation
""" Abstract mixin class to contain metadata fields found in Investigation
and Study sections of ISA

Attributes:
identifier: An identifier associated with objects of this class.
title: A title associated with objects of this class.
description: A description associated with objects of this class.
submission_date: A submission date associated with objects of this
identifier: An identifier associated with objects of this class.
title: A title associated with objects of this class.
description: A description associated with objects of this class.
submission_date: A submission date associated with objects of this
class.
public_release_date: A submission date associated with objects of this
public_release_date: A submission date associated with objects of this
class.
"""

Expand Down Expand Up @@ -161,24 +161,23 @@ def contacts(self, val):


class StudyAssayMixin(metaclass=ABCMeta):
"""Abstract mixin class to contain common fields found in Study
""" Abstract mixin class to contain common fields found in Study
and Assay sections of ISA

Attributes:
filename: A field to specify the file for compatibility with ISA-Tab.
materials: Materials associated with the Study or Assay.
sources: Sources associated with the Study or Assay.
samples: Samples associated with the Study or Assay.
other_material: Other Material types associated with the Study or
Assay.
units: A list of Units used in the annotation of materials.
characteristic_categories-: A list of OntologyAnnotation used in
the annotation of material characteristics.
process_sequence: A list of Process objects representing the
experimental graphs.
comments: Comments associated with instances of this class.
graph: Graph representation of the experimental graph.

filename: A field to specify the file for compatibility with ISA-Tab.
materials: Materials associated with the Study or Assay.
sources: Sources associated with the Study or Assay.
samples: Samples associated with the Study or Assay.
other_material: Other Material types associated with the Study or
Assay.
units: A list of Units used in the annotation of materials.
characteristic_categories-: A list of OntologyAnnotation used in
the annotation of material characteristics.
process_sequence: A list of Process objects representing the
experimental graphs.
comments: Comments associated with instances of this class.
graph: Graph representation of the experimental graph.
"""

def __init__(
Expand Down Expand Up @@ -252,7 +251,7 @@ def sources(self, val):
raise AttributeError("{}.sources must be iterable containing Sources".format(type(self).__name__))

def add_source(self, name="", characteristics=None, comments=None):
"""Adds a new source to the source materials list.
""" Adds a new source to the source materials list.
:param string name: Source name
:param list[Characteristics] characteristics: Characteristics about the Source
:param list comments: Comments about the Source
Expand All @@ -261,7 +260,7 @@ def add_source(self, name="", characteristics=None, comments=None):
self.sources.append(s)

def yield_sources(self, name=None):
"""Gets an iterator of matching sources for a given name.
""" Gets an iterator of matching sources for a given name.

Args:
name: Source name
Expand All @@ -273,7 +272,7 @@ def yield_sources(self, name=None):
return filter(lambda x: x, self.sources) if name is None else filter(lambda x: x.name == name, self.sources)

def get_source(self, name):
"""Gets the first matching source material for a given name.
""" Gets the first matching source material for a given name.

Args:
name: Source name
Expand All @@ -288,7 +287,7 @@ def get_source(self, name):
return None

def yield_sources_by_characteristic(self, characteristic=None):
"""Gets an iterator of matching sources for a given characteristic.
""" Gets an iterator of matching sources for a given characteristic.

Args:
characteristic: Source characteristic
Expand All @@ -302,7 +301,7 @@ def yield_sources_by_characteristic(self, characteristic=None):
return filter(lambda x: characteristic in x.characteristics, self.sources)

def get_source_by_characteristic(self, characteristic):
"""Gets the first matching source material for a given characteristic.
""" Gets the first matching source material for a given characteristic.

Args:
characteristic: Source characteristic
Expand All @@ -318,7 +317,7 @@ def get_source_by_characteristic(self, characteristic):
return None

def get_source_names(self):
"""Gets all of the source names.
""" Gets all the source names.

Returns:
:obj:`list` of str.
Expand All @@ -340,7 +339,7 @@ def samples(self, val):
raise AttributeError("{}.samples must be iterable containing Samples".format(type(self).__name__))

def add_sample(self, name="", characteristics=None, factor_values=None, derives_from=None, comments=None):
"""Adds a new sample to the sample materials list.
""" Adds a new sample to the sample materials list.
:param string name: Sample name
:param list[Characteristics] characteristics: Characteristics about the sample
:param list comments: Comments about the sample
Expand All @@ -358,14 +357,14 @@ def add_sample(self, name="", characteristics=None, factor_values=None, derives_
self.samples.append(sample)

def yield_samples(self, name=None):
"""Gets an iterator of matching samples for a given name.
""" Gets an iterator of matching samples for a given name.
:param string name: Sample name
:return: object:`filter` of object:`Source` that can be iterated on. If name is None, yields all samples.
"""
return filter(lambda x: x, self.samples) if name is None else filter(lambda x: x.name == name, self.samples)

def get_sample(self, name):
"""Gets the first matching sample material for a given name.
""" Gets the first matching sample material for a given name.

Args:
name: Sample name
Expand All @@ -380,7 +379,7 @@ def get_sample(self, name):
return None

def yield_samples_by_characteristic(self, characteristic=None):
"""Gets an iterator of matching samples for a given characteristic.
""" Gets an iterator of matching samples for a given characteristic.

Args:
characteristic: Sample characteristic
Expand All @@ -395,7 +394,7 @@ def yield_samples_by_characteristic(self, characteristic=None):
return filter(lambda x: characteristic in x.characteristics, self.samples)

def get_sample_by_characteristic(self, characteristic):
"""Gets the first matching sample material for a given characteristic.
""" Gets the first matching sample material for a given characteristic.

Args:
characteristic: Sample characteristic
Expand All @@ -412,7 +411,7 @@ def get_sample_by_characteristic(self, characteristic):
return None

def yield_samples_by_factor_value(self, factor_value=None):
"""Gets an iterator of matching samples for a given factor_value.
""" Gets an iterator of matching samples for a given factor_value.

Args:
factor_value: Sample factor value
Expand All @@ -427,7 +426,7 @@ def yield_samples_by_factor_value(self, factor_value=None):
return filter(lambda x: factor_value in x.factor_values, self.samples)

def get_sample_by_factor_value(self, factor_value):
"""Gets the first matching sample material for a given factor_value.
""" Gets the first matching sample material for a given factor_value.

Args:
factor_value: Sample factor value
Expand All @@ -444,7 +443,7 @@ def get_sample_by_factor_value(self, factor_value):
return None

def get_sample_names(self):
"""Gets all of the sample names.
""" Gets all the sample names.

Returns:
:obj:`list` of str.
Expand All @@ -466,7 +465,7 @@ def other_material(self, val):
raise AttributeError("{}.other_material must be iterable containing Materials".format(type(self).__name__))

def yield_materials_by_characteristic(self, characteristic=None):
"""Gets an iterator of matching materials for a given characteristic.
""" Gets an iterator of matching materials for a given characteristic.

Args:
characteristic: Material characteristic
Expand All @@ -481,7 +480,7 @@ def yield_materials_by_characteristic(self, characteristic=None):
return filter(lambda x: characteristic in x.characteristics, self.other_material)

def get_material_by_characteristic(self, characteristic):
"""Gets the first matching material material for a given
""" Gets the first matching material for a given
characteristic.

Args:
Expand Down
9 changes: 6 additions & 3 deletions isatools/model/ontology_source.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Any, List

from isatools.model.comments import Comment, Commentable
from isatools.model.identifiable import Identifiable


class OntologySource(Commentable):
class OntologySource(Commentable, Identifiable):
"""An OntologySource describes the resource from which the value of an
OntologyAnnotation is derived from.

Expand All @@ -18,10 +19,10 @@ class OntologySource(Commentable):
"""

def __init__(
self, name: str, file: str = "", version: str = "", description: str = "", comments: List[Comment] = None
self, id_="", name: str = "", file: str = "", version: str = "", description: str = "", comments: List[Comment] = None
):
super().__init__(comments)

self.id = id_
self.__name = name
self.__file = file
self.__version = version
Expand Down Expand Up @@ -119,6 +120,7 @@ def __ne__(self, other):

def to_dict(self, ld=False):
ontology_source_ref = {
"@id": self.id,
"name": self.name,
"file": self.file,
"version": self.version,
Expand All @@ -128,6 +130,7 @@ def to_dict(self, ld=False):
return self.update_isa_object(ontology_source_ref, ld=ld)

def from_dict(self, ontology_source):
self.id = ontology_source.get("@id","")
self.name = ontology_source["name"] if "name" in ontology_source else ""
self.file = ontology_source["file"] if "file" in ontology_source else ""
self.version = ontology_source["version"] if "version" in ontology_source else ""
Expand Down
4 changes: 3 additions & 1 deletion isatools/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from isatools.model.assay import Assay
from isatools.model.comments import Commentable
from isatools.model.factor_value import StudyFactor
from isatools.model.identifiable import Identifiable
from isatools.model.loader_indexes import loader_states as indexes
from isatools.model.logger import log
from isatools.model.mixins import MetadataMixin, StudyAssayMixin
Expand All @@ -17,7 +18,7 @@
from isatools.model.source import Source


class Study(Commentable, StudyAssayMixin, MetadataMixin, object):
class Study(Commentable, Identifiable, StudyAssayMixin, MetadataMixin, object):
"""Study is the central unit, containing information on the subject under
study, its characteristics and any treatments applied.

Expand Down Expand Up @@ -396,6 +397,7 @@ def to_dict(self, ld=False):

def from_dict(self, study):
indexes.reset_process()
self.id = study.get("@id", "")
self.filename = study.get("filename", "")
self.identifier = study.get("identifier", "")
self.title = study.get("title", "")
Expand Down
Loading
Loading