예제 #1
0
def get_plate_image_url( qlbplate_id ):
    # still using qlbplate is bad but hard to unwind without complete rename of all folders...
    plate = Session.query(QLBPlate).get(qlbplate_id)
    local = plate.plate.box2.fileroot in config['qlb.local_fileroots']

    if local:
        image_url = config['qlb.image_url']
    else:
        image_url = config['qlb.%s_image_url' % plate.plate.box2.fileroot]

    image_source = QLBImageSource( image_url, isLocal = False )
    plate_image_url = image_source.get_path(  str( plate.id ) )

    return plate_image_url
예제 #2
0
    def command(self):
        from qtools.lib.mplot import plot_cluster_2d, cleanup as plt_cleanup
        app = self.load_wsgi_app()

        image_root = app.config['qlb.image_store']
        image_source = QLBImageSource(image_root)

        # enforce config.ini
        if len(self.args) < 2:
            raise ValueError, self.__class_.usage

        analysis_group_id = int(self.args[0])
        if len(self.args) == 3:
            reprocess_config = Session.query(ReprocessConfig).filter_by(code=self.args[1]).one()
            reprocess_config_id = reprocess_config.id
        else:
            reprocess_config = None
            reprocess_config_id = None

        if reprocess_config:
            data_root = app.config['qlb.reprocess_root']
            storage = QLPReprocessedFileSource(data_root, reprocess_config)
        else:
            storage = QLStorageSource(app.config)

        analysis_group = Session.query(AnalysisGroup).get(analysis_group_id)
        if not analysis_group:
            raise ValueError, "No analysis group for id %s" % analysis_group_id

        plates = analysis_group.plates
        for plate in plates:
            # TODO: UGH THIS CODE INVARIANT SUCKS (should merge QLReprocessedFile/QLStorageSources)
            if reprocess_config:
                plate_path = storage.full_path(analysis_group, plate)
            else:
                plate_path = storage.plate_path(plate)
            print "Reading %s" % plate_path
            qlplate = get_plate(plate_path)
            if not qlplate:
                print "Could not read plate: %s" % plate.name
                continue
            print "Generating thumbnails for %s" % plate.name
            for name, qlwell in sorted(qlplate.analyzed_wells.items()):
                # TODO abstract into utility image generation function (thumbnail.py?)

                threshold_fallback = qlwell.clustering_method == QLWell.CLUSTERING_TYPE_THRESHOLD
                fig = plot_cluster_2d(qlwell.peaks,
                                      width=60,
                                      height=60,
                                      thresholds=[qlwell.channels[0].statistics.threshold,
                                                  qlwell.channels[1].statistics.threshold],
                                      boundaries=[0,0,12000,24000],
                                      show_axes=False,
                                      antialiased=True,
                                      unclassified_alpha=0.5,
                                      use_manual_clusters=not well_channel_automatic_classification(qlwell),
                                      highlight_thresholds=threshold_fallback)
                image_path = image_source.get_path('%s/%s_2d.png' % (plate.qlbplate.id, name))
                print image_path
                fig.savefig(image_path, format='png', dpi=72)
                plt_cleanup(fig)