Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from ch.systemsx.cisd.openbis.dss.etl.dto.api.v1 import ImageMetadata, SimpleImageDataConfig, Location
from ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto import Geometry
from ch.systemsx.cisd.imagereaders.bioformats import FlexHelper
from ch.systemsx.cisd.openbis.dss.etl.dto.api.v1.utils import DropboxUtils
"""
The code needed to import Evotec/PerkinElmer Opera Flex files with images.
"""
class OperaFlexImageDataSet(SimpleImageDataConfig):
"""
Returns meta-data for each image in the specified image container.
Parameter imagePath: path to the flex container with many images
Parameter imageIdentifiers: identifiers of all images contained in the image file.
"""
def extractImagesMetadata(self, imagePath, imageIdentifiers):
tokens = []
self.flexHelper = FlexHelper(incoming.getAbsolutePath() + '/' + imagePath)
for image in imageIdentifiers:
token = ImageMetadata()
token.well = extractWellCode(imagePath)
imageIndex = image.getTimeSeriesIndex()
token.tileNumber = self.flexHelper.getTileNumber(imageIndex)
token.channelCode = self.flexHelper.getChannelCode(imageIndex)
token.imageIdentifier = image
tokens.append(token)
return tokens
""" Extracts well code (e.g. C2) from the flex file path. """
def extractWellCode(self, imagePath):
basename = os.path.basename(imagePath)
fileName = os.path.splitext(basename)[0]
row = int(fileName[0:3])
col = int(fileName[3:6])
well = DropboxUtils.translateRowNumberIntoLetterCode(row) + str(col)
return well
"""
Calculates the width and height of the matrix of tiles (a.k.a. fields or sides) in the well
using the content of the Flex file. Passed parameters are not used.
Returns:
Geometry
"""
def getTileGeometry(self, imageTokens, maxTileNumber):
tileLocations = self._getTileLocationsMap().values()
return DropboxUtils.figureGeometry(tileLocations)
"""
For a given tile number and tiles geometry returns (x,y) which describes where the tile is
located on the well.
Uses flex file to find this out.
Parameter tileNumber: number of the tile
Parameter tileGeometry: the geometry of the well matrix
Returns:
Location
"""
def getTileCoordinates(self, tileNumber, tileGeometry):
return self._getTileLocationsMap().get(tileNumber)
def _getTileLocationsMap(self):
tileSpatialPoints = self.flexHelper.getTileCoordinates()
# a maximal distance between two points so that they are still considered to describe one point
precision = 1e-7
return DropboxUtils.tryFigureLocations(tileSpatialPoints, precision)
if incoming.isDirectory():
imageDataset = OperaFlexImageDataSet()
imageDataset.setRawImageDatasetType()
# we use BioFormat library to interpret images with .flex extension
imageDataset.setImageLibrary("BioFormats", "TiffDelegateReader")
imageDataset.setRecognizedImageExtensions(["flex"])
# Here one can add more specific configuration code.
# For simplisity we just assume that the plate sample "/MY-SPACE/MY-PLATE" already exists.
imageDataset.setPlate("MY-SPACE", "MY-PLATE")
# boilerplate code
tr = service.transaction()
dataSetRegistrationDetails = factory.createImageRegistrationDetails(imageDataset, incoming)
dataSet = tr.createNewDataSet(dataSetRegistrationDetails)
tr.moveFile(incoming.getAbsolutePath(), dataSet)