diff --git a/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-results.py b/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-results.py index ffd4fa1e9f61d895df601179988036a45e224ded..ff40a95a6563571c6c7935ee98de85ae0c2dd13a 100755 --- a/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-results.py +++ b/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-results.py @@ -3,9 +3,9 @@ This is the analysis result dropbox which accepts single files with xml extensio Each file should contain image analysis results on the well level. It will be registered as one dataset. The naming convention of the xml file is the following: - <raw-image-dataset-code>_<any-text>.xml + <any-text>_<raw-image-dataset-code>.xml e.g. - 20110809142909177-826_LC80463-RS101202.xml + LC80463-RS101202_20110809142909177-826.xml The dataset with the code specified in the file name will become a parent of the new dataset. """ import utils @@ -43,7 +43,10 @@ if fileExt == "xml": transaction = service.transaction(incoming, factory) - parentDatasetCode = utils.extractFileBasename(incoming.getName()).split('_')[0] + tokens = utils.extractFileBasename(incoming.getName()).split('_') + if (len(tokens) < 2): + raise ValidationException("Incoming directory name "+incoming.getName()+" does not adhere to the naming convention <any-text>_<raw-image-dataset-code>.xml") + parentDatasetCode = tokens[-1] (plate, experiment) = registration.findConnectedPlate(transaction, parentDatasetCode) plateCode = plate.getCode() diff --git a/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-segmentation.py b/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-segmentation.py new file mode 100755 index 0000000000000000000000000000000000000000..141385de8acbc445e6bfea67e4039d1e1bb92506 --- /dev/null +++ b/sanofi/dist/etc/sanofi-dropbox/dropbox-analysis-segmentation.py @@ -0,0 +1,85 @@ +""" +This is the dropbox which accepts directories containing segmentation images and analysis results. + +- if the incoming item is a file, then it is expected to contain analysis results and have xml extension. +The naming convention of the file is the following: + <any-text>_<raw-image-dataset-code>.xml +e.g. + myAnalysis_20110809142909177-826.xml + +- if the incoming item is a directory, then it's expected to contain an xml file with analysis results +and a directory (with 'ROITiff' suffix) with image segmentation results. +Two datasets will be registered. +The naming convention of the incoming directory is the following: + <any-text>_<raw-image-dataset-code> +e.g. + myOverlaysAndAnalysis_20110809142909177-826 + +The dataset with the code specified in the file or directory name will become a parent of the new datasets. +The new datasets are supposed to contain segmentation and analysis results of the parent dataset. +""" + +import utils +import config +import notifications +import registration + +from ch.systemsx.cisd.openbis.generic.shared.basic.dto.api import ValidationException + +reload(utils) +reload(config) +# Can be switched on manually only after the module's code has been changed on the fly: +#reload(notifications) +#reload(registration) + +def createEmailUtils(): + global experiment + global plateCode + + return notifications.EmailUtils(state, incoming, experiment, plateCode) + +def commit_transaction(service, transaction): + createEmailUtils().sendSuccessConfirmation() + +def rollback_service(service, ex): + createEmailUtils().sendRollbackError(ex) + +def findConnectedPlate(incoming): + transaction = service.transaction(incoming, factory) + + tokens = utils.extractFileBasename(incoming.getName()).split('_') + if (len(tokens) < 2): + raise ValidationException("Incoming directory name "+incoming.getName()+" does not adhere to the naming convention <any-text>_<raw-image-dataset-code>") + parentDatasetCode = tokens[-1] + (plate, experiment) = registration.findConnectedPlate(transaction, parentDatasetCode) + return (transaction, parentDatasetCode, plate, experiment) + +# --------------------- + +global experiment +global plateCode + +experiment = None +plateCode = None + +if incoming.isDirectory(): + transaction, parentDatasetCode, plate, experiment = findConnectedPlate(incoming) + plateCode = plate.getCode() + + # transform and move analysis file + analysisFile = utils.findFileByExt(incoming, "xml") + if analysisFile is not None: + analysisProcedureCode = registration.registerAnalysisData(analysisFile, plate, parentDatasetCode, transaction, factory) + + # check for overlays folder + overlaysDir = utils.findDir(incoming, config.OVERLAYS_DIR_PATTERN) + if overlaysDir is not None: + registration.registerSegmentationImages(overlaysDir, plate, parentDatasetCode, analysisProcedureCode, transaction, factory) +else: + fileExt = utils.getFileExt(incoming.getName()) + if fileExt == "xml": + transaction, parentDatasetCode, plate, experiment = findConnectedPlate(incoming) + plateCode = plate.getCode() + + registration.registerAnalysisData(incoming, plate, parentDatasetCode, transaction, factory) + diff --git a/sanofi/resource/examples/datasets/datasets.zip b/sanofi/resource/examples/datasets/datasets.zip index 1cce14ce1381a8e4ef0cf661424df3b92e5578af..077080283bcae7fefeb5f7a2e060744526ff329e 100644 Binary files a/sanofi/resource/examples/datasets/datasets.zip and b/sanofi/resource/examples/datasets/datasets.zip differ