コード例 #1
0
    def test_fuzzy_filter(self):

        pixelset = PixelSetParser(self.pixelset_path)
        pixelset.parse()
        pixels, na, fuzzy = pixelset.filter(fuzzy_filter=False)

        self.assertEqual(len(pixels), 1862)
        self.assertEqual(pixels.index[0], 'CAGL0F02695g')
        self.assertEqual(pixels.index[-1], 'CAGL0L01925g')
コード例 #2
0
    def test_na_filter(self):

        pixelset = PixelSetParser(self.pixelset_path)
        pixelset.parse()
        pixels, na, fuzzy = pixelset.filter(na_filter=False)

        self.assertEqual(len(pixels), 1911)
        self.assertEqual(pixels.index[0], 'CAGL0F02695g')
        self.assertEqual(pixels.index[-1], 'CAGL0M12749g')
コード例 #3
0
    def test_parse(self):

        pixelset = PixelSetParser(self.pixelset_path)
        pixelset.parse()

        self.assertIsNotNone(pixelset.pixels)
        self.assertEqual(len(pixelset.pixels), 1936)

        pixel = pixelset.pixels.loc['CAGL0F02695g', ]
        self.assertAlmostEqual(pixel.Value, 4.25954345565357)
        self.assertAlmostEqual(pixel.Quality_score, 5.0188163324757298e-5)
コード例 #4
0
    def test__to_pixels_with_existing_pixel(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )

        parser.parse()
        parser._set_pixel_set()
        self._load_cgd_entries()

        existing_db_pixel = self._create_pixel_from_set(parser.pixelset)

        parser._to_pixels()
        self.assertEqual(len(parser.db_pixels['new']), 1836)
        self.assertEqual(len(parser.db_pixels['update']), 1)

        # We should have updated existing pixel data
        identifier = existing_db_pixel.omics_unit.reference.identifier
        pixel = parser.pixels.ix[identifier]
        updated_db_pixel = parser.db_pixels['update'][0]
        self.assertEqual(updated_db_pixel.value, pixel.Value)
        self.assertEqual(updated_db_pixel.quality_score, pixel.Quality_score)
コード例 #5
0
    def test__to_pixels(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )

        # With no pixel file parsed, _to_pixels has no effect
        parser._to_pixels()
        self.assertEqual(parser.db_pixels, {
            'new': [],
            'update': [],
        })

        parser.parse()
        self._load_cgd_entries()
        parser._to_pixels()
        self.assertEqual(len(parser.db_pixels['new']), 1837)
        self.assertEqual(len(parser.db_pixels['update']), 0)

        db_pixel = parser.db_pixels['new'][0]
        pixel = parser.pixels.ix[db_pixel.omics_unit.reference.identifier]

        self.assertEqual(db_pixel.value, pixel.Value)
        self.assertEqual(db_pixel.quality_score, pixel.Quality_score)
コード例 #6
0
    def test_parse_with_force(self):

        pixelset = PixelSetParser(self.pixelset_path)
        self.assertIsNone(pixelset.pixels)

        pixelset.parse()
        self.assertIsNotNone(pixelset.pixels)

        old_pixels = pixelset.pixels
        pixelset.parse()
        self.assertEqual(id(pixelset.pixels), id(old_pixels))

        pixelset.parse(force=True)
        self.assertNotEqual(id(pixelset.pixels), id(old_pixels))
コード例 #7
0
    def test_save_with_same_reference_omics_units(self):

        # Create two OmicsUnits with the same identifier but for different
        # strains/types
        identifier = 'CAGL0B00990g'
        OmicsUnitFactory(reference=EntryFactory(identifier=identifier),
                         strain=StrainFactory(),
                         type=OmicsUnitTypeFactory())
        OmicsUnitFactory(reference=EntryFactory(identifier=identifier),
                         strain=self.strain,
                         type=self.omics_unit_type)

        parser = PixelSetParser(
            Path('apps/submission/fixtures/dataset-0002/data.txt'),
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        self._load_cgd_entries()

        self.assertEqual(Pixel.objects.count(), 0)
        parser.save()
        # Even if we've created two OmicsUnits with the same reference
        # identifier, only the pixel corresponding to the OmicsUnit with the
        # relevant strain & OmicsUnitType will be imported. Hence, we expect
        # to have created 7 pixels and not 8, see:
        # - https://github.com/Candihub/pixel/pull/292
        # - https://github.com/Candihub/pixel/pull/296
        self.assertEqual(Pixel.objects.count(), 7)
コード例 #8
0
    def test_save_with_existing_pixel(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        parser._set_pixel_set()
        self._load_cgd_entries()

        self._create_pixel_from_set(parser.pixelset)
        self.assertEqual(Pixel.objects.count(), 1)
        parser.save()
        self.assertEqual(Pixel.objects.count(), 1837)
コード例 #9
0
    def test__set_pixel_set(self):

        parser = PixelSetParser(self.pixelset_path)
        with self.assertRaises(PixelSetParserError):
            parser._set_pixel_set()

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
        )
        parser._set_pixel_set()
        pixelset = parser.pixelset
        self.assertIsNotNone(pixelset)
        self.assertEqual(
            # pixelset.pixels_file.name is a PosixPath
            pixelset.pixels_file.name.name,
            self.pixelset_path.name)
        self.assertEqual(pixelset.description, self.description)
        self.assertEqual(pixelset.analysis, self.analysis)
コード例 #10
0
    def test_save(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        self._load_cgd_entries()

        self.assertEqual(Pixel.objects.count(), 0)
        parser.save()
        self.assertEqual(Pixel.objects.count(), 1837)
コード例 #11
0
    def test_save_with_update(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        parser._set_pixel_set()
        self._load_cgd_entries()

        pixel = self._create_pixel_from_set(parser.pixelset)
        self.assertEqual(Pixel.objects.count(), 1)
        self.assertEqual(pixel.value, 4.2)
        self.assertEqual(pixel.quality_score, 0.8)

        parser.save(update=True)
        self.assertEqual(Pixel.objects.count(), 1837)

        pixel = Pixel.objects.get(pk=pixel.pk)
        self.assertEqual(pixel.value, 2.703695974165)
        self.assertEqual(pixel.quality_score, 0.00268822352590468)
コード例 #12
0
    def test_save_populates_cached_fields(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        self._load_cgd_entries()
        parser.save()

        self.assertEqual(parser.pixelset.cached_species,
                         [self.strain.species.name])
        self.assertEqual(parser.pixelset.cached_omics_areas, [])
        self.assertEqual(parser.pixelset.cached_omics_unit_types,
                         [self.omics_unit_type.name])
コード例 #13
0
    def test_filter(self):

        pixelset = PixelSetParser(self.pixelset_path)

        self.assertEqual(pixelset.filter(), tuple([None] * 3))

        pixelset.parse()
        pixels, na, fuzzy = pixelset.filter()

        self.assertEqual(len(pixels), 1837)
        self.assertEqual(pixels.index[0], 'CAGL0F02695g')
        self.assertEqual(pixels.index[-1], 'CAGL0L01925g')

        self.assertEqual(len(na), 74)
        self.assertEqual(na.index[0], 'CAGL0C02475g')
        self.assertEqual(na.index[-1], 'CAGL0M12749g')

        self.assertEqual(len(fuzzy), 25)
        self.assertEqual(fuzzy.index[0], 'CAGL0A02211g;CAGL0D02640g')
        self.assertEqual(fuzzy.index[-1], 'CAGL0G08173g;CAGL0D05082g')
コード例 #14
0
    def test_init(self):

        pixelset = PixelSetParser(self.pixelset_path)

        self.assertEqual(pixelset.pixelset_path, self.pixelset_path)
        self.assertIsNone(pixelset.pixels)
コード例 #15
0
    def test__get_omics_units(self):

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
        )
        with self.assertRaises(PixelSetParserSaveError):
            parser._get_omics_units(None)

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            strain=self.strain,
        )
        with self.assertRaises(PixelSetParserSaveError):
            parser._get_omics_units(None)

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
        )
        with self.assertRaises(PixelSetParserSaveError):
            parser._get_omics_units(None)

        parser = PixelSetParser(
            self.pixelset_path,
            description=self.description,
            analysis=self.analysis,
            omics_unit_type=self.omics_unit_type,
            strain=self.strain,
        )
        parser.parse()
        pixels, _, _ = parser.filter()

        # We need to load Entries first!
        self.assertEqual(OmicsUnit.objects.count(), 0)
        with self.assertRaises(PixelSetParserSaveError):
            parser._get_omics_units(pixels)
        self.assertEqual(OmicsUnit.objects.count(), 0)

        # So… load entries
        self._load_cgd_entries()

        # Then create omics units
        omics_units = parser._get_omics_units(pixels, verbose=True)
        self.assertEqual(omics_units.count(), 1837)
        self.assertEqual(OmicsUnit.objects.count(), 1837)