Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: generalized get_raw_doc function #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion cutlass/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/Sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/SixteenSDnaPrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/SixteenSRawSeqSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/SixteenSTrimmedSeqSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/Study.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/Subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/Visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/WgsDnaPrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion cutlass/WgsRawSeqSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions cutlass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)