def test_read(self): version = 3 GridCornerUL = (206, 129) GridCornerUR = (3570, 107) GridCornerLR = (3597, 3470) GridCornerLL = (234, 3492) DatHeader = '[11..65533] 1g_A9AF:CLS=3684 RWS=3684 XIN=1 YIN=1 VE=30 2.0 08/23/07 11:23:24 50205880 M10 Tgondii_SNP1.1sq 570 25356.509766 3.500000 1.5600 6' Algorithm = 'Percentile' AlgorithmParameters = 'Percentile:75;CellMargin:2;OutlierHigh:1.500;OutlierLow:1.004;AlgVersion:6.0;FixedCellSize:TRUE;FullFeatureWidth:7;FullFeatureHeight:7;IgnoreOutliersInShiftRows:FALSE;FeatureExtraction:TRUE;PoolWidthExtenstion:2;PoolHeightExtension:2;UseSubgrids:FALSE;RandomizePixels:FALSE;ErrorBasis:StdvMean;StdMult:1.000000' NumberCells = 25 intensities = numpy.array([[234.0, 170.0, 22177.0, 164.0, 22104.0], [188.0, 188.0, 21871.0, 168.0, 21883.0], [188.0, 193.0, 21455.0, 198.0, 21300.0], [188.0, 182.0, 21438.0, 188.0, 20945.0], [193.0, 20370.0, 174.0, 20605.0, 168.0]]) stdevs = numpy.array([[24.0, 34.5, 2669.0, 19.7, 3661.2], [29.8, 29.8, 2795.9, 67.9, 2792.4], [29.8, 88.7, 2976.5, 62.0, 2914.5], [29.8, 76.2, 2759.5, 49.2, 2762.0], [38.8, 2611.8, 26.6, 2810.7, 24.1]]) npix = numpy.array([[25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25]]) nrows = 5 ncols = 5 nmask = 3 mask = numpy.array([[0., 0., 0., 0., 0.], [0., 0., 0., 1., 1.], [0., 0., 0., 0., 1.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]]) noutliers = 3 outliers = [[0., 0., 0., 0., 0.], [0., 1., 1., 0., 0.], [0., 0., 0., 0., 0.], [0., 1., 0., 0., 0.], [0., 0., 0., 0., 0.]] nmodified = 3 modified = [[0., 0., 0., 0., 0.], [0., 0., 0., 189., 220.], [0., 0., 0., 21775., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]] with open('./Affy/affy_v3_example.CEL') as handle: cel = CelFile.read(handle) self.assertEqual(version, cel.version) self.assertEqual(GridCornerUL, cel.GridCornerUL) self.assertEqual(GridCornerUR, cel.GridCornerUR) self.assertEqual(GridCornerLR, cel.GridCornerLR) self.assertEqual(GridCornerLL, cel.GridCornerLL) self.assertEqual(DatHeader, cel.DatHeader) self.assertEqual(Algorithm, cel.Algorithm) self.assertEqual(AlgorithmParameters, cel.AlgorithmParameters) self.assertEqual(NumberCells, cel.NumberCells) assert_array_equal(intensities, cel.intensities) assert_array_equal(stdevs, cel.stdevs) assert_array_equal(npix, cel.npix) self.assertEqual(nrows, cel.nrows) self.assertEqual(ncols, cel.ncols) self.assertEqual(nmask, cel.nmask) assert_array_equal(mask, cel.mask) self.assertEqual(noutliers, cel.noutliers) assert_array_equal(outliers, cel.outliers) self.assertEqual(nmodified, cel.nmodified) assert_array_equal(modified, cel.modified)
def testAffy4(self): with open(self.affy4, "rb") as f: record = CelFile.read(f) assert(record.intensities.shape == (5, 5)) assert(record.intensities.shape == record.stdevs.shape) assert(record.intensities.shape == record.npix.shape) assert(record.ncols == 5) assert(record.nrows == 5) numpy.testing.assert_allclose(record.intensities, [[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.], [10., 11., 12., 13., 14.], [15., 16., 17., 18., 19.], [20., 21., 22., 23., 24.]]) numpy.testing.assert_allclose(record.stdevs, [[0., -1., -2., -3., -4.], [-5., -6., -7., -8., -9.], [-10., -11., -12., -13., -14.], [-15., -16., -17., -18., -19.], [-20., -21., -22., -23., -24.]]) numpy.testing.assert_allclose(record.npix, [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]) assert(len(record.AlgorithmParameters) == 329) assert(len(record.GridCornerUL) == 7) assert(record.AlgorithmParameters[-3:] == '169')
def testAffy4(self): with open(self.affy4, "rb") as f: record = CelFile.read(f) assert (record.intensities.shape == (5, 5)) assert (record.intensities.shape == record.stdevs.shape) assert (record.intensities.shape == record.npix.shape) assert (record.ncols == 5) assert (record.nrows == 5) numpy.testing.assert_allclose( record.intensities, [[0., 1., 2., 3., 4.], [5., 6., 7., 8., 9.], [10., 11., 12., 13., 14.], [15., 16., 17., 18., 19.], [20., 21., 22., 23., 24.]]) numpy.testing.assert_allclose( record.stdevs, [[0., -1., -2., -3., -4.], [-5., -6., -7., -8., -9.], [-10., -11., -12., -13., -14.], [ -15., -16., -17., -18., -19. ], [-20., -21., -22., -23., -24.]]) numpy.testing.assert_allclose( record.npix, [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9]]) assert (len(record.AlgorithmParameters) == 329) assert (len(record.GridCornerUL) == 7) assert (record.AlgorithmParameters[-3:] == '169')
def testAffy4(self): with open(self.affy4, "rb") as f: record = CelFile.read(f) self.assertEqual(record.intensities.shape, (5, 5)) self.assertEqual(record.intensities.shape, record.stdevs.shape) self.assertEqual(record.intensities.shape, record.npix.shape) self.assertEqual(record.ncols, 5) self.assertEqual(record.nrows, 5) global message try: numpy.testing.assert_allclose( record.intensities, [ [0.0, 1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0, 9.0], [10.0, 11.0, 12.0, 13.0, 14.0], [15.0, 16.0, 17.0, 18.0, 19.0], [20.0, 21.0, 22.0, 23.0, 24.0], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) try: numpy.testing.assert_allclose( record.stdevs, [ [0.0, -1.0, -2.0, -3.0, -4.0], [-5.0, -6.0, -7.0, -8.0, -9.0], [-10.0, -11.0, -12.0, -13.0, -14.0], [-15.0, -16.0, -17.0, -18.0, -19.0], [-20.0, -21.0, -22.0, -23.0, -24.0], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) try: numpy.testing.assert_allclose( record.npix, [ [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) self.assertEqual(len(record.AlgorithmParameters), 329) self.assertEqual(len(record.GridCornerUL), 7) self.assertEqual(record.AlgorithmParameters[-3:], "169")
def testAffy3(self): with open(self.affy3, "r") as f: record = CelFile.read(f) assert(len(record.DatHeader) > 0) assert(record.intensities.shape == (5, 5)) assert(record.intensities.shape == record.stdevs.shape) assert(record.intensities.shape == record.npix.shape) assert(record.ncols == 5) assert(record.nrows == 5)
def testAffy3(self): with open(self.affy3, "r") as f: record = CelFile.read(f) assert (len(record.DatHeader) > 0) assert (record.intensities.shape == (5, 5)) assert (record.intensities.shape == record.stdevs.shape) assert (record.intensities.shape == record.npix.shape) assert (record.ncols == 5) assert (record.nrows == 5)
def testAffyWrongModeRead(self): try: with open(self.affy4, "r") as f: record = CelFile.read(f) except CelFile.ParserError: if int(sys.version[0]) >= 3: return # As expected in pyhthon 3 else: raise AssertionError("Expected CelFile.ParserError in python3") # the code just works in python 2 testRecordV4(record)
def testAffyStrict(self): record = CelFile.read("hello") assert record.DatHeader is None
def testAffy3(self): with open(self.affy3) as f: record = CelFile.read(f) self.assertGreater(len(record.DatHeader), 0) self.assertEqual(record.intensities.shape, (5, 5)) self.assertEqual(record.intensities.shape, record.stdevs.shape) self.assertEqual(record.intensities.shape, record.npix.shape) self.assertEqual(record.ncols, 5) self.assertEqual(record.nrows, 5) self.assertEqual(record.version, 3) self.assertEqual(record.GridCornerUL, (206, 129)) self.assertEqual(record.GridCornerUR, (3570, 107)) self.assertEqual(record.GridCornerLR, (3597, 3470)) self.assertEqual(record.GridCornerLL, (234, 3492)) self.assertEqual(record.DatHeader["filename"], "1g_A9AF") self.assertEqual(record.DatHeader["CLS"], 3684) self.assertEqual(record.DatHeader["RWS"], 3684) self.assertEqual(record.DatHeader["XIN"], 1) self.assertEqual(record.DatHeader["YIN"], 1) self.assertEqual(record.DatHeader["VE"], 30) self.assertAlmostEqual(record.DatHeader["laser-power"], 2.0) self.assertEqual(record.DatHeader["scan-date"], "08/23/07") self.assertEqual(record.DatHeader["scan-time"], "11:23:24") self.assertEqual(record.DatHeader["scanner-id"], "50205880") self.assertEqual(record.DatHeader["scanner-type"], "M10") self.assertEqual(record.DatHeader["array-type"], "Tgondii_SNP1.1sq") self.assertEqual(record.DatHeader["image-orientation"], 6) self.assertEqual(record.Algorithm, "Percentile") self.assertEqual(len(record.AlgorithmParameters), 16) self.assertEqual(record.AlgorithmParameters["Percentile"], 75) self.assertEqual(record.AlgorithmParameters["CellMargin"], 2) self.assertAlmostEqual(record.AlgorithmParameters["OutlierHigh"], 1.500) self.assertAlmostEqual(record.AlgorithmParameters["OutlierLow"], 1.004) self.assertEqual(record.AlgorithmParameters["AlgVersion"], "6.0") self.assertEqual(record.AlgorithmParameters["FixedCellSize"], True) # noqa: A502 self.assertEqual(record.AlgorithmParameters["FullFeatureWidth"], 7) self.assertEqual(record.AlgorithmParameters["FullFeatureHeight"], 7) self.assertEqual( record.AlgorithmParameters["IgnoreOutliersInShiftRows"], False) # noqa: A502 self.assertEqual(record.AlgorithmParameters["FeatureExtraction"], True) # noqa: A502 self.assertEqual(record.AlgorithmParameters["PoolWidthExtenstion"], 2) self.assertEqual(record.AlgorithmParameters["PoolHeightExtension"], 2) self.assertEqual(record.AlgorithmParameters["UseSubgrids"], False) # noqa: A502 self.assertEqual(record.AlgorithmParameters["RandomizePixels"], False) # noqa: A502 self.assertEqual(record.AlgorithmParameters["ErrorBasis"], "StdvMean") self.assertAlmostEqual(record.AlgorithmParameters["StdMult"], 1.0) self.assertEqual(record.NumberCells, 25) global message try: numpy.testing.assert_allclose( record.intensities, [ [234.0, 170.0, 22177.0, 164.0, 22104.0], [188.0, 188.0, 21871.0, 168.0, 21883.0], [188.0, 193.0, 21455.0, 198.0, 21300.0], [188.0, 182.0, 21438.0, 188.0, 20945.0], [193.0, 20370.0, 174.0, 20605.0, 168.0], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) try: numpy.testing.assert_allclose( record.stdevs, [ [24.0, 34.5, 2669.0, 19.7, 3661.2], [29.8, 29.8, 2795.9, 67.9, 2792.4], [29.8, 88.7, 2976.5, 62.0, 2914.5], [29.8, 76.2, 2759.5, 49.2, 2762.0], [38.8, 2611.8, 26.6, 2810.7, 24.1], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) try: numpy.testing.assert_array_equal( record.npix, [ [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], [25, 25, 25, 25, 25], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) self.assertEqual(record.nmask, 3) try: numpy.testing.assert_array_equal( record.mask, [ [False, False, False, False, False], [False, False, False, True, True], [False, False, False, False, True], [False, False, False, False, False], [False, False, False, False, False], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) self.assertEqual(record.noutliers, 3) try: numpy.testing.assert_array_equal( record.outliers, [ [False, False, False, False, False], [False, True, True, False, False], [False, False, False, False, False], [False, True, False, False, False], [False, False, False, False, False], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message) self.assertEqual(record.nmodified, 3) try: numpy.testing.assert_allclose( record.modified, [ [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 189.0, 220.0], [0.0, 0.0, 0.0, 21775.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0], ], ) message = None except AssertionError as err: message = str(err) if message is not None: self.fail(message)
def testAffyWrongModeReadV4(self): with self.assertRaises(ValueError): with open(self.affy4, "rt") as f: record = CelFile.read(f, version=4)
def testAffyBadHeader(self): with self.assertRaises(CelFile.ParserError): with open(self.affy4Bad, "rb") as f: record = CelFile.read(f)
def testAffy4(self): with open(self.affy4, "rb") as f: record = CelFile.read(f) testRecordV4(record)
def testAffyStrict(self): with self.assertRaises(IOError): record = CelFile.read("hello", strict=True)
maxInt = int(maxInt / 10) decrement = True if not os.path.exists('./json_temp'): os.makedirs('./json_temp') cel_filenames = ['159834720_B', '597785396_B'] cel_results = {} for cel_filename in cel_filenames: try: cel_results[cel_filename] = json.load( open('./json_temp/' + cel_filename + '.CEL.json')) except FileNotFoundError: with open('./input/' + cel_filename + '.CEL', 'rb') as handle: c = CelFile.read(handle) cel_results[cel_filename] = {} for i in range(c.nrows): cel_results[cel_filename][i] = {} for j in range(c.ncols): cel_results[cel_filename][i][j] = c.intensities[i][j] with open('./json_temp/' + cel_filename + '.CEL.json', 'w', encoding='utf-8') as results: results.write(json.dumps(cel_results[cel_filename])) try: cdf_results = json.load(open('./json_temp/HuEx-1_0-st-v2.text.cdf.json')) except FileNotFoundError: cdf_results = {} with open('./input/HuEx-1_0-st-v2.text.cdf', 'r') as file: