Skip to content

Commit

Permalink
renamed main function #356
Browse files Browse the repository at this point in the history
  • Loading branch information
Zigur committed May 11, 2020
1 parent 95f0d31 commit c8ba133
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions isatools/create/connectors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from isatools.model import OntologyAnnotation, OntologySource, FactorValue
from isatools.create.models import StudyDesign, NonTreatment, Treatment, StudyCell, StudyArm, SampleAndAssayPlan, \
SAMPLE, ORGANISM_PART
from isatools.create.models import SCREEN, RUN_IN, FOLLOW_UP, WASHOUT, BASE_FACTORS, INTERVENTIONS
from isatools.create.models import SCREEN, BASE_FACTORS, INTERVENTIONS
from collections import OrderedDict

AGENT = 'agent'
Expand Down Expand Up @@ -196,34 +196,35 @@ def _generate_sample_dict_from_config(sample_type_config):
)


def generate_isa_study_design_from_datascriptor_config(datascriptor_design_config):
def generate_study_design_from_config(study_design_config):
"""
Generates the StudyDesign object out of the Datascriptor representation of it.
:param datascriptor_design_config: dict - a dictionary describing a study design as produced by Datascriptor ()
Generates the StudyDesign object out of the synthetic JSON-like "config" representation of it.
:param study_design_config: dict - a JSON-like dictionary describing a study design as produced and consumed by
third party tools
:return: isatools.models.create.StudyDesign
"""
# create each StudyCell and each SampleAndAssayPlan while iterating over the studyArms
arms = []
for arm_dict in datascriptor_design_config['arms']:
for arm_dict in study_design_config['arms']:
arm_map = OrderedDict()
for epoch_ix, epoch_dict in enumerate(arm_dict['epochs']):
element_ids = epoch_dict.get('elements', [])
elements = [
_generate_element(element_dict) for element_dict in
filter(lambda el: el['id'] in element_ids, datascriptor_design_config['elements'])
filter(lambda el: el['id'] in element_ids, study_design_config['elements'])
]
cell_name = 'CELL_{}_{}'.format(arm_dict['name'], epoch_ix)
cell = StudyCell(name=cell_name, elements=elements)
sample_type_dicts = [
_generate_sample_dict_from_config(st_config) for st_config in filter(
lambda ev: ev['id'] in epoch_dict.get('events', []) and ev['action'] == EVENT_TYPE_SAMPLING,
datascriptor_design_config['events']
study_design_config['events']
)
]
assay_ord_dicts = [
assay_template_to_ordered_dict(at_dict['template']) for at_dict in filter(
lambda ev: ev['id'] in epoch_dict.get('events', []) and ev['action'] == EVENT_TYPE_ASSAY,
datascriptor_design_config['events']
study_design_config['events']
)
]
sa_plan_name = 'SA_PLAN_{}_{}'.format(arm_dict['name'], epoch_ix)
Expand All @@ -238,5 +239,5 @@ def generate_isa_study_design_from_datascriptor_config(datascriptor_design_confi
arm_map=arm_map
)
arms.append(arm)
return StudyDesign(name=datascriptor_design_config['type'], study_arms=arms)
return StudyDesign(name=study_design_config['type'], study_arms=arms)

4 changes: 2 additions & 2 deletions tests/test_create_connectors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from isatools.create.connectors import assay_template_to_ordered_dict, assay_ordered_dict_to_template, \
generate_isa_study_design_from_datascriptor_config
generate_study_design_from_config

import unittest
import os
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_generate_isa_study_design_from_datascriptor_model_simple(self):
ds_design_config['events'][-2]['template'] = self.met_prof_jsons[0]
# the second assay template is Metabolite Profiling - NMR
ds_design_config['events'][-1]['template'] = self.met_prof_jsons[2]
design = generate_isa_study_design_from_datascriptor_config(ds_design_config)
design = generate_study_design_from_config(ds_design_config)
self.assertIsInstance(design, StudyDesign)
self.assertEqual(len(design.study_arms), len(ds_design_config['arms']))
for arm in design.study_arms:
Expand Down

0 comments on commit c8ba133

Please sign in to comment.