-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added metagenomics_batch_api.py and metagenomics_batch_item_api.py * Added MetagenomicsBatch.py and MetagenomicsBatchItem.py * Added schema.py files for Metagenomics support * Class name correction * Corrections in Schema and Entity files * Added schema tests * Minor correction * Schema tests pass * Added create test for Metagenomics Batch and Batch Items * - Removed writing to file for metagenomic batch test, --------- Co-authored-by: John Phan <[email protected]>
- Loading branch information
1 parent
df56ffa
commit 4ff1331
Showing
10 changed files
with
555 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Class that extracts common functionality for Metagenomics Batch entity""" | ||
|
||
from .seqdbapi import SeqDBApi | ||
|
||
class MetagenomicsBatchApi(SeqDBApi): | ||
|
||
def __init__(self, config_path: str = None, base_url: str = None) -> None: | ||
""" | ||
Parameters: | ||
config_path (str, optional): Path to a config file (default: None). | ||
base_url (str, optional): URL to the URL to perform the API requests against. If not | ||
provided then local deployment URL is used. Should end with a forward slash. | ||
""" | ||
super().__init__(config_path, base_url) | ||
self.base_url += "metagenomics-batch" | ||
|
||
def get_relationship_entity(self, entity_id, endpoint): | ||
entity_id = str(entity_id) if isinstance(entity_id, int) else entity_id | ||
new_request_url = self.base_url + '/'+ str(entity_id) + f'/relationships/{endpoint}' | ||
print(new_request_url) | ||
jsn_resp = self.get_req_dina(request_url = new_request_url) | ||
return jsn_resp if jsn_resp else '' | ||
|
||
def get_entity_with_param(self, entity_id,param): | ||
entity_id = str(entity_id) if isinstance(entity_id, int) else entity_id | ||
new_request_url = self.base_url + '/' + entity_id | ||
jsn_resp = self.get_req_dina(new_request_url, params = param) | ||
return jsn_resp if jsn_resp else '' | ||
|
||
def get_entity_by_param(self, param=None): | ||
print(self.base_url,param) | ||
jsn_resp = self.get_req_dina(self.base_url, params = param) | ||
return jsn_resp if jsn_resp else '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Class that extracts common functionality for Metagenomics Batch Item entity""" | ||
|
||
from .seqdbapi import SeqDBApi | ||
|
||
class MetagenomicsBatchItemApi(SeqDBApi): | ||
|
||
def __init__(self, config_path: str = None, base_url: str = None) -> None: | ||
""" | ||
Parameters: | ||
config_path (str, optional): Path to a config file (default: None). | ||
base_url (str, optional): URL to the URL to perform the API requests against. If not | ||
provided then local deployment URL is used. Should end with a forward slash. | ||
""" | ||
super().__init__(config_path, base_url) | ||
self.base_url += "metagenomics-batch-item" | ||
|
||
def get_relationship_entity(self, entity_id, endpoint): | ||
entity_id = str(entity_id) if isinstance(entity_id, int) else entity_id | ||
new_request_url = self.base_url + '/'+ str(entity_id) + f'/relationships/{endpoint}' | ||
print(new_request_url) | ||
jsn_resp = self.get_req_dina(request_url = new_request_url) | ||
return jsn_resp if jsn_resp else '' | ||
|
||
def get_entity_with_param(self, entity_id,param): | ||
entity_id = str(entity_id) if isinstance(entity_id, int) else entity_id | ||
new_request_url = self.base_url + '/' + entity_id | ||
jsn_resp = self.get_req_dina(new_request_url, params = param) | ||
return jsn_resp if jsn_resp else '' | ||
|
||
def get_entity_by_param(self, param=None): | ||
print(self.base_url,param) | ||
jsn_resp = self.get_req_dina(self.base_url, params = param) | ||
return jsn_resp if jsn_resp else '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
class MetagenomicsBatchDTO: | ||
def __init__(self, id=None, type=None, attributes=None, relationships=None): | ||
self.id = id | ||
self.type = type | ||
self.attributes = attributes | ||
self.relationships = relationships | ||
|
||
def get_id(self): | ||
return self.id | ||
|
||
def get_type(self): | ||
return self.type | ||
|
||
class MetagenomicsBatchDTOBuilder: | ||
def __init__(self): | ||
self._id = None | ||
self._type = 'metagenomics-batch' | ||
self._attributes = None | ||
self._relationships = None | ||
|
||
def set_id(self, id): | ||
self._id = id | ||
return self | ||
|
||
def set_type(self, type): | ||
self._type = type | ||
return self | ||
|
||
def set_attributes(self, attributes): | ||
self._attributes = attributes | ||
return self | ||
|
||
def set_relationships(self, relationships): | ||
self._relationships = relationships | ||
return self | ||
|
||
def build(self): | ||
return MetagenomicsBatchDTO(self._id, self._type, self._attributes, self._relationships) | ||
|
||
class MetagenomicsBatchAttributesDTO: | ||
def __init__(self, createdBy=None, createdOn=None, group=None, name=None): | ||
self.createdBy = createdBy | ||
self.createdOn = createdOn | ||
self.group = group | ||
self.name = name | ||
|
||
class MetagenomicsBatchAttributesDTOBuilder: | ||
def __init__(self): | ||
self._createdBy = 'undefined' | ||
self._createdOn = 'undefined' | ||
self._group = 'undefined' | ||
self._name = 'undefined' | ||
|
||
def set_createdBy(self, createdBy): | ||
self._createdBy = createdBy | ||
return self | ||
|
||
def set_createdOn(self, createdOn): | ||
self._createdOn = createdOn | ||
return self | ||
|
||
def set_group(self, group): | ||
self._group = group | ||
return self | ||
|
||
def set_name(self, name): | ||
self._name = name | ||
return self | ||
|
||
def build(self): | ||
return MetagenomicsBatchAttributesDTO( | ||
self._createdBy, | ||
self._createdOn, | ||
self._group, | ||
self._name | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class MetagenomicsBatchItemDTO: | ||
def __init__(self, id=None, type=None, attributes=None, relationships=None): | ||
self.id = id | ||
self.type = type | ||
self.attributes = attributes | ||
self.relationships = relationships | ||
|
||
def get_id(self): | ||
return self.id | ||
|
||
def get_type(self): | ||
return self.type | ||
|
||
class MetagenomicsBatchItemDTOBuilder: | ||
def __init__(self): | ||
self._id = None | ||
self._type = 'metagenomics-batch-item' | ||
self._attributes = None | ||
self._relationships = None | ||
|
||
def set_id(self, id): | ||
self._id = id | ||
return self | ||
|
||
def set_type(self, type): | ||
self._type = type | ||
return self | ||
|
||
def set_attributes(self, attributes): | ||
self._attributes = attributes | ||
return self | ||
|
||
def set_relationships(self, relationships): | ||
self._relationships = relationships | ||
return self | ||
|
||
def build(self): | ||
return MetagenomicsBatchItemDTO(self._id, self._type, self._attributes, self._relationships) | ||
|
||
class MetagenomicsBatchItemAttributesDTO: | ||
def __init__(self, createdBy=None, createdOn=None): | ||
self.createdBy = createdBy | ||
self.createdOn = createdOn | ||
|
||
class MetagenomicsBatchItemAttributesDTOBuilder: | ||
def __init__(self): | ||
self._createdBy = 'undefined' | ||
self._createdOn = 'undefined' | ||
|
||
def set_createdBy(self, createdBy): | ||
self._createdBy = createdBy | ||
return self | ||
|
||
def set_createdOn(self, createdOn): | ||
self._createdOn = createdOn | ||
return self | ||
|
||
def build(self): | ||
return MetagenomicsBatchItemAttributesDTO( | ||
self._createdBy, | ||
self._createdOn | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# This file holds schemas for serializing and deserializing MetagenomicsBatchItem entities | ||
# using the JSON API format. It utilizes the marshmallow_jsonapi library. | ||
from marshmallow_jsonapi import Schema, fields | ||
from marshmallow import post_load,pre_load,post_dump,ValidationError | ||
|
||
from dinapy.entities.MetagenomicsBatchItem import MetagenomicsBatchItemDTO | ||
from .customFields import SkipUndefinedField | ||
from .BaseSchema import * | ||
|
||
class MetagenomicsBatchSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'metagenomics-batch' | ||
|
||
class PcrBatchItemSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'pcr-batch-item' | ||
|
||
class MolecularAnalysisRunItemSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'molecular-analysis-run-item' | ||
|
||
class NgsIndexSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'ngs-index' | ||
|
||
class MetagenomicsBatchItemSchema(Schema): | ||
id = fields.Str(load_only=True) | ||
createdBy = SkipUndefinedField(fields.Str, attribute="attributes.createdBy") | ||
createdOn = SkipUndefinedField(fields.Str, load_only=True, attribute="attributes.createdOn") | ||
|
||
metagenomicsBatch = create_relationship("metagenomics-batch-item", "metagenomics-batch", "metagenomicsBatch") | ||
pcrBatchItem = create_relationship("metagenomics-batch-item", "pcr-batch-item", "pcrBatchItem") | ||
molecularAnalysisRunItem = create_relationship("metagenomics-batch-item", "molecular-analysis-run-item", "molecularAnalysisRunItem") | ||
indexI5 = create_relationship("metagenomics-batch-item", "ngs-idnex", "indexI5") | ||
indexI7 = create_relationship("metagenomics-batch-item", "ngs-idnex", "indexI7") | ||
|
||
@post_load | ||
def set_none_to_undefined(self, data, **kwargs): | ||
for attr in data.attributes: | ||
if data.attributes[attr] is None: | ||
data.attributes[attr] = 'undefined' | ||
return data | ||
|
||
@post_dump | ||
def remove_skipped_fields(self, data, many, **kwargs): | ||
# Remove fields with the special marker value | ||
return {key: value for key, value in data.items() if value is not SkipUndefinedField(fields.Field).SKIP_MARKER} | ||
|
||
@post_load | ||
def object_deserialization(self, data, **kwargs): | ||
if 'meta' in data: | ||
del data['meta'] | ||
return MetagenomicsBatchItemDTO(**data) | ||
|
||
meta = fields.DocumentMeta() | ||
|
||
class Meta: | ||
type_ = 'metagenomics-batch-item' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# This file holds schemas for serializing and deserializing MetagenomicsBatch entities | ||
# using the JSON API format. It utilizes the marshmallow_jsonapi library. | ||
from marshmallow_jsonapi import Schema, fields | ||
from marshmallow import post_load,pre_load,post_dump,ValidationError | ||
|
||
from dinapy.entities.MetagenomicsBatch import MetagenomicsBatchDTO | ||
from .customFields import SkipUndefinedField | ||
from .BaseSchema import * | ||
|
||
class ProtocolSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'protocol' | ||
|
||
class IndexSetSchema(BaseSchema): | ||
class Meta: | ||
type_ = 'index-set' | ||
|
||
class MetagenomicsBatchSchema(Schema): | ||
id = fields.Str(load_only=True) | ||
createdBy = SkipUndefinedField(fields.Str, load_only=True, attribute="attributes.createdBy") | ||
createdOn = SkipUndefinedField(fields.Str, load_only=True, attribute="attributes.createdOn") | ||
group = SkipUndefinedField(fields.Str, required=True, attribute="attributes.group") | ||
name = SkipUndefinedField(fields.Str, attribute="attributes.name") | ||
|
||
protocol = create_relationship("metagenomics-batch", "protocol") | ||
indexSet = create_relationship("metagenomics-batch", "index-set", "indexSet") | ||
|
||
@post_load | ||
def set_none_to_undefined(self, data, **kwargs): | ||
for attr in data.attributes: | ||
if data.attributes[attr] is None: | ||
data.attributes[attr] = 'undefined' | ||
return data | ||
|
||
@post_dump | ||
def remove_skipped_fields(self, data, many, **kwargs): | ||
# Remove fields with the special marker value | ||
return {key: value for key, value in data.items() if value is not SkipUndefinedField(fields.Field).SKIP_MARKER} | ||
|
||
@post_load | ||
def object_deserialization(self, data, **kwargs): | ||
if 'meta' in data: | ||
del data['meta'] | ||
return MetagenomicsBatchDTO(**data) | ||
|
||
meta = fields.DocumentMeta() | ||
|
||
class Meta: | ||
type_ = 'metagenomics-batch' |
Oops, something went wrong.