Exemplo n.º 1
0
 def setUp(self):
     self.design = InterventionStudyDesign()
     self.agent = StudyFactor(name=BASE_FACTORS[0]['name'],
                              factor_type=BASE_FACTORS[0]['type'])
     self.intensity = StudyFactor(name=BASE_FACTORS[1]['name'],
                                  factor_type=BASE_FACTORS[1]['type'])
     self.duration = StudyFactor(name=BASE_FACTORS[2]['name'],
                                 factor_type=BASE_FACTORS[2]['type'])
     self.first_treatment = Treatment(
         treatment_type=INTERVENTIONS['CHEMICAL'],
         factor_values=(FactorValue(factor_name=self.agent, value='crack'),
                        FactorValue(factor_name=self.intensity,
                                    value='low'),
                        FactorValue(factor_name=self.duration,
                                    value='medium')))
     self.second_treatment = Treatment(
         treatment_type=INTERVENTIONS['CHEMICAL'],
         factor_values=(FactorValue(factor_name=self.agent, value='crack'),
                        FactorValue(factor_name=self.intensity,
                                    value='high'),
                        FactorValue(factor_name=self.duration,
                                    value='medium')))
     self.test_sequence = TreatmentSequence(
         ranked_treatments=[(self.first_treatment,
                             1), (self.second_treatment, 2)])
     self.sample_plan = SampleAssayPlan(group_size=10,
                                        sample_plan={},
                                        assay_plan=None)
Exemplo n.º 2
0
    def setUp(self):
        self.plan = SampleAssayPlan()
        self.plan.group_size = 20
        self.plan.add_sample_type('liver')
        self.plan.add_sample_type('tissue')
        self.plan.add_sample_plan_record('liver', 3)
        self.plan.add_sample_plan_record('tissue', 5)

        self.top_mods = AssayTopologyModifiers()
        self.top_mods.technical_replicates = 2
        self.top_mods.injection_modes = {'LC', 'GC'}
        self.top_mods.acquisition_modes = {'positive', 'negative'}
        self.top_mods.chromatography_instruments = {'Agilent Q12324A'}
        self.top_mods.instruments = {'Agilent QTOF'}
        self.top_mods.array_designs = {'A-AFFY-27', 'A-AFFY-28'}

        self.assay_type = AssayType(measurement_type='genome sequencing',
                                    technology_type='DNA microarray')
Exemplo n.º 3
0
 def test_sequences_plan_property(self):
     other_test_sequence = TreatmentSequence(
         ranked_treatments=[(self.first_treatment,
                             2), (self.second_treatment, 1)])
     other_sample_plan = SampleAssayPlan(group_size=12)
     sequences_plan = {
         self.test_sequence: self.sample_plan,
         other_test_sequence: other_sample_plan
     }
     self.design.sequences_plan = sequences_plan
     self.assertEqual(self.design.sequences_plan, sequences_plan)
Exemplo n.º 4
0
    def test_serialize_default_sampleassayplan(self):
        expected = ordered(
            json.loads("""{
                "group_size": 0,
                "assay_types": [],
                "sample_plan": [],
                "sample_types": [],
                "sample_qc_plan": [],
                "assay_plan": []
            }"""))

        actual = ordered(
            json.loads(
                json.dumps(SampleAssayPlan(), cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)
Exemplo n.º 5
0
def create_descriptor():
    """Returns a ISA-Tab descriptor using a simple sample plan for
    illustration."""
    investigation = Investigation(identifier='I1')
    plan = SampleAssayPlan()
    plan.add_sample_type('liver')
    plan.add_sample_plan_record('liver', 5)
    plan.add_sample_type('blood')
    plan.add_sample_plan_record('blood', 3)
    plan.group_size = 2
    f1 = StudyFactor(name='AGENT',
                     factor_type=OntologyAnnotation(term='pertubation agent'))
    f2 = StudyFactor(name='INTENSITY',
                     factor_type=OntologyAnnotation(term='intensity'))
    f3 = StudyFactor(name='DURATION',
                     factor_type=OntologyAnnotation(term='time'))
    treatment_factory = TreatmentFactory(factors=[f1, f2, f3])
    treatment_factory.add_factor_value(f1, {'cocaine', 'crack', 'aether'})
    treatment_factory.add_factor_value(f2, {'low', 'medium', 'high'})
    treatment_factory.add_factor_value(f3, {'short', 'long'})
    ffactorial_design_treatments = treatment_factory\
        .compute_full_factorial_design()
    treatment_sequence = TreatmentSequence(
        ranked_treatments=ffactorial_design_treatments)
    # treatment_factory.add_factor_value('intensity', 1.05)
    study = IsaModelObjectFactory(plan, treatment_sequence)\
        .create_study_from_plan()
    study.filename = 's_study.txt'
    investigation.studies = [study]
    print(isatab.dumps(investigation))
Exemplo n.º 6
0
    def test_create_study_from_plan_with_qc(self):
        plan = SampleAssayPlan()
        plan.add_sample_type('liver')
        plan.add_sample_plan_record('liver', 5)
        plan.add_sample_type('blood')
        plan.add_sample_plan_record('blood', 3)
        plan.group_size = 2
        plan.add_sample_type('solvent')
        plan.add_sample_qc_plan_record('solvent', 8)

        treatment_factory = TreatmentFactory(
            factors=[self.f1, self.f2, self.f3])
        treatment_factory.add_factor_value(self.f1,
                                           {'cocaine', 'crack', 'aether'})
        treatment_factory.add_factor_value(self.f2, {'low', 'medium', 'high'})
        treatment_factory.add_factor_value(self.f3, {'short', 'long'})
        ffactorial_design_treatments = \
            treatment_factory.compute_full_factorial_design()
        treatment_sequence = TreatmentSequence(
            ranked_treatments={(x, i)
                               for i, x in enumerate(
                                   ffactorial_design_treatments)})
        # makes each study group ranked in sequence
        study = IsaModelObjectFactory(
            plan, treatment_sequence).create_study_from_plan()
        study.filename = 's_study.txt'
        # print(isatab.dumps(self.investigation))
        self.investigation.studies = [study]
        # 36 sources, 36 QC sources
        self.assertEqual(72, len(study.sources))
        self.assertEqual(
            36,
            len([
                x for x in study.sources
                if x.get_char('Material Type').value.term == 'solvent'
            ]))
        # 288 samples plus 36 QC samples
        self.assertEqual(324, len(study.samples))
Exemplo n.º 7
0
 def test_create_study_from_plan(self):
     plan = SampleAssayPlan()
     plan.add_sample_type('liver')
     plan.add_sample_plan_record('liver', 5)
     plan.add_sample_type('blood')
     plan.add_sample_plan_record('blood', 3)
     plan.group_size = 2
     treatment_factory = TreatmentFactory(
         factors=[self.f1, self.f2, self.f3])
     treatment_factory.add_factor_value(self.f1,
                                        {'cocaine', 'crack', 'aether'})
     treatment_factory.add_factor_value(self.f2, {'low', 'medium', 'high'})
     treatment_factory.add_factor_value(self.f3, {'short', 'long'})
     ffactorial_design_treatments = \
         treatment_factory.compute_full_factorial_design()
     treatment_sequence = TreatmentSequence(
         ranked_treatments={(x, i)
                            for i, x in enumerate(
                                ffactorial_design_treatments)})
     # makes each study group ranked in sequence
     study = IsaModelObjectFactory(
         plan, treatment_sequence).create_study_from_plan()
     study.filename = 's_study.txt'
     self.investigation.studies = [study]
     self.assertEqual(36, len(study.sources))
     self.assertEqual(288, len(study.samples))
Exemplo n.º 8
0
 def test_init_group_size(self):
     group_size = 100
     sample_assay_plan = SampleAssayPlan(group_size=group_size)
     self.assertEqual(sample_assay_plan.group_size, group_size)
Exemplo n.º 9
0
 def setUp(self):
     self.plan = SampleAssayPlan()
Exemplo n.º 10
0
class SampleAssayPlanTest(unittest.TestCase):
    def setUp(self):
        self.plan = SampleAssayPlan()

    def test_init_default(self):
        sample_plan = self.plan
        self.assertEqual(sample_plan.group_size, 0)
        self.assertEqual(sample_plan.sample_types, set())

    def test_init_group_size(self):
        group_size = 100
        sample_assay_plan = SampleAssayPlan(group_size=group_size)
        self.assertEqual(sample_assay_plan.group_size, group_size)

    def test_add_sample_type(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='liver')
        self.plan.add_sample_type(liver_sample_type)
        self.assertEqual(self.plan.sample_types, {liver_sample_type})

    def test_add_sample_type_str(self):
        liver_sample_type = 'liver'
        self.plan.add_sample_type(liver_sample_type)
        self.assertEqual(
            self.plan.sample_types, {
                Characteristic(
                    category=OntologyAnnotation(term='organism part'),
                    value=OntologyAnnotation(term=liver_sample_type))
            })

    def test_sample_types_property_from_set(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='liver')
        blood_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='blood')
        heart_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='heart')
        test_sample_types = {
            liver_sample_type, blood_sample_type, heart_sample_type
        }
        self.plan.sample_types = test_sample_types
        self.assertEqual(self.plan.sample_types, test_sample_types)

    def test_sample_types_property_from_list(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='liver')
        blood_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'), value='blood')
        brain_sample_type = 'brain'
        test_sample_types = [
            liver_sample_type, blood_sample_type, liver_sample_type,
            brain_sample_type
        ]
        self.plan.sample_types = test_sample_types
        self.assertEqual(
            self.plan.sample_types, {
                blood_sample_type, liver_sample_type,
                Characteristic(
                    category=OntologyAnnotation(term='organism part'),
                    value=OntologyAnnotation(term=brain_sample_type))
            })

    def test_add_assay_type(self):
        ngs = OntologyAnnotation(term='ngs')
        test_assay_type = AssayType(measurement_type=ngs)
        self.plan.add_assay_type(test_assay_type)
        self.assertEqual(self.plan.assay_types, {test_assay_type})

    def test_add_assay_type_str(self):
        ngs = 'ngs'
        self.plan.add_assay_type(ngs)
        assay_type = AssayType(measurement_type=ngs)
        self.assertEqual(self.plan.assay_types, {assay_type})

    def test_add_assay_type_err(self):
        not_an_assay = OntologyAnnotation(term='bao')
        self.assertRaises(TypeError, self.plan.add_assay_type, not_an_assay)

    def test_add_sample_plan_record(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'),
            value=OntologyAnnotation(term='liver'))
        self.plan.add_sample_type(liver_sample_type)
        self.plan.add_sample_plan_record(liver_sample_type, 5)
        self.assertEqual(self.plan.sample_plan, {liver_sample_type: 5})

    def test_add_sample_plan_record_err(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'),
            value=OntologyAnnotation(term='liver'))
        self.plan.add_sample_type(liver_sample_type)
        self.assertRaises(TypeError, self.plan.add_sample_plan_record,
                          liver_sample_type, 'five')

    def test_add_assay_plan_record(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'),
            value=OntologyAnnotation(term='liver'))
        self.plan.add_sample_type(liver_sample_type)
        self.plan.add_sample_plan_record(liver_sample_type, 5)
        ngs_assay_type = AssayType(measurement_type='ngs')
        self.plan.add_assay_type(ngs_assay_type)
        self.plan.add_assay_plan_record(liver_sample_type, ngs_assay_type)
        self.assertEqual(self.plan.assay_plan,
                         {(liver_sample_type, ngs_assay_type)})

    def test_add_assay_plan_record_err(self):
        liver_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'),
            value=OntologyAnnotation(term='liver'))
        self.plan.add_sample_type(liver_sample_type)
        self.plan.add_sample_plan_record(liver_sample_type, 5)
        ngs_assay_type = AssayType(measurement_type='ngs')
        self.plan.add_assay_type(ngs_assay_type)
        blood_sample_type = Characteristic(
            category=OntologyAnnotation(term='organism part'),
            value=OntologyAnnotation(term='blood'))
        self.assertRaises(ValueError, self.plan.add_assay_plan_record,
                          blood_sample_type, ngs_assay_type)
Exemplo n.º 11
0
class SerializeToJsonTests(unittest.TestCase):
    def setUp(self):
        self.plan = SampleAssayPlan()
        self.plan.group_size = 20
        self.plan.add_sample_type('liver')
        self.plan.add_sample_type('tissue')
        self.plan.add_sample_plan_record('liver', 3)
        self.plan.add_sample_plan_record('tissue', 5)

        self.top_mods = AssayTopologyModifiers()
        self.top_mods.technical_replicates = 2
        self.top_mods.injection_modes = {'LC', 'GC'}
        self.top_mods.acquisition_modes = {'positive', 'negative'}
        self.top_mods.chromatography_instruments = {'Agilent Q12324A'}
        self.top_mods.instruments = {'Agilent QTOF'}
        self.top_mods.array_designs = {'A-AFFY-27', 'A-AFFY-28'}

        self.assay_type = AssayType(measurement_type='genome sequencing',
                                    technology_type='DNA microarray')

    def test_serialize_assay_default_topology_modifiers(self):
        expected = ordered(
            json.loads("""{
                "technical_replicates": 1,
                "instruments": [],
                "distinct_libraries": 0,
                "injection_modes": [],
                "chromatography_instruments": [],
                "pulse_sequences": [],
                "array_designs": [],
                "acquisition_modes": []
            }"""))

        actual = ordered(
            json.loads(
                json.dumps(AssayTopologyModifiers(),
                           cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_assay_topology_modifiers(self):
        expected = ordered(
            json.loads("""{
                "distinct_libraries": 0,
                "instruments": ["Agilent QTOF"],
                "injection_modes": ["GC", "LC"],
                "acquisition_modes": ["negative", "positive"],
                "pulse_sequences": [],
                "array_designs": ["A-AFFY-27", "A-AFFY-28"],
                "chromatography_instruments": ["Agilent Q12324A"],
                "technical_replicates": 2
            }"""))

        actual = ordered(
            json.loads(json.dumps(self.top_mods, cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_default_assay_type(self):
        expected = ordered(
            json.loads("""{
                "measurement_type": "",
                "technology_type": "",
                "topology_modifiers": []
            }"""))

        actual = ordered(
            json.loads(json.dumps(AssayType(), cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_assay_type(self):
        expected = ordered(
            json.loads("""{
                "measurement_type": "genome sequencing",
                "technology_type": "DNA microarray",
                "topology_modifiers": []
            }"""))

        actual = ordered(
            json.loads(json.dumps(self.assay_type,
                                  cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_assay_type_with_top_mods(self):
        self.assay_type.topology_modifiers = self.top_mods

        expected = ordered(
            json.loads("""{
                "topology_modifiers": {
                    "acquisition_modes": ["negative", "positive"],
                    "pulse_sequences": [],
                    "chromatography_instruments": ["Agilent Q12324A"],
                    "injection_modes": ["GC", "LC"],
                    "instruments": ["Agilent QTOF"],
                    "technical_replicates": 2,
                    "distinct_libraries": 0,
                    "array_designs": ["A-AFFY-27", "A-AFFY-28"]
                },
                "measurement_type": "genome sequencing",
                "technology_type": "DNA microarray"
            }"""))

        actual = ordered(
            json.loads(json.dumps(self.assay_type,
                                  cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_default_sampleassayplan(self):
        expected = ordered(
            json.loads("""{
                "group_size": 0,
                "assay_types": [],
                "sample_plan": [],
                "sample_types": [],
                "sample_qc_plan": [],
                "assay_plan": []
            }"""))

        actual = ordered(
            json.loads(
                json.dumps(SampleAssayPlan(), cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_sampleplan(self):
        expected = ordered(
            json.loads("""{
                "group_size": 20,
                "assay_plan": [],
                "sample_plan": [
                    {
                        "sample_type": "liver",
                        "sampling_size": 3
                    },
                    {
                        "sample_type": "tissue",
                        "sampling_size": 5
                    }
                ],
                "sample_qc_plan": [],
                "assay_types": [],
                "sample_types": ["liver", "tissue"]
            }"""))

        actual = ordered(
            json.loads(json.dumps(self.plan, cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_sampleplan_with_qc(self):
        self.plan.add_sample_type('water')
        self.plan.add_sample_qc_plan_record('water', 8)

        expected = ordered(
            json.loads("""{
                        "group_size": 20,
                        "assay_plan": [],
                        "sample_plan": [
                            {
                                "sample_type": "liver",
                                "sampling_size": 3
                            },
                            {
                                "sample_type": "tissue",
                                "sampling_size": 5
                            }
                        ],
                        "sample_qc_plan": [
                            {
                                "sample_type": "water",
                                "injection_interval": 8
                            }
                        ],
                        "assay_types": [],
                        "sample_types": ["liver", "tissue", "water"]
                    }"""))

        actual = ordered(
            json.loads(json.dumps(self.plan, cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)

    def test_serialize_sampleassayplan(self):
        self.plan.add_sample_type('water')
        self.plan.add_sample_qc_plan_record('water', 8)

        self.assay_type.topology_modifiers = self.top_mods

        self.plan.add_assay_type(self.assay_type)
        self.plan.add_assay_plan_record('liver', self.assay_type)
        self.plan.add_assay_plan_record('tissue', self.assay_type)

        expected = ordered(
            json.loads("""{
                "sample_types": ["liver", "tissue", "water"],
                "group_size": 20,
                "sample_plan": [
                    {
                        "sampling_size": 3,
                        "sample_type": "liver"
                    },
                    {
                        "sampling_size": 5,
                        "sample_type": "tissue"
                    }
                ],
                "sample_qc_plan": [
                    {
                        "injection_interval": 8,
                        "sample_type": "water"
                    }
                ],
                "assay_types": [
                    {
                        "topology_modifiers": {
                            "distinct_libraries": 0,
                            "technical_replicates": 2,
                            "acquisition_modes": ["negative", "positive"],
                            "instruments": ["Agilent QTOF"],
                            "injection_modes": ["GC", "LC"],
                            "array_designs": ["A-AFFY-27", "A-AFFY-28"],
                            "pulse_sequences": [],
                            "chromatography_instruments": ["Agilent Q12324A"]
                        }, 
                        "technology_type": "DNA microarray", 
                        "measurement_type": "genome sequencing"
                    }],
                "assay_plan": [
                    {
                        "sample_type": "liver",
                        "assay_type": {
                            "topology_modifiers": {
                                "distinct_libraries": 0,
                                "technical_replicates": 2,
                                "acquisition_modes": ["negative", "positive"],
                                "instruments": ["Agilent QTOF"],
                                "injection_modes": ["GC", "LC"],
                                "array_designs": ["A-AFFY-27", "A-AFFY-28"],
                                "pulse_sequences": [], 
                                "chromatography_instruments": ["Agilent Q12324A"]
                            },
                            "technology_type": "DNA microarray",
                            "measurement_type": "genome sequencing"
                        }
                    },
                    {
                        "sample_type": "tissue",
                        "assay_type": {
                            "topology_modifiers": {
                                "distinct_libraries": 0, 
                                "technical_replicates": 2, 
                                "acquisition_modes": ["negative", "positive"], 
                                "instruments": ["Agilent QTOF"], 
                                "injection_modes": ["GC", "LC"], 
                                "array_designs": ["A-AFFY-27", "A-AFFY-28"], 
                                "pulse_sequences": [], 
                                "chromatography_instruments": ["Agilent Q12324A"]
                            }, 
                            "technology_type": "DNA microarray", 
                            "measurement_type": "genome sequencing"
                        }
                    }
                ]
            }"""))

        actual = ordered(
            json.loads(json.dumps(self.plan, cls=SampleAssayPlanEncoder)))
        self.assertTrue(expected == actual)