From c7ae2554d9fd6d294e9a6245485fbc820c501a10 Mon Sep 17 00:00:00 2001 From: schwager-hsph Date: Wed, 9 Dec 2015 14:02:16 -0500 Subject: [PATCH] feature: generalized load function --- cutlass/Project.py | 3 ++- cutlass/Sample.py | 3 ++- cutlass/SixteenSDnaPrep.py | 3 ++- cutlass/SixteenSRawSeqSet.py | 3 ++- cutlass/SixteenSTrimmedSeqSet.py | 3 ++- cutlass/Study.py | 3 ++- cutlass/Subject.py | 3 ++- cutlass/Visit.py | 3 ++- cutlass/WgsDnaPrep.py | 3 ++- cutlass/WgsRawSeqSet.py | 3 ++- cutlass/__init__.py | 20 ++++++++++++++++++++ 11 files changed, 40 insertions(+), 10 deletions(-) diff --git a/cutlass/Project.py b/cutlass/Project.py index 7605e70..1575b01 100644 --- a/cutlass/Project.py +++ b/cutlass/Project.py @@ -24,6 +24,7 @@ class Project(Base): namespace (str): The namespace this class will use in OSDF. """ namespace = "ihmp" + osdf_node_type = "project" def __init__(self): """ @@ -384,7 +385,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': Project.namespace, - 'node_type': 'project', + 'node_type': self.osdf_node_type, 'meta': { 'name': self._name, 'mixs': self._mixs, diff --git a/cutlass/Sample.py b/cutlass/Sample.py index 2b5a0c7..6b04da2 100644 --- a/cutlass/Sample.py +++ b/cutlass/Sample.py @@ -24,6 +24,7 @@ class Sample(Base): namespace (str): The namespace this class will use in OSDF. """ namespace = "ihmp" + osdf_node_type = "sample" def __init__(self): """ @@ -384,7 +385,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': Sample.namespace, - 'node_type': 'sample', + 'node_type': self.osdf_node_type, 'meta': { 'fma_body_site': self._fma_body_site, 'mixs': self._mixs, diff --git a/cutlass/SixteenSDnaPrep.py b/cutlass/SixteenSDnaPrep.py index 2d302ac..6f07040 100644 --- a/cutlass/SixteenSDnaPrep.py +++ b/cutlass/SixteenSDnaPrep.py @@ -24,6 +24,7 @@ class SixteenSDnaPrep(Base): namespace (str): The namespace this class will use in the OSDF instance """ namespace = "ihmp" + osdf_node_type = "16s_dna_prep" date_format = '%Y-%m-%d' @@ -440,7 +441,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': SixteenSDnaPrep.namespace, - 'node_type': '16s_dna_prep', + 'node_type': self.osdf_node_type, 'meta': { 'comment': self._comment, 'lib_layout': self._lib_layout, diff --git a/cutlass/SixteenSRawSeqSet.py b/cutlass/SixteenSRawSeqSet.py index ebda81b..8520806 100644 --- a/cutlass/SixteenSRawSeqSet.py +++ b/cutlass/SixteenSRawSeqSet.py @@ -26,6 +26,7 @@ class SixteenSRawSeqSet(Base): namespace (str): The namespace this class will use in the OSDF instance """ namespace = "ihmp" + osdf_node_type = "16s_raw_seq_set" aspera_server = "aspera.ihmpdcc.org" @@ -468,7 +469,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': SixteenSRawSeqSet.namespace, - 'node_type': '16s_raw_seq_set', + 'node_type': self.osdf_node_type, 'meta': { "checksums": self._checksums, "comment": self._comment, diff --git a/cutlass/SixteenSTrimmedSeqSet.py b/cutlass/SixteenSTrimmedSeqSet.py index b77e619..b4163ba 100644 --- a/cutlass/SixteenSTrimmedSeqSet.py +++ b/cutlass/SixteenSTrimmedSeqSet.py @@ -23,6 +23,7 @@ class SixteenSTrimmedSeqSet(Base): namespace (str): The namespace this class will use in the OSDF instance """ namespace = "ihmp" + osdf_node_type = "16s_trimmed_seq_set" def __init__(self): """ @@ -390,7 +391,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': SixteenSTrimmedSeqSet.namespace, - 'node_type': '16s_trimmed_seq_set', + 'node_type': self.osdf_node_type, 'meta': { "checksums": self._checksums, "comment": self._comment, diff --git a/cutlass/Study.py b/cutlass/Study.py index 3748626..117f1d6 100644 --- a/cutlass/Study.py +++ b/cutlass/Study.py @@ -22,6 +22,7 @@ class Study(Base): namespace (str): The namespace this class will use in OSDF. """ namespace = "ihmp" + osdf_node_type = "study" def __init__(self): """ @@ -268,7 +269,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': Study.namespace, - 'node_type': 'study', + 'node_type': self.osdf_node_type, 'meta': { 'name': self._name, 'description': self._description, diff --git a/cutlass/Subject.py b/cutlass/Subject.py index eed6839..8ab99b3 100644 --- a/cutlass/Subject.py +++ b/cutlass/Subject.py @@ -22,6 +22,7 @@ class Subject(Base): namespace (str): The namespace this class will use in the OSDF instance """ namespace = "ihmp" + osdf_node_type = "subject" valid_races = ( "african_american", "american_indian_or_alaska_native", "asian", "caucasian", "hispanic_or_latino", "native_hawaiian", @@ -215,7 +216,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': Subject.namespace, - 'node_type': 'subject', + 'node_type': self.osdf_node_type, 'meta': { 'gender': self._gender, 'rand_subject_id': self._rand_subject_id, diff --git a/cutlass/Visit.py b/cutlass/Visit.py index a9d0cba..325cd53 100644 --- a/cutlass/Visit.py +++ b/cutlass/Visit.py @@ -23,6 +23,7 @@ class Visit(Base): namespace (str): The namespace this class will use in OSDF. """ namespace = "ihmp" + osdf_node_type = "visit" date_format = '%Y-%m-%d' @@ -230,7 +231,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': Visit.namespace, - 'node_type': 'visit', + 'node_type': self.osdf_node_type, 'meta': { 'visit_number': self._visit_number, 'date': self._date, diff --git a/cutlass/WgsDnaPrep.py b/cutlass/WgsDnaPrep.py index ab322f4..a0dd660 100644 --- a/cutlass/WgsDnaPrep.py +++ b/cutlass/WgsDnaPrep.py @@ -24,6 +24,7 @@ class WgsDnaPrep(Base): namespace (str): The namespace this class will use in OSDF. """ namespace = "ihmp" + osdf_node_type = "wgs_dna_prep" def __init__(self): """ @@ -437,7 +438,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': WgsDnaPrep.namespace, - 'node_type': 'wgs_dna_prep', + 'node_type': self.osdf_node_type, 'meta': { 'comment': self._comment, 'lib_layout': self._lib_layout, diff --git a/cutlass/WgsRawSeqSet.py b/cutlass/WgsRawSeqSet.py index 49ceebe..e07f1a5 100644 --- a/cutlass/WgsRawSeqSet.py +++ b/cutlass/WgsRawSeqSet.py @@ -24,6 +24,7 @@ class WgsRawSeqSet(Base): namespace (str): The namespace this class will use in the OSDF instance """ namespace = "ihmp" + osdf_node_type = "wgs_raw_seq_set" aspera_server = "aspera.ihmpdcc.org" @@ -450,7 +451,7 @@ def _get_raw_doc(self): }, 'linkage': self._links, 'ns': WgsRawSeqSet.namespace, - 'node_type': 'wgs_raw_seq_set', + 'node_type': self.osdf_node_type, 'meta': { "checksums": self._checksums, "comment": self._comment, diff --git a/cutlass/__init__.py b/cutlass/__init__.py index 7cb66de..852b881 100644 --- a/cutlass/__init__.py +++ b/cutlass/__init__.py @@ -13,3 +13,23 @@ from .mixs import MIXS, MixsException from .mims import MIMS, MimsException from .mimarks import MIMARKS, MimarksException + +_node_type_idx = { + Project.osdf_node_type : Project.load_project, + Study.osdf_node_type : Study.load_study, + Visit.osdf_node_type : Visit.load_visit, + Sample.osdf_node_type : Sample.load_sample, + Subject.osdf_node_type : Subject.load_subject, + SixteenSDnaPrep.osdf_node_type : SixteenSDnaPrep.load_sixteenSDnaPrep, + WgsDnaPrep.osdf_node_type : WgsDnaPrep.load_wgsDnaPrep, + SixteenSRawSeqSet.osdf_node_type : SixteenSRawSeqSet.load_sixteenSRawSeqSet, + WgsRawSeqSet.osdf_node_type : WgsRawSeqSet.load_wgsRawSeqSet, + SixteenSTrimmedSeqSet.osdf_node_type : SixteenSTrimmedSeqSet.load_sixteenSTrimmedSeqSet, +} + +def load(node_id): + doc = iHMPSession.get_session().get_osdf().get_node(node_id) + load_func = _node_type_idx.get(doc['node_type'], None) + if load_func is None: + raise ValueError("Unknown node type: "+nodetype) + return load_func(doc)