Example #1
0
    def setUp(self):
        create_users(user_defs=user_defs)

        MASTERPATH = os.path.join(BASEPATH, "master")
        study_path = os.path.join(BASEPATH, "master/studies/170509-microwell")
        self.ma = Master(MASTERPATH)
        study = Study(study_path).read()
        study_dic = {"170509-microwell": study}
        self.db = DatabaseDJ(self.ma)
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()
        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)

        ligand_batches = self.ma.read_ligand_batches()
        self.db.update_ligands_or_batches(ligand_batches)

        steps = self.ma.read_steps()
        self.db.update_steps(steps)
        self.db.update_studies(study_dic)

        self.c = Client()
        self.c.login(username='******', password=DEFAULT_USER_PASSWORD)
Example #2
0
def write_all_steps(master_path):
    ma = Master(master_path)
    for step in STEPS:
        ma.write_steps({step: read_steps(step)})
Example #3
0
def write_all_ligand_batches(master_path):
    ma = Master(master_path)
    for ligand_batches in LIGAND_BATCHES:
        ma.write_ligand_batches(
            {ligand_batches: read_ligand_batches(ligand_batches)})
Example #4
0
def write_all_ligands(master_path):
    ma = Master(master_path)
    ma.write_ligands({"complex": read_complex()})
    for ligand in LIGANDS:
        ma.write_ligands({ligand: read_ligands(ligand)})
Example #5
0
class ViewTestCaseOneCollectionLogedIn(TransactionTestCase):
    def setUp(self):
        create_users(user_defs=user_defs)

        MASTERPATH = os.path.join(BASEPATH, "master")
        study_path = os.path.join(BASEPATH, "master/studies/170509-microwell")
        self.ma = Master(MASTERPATH)
        study = Study(study_path).read()
        study_dic = {"170509-microwell": study}
        self.db = DatabaseDJ(self.ma)
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()
        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)

        ligand_batches = self.ma.read_ligand_batches()
        self.db.update_ligands_or_batches(ligand_batches)

        steps = self.ma.read_steps()
        self.db.update_steps(steps)
        self.db.update_studies(study_dic)

        self.c = Client()
        self.c.login(username='******', password=DEFAULT_USER_PASSWORD)

    def tearDown(self):
        create_users(user_defs=None, delete_all=True)

    def test_index_view_200(self):
        response = self.c.post('/flutype/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "Studies")
        self.assertContains(response, "tutorial")

    def test_antibody_view_200(self):
        response = self.c.post('/flutype/antibodies_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

        response = self.c.post('/flutype/antibodies_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

        response = self.c.post('/flutype/antibodies/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "AK_28665")

    def test_antibodybatches_view_200(self):
        response = self.c.post('/flutype/antibodybatches/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "AK025")

        response = self.c.post('/flutype/antibodybatches_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

        response = self.c.post('/flutype/antibodybatches_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

    def test_viruses_view_200(self):
        response = self.c.post('/flutype/viruses/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "A/Aichi/2/68")

        response = self.c.post('/flutype/viruses_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "A/Aichi/2/68")

        response = self.c.post('/flutype/viruses_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

    def test_virusbatches_view_200(self):
        response = self.c.post('/flutype/virusbatches/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "X31")

        response = self.c.post('/flutype/virusbatches_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "X31")

        response = self.c.post('/flutype/virusbatches_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "No entries in database")

    def test_peptides_view_200(self):
        response = self.c.post('/flutype/peptides/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "P001")

        response = self.c.post('/flutype/peptides_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "No entries in database")

        response = self.c.post('/flutype/peptides_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "P001")

    def test_peptidebatches_view_200(self):
        response = self.c.post('/flutype/peptidebatches/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "L002")

        response = self.c.post('/flutype/peptidebatches_mobile/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "No entries in database")

        response = self.c.post('/flutype/peptidebatches_fixed/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "L002")

    def test_processes_view_200(self):
        response = self.c.post('/flutype/processes/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "170509-00")

    def test_process_view_200(self):
        id = Process.objects.last().id
        response = self.c.post('/flutype/process/' + str(id) + "/", {})
        status = response.status_code

        self.assertEqual(status, 200, "view 200")

    def test_process_with_process_steps_view_200(self):
        id = Process.objects.last().id
        response = self.c.post('/flutype/process/' + str(id) + "/", {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")

    def test_users_view_200(self):
        response = self.c.post('/flutype/users/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
        self.assertContains(response, "*****@*****.**")

    def test_rawspotcollection_view_200(self):
        id = RawSpotCollection.objects.first().id
        response = self.c.get('/flutype/measurement/' + str(id) + '/', {})
        status = response.status_code
        self.assertEqual(status, 200, "view 200")
Example #6
0
class MasterTestCase(TransactionTestCase):
    def setUp(self):
        self.ma = Master(MASTERPATH)

    def test_master_init(self):
        #all studies
        self.assertEqual({'170929-tutorial'}, self.ma.study_sids)
        #steps
        self.assertEqual(set(self.ma.read_steps().keys()), set(self.ma.steps))
        self.assertEqual(set(self.ma.read_ligands().keys()),
                         set(self.ma.ligands))
        ################################################################################################################
        ligand_batches = {"bufferBatch", "complexBatch"}
        for ligand in self.ma.ligands:
            ligand_batches.add("{}Batch".format(ligand))
        self.assertEqual(set(self.ma.read_ligand_batches().keys()),
                         ligand_batches)
        self.assertEqual(set(self.ma.read_studies().keys()),
                         {'170929-tutorial'})

    def test_study_init(self):
        path_study = os.path.join(self.ma.path_study,
                                  next(iter(self.ma.study_sids)))
        st = Study(path_study)
        self.assertEqual(st.sid, "170929-tutorial")
        self.assertEqual(st.Master.study_sids, {'170929-tutorial'})
        self.assertEqual(st.raw_docs_fnames,
                         {'170929-tutorial.tar.gz', 'test_file_1.txt'})
        self.assertEqual(
            st.measurement_sids, {
                '170929-tutorial-elisa-1', '170929-tutorial-microwell-1',
                '170929-tutorial-microarray-1'
            })
        self.assertEqual(
            set(st.meta.keys()),
            {'comment', 'user', 'description', 'date', 'hidden', 'status'})
        self.assertEqual(
            set(st.read_measurements().keys()), {
                '170929-tutorial-elisa-1', '170929-tutorial-microwell-1',
                '170929-tutorial-microarray-1'
            })

    def test_measurement_init(self):
        path_study = os.path.join(self.ma.path_study,
                                  next(iter(self.ma.study_sids)))
        st = Study(path_study)
        path_measurement = os.path.join(st.path_measurements,
                                        "170929-tutorial-elisa-1")
        meas = Measurement(path_measurement)
        self.assertEqual(meas.sid, "170929-tutorial-elisa-1")
        self.assertEqual(meas.Study.sid, st.sid)
        self.assertEqual(
            set(meas.meta.keys()), {
                'measurement_type',
                'batch_sid',
                'manufacturer',
                'hidden',
                'comment',
                'functionalization',
            })
        self.assertEqual(next(iter(meas.read_results().keys())), "raw")
        self.assertEqual(
            set(meas.read().keys()),
            {"meta", "lig_mob_path", "lig_fix_path", "steps_path", "results"})

    def test_measurement_results_init(self):
        path_study = os.path.join(self.ma.path_study,
                                  next(iter(self.ma.study_sids)))
        st = Study(path_study)
        path_measurement = os.path.join(st.path_measurements,
                                        "170929-tutorial-elisa-1")
        meas = Measurement(path_measurement)
        path_measurement_results = os.path.join(meas.path_results,
                                                next(iter(meas.results_sids)))
        mea_result = MeasurementResult(path_measurement_results)
        self.assertEqual(mea_result.sid, "raw")
        self.assertEqual(set(mea_result.read().keys()),
                         {'intensities', 'meta'})
Example #7
0
 def setUp(self):
     self.ma = Master(MASTERPATH)
Example #8
0
 def setUp(self):
     create_users(user_defs=user_defs)
     self.ma = Master(MASTERPATH)
     self.db = DatabaseDJ(self.ma)
Example #9
0
class DatabaseDJTestCase(TransactionTestCase):

    def setUp(self):
        create_users(user_defs=user_defs)
        self.ma = Master(MASTERPATH)
        self.db = DatabaseDJ(self.ma)


    def test_update_ligands(self):
        Ligand_count = {"Antibody":4, "Complex":1, "Virus":6, "Peptide":66}
        #read ligands from master
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()
        #fill database with ligands
        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)
        #test count
        for ligand in Ligand_count:
            Ligand = apps.get_model("flutype", ligand)
            self.assertEqual(Ligand.objects.all().count(), Ligand_count[ligand])


    def test_update_batches(self):
        Ligand_batch_count = {"AntibodyBatch":12,"BufferBatch":3, "ComplexBatch":1, "VirusBatch":64, "PeptideBatch":234}

        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()
        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)
        ligand_batches = self.ma.read_ligand_batches()
        self.db.update_ligands_or_batches(ligand_batches)

        for ligand_batch in Ligand_batch_count:
            LigandBatch = apps.get_model("flutype", ligand_batch)
            self.assertEqual(LigandBatch.objects.all().count(), Ligand_batch_count[ligand_batch])

    def test_update_steps(self):

        steps = self.ma.read_steps()
        self.db.update_steps(steps)
        steps_count = {"Incubating":17,
                       "Blocking":2,
                       "Drying":2,
                       "IncubatingAnalyt":3,
                       "Quenching":2,
                       "Scanning":4,
                       "Spotting":6,
                       "Washing":7}
        for step in steps_count:
            Step = apps.get_model("flutype", step)
            self.assertEqual(Step.objects.all().count(), steps_count[step])


    def test_update_study(self):
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()

        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)

        ligand_batches = self.ma.read_ligand_batches()
        self.db.update_ligands_or_batches(ligand_batches)

        steps = self.ma.read_steps()
        self.db.update_steps(steps)

        studies = self.ma.read_studies()
        self.db.update_studies(studies)



        Study = apps.get_model("flutype", "Study")
        RawSpotCollection = apps.get_model("flutype", "RawSpotCollection")
        SpotCollection = apps.get_model("flutype", "SpotCollection")

        studies = Study.objects.all()
        raw_spot_collections = RawSpotCollection.objects.all()
        spot_collections = SpotCollection.objects.all()

        self.assertEqual(studies.count(), 1)
        self.assertEqual(raw_spot_collections.count(), 3)
        self.assertEqual(spot_collections.count(), 4)

    def test_read_ligand(self):
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()

        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)


        ligands1 = self.ma.ligands
        for ligand in ligands1:
            df = read_ligands(ligand)
            self.assertTrue(ligands[ligand].equals(df))
        self.assertTrue(complex["complex"].equals(read_complex()))

    def test_read_ligand_batches(self):
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()
        self.db.update_ligands_or_batches(ligands)
        self.db.update_ligands_or_batches(complex)


        ligand_batches = self.ma.read_ligand_batches()
        self.db.update_ligands_or_batches(ligand_batches)

        for ligand_batch in ligand_batches.keys():
            df = read_ligand_batches(ligand_batch)
            self.assertTrue(ligand_batches[ligand_batch]["sid"].equals(df["sid"]))
            self.assertTrue(ligand_batches[ligand_batch]["comment"].equals(df["comment"]))
            self.assertTrue(ligand_batches[ligand_batch]["buffer"].equals(df["buffer"]))
            self.assertTrue(ligand_batches[ligand_batch]["produced_by"].equals(df["produced_by"]))
            self.assertTrue(ligand_batches[ligand_batch]["ph"].equals(df["ph"]))
            self.assertTrue(ligand_batches[ligand_batch]["production_date"].equals(df["production_date"]))
            self.assertEqual(len(ligand_batches[ligand_batch]),len(df))
            self.assertEqual(ligand_batches[ligand_batch].keys().all(),df.keys().all())


            if ligand_batch =="bufferBatch":
                #self.assertTrue(ligand_batches[ligand_batch].equals(df))
                pass

            elif ligand_batch =="virusBatch":
                self.assertTrue(ligand_batches[ligand_batch]["active"].equals(df["active"]))
                self.assertTrue(ligand_batches[ligand_batch]["passage_history"].equals(df["passage_history"]))
                self.assertTrue(ligand_batches[ligand_batch]["ligand"].equals(df["ligand"]))
                self.assertTrue(ligand_batches[ligand_batch]["labeling"].equals(df["labeling"]))
                self.assertTrue(ligand_batches[ligand_batch]["purity"].equals(df["purity"]))
                con = ligand_batches[ligand_batch]["concentration"].astype(float)
                con2 = df["concentration"].astype(float)
                self.assertTrue(con.equals(con2))

            else:
                self.assertTrue(ligand_batches[ligand_batch]["ligand"].equals(df["ligand"]))
                self.assertTrue(ligand_batches[ligand_batch]["labeling"].equals(df["labeling"]))
                self.assertTrue(ligand_batches[ligand_batch]["purity"].equals(df["purity"]))

    def test_read_steps(self):
        steps = self.ma.read_steps()
        self.db.update_steps(steps)
        for step in steps.keys():
            df = read_steps(step)
            self.assertTrue(steps[step]["sid"].equals(df["sid"]))
            self.assertTrue(steps[step]["comment"].equals(df["comment"]))
            self.assertTrue(steps[step]["temperature"].equals(df["temperature"]))
            self.assertTrue(steps[step]["method"].equals(df["method"]))

            if "substance" in steps[step].keys():
                self.assertTrue(steps[step]["substance"].equals(df["substance"]))

    def test_duration(self):
        time_delta = "2:12:12:30"
        dt = get_duration_or_none(time_delta)
        dt2 = duration_to_string(dt)
        self.assertEqual(dt2,time_delta)
Example #10
0
    def update_db(self):
        ligands = self.ma.read_ligands()
        complex = self.ma.read_complex()

        self.update_ligands_or_batches(ligands)
        self.update_ligands_or_batches(complex)

        ligand_batches = self.ma.read_ligand_batches()
        self.update_ligands_or_batches(ligand_batches)

        steps = self.ma.read_steps()
        self.update_steps(steps)

        studies = self.ma.read_studies()
        self.update_studies(studies)





if __name__ == "__main__":
    MASTERPATH = os.path.join(BASEPATH, "master")

    ma = Master(MASTERPATH)
    DatabaseDJ(ma).update_db()